[lld] [ELF] Include sharded relocations in RelocationBaseSection::getSize (PR #173285)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 22 09:08:45 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lld-elf
Author: Jessica Clarke (jrtc27)
<details>
<summary>Changes</summary>
Although mergeRels is called prior to using this size for final layout,
Writer::setReservedSymbolSections uses this in order to set the value of
__rel[a]_iplt_end and, downstream in Morello LLVM, __rel[a]_dyn_end.
Currently none of the relocations that can exist when static linking (as
the case when these symbols are defined) are sharded, but a future
commit will change this for R_AARCH64_AUTH_RELATIVE, and similarly
R_MORELLO_RELATIVE is sharded downstream in Morello LLVM. Make sure we
compute the right size when called prior to mergeRels, and add a
regression test to demonstrate that R_AARCH64_AUTH_RELATIVE still gets
the right __rel[a]_ipt_end in future even when sharding is adopted.
---
Full diff: https://github.com/llvm/llvm-project/pull/173285.diff
2 Files Affected:
- (modified) lld/ELF/SyntheticSections.h (+6-1)
- (added) lld/test/ELF/aarch64-pauth-rela-iplt-end.s (+20)
``````````diff
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 16bdda8ef75bb..47d87e76357f3 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -528,7 +528,12 @@ class RelocationBaseSection : public SyntheticSection {
return !relocs.empty() ||
llvm::any_of(relocsVec, [](auto &v) { return !v.empty(); });
}
- size_t getSize() const override { return relocs.size() * this->entsize; }
+ size_t getSize() const override {
+ size_t count = relocs.size();
+ for (const auto &v : relocsVec)
+ count += v.size();
+ return count * this->entsize;
+ }
size_t getRelativeRelocCount() const { return numRelativeRelocs; }
void mergeRels();
void partitionRels();
diff --git a/lld/test/ELF/aarch64-pauth-rela-iplt-end.s b/lld/test/ELF/aarch64-pauth-rela-iplt-end.s
new file mode 100644
index 0000000000000..b2c7fe0c61c99
--- /dev/null
+++ b/lld/test/ELF/aarch64-pauth-rela-iplt-end.s
@@ -0,0 +1,20 @@
+# REQUIRES: aarch64
+# RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o
+# RUN: ld.lld --static %t.o -o %t
+# RUN: llvm-readelf -S -s -d %t | FileCheck %s
+
+## Verify that R_AARCH64_AUTH_RELATIVE relocations are included within the
+## bounds of __rela_iplt_start/end, as relative relocations still emitted for
+## static PDEs due to needing run-time signing. Historically this would not be
+## the case if added to .rela.dyn with sharding.
+
+# CHECK: .rela.dyn RELA 0000000000200158 000158 000018 18 A 0 0 8
+# CHECK: 0000000000200158 0 NOTYPE LOCAL HIDDEN 1 __rela_iplt_start
+# CHECK: 0000000000200170 0 NOTYPE LOCAL HIDDEN 1 __rela_iplt_end
+
+adrp x0, __rela_iplt_start
+adrp x0, __rela_iplt_end
+
+.data
+foo:
+.quad foo at AUTH(da,42)
``````````
</details>
https://github.com/llvm/llvm-project/pull/173285
More information about the llvm-commits
mailing list