【问题标题】:.dbug_loc is missing from binary二进制文件中缺少 .dbug_loc
【发布时间】:2019-10-30 11:22:41
【问题描述】:

我正在检查 ELF 二进制文件以查找下面提到的代码。 我在 Virtual Box 的 Ubuntu x86_64 系统上的 gcc 7.4.0 上将其编译为:

gcc -g scratch1.c -o scratch1.out

#include <stdio.h>
void do_stuff(int my_arg){
    int my_local = my_arg + 2;
    int i;
    for (i = 0; i < my_local; ++i) printf("i = %d\n", i);
}

int main(){
    do_stuff(2);
    return 0;
}

但是,当我尝试引用 .debug_loc 部分时,它是空的。

objdump --dwarf=loc scratch1.out

scratch1.out:     file format elf64-x86-64

虽然,我确实看到了一些其他的 debug_ 部分

[26] .debug_aranges    PROGBITS         0000000000000000  0000103b
       0000000000000030  0000000000000000           0     0     1
[27] .debug_info       PROGBITS         0000000000000000  0000106b
       000000000000035f  0000000000000000           0     0     1
[28] .debug_abbrev     PROGBITS         0000000000000000  000013ca
       0000000000000125  0000000000000000           0     0     1
[29] .debug_line       PROGBITS         0000000000000000  000014ef
       00000000000000e6  0000000000000000           0     0     1
[30] .debug_str        PROGBITS         0000000000000000  000015d5
       00000000000002b5  0000000000000001  MS       0     0     1

需要您的帮助,为什么缺少此部分。

【问题讨论】:

    标签: gcc x86-64 elf abi dwarf


    【解决方案1】:

    需要您的帮助,为什么缺少此部分。

    .debug_loc 部分包含 DW_AT_location 列表,通常为优化代码发出。

    由于您编译没有优化,编译器没有发出此部分。尝试构建:

    gcc -g -O3 scratch1.c -o scratch1.out
    

    这是我在 gcc 8.3.0 中看到的:

    $ gcc -g scratch.c && readelf -WS a.out | grep debug_loc
      # no output
    
    $ gcc -g scratch.c -O3 && readelf -WS a.out | grep debug_loc
      [32] .debug_loc        PROGBITS        0000000000000000 0039db 000230 00      0   0  1
    

    【讨论】:

    • 谢谢,不知道 - 我什至在 O1 级也能得到它。
    猜你喜欢
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多