[lld] [lld][AArch64][ELF][PAC] Support AUTH relocations and AUTH ELF marking (PR #72714)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 7 21:11:45 PST 2024


================
@@ -1734,9 +1742,34 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
       in.mipsGot->updateAllocSize();
 
     for (Partition &part : partitions) {
+      // We've put relocations in relrAuthDyn during
+      // RelocationScanner::processAux, but the target VA for some of them might
+      // be wider than 32 bits which does not fit the place for implicit value
+      // of relr AUTH reloc. We can only know the final VA at this point, so
+      // move relocations with large values from relr to rela.
+      if (part.relrAuthDyn) {
+        for (auto it = part.relrAuthDyn->relocs.begin();
+             it != part.relrAuthDyn->relocs.end();) {
+          if (isInt<32>(it->reloc->sym->getVA(it->reloc->addend))) {
+            ++it;
+            continue;
+          }
+          part.relaDyn->addReloc({R_AARCH64_AUTH_RELATIVE, it->inputSec,
+                                  it->reloc->offset,
+                                  DynamicReloc::AddendOnlyWithTargetVA,
+                                  *it->reloc->sym, it->reloc->addend, R_ABS});
+          part.relrAuthDyn->relocs.erase(it);
----------------
MaskRay wrote:

Each erase is linear. We should implement an in-place filter algorithm here.

https://github.com/llvm/llvm-project/pull/72714


More information about the llvm-commits mailing list