Skip to content

[AAELF64] Simplify expressions used for relative relocations#337

Merged
smithp35 merged 1 commit intoARM-software:mainfrom
pcc:relative
Mar 5, 2026
Merged

[AAELF64] Simplify expressions used for relative relocations#337
smithp35 merged 1 commit intoARM-software:mainfrom
pcc:relative

Conversation

@pcc
Copy link
Copy Markdown
Contributor

@pcc pcc commented Jul 14, 2025

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.

@smithp35
Copy link
Copy Markdown
Contributor

I expect that the symbol relative case is a transplant from the 32-bit ABI, in particular the BPABI https://github.com/ARM-software/abi-aa/blob/main/bpabi32/bpabi32.rst

There was a pseudo ELF target for Symbian DLLs (Symbian had an ELF to E32 conversion tool) and the SBREL position independent which was defined for an OS that did not have a MMU, although I don't think that this got used.

In open-source and open-source linkers, particularly for the sysvabi64 then I think the simplification can be made. I'd like to check to see if I can find any information on proprietary toolchains that may have built of the ABI before taking things out.

An alternative could be to find a way of preserving the original content, but moving it out of line, perhaps to an appendix.

@pcc
Copy link
Copy Markdown
Contributor Author

pcc commented Jul 16, 2025

Interesting. I had thought that this might have had something to do with a no-MMU mode inherited from 32-bit.

Another possibility could be to say that the behavior is unspecified if S is non-null. But I would prefer to just remove it if we can't easily find any evidence of proprietary toolchains implementing it. We can always make another change if we later discover a toolchain implementing it.

@smithp35 smithp35 added the aaelf64 Issue affects ELF for the Arm Architecture label Feb 9, 2026
Comment thread pauthabielf64/pauthabielf64.rst Outdated
| 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)) |
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 1821 of aaelf64/aaelf64.rst (above) DELTA(S) is rewritten as Delta, going for Title Case. Is that not wanted here too?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting.

I think that's probably my fault as I added those relocations from PAuthABI where I mistakenly used DELTA rather than Delta. This also affects the PAuthABI document.

I'll submit a PR to standardise all the DELTA instances to Delta.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#372 to change DELTA to Delta across the repository.

@smithp35
Copy link
Copy Markdown
Contributor

smithp35 commented Mar 2, 2026

I expect that the symbol relative case is a transplant from the 32-bit ABI, in particular the BPABI https://github.com/ARM-software/abi-aa/blob/main/bpabi32/bpabi32.rst

There was a pseudo ELF target for Symbian DLLs (Symbian had an ELF to E32 conversion tool) and the SBREL position independent which was defined for an OS that did not have a MMU, although I don't think that this got used.

In open-source and open-source linkers, particularly for the sysvabi64 then I think the simplification can be made. I'd like to check to see if I can find any information on proprietary toolchains that may have built of the ABI before taking things out.

An alternative could be to find a way of preserving the original content, but moving it out of line, perhaps to an appendix.

I've checked through Arm's proprietary linker and any history I can find about why R_ARM_RELATIVE was defined the way it was.

In the implementation, I can't find any use of R_ARM_RELATIVE or R_AARCH64_RELATIVE against a symbol. The relocation is only used when outputting a SVr4 style ELF file with a fixed pc-relative offset between loadable segments. In that case the displacement of the symbol will always be the same as the displacement of the segment containing the relocation.

In theory R_*_RELATIVE with a symbol target could be used in something like vxworks RTP with -mno-pic-data-is-text-relative shared libraries. In these systems the code and data segments have different deltas. However in playing around with the ARM GCC and GNU ld I've not been able to see R_ARM_RELATIVE generated relative to a symbol.

It looks like vxworks has an AArch64 port but I don't have easy access to the toolchains without clicking through EULAs. Neither clang or GCC has a -mno-pic-data-is-text-relative option for AArch64 so I think it is unlikely.

I think we should go ahead with the wording simplification, and can put it back if it turns out that there is a proprietary implementation in vxworks or something like it.

Copy link
Copy Markdown
Contributor

@smithp35 smithp35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change LGTM, sorry for the delay, but it will need to be rebased prior to merging. @pcc are you happy to do that? If not then I can make a new PR with the changes.

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_<CLS>_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_<CLS>_RELATIVE description to match.
Copy link
Copy Markdown
Contributor Author

@pcc pcc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change LGTM, sorry for the delay, but it will need to be rebased prior to merging. @pcc are you happy to do that? If not then I can make a new PR with the changes.

Done

| 0x244 (580) | R\_AARCH64\_AUTH\_ABS64 | SIGN((S + A), SCHEMA(\*P)) | SIGN((LDG(S) + A), SCHEMA(\*P)) |
+--------------+-----------------------------+---------------------------------+-------------------------------------------------------------------+
| 0x413 (1043) | R\_AARCH64\_AUTH\_RELATIVE | SIGN(Delta(S) + A, SCHEMA(\*P)) | SIGN((LDG(Delta(S) + A + ADDEND(\*P)) - ADDEND(\*P), SCHEMA(\*P)) |
| 0x413 (1043) | R\_AARCH64\_AUTH\_RELATIVE | SIGN(Delta + A, SCHEMA(\*P)) | SIGN((LDG(Delta + A + ADDEND(\*P)) - ADDEND(\*P), SCHEMA(\*P)) |
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that this relocation number (and the one below) are wrong, that can probably be fixed in a followup.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I'll fix that with a follow up patch.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smithp35 smithp35 merged commit 0f350ba into ARM-software:main Mar 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aaelf64 Issue affects ELF for the Arm Architecture

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants