简体   繁体   English

了解 GOT(全局偏移表)和 PLT?

[英]Understanding GOT (Global Offset Table) and PLT?

Before writing this question I wanted to highlight that I did my own research for Weeks read tens of articles but still this problem wasn't solved and the explanations I got don't make sense at all (maybe because I'm new to linking world).在写这个问题之前,我想强调一下,我自己做了几个星期的研究,阅读了数十篇文章,但这个问题仍然没有解决,我得到的解释根本没有意义(也许是因为我是连接世界的新手). So I hope someone can provide simply yet very detailed answer.所以我希望有人能提供简单但非常详细的答案。

I know that GOT (Global Offset Table) helps us resolve global symbols in dynamic linking which are referenced from another.我知道 GOT(全局偏移表)帮助我们解析动态链接中从另一个引用的全局符号。 Plus I read: "Each shared library has its own GOT"另外我读到:“每个共享库都有自己的 GOT”

  1. But that is problematic, what if 2 programs use same shared library?但这是有问题的,如果 2 个程序使用同一个共享库怎么办? both will have same values for global variables which shouldn't be the case.两者都将具有相同的全局变量值,但事实并非如此。

  2. As to my MAIN question: If I don't want to use lazy binding then why we need PLT at all, why not just use normal GOT as with variables?至于我的主要问题:如果我不想使用惰性绑定那么为什么我们根本需要 PLT,为什么不使用普通的 GOT 作为变量呢?

(2) - that's exactly what gcc -fno-plt does; (2) - 这正是gcc -fno-plt所做的; using call puts@gotpcrel(%rip) which references the normal GOT entry, not the part of the GOT that's updated by PLT stubs .使用引用普通 GOT 条目的call puts@gotpcrel(%rip)而不是 PLT stubs 更新的 GOT 部分
See x86_64: Is it possible to "in-line substitute" PLT/GOT references?请参阅x86_64:是否可以“内嵌替换”PLT/GOT 引用?


(1) " Each shared library has its own GOT " means as opposed to having one per process . (1) “每个共享库都有自己的 GOT ”是指每个进程都有一个 GOT。 It's not saying that there's only one GOT for the library in shared memory that every process using the library maps.这并不是说共享 memory 中的库只有一个 GOT,每个进程都使用库映射。

Remember that Unix-like OSes (like all modern mainstream OSes) use virtual memory to isolate processes from each other, so it normally goes without saying that every process has its own independent copy of read/write data.请记住,类 Unix 操作系统(与所有现代主流操作系统一样)使用虚拟 memory 将进程彼此隔离,因此通常不用说每个进程都有自己独立的读/写数据副本。

Of course global variables like errno or environ aren't shared between processes using the same library, that would break things so you can rule out that interpretation.当然,像errnoenviron这样的全局变量不会在使用同一个库的进程之间共享,这会破坏事情,因此您可以排除这种解释。 (As well as being not what dynamic linking is doing if you strace /bin/ls ) (如果你strace /bin/ls也不是动态链接在做什么)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以以编程方式更改全局偏移表/GOT 或程序链接表/PLT 吗? - Can I change the Global Offset Table/GOT or Procedural Linkage Table/PLT programmatically? 如何最好地在x86上为我的语言传递全局偏移表(GOT)? - How can I best pass a Global Offset Table (GOT) for my language on x86? 从全局偏移量表中查找负载偏移量 - Find load offset from global offset table .plt.plt.got 有什么不同? - .plt .plt.got what is different? 导入地址表和全局偏移表有什么区别? - What is the difference between Import Address Table and Global Offset Table? 为什么对共享库本身中定义的符号使用全局偏移表? - Why use the Global Offset Table for symbols defined in the shared library itself? PIC / PIE二进制文件中全局符号表(GOT)的地址 - Address of global symbol table (GOT) in PIC/PIE binaries 为什么除了GOT之外还存在PLT,而不仅仅是使用GOT? - Why does the PLT exist in addition to the GOT, instead of just using the GOT? 为什么带有_GLOBAL_OFFSET_TABLE_的不合格引用的nasm组装显然可以作为PIC进行组装和链接? - Why can nasm assembly with unqualified references to _GLOBAL_OFFSET_TABLE_ apparently be assembled and linked as PIC? 在 gcc 32 位代码中未定义对“_GLOBAL_OFFSET_TABLE_”的引用,用于简单的功能,独立的操作系统 - undefined reference to `_GLOBAL_OFFSET_TABLE_' in gcc 32-bit code for a trivial function, freestanding OS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM