| yichun 回复于:2004-09-02 09:21:09
|
ELF中的section主要提供给Linker用的, 而segment提供给Loader用. Linker需要关心.text, .rel.text, .data, .rodata等等, 一个重点是link时要做relocation. 而 Loader 只需要知道 Read/Write/Execute. a.out格式没有这种区分, 我想ELF这么做提供了更多的灵活性
|
| simtiger 回复于:2004-09-02 10:52:25
|
[quote:bb762ff504="yichun"]ELF中的section主要提供给Linker用的, 而segment提供给Loader用. Linker需要关心.text, .rel.text, .data, .rodata等等, 一个重点是link时要做relocation. 而 Loader 只需要知道 Read/Write/Execute. a.out格式没有?.........[/quote:bb762ff504]
非常感谢您的回答
那么我再问问,如果一个文件没有section(比如是executable文件),那么该文件就没有代码段与数据段的区分,对吗?
|
| yichun 回复于:2004-09-02 11:09:06
|
如果你指的是"文件中"代码段与数据段的区分, 那确实没有,但Loader仍可以从segment的Read/Write/Execute的设置来区分指令和数据
|
| simtiger 回复于:2004-09-02 13:30:36
|
[quote:4dda78383a="yichun"]如果你指的是"文件中"代码段与数据段的区分, 那确实没有,但Loader仍可以从segment的Read/Write/Execute的设置来区分指令和数据[/quote:4dda78383a]
再次感谢您的回答。
文档上说了executable的elf文件必须有segment,而section可有可无,那么执行时,指令代码既可能放在.text section中,也可能放在Execute 的segment中,那么执行时到底是执行哪一部分代码?
再次请教!
|
| yichun 回复于:2004-09-02 13:52:15
|
可以是同一份代码, ELF文件中间部分是共用的, 如Shared objects就可以同时拥有Program header table和Section Header Table, 这样load完后还可以relocate.
|
| simtiger 回复于:2004-09-02 16:48:14
|
[quote:90f0ec8338="yichun"]可以是同一份代码, ELF文件中间部分是共用的, 如Shared objects就可以同时拥有Program header table和Section Header Table, 这样load完后还可以relocate.[/quote:90f0ec8338]
"可以是同一份代码"是指两部分(section&segment)包含重复的代码,还是section header table与program header table中将对应section/segment的位置(offset)置为相同(也就是共享同一段代码)?
谢谢!
|
| yichun 回复于:2004-09-02 17:16:24
|
offset相同(也就是共享同一段代码)
|
| simtiger 回复于:2004-09-02 18:00:10
|
[quote:d0262ef768="yichun"]如果你指的是"文件中"代码段与数据段的区分, 那确实没有,但Loader仍可以从segment的Read/Write/Execute的设置来区分指令和数据[/quote:d0262ef768]
不好意思,还有一点不懂
ELF中segment的什么属性标志Read/Write/Execute?
看了看program header table中segment的各个属性,p_type的值不是(p_type是pt_load,pt_dynamic之类的值),其他属性好像也不是,那么怎么标志一个segment是Read/Write/Execute?
再次感谢您的回答。
|
| yichun 回复于:2004-09-02 20:12:35
|
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)
[b:f1ef459101]int flags; // Read, Write, Execute bits[/b:f1ef459101]
int align; // required alignment, invariably hardware page size
|
| simtiger 回复于:2004-09-02 22:45:45
|
非常感谢yichun您的回答~再次感谢
|