Is there a way to find the object files from which the current executable is generated in Linux (RHEL to be specific). I understand that one can use "nm" to find the exported symbols, "ldd" to find dependent shared object.
But I could not find command to find out the name of object (.o) files of which executable is composed of. Is it possible?
Definition. An object file is a file that contains an object code that has relocatable format machine code which is not directly executable. An executable file is a file that can be directly executed by the computer and is capable of performing the indicated tasks according to the encoded instructions.
By running the linker, gcc creates an executable file from the object files. The resulting executable file can now be run: $ ./hello Hello, world! It produces the same output as the version of the program using a single source file in the previous section.
An object file in Linux is a computer-generated file that contains the object code. Generally, object code is not directly executed and must be called using a command in order to execute.
An executable file, also called an executable or a binary, is the ready-to-run (i.e., executable) form of a program. A program is a sequence of instructions understandable by a computer's CPU (central processing unit) that indicates which operations the computer should perform on a set of data.
The original names of the object files are not stored in the DWARF debugging information.
Each object file has a DW_TAG_compile_unit
entry in the .debug_info
section. This entry contains a reference to the "primary source file
from which the compilation unit was derived", but not the name of the object file. The DWARF standard contains a list of the attributes that can be stored for each compilation unit (section 3.1.1, page number 44, pdf page 58).
You can view the information that is stored with the following command:
$ readelf --debug-dump=info --dwarf-depth=1 hw
Output:
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With