Skip to content

Commit d455ef1

Browse files
authored
[AAELF64] Allow R_AARCH64_TLS_DTPREL to be used statically. (#330)
Permit the R_AARCH64_TLS_DTPREL dynamic relocation to be used statically so that debug information can describe the location of TLS variables. All code sequences to access TLS data use immediates, hence all existing static TLS relocations are instruction relocations. To describe the location of a TLS variable in debug information requires a static data relocation. The necessary expression needed is DTPREL(S + A) which is performed by the traditional dialect dynamic relocation R_AARCH64_TLS_DTPREL. There is prior art in the x86_64 and PPC64 ABIs to use the equivalent relocation R_X86_64_DTPOFF64 and R_PPC_DTPREL64 respectively for relocating debug information statically. We also introduce a syntax for assembler operators operating on data directives, with an instance %dtprel(expr) to generate R_AARCH64_DTPREL. The 32-bit Arm ABI uses the R_ARM_TLS_LDO32 static local dynamic relocation. The advantage of using local dynamic is that these only apply to a TLS variable local to the module so no additional note is needed. An alternative design adds a new relocation code to local dynamic. fixes: #176
1 parent a78fa26 commit d455ef1

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

aaelf64/aaelf64.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ changes to the content of the document for that release.
295295
| | | - Added section for structure protection|
296296
| | | extension relocations. |
297297
+---------------+--------------------+-----------------------------------------+
298+
| 2026Q1 | 12\ :sup:`th` | - R_AARCH64_TLS_DTPREL can be used as a |
299+
| | January 2026 | static relocation as well as dynamic |
300+
+---------------+--------------------+-----------------------------------------+
298301

299302
References
300303
----------
@@ -1730,6 +1733,27 @@ Thread-local storage descriptors
17301733
Relocation codes ``R_<CLS>_TLSDESC_LDR``, ``R_<CLS>_TLSDESC_ADD`` and ``R_<CLS>_TLSDESC_CALL`` are needed to permit linker optimization of TLS descriptor code sequences to use Initial-exec or Local-exec TLS sequences; this can only be done if all relevant uses of TLS descriptors are marked to permit accurate relaxation. Object producers that are unable to satisfy this requirement must generate traditional General-dynamic TLS
17311734
sequences using the relocations described in `General Dynamic thread-local storage model`_. The details of TLS descriptors are beyond the scope of this specification; a general introduction can be found in [TLSDESC_].
17321735

1736+
Thread Local Storage Data Relocations
1737+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1738+
1739+
A data relocation is required to describe the location of a TLS variable in debug information.
1740+
1741+
.. class:: aaelf64-tls-data-relocations
1742+
1743+
.. table:: TLS data relocations
1744+
1745+
+------------+------------+-----------------------------+------------------------------------+-------------------------------------------+
1746+
| 1028 | 184 | R\_<CLS>\_TLS\_IMPDEF1 | | See note below |
1747+
+------------+------------+-----------------------------+------------------------------------+-------------------------------------------+
1748+
| 1029 | 185 | R\_<CLS>\_TLS\_IMPDEF2 | | See note below |
1749+
+------------+------------+-----------------------------+------------------------------------+-------------------------------------------+
1750+
| | | R\_<CLS>\_TLS\_DTPREL | DTPREL(S+A) | See note below |
1751+
+------------+------------+-----------------------------+------------------------------------+-------------------------------------------+
1752+
1753+
``R_<CLS>_TLS_DTPREL`` is both a static and dynamic relocation. When used as a static relocation ``S`` must be fully resolved at static link time to a symbol definition in the same module as the relocation.
1754+
1755+
It is implementation defined whether ``R_<CLS>_TLS_IMPDEF1`` implements ``R_<CLS>_TLS_DTPREL`` and ``R_<CLS>_TLS_IMPDEF2`` implements ``R_<CLS>_TLS_DTPMOD`` or whether ``R_<CLS>_TLS_IMPDEF1`` implements ``R_<CLS>_TLS_DTPMOD`` and ``R_<CLS>_TLS_IMPDEF2`` implements ``R_<CLS>_TLS_DTPREL``; a platform must document its choice\ [#aaelf64-f1]_.
1756+
17331757
Relocations for PAuth ABI Extension
17341758
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17351759

sysvabi64/sysvabi64.rst

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ Change History
218218
| | | .note.gnu.property section is present. |
219219
| | | - Update distance to GOT for small code-model |
220220
+------------+------------------------------+-------------------------------------------------------+
221+
| 2026Q1 | 12\ :sup:`th` January 2026 | Add assembler conventions for data directive |
222+
| | | relocation expressions. |
223+
+------------+------------------------------+-------------------------------------------------------+
221224

222225
References
223226
----------
@@ -461,8 +464,8 @@ variant of PIC called PIE (position-independent executable) can be
461464
used to build an executable. PIE assumes that global symbols cannot be
462465
pre-empted, which means that an indirection via the GOT is not needed.
463466

464-
Assembler language addressing mode conventions
465-
----------------------------------------------
467+
Assembler language addressing mode conventions for instructions
468+
---------------------------------------------------------------
466469

467470
The assembler examples in this document make use of operators to
468471
modify the addressing mode used to form the immediate value of the
@@ -654,6 +657,23 @@ syntax is of the form ``#:<operator>:<symbol name>``
654657
655658
PageBreak oneColumn
656659
660+
Assembler language addressing mode conventions for data
661+
-------------------------------------------------------
662+
663+
The assembler operators that apply to instructions use the syntax
664+
``#:<operator>:<symbol name>``. This syntax is not easy to apply to
665+
data directives due to a parsing ambiguity with labels.
666+
667+
The recommended syntax for data directives is ``<directive> %operator(expression)``
668+
669+
.. table:: TLS operators
670+
671+
+-----------------------+------------+------------------+
672+
| Operator | Data size | Relocation |
673+
+=======================+============+==================+
674+
| ``dtprel`` | 8 bytes | R_AARCH64_DTPREL |
675+
+-----------------------+------------+------------------+
676+
657677
Code Models
658678
===========
659679

0 commit comments

Comments
 (0)