[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:44:49 PST 2024


================
@@ -1141,12 +1142,37 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
         (rel == target->symbolicRel && !sym.isPreemptible)) {
       addRelativeReloc<true>(*sec, offset, sym, addend, expr, type);
       return;
-    } else if (rel != 0) {
+    }
+    if (rel != 0) {
       if (config->emachine == EM_MIPS && rel == target->symbolicRel)
         rel = target->relativeRel;
       std::lock_guard<std::mutex> lock(relocMutex);
-      sec->getPartition().relaDyn->addSymbolReloc(rel, *sec, offset, sym,
-                                                  addend, type);
+      Partition &part = sec->getPartition();
+      if (config->emachine == EM_AARCH64 && type == R_AARCH64_AUTH_ABS64) {
+        // For a preemptible symbol, we can't use a relative relocation. For an
+        // undefined symbol, we can't compute offset at link-time and use a
+        // relative relocation. Use a symbolic relocation instead.
+        if (sym.isPreemptible) {
+          part.relaDyn->addSymbolReloc(type, *sec, offset, sym, addend, type);
+        } else if (part.relrAuthDyn && sec->addralign >= 2 && offset % 2 == 0 &&
+                   isInt<32>(sym.getVA(addend))) {
+          // Implicit addend is below 32-bits so we can use the compressed
----------------
MaskRay wrote:

Since symbol values are all zeroes here, the condition is essentially `isInt<32>(addend)`.

Since most sections with an absolute relocation in the wild are aligned by at least 2. It seems that we should just remove the test here and unconditionally add relocations to part.relrAuthDyn->relocs and fix it in `finalizeAddressDependentContent`?

The comment can be shortened.
```
When symbol values are determined in finalizeAddressDependentContent, some relrAuthDyn relocations may be moved to relaDyn.
```

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


More information about the llvm-commits mailing list