【发布时间】:2011-05-06 18:52:26
【问题描述】:
int i;
int main() {
return i;
}
-static 编译后readelf -l 显示来自精灵的程序头:
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
谁能解释一下,为什么第 2 和第 4 程序头确实相交(它们以相同的偏移量 0x079f94 和 VirtAddr 0x080c2f94 开始)。
此外,段部分.tdata 被引用两次。
如何为第一个线程(程序本身)加载PT_TLS 和PT_LOAD?
.tbss在内存中的哪个位置?
【问题讨论】:
-
看起来像是放在 HEAP 上的 tls...
-
您可以通过 strace grepping for
set_thread_areasyscall 来检查 TLS 是如何加载的
标签: linux elf glibc thread-local-storage