Chapter 7 Linking --- Object files and ELF format

Object files come in three forms:
1. Relocatable object file. Contains binary code and data in a form that can be combined with other
relocatable object files at compile time to create an executable object file.


2. Executable object file. Contains binary code and data in a form that can be copied directly into
memory and executed.


3. Shared object file. A special type of relocatable object file that can be loaded into memory and linked
dynamically, at either load time or run time.

 

 

Object file的格式有很多种。不同的平台和规范有不同的格式。 这里主要介绍ELF的格式

 

                  ______________________________

                 |                ELF Header                          |

                 |______________________________|

                 |                .text                                     |

                 |______________________________|

                 |                .rodata                                 |

                 |______________________________|

                 |                .data                                    |

                 |______________________________|

                 |                .bss                                      |

                 |______________________________|

                 |                .symtab                                |

                 |______________________________|

                 |                .rel.text                                |

                 |______________________________|

                 |                .debug                                 |

                 |______________________________|

                 |                .line                                     |

                 |______________________________|

                 |                .strtab                                  |

                 |______________________________|

                 |           Setction header table               |

                 |______________________________|

 

 

 

.text : The machine code of the compiled program.
.rodata: Read-only data such as the format strings in printf statements, and jump tables for switch
             statements (see Problem 7.14).
.data: Initialized global C variables. Local C variables are maintained at run time on the stack, and do
           not appear in either the .data or .bss sections.

.bss: Uninitialized global C variables. This section occupies no actual space in the object file; it is merely
         a place holder. Object file formats distinguish between initialized and uninitialized variables for space
         efficiency: uninitialized variables do not have to occupy any actual disk space in the object file.
.symtab : A symbol table with information about functions and global variables that are defined and
              referenced in the program. Some programmers mistakenly believe that a program must be compiled
              with the -g option to get symbol table information. In fact, every relocatable object file has a symbol
              table in .symtab. However, unlike the symbol table inside a compiler, the .symtab symbol table
              does not contain entries for local variables.
.rel.text: A list of locations in the .text section that will need to be modified when the linker
               combines this object file with others. In general, any instruction that calls an external function or
               references a global variable will need to be modified. On the other hand, instructions that call local
               functions do not need to be modified. Note that relocation information is not needed in executable
               object files, and is usually omitted unless the user explicitly instructs the linker to include it.
.rel.data: Relocation information for any global variables that are referenced or defined by the module.
                In general, any initialized global variable whose initial value is the address of a global variable
                or externally defined function will need to be modified.
.debug: A debugging symbol table with entries for local variables and typedefs defined in the program,
             global variables defined and referenced in the program, and the original C source file. It is only
             present if the compiler driver is invoked with the -g option.
.line: A mapping between line numbers in the original C source program and machine code instructions
          in the .text section. It is only present if the compiler driver is invoked with the -g option.
.strtab: A string table for the symbol tables in the .symtab and .debug sections, and for the section
             names in the section headers. A string table is a sequence of null-terminated character strings.

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值