Skip to content

Commit 576740d

Browse files
authored
[aaelf64] Clarify addend for R_AARCH64_GOTPCREL32 (#342)
Define the expression for R_AARCH64_GOTPCREL32 as GDAT(S)-P+A. This matches the only implementation in clang and lld. The relocation is used to calculate the offset from the start of the vtable to a GOT entry that contains the address of the RTTI object. As the table entry for the RTTI pointer is at an offset from the start of the vtable the relocation addend contains -offset to cancel out. Previously in #272 the relocation definition of relocations using GDAT(S+A) were changed to require A to be 0 as lld and GNU ld were implementing GDAT(S+A) as GDAT(S) + A and GDAT(S) + 0 respectively. As this specific relocation is only implemented in clang and lld it is safe to update the description to match the implementation without affecting portability. We use GDAT(S)-P+A rather than GDAT(S) + A - P as the latter implies that we are calculating an offset to a different GOT slot to GDAT(S) rather than an offset from P. Discussion and example: #272
1 parent d455ef1 commit 576740d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

aaelf64/aaelf64.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ changes to the content of the document for that release.
294294
| | | when BTI guarded pages are used. |
295295
| | | - Added section for structure protection|
296296
| | | extension relocations. |
297+
| | | - R_AARCH64_GOTPCREL32, clarify addend |
297298
+---------------+--------------------+-----------------------------------------+
298299
| 2026Q1 | 12\ :sup:`th` | - R_AARCH64_TLS_DTPREL can be used as a |
299300
| | January 2026 | static relocation as well as dynamic |
@@ -1319,7 +1320,7 @@ The following tables record single instruction relocations and relocations that
13191320
| 308 | \- | R\_<CLS>\_GOTREL32 | S+A-GOT | Write bits [31:0] of X at byte-aligned place P. This represents a 32-bit offset relative to GOT, treated as signed; |
13201321
| | | | | Check that -2\ :sup:`31` <= X < 2\ :sup:`31`. |
13211322
+------------+------------+----------------------+------------------+-------------------------------------------------------------------------------------------------------------------------+
1322-
| 315 | \- | R\_<CLS>\_GOTPCREL32 | G(GDAT(S))- P | Write bits [31:0] of X at byte-aligned place P. This represents a 32-bit offset relative to GOT entry for an address, |
1323+
| 315 | \- | R\_<CLS>\_GOTPCREL32 | G(GDAT(S))-P+A | Write bits [31:0] of X at byte-aligned place P. This represents a 32-bit offset relative to GOT entry for an address, |
13231324
| | | | | treated as signed; Check that -2\ :sup:`31` <= X < 2\ :sup:`31`. |
13241325
+------------+------------+----------------------+------------------+-------------------------------------------------------------------------------------------------------------------------+
13251326

0 commit comments

Comments
 (0)