gpt4 book ai didi

linux - ELF 文件 TLS 和 LOAD 程序部分

转载 作者:IT王子 更新时间:2023-10-29 01:02:40 25 4
gpt4 key购买 nike

int i;
int main() {
return i;
}

-static 编译后 readelf -l 显示来自 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 开始)。

此外,段部分 .tdata 被引用了两次。

如何为第一个线程(程序本身)加载 PT_TLSPT_LOAD.tbss在内存中的什么位置?

最佳答案

第一个 .tdata 部分 - 是 TLS 数据的“初始图像”。它是 TLS 变量的初始值,将在每个线程(以及主线程)中使用。在 crt(我假设)中,将 TLS 初始图像复制到主线程的 TLS 中。 pthread_create 中有相同的代码。

PT_TLS 未加载,因为 PT_LOAD 加载并且 PT_LOAD 已包含此 PT_TLS。我认为 PT_TLS 用于初始图像 - 因为它比整个线程本地数据短 ( tbss+tdata > size(PT_TLS) )。

关于linux - ELF 文件 TLS 和 LOAD 程序部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4126184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com