foreword
-
musl is a lightweight standard C library built on top of system calls. It can be considered as a [user mode] C library, which belongs to the same category as glibc or uClibc.
-
The musl-based gcc toolchain includes a cross-compilation toolchain, which can be used to compile Linux or other operating systems. For example, the current Lite-OS and RT-Smart use musl gcc as the compilation toolchain, and use musl libc as the user mode application. C library.
-
musl is based on MIT authorization, open source, lightweight, and free. It is estimated that more and more operating systems have begun to adopt musl as the standard C library
-
Recently, I have been studying the ldso of musl libc, which is the dynamic loading function. The dynamic loading function of musl is integrated in musl libc.so.
elf format file
-
musl itself integrates the dynamic loading function ldso, after a preliminary look at the code, it is found that it supports dynamic compiled application loading in elf format.
-
For applications compiled using the musl gcc toolchain (cross-compilation toolchain), you can
readelf -l xxx.elf
check whether there is dynamic link information in the elf file. If it is included, you need to use musl ldso to load the dependent shared library -
Example: Check whether a dynamically linked application exists [interpreter segment] information:
INTERP
type of
command: aarch64-linux-musleabi-readelf.exe -l glib_gio_test_s.elf
orreadelf.exe -l glib_gio_test_s.elf
It is found that there are INTERP
segments of information,[Requesting program interpreter: /lib/ld-musl-aarch64.so.1]
View the shared library that the elf file depends on
- Statically compiled elf has no dynamic link information and does not depend on shared libraries, while dynamically compiled and linked elf files have dynamic link information. You can check the dependent shared libraries through
aarch64-linux-musleabi-readelf.exe -d glib_gio_test_s.elf
orreadelf.exe -d glib_gio_test_s.elf
Check the head information of elf
- Use
aarch64-linux-musleabi-readelf.exe -h glib_gio_test_s.elf
orreadelf.exe -h glib_gio_test_s.elf
to view the header information of the application elf, such as obtaining the address of the entry function, etc.
View elf symbol information
- The so-called elf symbols are some variable names, function names, arrays, etc., which can still be
readelf
viewed through
aarch64-linux-musleabi-readelf.exe -s glib_gio_test_s.elf
Or readelf.exe -s glib_gio_test_s.elf
, note that because some applications have a lot of symbols in the elf file, you can output it to a text file and then use the file viewing tool to view it
aarch64-linux-musleabi-readelf.exe -s glib_gio_test_s.elf > sym_01.s
, here export the symbol to sym_01.s
a file, and then use the text viewer to open it for viewing
elf viewing tool
-
The above is to view the elf file through
readelf
, so is there any other tool to view the elf file? -
Recommended use:
EmEditor
binary viewing tool, which can view, search, and edit binary files, and elf files are actually binary files.
-
It is recommended to use Die, the famous Detect It Easy tool to analyze and view the elf file, which can be viewed in binary, disassembled, and viewed in each segment, section, etc.
-
Open an elf file with die
- Use die to view elf file information: elf header
summary
-
This article mainly records the viewing of elf files, and has a preliminary understanding of the files to be dynamically loaded, that is, before studying dynamic loading, you must be familiar with the elf format files, file composition, file header, file Program Header, each section of the file, file section, which content of the elf file needs to be loaded dynamically
-
At present, I understand that an elf file has only one header and one or more Program Headers. The size of a Program Header is fixed, that is, a structure. The content inside describes a segment of information. How many does an elf file have? Program Header? This needs to be obtained by parsing the header of the elf file: elf Header
-
It is recommended to check the standard specification of elf, be familiar with elf, its composition and loading mechanism, which is very important for the subsequent study of dynamic loading.