[llvm-branch-commits] [lld] MC: Introduce R_AARCH64_FUNCINIT64 relocation type. (PR #133531)
Peter Collingbourne via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Oct 9 14:43:42 PDT 2025
https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133531
>From 96e7da9a083888683c2ba00d97f886fd748ea10b Mon Sep 17 00:00:00 2001
From: Peter Collingbourne <pcc at google.com>
Date: Wed, 9 Apr 2025 20:30:57 -0700
Subject: [PATCH 1/3] Undo unnecessary change
Created using spr 1.3.6-beta.1
---
lld/ELF/SyntheticSections.cpp | 2 +-
lld/ELF/SyntheticSections.h | 2 +-
lld/ELF/Writer.cpp | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 8cab71c4c8d94..106749e90a82b 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1696,7 +1696,7 @@ void RelocationBaseSection::addAddendOnlyRelocIfNonPreemptible(
sym, 0, R_ABS, addendRelType);
}
-void RelocationBaseSection::mergeRels(Ctx &ctx) {
+void RelocationBaseSection::mergeRels() {
size_t newSize = relocs.size();
for (const auto &v : relocsVec)
newSize += v.size();
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 7a85906e8601d..2dd4b80eb85bf 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -553,7 +553,7 @@ class RelocationBaseSection : public SyntheticSection {
}
size_t getSize() const override { return relocs.size() * this->entsize; }
size_t getRelativeRelocCount() const { return numRelativeRelocs; }
- void mergeRels(Ctx &ctx);
+ void mergeRels();
void partitionRels();
void finalizeContents() override;
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 67004055f1af5..28b24f90716b8 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -2076,7 +2076,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
// symbol table section (dynSymTab) must be the first one.
for (Partition &part : ctx.partitions) {
if (part.relaDyn) {
- part.relaDyn->mergeRels(ctx);
+ part.relaDyn->mergeRels();
// Compute DT_RELACOUNT to be used by part.dynamic.
part.relaDyn->partitionRels();
finalizeSynthetic(ctx, part.relaDyn.get());
>From b33113cee03cd0b68b7e8c7e98bfa56dfbe02a46 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne <pcc at google.com>
Date: Fri, 1 Aug 2025 14:03:45 -0700
Subject: [PATCH 2/3] Fix build
Created using spr 1.3.6-beta.1
---
lld/ELF/Relocations.cpp | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 2573cf5c9fbbf..e2f594f3d2bba 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -1175,9 +1175,8 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
<< " cannot be used against ifunc symbol '" << &sym << "'";
printLocation(diag, *sec, sym, offset);
} else {
- part.relaDyn->addReloc({ctx.target->iRelativeRel, sec, offset,
- DynamicReloc::AddendOnlyWithTargetVA, sym,
- addend, R_ABS});
+ part.relaDyn->addReloc({ctx.target->iRelativeRel, sec, offset, false,
+ sym, addend, R_ABS});
return;
}
}
>From 1137b9ee88a6378cafeedb78db22d79b306b7240 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne <pcc at google.com>
Date: Tue, 2 Sep 2025 18:27:33 -0700
Subject: [PATCH 3/3] Split out lld changes
Created using spr 1.3.6-beta.1
---
lld/ELF/Arch/AArch64.cpp | 5 +----
lld/ELF/Relocations.cpp | 21 ++-------------------
lld/ELF/Target.h | 1 -
lld/test/ELF/aarch64-funcinit64-invalid.s | 18 ------------------
lld/test/ELF/aarch64-funcinit64.s | 19 -------------------
5 files changed, 3 insertions(+), 61 deletions(-)
delete mode 100644 lld/test/ELF/aarch64-funcinit64-invalid.s
delete mode 100644 lld/test/ELF/aarch64-funcinit64.s
diff --git a/lld/ELF/Arch/AArch64.cpp b/lld/ELF/Arch/AArch64.cpp
index ff13773aee5d4..27e77e943c197 100644
--- a/lld/ELF/Arch/AArch64.cpp
+++ b/lld/ELF/Arch/AArch64.cpp
@@ -114,7 +114,6 @@ AArch64::AArch64(Ctx &ctx) : TargetInfo(ctx) {
copyRel = R_AARCH64_COPY;
relativeRel = R_AARCH64_RELATIVE;
iRelativeRel = R_AARCH64_IRELATIVE;
- iRelSymbolicRel = R_AARCH64_FUNCINIT64;
gotRel = R_AARCH64_GLOB_DAT;
pltRel = R_AARCH64_JUMP_SLOT;
symbolicRel = R_AARCH64_ABS64;
@@ -138,7 +137,6 @@ RelExpr AArch64::getRelExpr(RelType type, const Symbol &s,
case R_AARCH64_ABS16:
case R_AARCH64_ABS32:
case R_AARCH64_ABS64:
- case R_AARCH64_FUNCINIT64:
case R_AARCH64_ADD_ABS_LO12_NC:
case R_AARCH64_LDST128_ABS_LO12_NC:
case R_AARCH64_LDST16_ABS_LO12_NC:
@@ -269,8 +267,7 @@ bool AArch64::usesOnlyLowPageBits(RelType type) const {
}
RelType AArch64::getDynRel(RelType type) const {
- if (type == R_AARCH64_ABS64 || type == R_AARCH64_AUTH_ABS64 ||
- type == R_AARCH64_FUNCINIT64)
+ if (type == R_AARCH64_ABS64 || type == R_AARCH64_AUTH_ABS64)
return type;
return R_AARCH64_NONE;
}
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index bf7c2fd6ce8ef..6f55bac2ecf16 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -989,8 +989,8 @@ bool RelocationScanner::isStaticLinkTimeConstant(RelExpr e, RelType type,
// only the low bits are used.
if (e == R_GOT || e == R_PLT)
return ctx.target->usesOnlyLowPageBits(type) || !ctx.arg.isPic;
- // R_AARCH64_AUTH_ABS64 and iRelSymbolicRel require a dynamic relocation.
- if (e == RE_AARCH64_AUTH || type == ctx.target->iRelSymbolicRel)
+ // R_AARCH64_AUTH_ABS64 requires a dynamic relocation.
+ if (e == RE_AARCH64_AUTH)
return false;
// The behavior of an undefined weak reference is implementation defined.
@@ -1163,23 +1163,6 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
}
return;
}
- if (LLVM_UNLIKELY(type == ctx.target->iRelSymbolicRel)) {
- if (sym.isPreemptible) {
- auto diag = Err(ctx);
- diag << "relocation " << type
- << " cannot be used against preemptible symbol '" << &sym << "'";
- printLocation(diag, *sec, sym, offset);
- } else if (isIfunc) {
- auto diag = Err(ctx);
- diag << "relocation " << type
- << " cannot be used against ifunc symbol '" << &sym << "'";
- printLocation(diag, *sec, sym, offset);
- } else {
- part.relaDyn->addReloc({ctx.target->iRelativeRel, sec, offset, false,
- sym, addend, R_ABS});
- return;
- }
- }
part.relaDyn->addSymbolReloc(rel, *sec, offset, sym, addend, type);
// MIPS ABI turns using of GOT and dynamic relocations inside out.
diff --git a/lld/ELF/Target.h b/lld/ELF/Target.h
index 58393e7afa20f..e121fa1183e9e 100644
--- a/lld/ELF/Target.h
+++ b/lld/ELF/Target.h
@@ -134,7 +134,6 @@ class TargetInfo {
RelType relativeRel = 0;
RelType iRelativeRel = 0;
RelType symbolicRel = 0;
- RelType iRelSymbolicRel = 0;
RelType tlsDescRel = 0;
RelType tlsGotRel = 0;
RelType tlsModuleIndexRel = 0;
diff --git a/lld/test/ELF/aarch64-funcinit64-invalid.s b/lld/test/ELF/aarch64-funcinit64-invalid.s
deleted file mode 100644
index 2507c07056783..0000000000000
--- a/lld/test/ELF/aarch64-funcinit64-invalid.s
+++ /dev/null
@@ -1,18 +0,0 @@
-# REQUIRES: aarch64
-
-# RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o
-# RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck --check-prefix=ERR %s
-
-.rodata
-# ERR: relocation R_AARCH64_FUNCINIT64 cannot be used against local symbol
-.8byte func at FUNCINIT
-
-.data
-# ERR: relocation R_AARCH64_FUNCINIT64 cannot be used against ifunc symbol 'ifunc'
-.8byte ifunc at FUNCINIT
-
-.text
-func:
-.type ifunc, @gnu_indirect_function
-ifunc:
-ret
diff --git a/lld/test/ELF/aarch64-funcinit64.s b/lld/test/ELF/aarch64-funcinit64.s
deleted file mode 100644
index 5f2b863ee884b..0000000000000
--- a/lld/test/ELF/aarch64-funcinit64.s
+++ /dev/null
@@ -1,19 +0,0 @@
-# REQUIRES: aarch64
-
-# RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o
-# RUN: ld.lld %t.o -o %t
-# RUN: llvm-readelf -s -r %t | FileCheck %s
-# RUN: ld.lld %t.o -o %t -pie
-# RUN: llvm-readelf -s -r %t | FileCheck %s
-# RUN: not ld.lld %t.o -o %t -shared 2>&1 | FileCheck --check-prefix=ERR %s
-
-.data
-# CHECK: R_AARCH64_IRELATIVE [[FOO:[0-9a-f]*]]
-# ERR: relocation R_AARCH64_FUNCINIT64 cannot be used against preemptible symbol 'foo'
-.8byte foo at FUNCINIT
-
-.text
-# CHECK: {{0*}}[[FOO]] {{.*}} foo
-.globl foo
-foo:
-ret
More information about the llvm-branch-commits
mailing list