Linux中可执行文件中的对象文件

spk*_*ira 8 linux executable object-files

有没有办法找到在Linux中生成当前可执行文件的目标文件(RHEL是特定的).据我所知,可以使用"nm"查找导出的符号,"ldd"查找依赖的共享对象.

但是我找不到命令来查找由哪个可执行文件组成的对象(.o)文件的名称.可能吗?

Jas*_*son 6

如果它已经编译与调试信息是.使用gdb(man gdb)查找信息.

如果它没有编译没有调试信息.你运气不好.


Mik*_*ski 5

对象文件的原始名称未存储在DWARF调试信息中。

每个目标文件DW_TAG_compile_unit在该.debug_info部分都有一个条目。该条目包含对“派生编译单元的原始源文件”的引用,但不包含目标文件的名称。DWARF标准包含可为每个编译单元存储的属性列表(第3.1.1节,第44页,pdf,第58页)。

您可以使用以下命令查看存储的信息:

$ readelf --debug-dump=info --dwarf-depth=1 hw
Run Code Online (Sandbox Code Playgroud)

输出:

Contents of the .debug_info section:
<some compilation units removed>       
  Compilation Unit @ offset 0x133:
   Length:        0x8b (32-bit)
   Version:       4
   Abbrev Offset: 0x64
   Pointer Size:  4
 <0><13e>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <13f>   DW_AT_producer    : (indirect string, offset: 0x131): GNU C11 5.3.0 -mtune=generic -march=pentiumpro -g
    <143>   DW_AT_language    : 12      (ANSI C99)
    <144>   DW_AT_name        : (indirect string, offset: 0x163): hw.c
    <148>   DW_AT_comp_dir    : (indirect string, offset: 0x168): /home/mikel/src/hw
    <14c>   DW_AT_low_pc      : 0x80483db
    <150>   DW_AT_high_pc     : 0x2e
    <154>   DW_AT_stmt_list   : 0xea
 <1><158>: ...
<some compilation units removed>
Run Code Online (Sandbox Code Playgroud)