ELF文件TLS和LOAD程序部分 [英] ELF file TLS and LOAD program sections
问题描述
int i;
int main() {
return i;
}
-static
编译后,readelf -l
显示elf的程序头:
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 0x080c2f94 0x00010 0x0002c R 0x4 <<
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4
PAX_FLAGS 0x000000 0x00000000 0x00000000 0x00000 0x00000 0x4
Section to Segment mapping:
Segment Sections...
00 .note.ABI-tag .init .text __libc_freeres_fn .fini .rodata __libc_subfreeres __libc_atexit .eh_frame .gcc_except_table
01 .tdata .ctors .dtors .jcr .data.rel.ro .got .got.plt .data .bss __libc_freeres_ptrs
02 .note.ABI-tag
03 .tdata .tbss
有人可以解释为什么第二个和第四个程序标头确实相交(它们以相同的偏移量0x079f94和VirtAddr 0x080c2f94开头).
Can somebody explain, why the 2nd and 4th program headers does intersect (they begin with same offset 0x079f94 and VirtAddr 0x080c2f94).
此外,段段.tdata
被引用两次.
Also, the segment section .tdata
is referred twice.
如何为第一个线程(程序本身)加载PT_TLS
和PT_LOAD
?
.tbss
在内存中的什么位置?
How PT_TLS
and PT_LOAD
will be loaded for first thread (the program itself)?
Where does .tbss
lie in the memory?
推荐答案
第一个.tdata
部分-是TLS数据的初始映像".它是TLS变量的初始值,将在每个线程(以及主线程中)中使用.在crt
(我假设)中,存在TLS初始映像到主线程TLS的复制.相同的代码在pthread_create
中.
First .tdata
section - is an "initial image" of TLS data. It is the initial values of TLS vars, which will be used in every thread (and in main thread too). In the crt
(I assume) there is a copying of TLS initial image into TLS of main thread. Same code is in pthread_create
.
未加载PT_TLS,因为PT_LOAD会加载并且PT_LOAD已包含此PT_TLS.我认为PT_TLS用于初始映像-因为它比整个线程本地数据(tbss + tdata> size(PT_TLS))短.
PT_TLS is not loaded, because PT_LOAD does and PT_LOAD already contains this PT_TLS. I think that PT_TLS is for initial image - because it is shorter than entire thread-local data ( tbss+tdata > size(PT_TLS) ).
这篇关于ELF文件TLS和LOAD程序部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!