Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Position-independent code
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== SunOS 4.x and ELF == Procedure calls inside a shared library are typically made through small procedure linkage table (PLT) [[method stub|stub]]s, which then call the definitive function. This notably allows a shared library to inherit certain function calls from previously loaded libraries rather than using its own versions.<ref name="sunos 4.x">{{cite conference |url=https://www.cs.cornell.edu/courses/cs414/2001FA/sharedlib.pdf |title=Shared Libraries in SunOS |first1=Robert A. |last1=Gingell |first2=Meng |last2=Lee |first3=Xuong T. |last3=Dang |first4=Mary S. |last4=Weeks |conference=1987 Summer USENIX Technical Conference and Exhibition |pages=131β146}}</ref> Data references from position-independent code are usually made indirectly, through [[Global Offset Table]]s (GOTs), which store the addresses of all accessed [[global variable]]s. There is one GOT per compilation unit or object module, and it is located at a fixed offset from the code (although this offset is not known until the library is [[Library linking|linked]]). When a [[Linker (computing)|linker]] links modules to create a shared library, it merges the GOTs and sets the final offsets in code. It is not necessary to adjust the offsets when loading the shared library later.<ref name="sunos 4.x" /> Position-independent code that accesses global data does so by fetching the address for the global variable from its entry in the GOT. As the GOT is at a fixed offset from the code, the offset between the address of a given instruction in the code and the address of a GOT entry for a given global variable is also fixed, so that the offset does not need to be changed depending on the address at which the position-independent code is loaded. An instruction that fetches the GOT entry for a global variable would use an [[addressing mode]] that contains an offset relative to some instruction in the code; this might be a [[addressing mode#PC-relative 2|PC-relative]] addressing mode if the [[instruction set architecture]] supports it, or a [[addressing mode#Base plus offset, and variations|register-relative]] addressing mode, with functions loading that register with the address of an instruction in the [[function prologue]].<ref name="sunos 4.x" /><ref>{{cite book |title=System V Application Binary Interface Motorola 68000 Processor Family Supplement |date=1990 |url=https://people.debian.org/~glaubitz/m68k-sysv-abi.pdf |pages=3{{hyp}}32-3{{hyp}}35 |publisher=Prentice-Hall |isbn=0-13-877663-6}}</ref><ref>{{cite book |title=System V Application Binary Interface i386 Architecture Processor Supplement |edition=Fourth |url=https://www.sco.com/developers/devspecs/abi386-4.pdf |pages=3{{hyp}}35-3{{hyp}}39}}</ref><ref>{{cite book |title=System V Application Binary Interface AMD64 Architecture Processor Supplement (With LP64 and ILP32 Programming Models) Version 1.0 |url=https://cs61.seas.harvard.edu/site/2022/pdf/x86-64-abi-20210928.pdf |date=September 28, 2021}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)