[lld] [lld][AArch64][ELF][PAC] Support AUTH relocations and AUTH ELF marking (PR #72714)
Daniil Kovalev via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 8 02:49:55 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
----------------
kovdan01 wrote:
I deleted the check against 32 bits since we anyway need to re-check that in `finalizeAddressDependentContent`. See b215b0d60ac0c2ac29aeb318da7c95725be6ef86
Regarding this:
> It seems that we should just remove the test here and unconditionally add relocations to part.relrAuthDyn->relocs and do the fixup in `finalizeAddressDependentContent`
I don't think so. We anyway must keep the check against `part.relrAuthDyn` since it might be `nullptr`, so, even if checks `sec->addralign >= 2 && offset % 2 == 0` go to `finalizeAddressDependentContent`, both `else if` and `else` branches here will still be present and the `processAux` won't become significantly more simple. It looks like that we'd better leave `else if (part.relrAuthDyn && sec->addralign >= 2 && offset % 2 == 0)` here just like we have for regular relr relocs in `addRelativeReloc`. It would keep things consistent and we'll only have a single check against 32 bits in `finalizeAddressDependentContent`, while checks `sec->addralign >= 2 && offset % 2 == 0` suite better here in `processAux`. Please let me know if I miss something.
https://github.com/llvm/llvm-project/pull/72714
More information about the llvm-commits
mailing list