Skip to content

[AArch64] Add support for pointer authentication relocations#801

Open
nezetic wants to merge 1 commit intoqualcomm:mainfrom
nezetic:auth-reloc-support
Open

[AArch64] Add support for pointer authentication relocations#801
nezetic wants to merge 1 commit intoqualcomm:mainfrom
nezetic:auth-reloc-support

Conversation

@nezetic
Copy link
Contributor

@nezetic nezetic commented Feb 10, 2026

Implements basic PAuth support for AArch64 following the PAuth ABI Extension specification (2025Q1):
https://github.com/ARM-software/abi-aa/blob/main/pauthabielf64/pauthabielf64.rst

Adds:

  • R_AARCH64_AUTH_ABS64 (0x244): authenticated absolute relocations
  • R_AARCH64_AUTH_RELATIVE (0x411): authenticated relative relocations

Testing:
Covers PIE/non-PIE/static executables, as well as various corner cases from the spec like undefined weak references, COPY relocations and non-allocating sections.

Not included:
GOT/PLT signing, additional AUTH relocation types (future work).

Notes:
I changed the way GNULDBackend::recordRelativeReloc store relative relocations. The original map is only iterated once (in a linear way), but reversing the key / values allows to implement an efficient GNULDBackend::findRelativeReloc.

No changes to existing non-AUTH relocation behavior.

@nezetic nezetic force-pushed the auth-reloc-support branch 2 times, most recently from 2d93aa4 to 7c37e18 Compare February 10, 2026 15:12
@svs-quic
Copy link
Contributor

@pzhengqc might be a better suited to review this.

uint32_t relaCount = 0;
for (auto &R : m_Backend.getRelaDyn()->getRelocations()) {
if (R->type() == llvm::ELF::R_AARCH64_RELATIVE)
if (R->type() == llvm::ELF::R_AARCH64_RELATIVE ||
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this may lead to a potentially wrong DT_RELACOUNT value with eld (lld does not count AARCH64_AUTH_RELATIVE here).

Copy link
Contributor Author

@nezetic nezetic Feb 12, 2026

Choose a reason for hiding this comment

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

My understanding if that DT_RELACOUNT represents the number of relative relocations in .rela.dyn. AARCH64_AUTH_RELATIVE relocations will end up in this section, so they must be counted.

Relocation section '.rela.dyn' at offset 0x1e8 contains 11 entries:
Offset Info Type Symbol's Value Symbol's Name + Addend
0000000000001130 0000000000000411 R_AARCH64_AUTH_RELATIVE 341
0000000000001138 0000000000000411 R_AARCH64_AUTH_RELATIVE 1132

It's important to note LLD implement a very tedious (and optional) Relocation Compression (section 11) , that is not in the scope of this PR.

I did not perform a 1:1 comparaison with LLD, but made sure ELD is passing similar tests.

@quic-seaswara
Copy link
Contributor

@efriedma-quic can you please review this change ?

Comment on lines 812 to 815
auto Entry = m_RelativeRelocMap.find(pReloc);
if (Entry == m_RelativeRelocMap.end())
return nullptr;
return Entry->second;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
auto Entry = m_RelativeRelocMap.find(pReloc);
if (Entry == m_RelativeRelocMap.end())
return nullptr;
return Entry->second;
return m_RelativeRelocMap.lookup(pReloc);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the code 👍

ValueType(0x23d, \
MappedType(&unsupport, \
"R_AARCH64_TLSLE_LDST128_DTPREL_LO12_NC", 32)), \
ValueType(0x244, MappedType(&abs, "R_AARCH64_AUTH_ABS64", 64)), \
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we arrange this header in the same order as llvm/BinaryFormat/ELFRelocs/AArch64.def, to make future updates easier?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the header based on AArch64.def, adding all AUTH relocations in the same order

// a dynamic relocations with RELATIVE type to this location is needed.
// Reserve an entry in .rel.dyn
if (config().isCodeIndep()) {
if (config().isCodeIndep() || isAuthReloc(pReloc)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Using isAuthReloc() instead of just pReloc.type() == llvm::ELF::R_AARCH64_AUTH_ABS64 feels a little strange.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, I simplified the code a bit, testing only with R_AARCH64_AUTH_ABS64 where I'm only matching this one (abs function and relocation scan switch cases).

# STATIC-NEXT: {{0x[0-9A-F]+}} R_AARCH64_AUTH_RELATIVE - {{0x[0-9A-F]+}}
# STATIC-NEXT: }

# Test PAuth relocations with static executable (without PIE)
Copy link
Contributor

Choose a reason for hiding this comment

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

In a static executable, what code actually processes the rela.dyn section?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the case of a baremetal binary (a firmware), a custom dynamic linker (as it's already the case for things like TZ).

foo:

#--- main.s
.section .test, "aw"
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe worth adding a test to show what happens if you try to use R_AARCH64_AUTH_ABS64 in a readonly section?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a few relocations in a read-only section in the tests.

As far I understand the specifications, there are no restrictions regarding read-only sections.

Copy link
Contributor

Choose a reason for hiding this comment

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

The spec might not say anything, but eld defaults to -z text, which should forbid such relocations?

Implements basic PAuth support for AArch64 following the PAuth ABI Extension
specification (2025Q1):
https://github.com/ARM-software/abi-aa/blob/main/pauthabielf64/pauthabielf64.rst

**Adds:**
- R_AARCH64_AUTH_ABS64 (0x244): authenticated absolute relocations
- R_AARCH64_AUTH_RELATIVE (0x411): authenticated relative relocations

**Testing:**
Covers PIE/non-PIE/static executables, as well as various corner cases from the
spec like undefined weak references, COPY relocations and non-allocating sections.

**Not included:**
GOT/PLT signing, additional AUTH relocation types (future work).

**Notes:**
I changed the way *GNULDBackend::recordRelativeReloc* store relative relocations.
The original map is only iterated once (in a linear way), but reversing
the key / values allows to implement an efficient *GNULDBackend::findRelativeReloc*.

No changes to existing non-AUTH relocation behavior.

Signed-off-by: Cedric Tessier <ctessier@qti.qualcomm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Comments