This article describes target-specific details about AArch64 in ELF linkers. AArch64 is the 64-bit execution environment for the Arm architecture.
ABI documents
- ELF for the Arm® 64-bit Architecture (AArch64)
- System V ABI for the Arm® 64-bit Architecture (AArch64)
Global Offset Table
The Global Offset Table consists of two sections:
.got.pltholds code addresses for PLT..gotholds other addresses and offsets.
_GLOBAL_OFFSET_TABLE_ is defined at the start of the
section .got. GNU ld reserves one entry for
.got and .got[0] holds the link-time address
of _DYNAMIC for a legacy reason glibc versions before 2.35
have the _DYNAMIC requirement. See All
about Global Offset Table.
.got.plt[1] and .got.plt[2] are for lazy
binding PLT. Linkers communicate the address of .got.plt to
rtld with the dynamic tag DT_PLTGOT.
GOT optimization
See All about Global Offset Table#GOT optimization.
Procedure Linkage Table
x16 (IP0) and x17 (IP1) are the first and
second intra-procedure-call temporary registers. They may be used by PLT
entries and veneers.
The PLT header looks like:
1 | bti c // If BTI |
The Nth PLT entry looks like:
1 | bti c // If BTI |
When BTI is enabled for the output file, the code sequence starts
with bti c. When PAC-PLT is enabled, the code sequence has
a autia1716 before br x17.
Relocation optimization
There are a few optimization schemes beside GOT optimization, e.g.
1 | add x2, x2, 0 // R_<CLS>_ADD_ABS_LO12_NC |
1 | adrp x0, :page: symbol |
See ELF for the Arm® 64-bit Architecture (AArch64)#Relocation optimization.
Program Property
A .note.gnu.property section contains program property
notes which describe special handling requirements for the linker and
the dynamic loader.
The linker parses input .note.gnu.property sections and
recognizes command line options -z force-bti and
-z pac-plt to compute the output
.note.gnu.property (type is SHT_NOTE) section.
Without the options linkers set the feature bit in the output file only
if all the input relocatable object files have the corresponding feature
set.
1 | for (ELFFileBase *f : ctx.objectFiles) { |
Range extension thunks
Function calls typically use B and BL
instructions. The twoinstructions have a range of +/-128MiB and may use
2 relocation types: R_AARCH64_CALL26 and
R_AARCH64_JUMP26. Linkers may insert a veneer (range
extension thunk) to a destination not reachable by a single
B/BL.
-no-pie links may use a thunk with absolute addressing
targeting any location in the 64-bit address space.
1 | <caller>: |
-pie and -shared links need to use a thunk
with PC-relative addressing targeting a range of +/-4GiB.
1 | <caller>: |
The branch target of a thunk may be a PLT entry:
1 | <caller>: |