gcc elf文件中的符号名称被修剪为25个字符

pgccezyw  于 2022-11-12  发布在  其他
关注(0)|答案(2)|浏览(187)

我正在Linux上用gcc编译一个简单的c文件,并使用readelf查找符号的信息。函数名(可能还有其他符号-我没有检查)被修剪为25个字符。
有没有办法告诉编译器/链接器保留更长的符号?
版本:
1.编译器:GCC(GCC)4.8.5 20150623(红帽4.8.5-44)

<prompt>$ cat test_long_fnames_in_elf.c 
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>

void verly_long_function_xjsakdghajkshdlasjkldashjkldhasjklfdsjkhfsdjkhfsdjklhdsjkl_v1(uint32_t val)
{
        int i = 0;
    for (i = 0 ; i < val; i++)
    {
        printf("%d\n", i);
    }
}

void verly_long_function_xjsakdghajkshdlasjkldashjkldhasjklfdsjkhfsdjkhfsdjklhdsjkl_v2(uint32_t val)
{

        int i = 0;  
        for (i = 0 ; i < val; i++)
    {
        printf("This is i = %d\n", i);
    }
}

int main()
{
    verly_long_function_xjsakdghajkshdlasjkldashjkldhasjklfdsjkhfsdjkhfsdjklhdsjkl_v1(5);
    verly_long_function_xjsakdghajkshdlasjkldashjkldhasjklfdsjkhfsdjkhfsdjklhdsjkl_v2(5);
}

<prompt>$ gcc test_long_fnames_in_elf.c -g -o test_long_fnames_in_elf.elf                                                                                                                                        <prompt>$ readelf -a te.elf | grep long

<prompt>$ readelf -a test_long_fnames_in_elf.elf | grep long
    41: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS test_long_fnames_in_elf.c
    52: 000000000040052d    61 FUNC    GLOBAL DEFAULT   13 verly_long_function_xjsak            <--  Function symbol is trimmed
    62: 000000000040056a    61 FUNC    GLOBAL DEFAULT   13 verly_long_function_xjsak            <--  Function symbol is trimmed

<prompt>$
piwo6bdm

piwo6bdm1#

有没有办法告诉编译器/链接器保留更长的符号?
编译器 * 保留了 * 较长的符号,但readelf不显示它们。
下面是我的系统上的输出,使用binutils-2.39中的readelf

readelf -a a.out | grep long
    18: 0000000000001139    68 FUNC    GLOBAL DEFAULT   15 verly_long_funct[...]
    29: 000000000000117d    68 FUNC    GLOBAL DEFAULT   15 verly_long_funct[...]

比较对象:

readelf -Ws a.out | grep long
    18: 0000000000001139    68 FUNC    GLOBAL DEFAULT   15 verly_long_function_xjsakdghajkshdlasjkldashjkldhasjklfdsjkhfsdjkhfsdjklhdsjkl_v1
    29: 000000000000117d    68 FUNC    GLOBAL DEFAULT   15 verly_long_function_xjsakdghajkshdlasjkldashjkldhasjklfdsjkhfsdjkhfsdjklhdsjkl_v2
fhity93d

fhity93d2#

使用objdump。谢谢Craig Estey

<prompt>$ objdump -t test_long_fnames_in_elf.elf | grep long
    test_long_fnames_in_elf.elf:     file format elf64-x86-64
    0000000000000000 l    df *ABS*  0000000000000000              test_long_fnames_in_elf.c
    000000000040052d g     F .text  000000000000003d              verly_long_function_xjsakdghajkshdlasjkldashjkldhasjklfdsjkhfsdjkhfsdjklhdsjkl_v1
    000000000040056a g     F .text  000000000000003d              verly_long_function_xjsakdghajkshdlasjkldashjkldhasjklfdsjkhfsdjkhfsdjklhdsjkl_v2
    <prompt>$

相关问题