elf

ELF文件格式理解

杀马特。学长 韩版系。学妹 提交于 2019-12-22 15:05:55
  ELF(Executable and Linking Format)是一种对象文件的格式,用于定义不同类型的对象文件(Object files)中都放了什么东西、以及都以什么样的格式去放这些东西。它自最早在 System V 系统上出现后,被 xNIX 世界所广泛接受,作为缺省的二进制文件格式来使用。可以说,ELF是构成众多xNIX系统的基础之一,所以作为嵌入式Linux系统乃至内核驱动程序开发人员,你最好熟悉并掌握它。换句话说,就是Windows上的EXE(Windows上其实不只EXE是可执行文件),嵌入式Linux上的ELF,它们比较相似。   一个可执行目标文件,从原代码,要经历预处理器、编译器、汇编器和加载器,才会加载到内存中执行。而目标文件,分为可重定位文件和可执行文件,目标中分成不同的节。 节 ELF 头 描述字的大小、生成该文件的系统的字节顺序、帮助链接解析和解释目标文件的信息 (ELF 头的大小、目标文件类型 -- 可重定位 / 可执行 / 共享 / 机器类型 / 节头部表的文件偏移 / 节头部表中表目大小和数量 ) .text 编译完后的机器码 .rodata 只读数据,如 printf 中的格式串和 switch 中的跳转表 .data 已初始化的全局 C 变量 .bss 未初始化的全局 C 变量 .symtab 符号表

relationship between VMA and ELF segments

与世无争的帅哥 提交于 2019-12-22 10:57:30
问题 I need to determine the VMAs for loadable segments of ELF executables. VMAs can be printed from /proc/pid/maps . The relationship between VMAs shown by maps with loadable segments is also clear to me. Each segment consists of one or more VMAs. what is the method used by kernel to form VMAs from ELF segments: whteher it takes into consideration only permissions/flags or something else is also required? As per my understanding, a segment with flags Read, Execute (code) will go in separate VMA

How can I view function names and parameters contained in an ELF file?

微笑、不失礼 提交于 2019-12-22 08:44:42
问题 If I look at the file's bytes I can definately see some of the function names in there. Is there any tool that will list them for me? Maybe even their parameters too? 回答1: This should print all defined symbols within your object file or library. nm -C --defined-only file.o nm has quite a lot of options that you could use to filter out the symbols like -g for displaying only global symbols , -l for printing the line number (if you had used gcc -g to enable debug symbols) and so on. If you have

Analyzing an ELF binary to minimize its size

对着背影说爱祢 提交于 2019-12-22 07:44:46
问题 I'm cross-compiling a V8 project to an embedded ARM target using the GCC arm-gnueabi cross compiler. I got the V8 library itself cross-compiled successfully, and as a smoke test I wanted to link it to Google's hello world example and run it on the ARM board. The libraries themselves clock in at a bit over 1.2 MB: v8 % find out/arm.release/obj.target/ -name '*.a' -exec du -h {} + 1.2M out/arm.release/obj.target/tools/gyp/libv8_base.a 12K out/arm.release/obj.target/tools/gyp/libv8_libbase.a 4

How can I generate an ELF file with GCC?

会有一股神秘感。 提交于 2019-12-22 06:56:47
问题 I am writing C and C++ code on Linux OS and I am using GCC. After finishing my code, I would like to generate an ELF file. I just can generate "a.out" file and I don't need it. How can I get ELF file ? ELF file occurs as a result of what ? or Is it possible to generate this file with this program ? 回答1: The compiler (i.e. gcc or g++ ) will invoke the linker ( ld ) which produces an ELF executable. In practice, you will use a builder program (like make ) to drive gcc commands. See this answer.

Global initialized variables declared as “const” go to text segment, while those declared “Static” go to data segment. Why?

有些话、适合烂在心里 提交于 2019-12-22 06:29:59
问题 #include <stdio.h> const int str[1000] = {0}; int main(void) { printf("arr is %d\n", str[0]); return 0; } Has the following output: [-exercises/adam/stack2]:size a.out text data bss dec hex filename 5133 272 24 5429 1535 a.out Whereas: #include <stdio.h> static int str[1000] = {0}; int main(void) { printf("arr is %d\n", str[0]); return 0; } Has the following output: [-exercises/adam/stack2]:size a.out text data bss dec hex filename 1080 4292 24 5396 1514 a.out When the array is uninitialized

ELF file TLS and LOAD program sections

孤者浪人 提交于 2019-12-21 19:31:51
问题 int i; int main() { return i; } After -static compile readelf -l shows program headers from elf: Elf file type is EXEC (Executable file) Entry point 0xxxxx30 There are 6 program headers, starting at offset 52 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x000000 0x08048000 0x08048000 0x79868 0x79868 R E 0x1000 > LOAD 0x079f94 0x080c2f94 0x080c2f94 0x0078c 0x02254 RW 0x1000 << NOTE 0x0000f4 0x080480f4 0x080480f4 0x00020 0x00020 R 0x4 > TLS 0x079f94 0x080c2f94

Symbol Resolution and Dynamic Linking

左心房为你撑大大i 提交于 2019-12-21 18:33:12
问题 I have been reading about the relocation and symbol resolution process and I have a few questions on the same. So the whole process(of loading the exec) starts with exec(BA_OS) command. During exec(BA_OS) , the system retrieves a path name from the PT_INTERP segment and creates the initial process image from the interpreter file’s segments. That is, instead of using the original executable file’s segment images, the system composes a memory image for the interpreter. It then is the interpreter

Linux: update embedded resource from executable

折月煮酒 提交于 2019-12-21 06:27:12
问题 I have an executable in which I embed a binary file resource using the objcopy method objcopy --input binary --output elf32-i386 --binary-architecture i386 data.txt data.o link to data.o and use extern char _binary_data_txt_start extern char _binary_data_txt_end Is it possible now to update this data inside the executable? The updated data can have the same exact size, I just need to change some of the bits. In windows PE files this is very simple to do using UpdateResource() 回答1: Nothing

Meaning of a Common String In Executables?

时光毁灭记忆、已成空白 提交于 2019-12-21 03:53:31
问题 There appear to be some similar-looking long alphanumeric strings that commonly occur in Mach-O 64 bit executables and ELF 64-bit LSB executables among other symbols that are not alphanumeric: cat /bin/bash | grep -c "AWAVAUATSH" has 181 results, and cat /usr/bin/gzip | grep -c "AWAVAUATSH" has 9 results. What are these strings? 回答1: Interesting question. Since I didn't know the answer, here are the steps I took to figure it out: Where in the file does the string occur? strings -otx /bin/gzip