zoukankan      html  css  js  c++  java
  • ELF文件中section与segment的区别

    http://blog.csdn.net/joker0910/article/details/7655606

    1. ELF中的section主要提供给Linker使用, 而segment提供给Loader用,Linker需要关心.text, .rel.text, .data, .rodata等等,关键是Linker需要做relocation。而Loader只需要知道Read/Write/Execute的属性。a.out格式没有这种区分。(注意现在使用gcc编译出来的a.out文件只是取该名字而已,文件格式是elf的.)


    2.一个executable的ELF文件可以没有section,但必须有segment。ELF文件中间部分是共用的(也就是代码段、数据段等),如shared objects就可以同时拥有Program header table和Section Header Table,这样load完后还可以relocate。


    3. 这样设定之后,使得Loader需要做的工作大大减少了,一定程度上提高了程序加载的效率。

    下图标记为红色的字段,就是segment区分Read/Write/Execute的属性。

    ELF program header 
    int type; // loadable code or data, dynamic linking info, etc. 
    int offset; // file offset of segment 
    int virtaddr; // virtual address to map segment 
    int physaddr; // physical address, not used 
    int filesize; // size of segment in file 
    int memsize; // size of segment in memory (bigger if contains BSS) 
    int flags; // Read, Write, Execute bits
    int align; // required alignment, invariably hardware page size

  • 相关阅读:
    2015年 Stoi&Gdoi 反思总结与未来计划
    bzoj4517: [Sdoi2016]排列计数--数学+拓展欧几里得
    bzoj4518: [Sdoi2016]征途--斜率DP
    BZOJ 1391: [Ceoi2008]order
    BZOJ 2527: [Poi2011]Meteors
    BZOJ 2087: [Poi2010]Sheep
    BZOJ 1283: 序列
    BZOJ 1914: [Usaco2010 OPen]Triangle Counting 数三角形
    BZOJ 3513: [MUTC2013]idiots
    BZOJ 3771: Triple
  • 原文地址:https://www.cnblogs.com/feng9exe/p/6899136.html
Copyright © 2011-2022 走看看