From a379ea37c30e2fa8b47814dac62775e5081f45b1 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Mon, 14 Jul 2025 14:03:18 -0700 Subject: [PATCH] [AAELF64] Simplify expressions used for relative relocations The function Delta(S) returns the current binary's load bias (for the null symbol as well as for locally-defined S), and is only used in the definition of RELATIVE family relocations, which are not expected to have a non-null symbol operand. Theoretically, a non-null symbol operand could be used to refer to a symbol in another binary, which would then cause Delta(S) to evaluate to the load bias of that binary. But I am unaware of any dynamic loader implementing this (checked glibc/musl/bionic/FreeBSD/NetBSD/OpenBSD), and its utility seems limited. The description of R__RELATIVE appears to contemplate a different case in which different segments in the same binary have different load biases. It is unclear to me how this would work in practice. If the idea is to accommodate individual segments being loaded at independent addresses, I don't think this would be enough; ELF is not generally designed to accommodate this so numerous other changes to relocation processing would need to be made in order for this to work. Therefore, simplify the definition of Delta as well as the users, and bring it in line with existing practice, by removing the argument and having it always produce the current binary's load bias, and adjust the R__RELATIVE description to match. --- aaelf64-morello/aaelf64-morello.rst | 8 +++----- aaelf64/aaelf64.rst | 10 +++++----- memtagabielf64/memtagabielf64.rst | 2 +- pauthabielf64/pauthabielf64.rst | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/aaelf64-morello/aaelf64-morello.rst b/aaelf64-morello/aaelf64-morello.rst index d9681cb2..f94e7b86 100644 --- a/aaelf64-morello/aaelf64-morello.rst +++ b/aaelf64-morello/aaelf64-morello.rst @@ -480,10 +480,8 @@ The following nomenclature is used in the descriptions of relocation operations: the second entry holds a platform-specific offset or pointer. The pair of pointer-sized entries will be relocated with ``R_MORELLO_TLSDESC(S+A)``. -- ``Delta(S)`` if ``S`` is a normal symbol, resolves to the difference between the - static link address of ``S`` and the execution address of ``S``. If ``S`` is the - null symbol (ELF symbol index 0), resolves to the difference between the static - link address of ``P`` and the execution address of ``P``. +- ``Delta`` resolves to the difference between the static link address of + ``P`` and the execution address of ``P``. - ``TPREL(S)`` resolves to a pair of two 64-bit values. The first value contains the offset in the static TLS block of the thread-local symbol ``S``. @@ -728,7 +726,7 @@ Dynamic Morello relocations | 59400 | ``R_MORELLO_FUNC_RELATIVE`` | ``CAP_INIT(S, A, CAP_SIZE, CAP_PERM)`` | See note below. | | | | | | +-------+-----------------------------+-----------------------------------------+------------------------------------------+ - | 59401 | ``R_AARCH64_FUNC_RELATIVE`` | ``Delta(S) + A`` | See note below. | + | 59401 | ``R_AARCH64_FUNC_RELATIVE`` | ``Delta + A`` | See note below. | | | | | | +-------+-----------------------------+-----------------------------------------+------------------------------------------+ diff --git a/aaelf64/aaelf64.rst b/aaelf64/aaelf64.rst index 6a581614..94125935 100644 --- a/aaelf64/aaelf64.rst +++ b/aaelf64/aaelf64.rst @@ -1051,7 +1051,7 @@ The following nomenclature is used in the descriptions of relocation operations: - ``G(expr)`` is the address of the GOT entry for the expression expr. -- ``Delta(S)`` if ``S`` is a normal symbol, resolves to the difference between the static link address of ``S`` and the execution address of ``S``. If ``S`` is the null symbol (ELF symbol index 0), resolves to the difference between the static link address of ``P`` and the execution address of ``P``. +- ``Delta`` resolves to the difference between the static link address of ``P`` and the execution address of ``P``. - ``Indirect(expr)`` represents the result of calling expr as a function. The result is the return value from the function that is returned in ``r0``. The arguments passed to the function are defined by the platform ABI. @@ -1802,7 +1802,7 @@ The dynamic relocations for those execution environments that support only a lim +------------+------------+-----------------------------+------------------------------------+-------------------------------------------+ | 1026 | 182 | R\_\_JUMP\_SLOT | S + A | See note below | +------------+------------+-----------------------------+------------------------------------+-------------------------------------------+ - | 1027 | 183 | R\_\_RELATIVE | Delta(S) + A | See note below | + | 1027 | 183 | R\_\_RELATIVE | Delta + A | See note below | +------------+------------+-----------------------------+------------------------------------+-------------------------------------------+ | 1028 | 184 | R\_\_TLS\_IMPDEF1 | | See note below | +------------+------------+-----------------------------+------------------------------------+-------------------------------------------+ @@ -1816,9 +1816,9 @@ The dynamic relocations for those execution environments that support only a lim +------------+------------+-----------------------------+------------------------------------+-------------------------------------------+ | 1031 | 187 | R\_\_TLSDESC | TLSDESC(S+A) | Identifies a TLS descriptor to be filled | +------------+------------+-----------------------------+------------------------------------+-------------------------------------------+ - | 1032 | 188 | R\_\_IRELATIVE | Indirect(Delta(S) + A) | See note below. | + | 1032 | 188 | R\_\_IRELATIVE | Indirect(Delta + A) | See note below. | +------------+------------+-----------------------------+------------------------------------+-------------------------------------------+ - | 1041 | \- | R\_\_AUTH\_RELATIVE | SIGN(DELTA(S) + A, SCHEMA(\*P)) | See note below. | + | 1041 | \- | R\_\_AUTH\_RELATIVE | SIGN(Delta + A, SCHEMA(\*P)) | See note below. | +------------+------------+-----------------------------+------------------------------------+-------------------------------------------+ | 1042 | \- | R\_AARCH64\_AUTH\_GLOB\_DAT | SIGN((S + A), SCHEMA(\*P)) | See note below. | +------------+------------+-----------------------------+------------------------------------+-------------------------------------------+ @@ -1849,7 +1849,7 @@ The need for copy relocations can be avoided if a compiler generates all code re - Because the initial value of the place is not related to the ultimate target of a ``R__JUMP_SLOT`` relocation the addend ``A`` of such a REL-type relocation shall be zero rather than the initial content of the place. A platform ABI shall prescribe whether or not the ``r_addend`` field of such a RELA-type relocation is honored. (There may be security-related reasons not to do so). -``R__RELATIVE`` represents a relative adjustment to the place based on the load address of the object relative to its original link address. All symbols defined in the same segment will have the same relative adjustment. If ``S`` is the null symbol (ELF symbol index 0) then the adjustment is based on the segment defining the place. On systems where all segments are mapped contiguously the adjustment will be the same for each relocation, thus adjustment never needs to resolve the symbol. This relocation represents an optimization; a static linker can use it to replace ``R__GLOB_DAT`` when the symbol is known at static link time to always resolve to the current link unit. +``R__RELATIVE`` represents a relative adjustment to the place based on the load address of the object relative to its original link address. All symbols defined in the same binary will have the same relative adjustment. This relocation represents an optimization; a static linker can use it to replace ``R__GLOB_DAT`` when the symbol is known at static link time to always resolve to the current link unit. ``R__IRELATIVE`` represents a dynamic selection of the place’s resolved value. The means by which this relocation is generated is platform specific, as are the conditions that must hold when resolving takes place. diff --git a/memtagabielf64/memtagabielf64.rst b/memtagabielf64/memtagabielf64.rst index c371c34c..acebd005 100644 --- a/memtagabielf64/memtagabielf64.rst +++ b/memtagabielf64/memtagabielf64.rst @@ -638,7 +638,7 @@ The relocations reference the following mnemonics: +------------+--------------------+----------------+-------------------------------+ | 1025 | R_AARCH64_GLOB_DAT | S + A | LDG(S) + A | +------------+--------------------+----------------+-------------------------------+ - | 1027 | R_AARCH64_RELATIVE | Delta(S) + A | LDG(Delta(S) + A + \*P) - \*P | + | 1027 | R_AARCH64_RELATIVE | Delta + A | LDG(Delta + A + \*P) - \*P | +------------+--------------------+----------------+-------------------------------+ ``R_AARCH64_ABS64`` and ``R_AARCH64_GLOB_DAT`` are thus extended to materialize diff --git a/pauthabielf64/pauthabielf64.rst b/pauthabielf64/pauthabielf64.rst index cf9a65df..a79311a8 100644 --- a/pauthabielf64/pauthabielf64.rst +++ b/pauthabielf64/pauthabielf64.rst @@ -744,7 +744,7 @@ relocation. +====================+==============================+====================================+ | 0x244 (580) | R\_AARCH64\_AUTH\_ABS64 | SIGN(S + A, SCHEMA(\*P)) | +--------------------+------------------------------+------------------------------------+ - | 0x411 (1041) | R\_AARCH64\_AUTH\_RELATIVE | SIGN(DELTA(S) + A, SCHEMA(\*P)) | + | 0x411 (1041) | R\_AARCH64\_AUTH\_RELATIVE | SIGN(DELTA + A, SCHEMA(\*P)) | +--------------------+------------------------------+------------------------------------+ .. raw:: pdf