Skip to content

Commit bfde4ef

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.6-beta.1
2 parents 8e7385a + 2504d84 commit bfde4ef

File tree

11 files changed

+71
-3
lines changed

11 files changed

+71
-3
lines changed

lld/ELF/Arch/AArch64.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ AArch64::AArch64(Ctx &ctx) : TargetInfo(ctx) {
114114
copyRel = R_AARCH64_COPY;
115115
relativeRel = R_AARCH64_RELATIVE;
116116
iRelativeRel = R_AARCH64_IRELATIVE;
117+
iRelSymbolicRel = R_AARCH64_FUNCINIT64;
117118
gotRel = R_AARCH64_GLOB_DAT;
118119
pltRel = R_AARCH64_JUMP_SLOT;
119120
symbolicRel = R_AARCH64_ABS64;
@@ -137,6 +138,7 @@ RelExpr AArch64::getRelExpr(RelType type, const Symbol &s,
137138
case R_AARCH64_ABS16:
138139
case R_AARCH64_ABS32:
139140
case R_AARCH64_ABS64:
141+
case R_AARCH64_FUNCINIT64:
140142
case R_AARCH64_ADD_ABS_LO12_NC:
141143
case R_AARCH64_LDST128_ABS_LO12_NC:
142144
case R_AARCH64_LDST16_ABS_LO12_NC:
@@ -267,7 +269,8 @@ bool AArch64::usesOnlyLowPageBits(RelType type) const {
267269
}
268270

269271
RelType AArch64::getDynRel(RelType type) const {
270-
if (type == R_AARCH64_ABS64 || type == R_AARCH64_AUTH_ABS64)
272+
if (type == R_AARCH64_ABS64 || type == R_AARCH64_AUTH_ABS64 ||
273+
type == R_AARCH64_FUNCINIT64)
271274
return type;
272275
return R_AARCH64_NONE;
273276
}

lld/ELF/Relocations.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,8 +989,8 @@ bool RelocationScanner::isStaticLinkTimeConstant(RelExpr e, RelType type,
989989
// only the low bits are used.
990990
if (e == R_GOT || e == R_PLT)
991991
return ctx.target->usesOnlyLowPageBits(type) || !ctx.arg.isPic;
992-
// R_AARCH64_AUTH_ABS64 requires a dynamic relocation.
993-
if (e == RE_AARCH64_AUTH)
992+
// R_AARCH64_AUTH_ABS64 and iRelSymbolicRel require a dynamic relocation.
993+
if (e == RE_AARCH64_AUTH || type == ctx.target->iRelSymbolicRel)
994994
return false;
995995

996996
// The behavior of an undefined weak reference is implementation defined.
@@ -1163,6 +1163,23 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
11631163
}
11641164
return;
11651165
}
1166+
if (LLVM_UNLIKELY(type == ctx.target->iRelSymbolicRel)) {
1167+
if (sym.isPreemptible) {
1168+
auto diag = Err(ctx);
1169+
diag << "relocation " << type
1170+
<< " cannot be used against preemptible symbol '" << &sym << "'";
1171+
printLocation(diag, *sec, sym, offset);
1172+
} else if (isIfunc) {
1173+
auto diag = Err(ctx);
1174+
diag << "relocation " << type
1175+
<< " cannot be used against ifunc symbol '" << &sym << "'";
1176+
printLocation(diag, *sec, sym, offset);
1177+
} else {
1178+
part.relaDyn->addReloc({ctx.target->iRelativeRel, sec, offset, false,
1179+
sym, addend, R_ABS});
1180+
return;
1181+
}
1182+
}
11661183
part.relaDyn->addSymbolReloc(rel, *sec, offset, sym, addend, type);
11671184

11681185
// MIPS ABI turns using of GOT and dynamic relocations inside out.

lld/ELF/Target.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class TargetInfo {
134134
RelType relativeRel = 0;
135135
RelType iRelativeRel = 0;
136136
RelType symbolicRel = 0;
137+
RelType iRelSymbolicRel = 0;
137138
RelType tlsDescRel = 0;
138139
RelType tlsGotRel = 0;
139140
RelType tlsModuleIndexRel = 0;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# REQUIRES: aarch64
2+
3+
# RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o
4+
# RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck --check-prefix=ERR %s
5+
6+
.rodata
7+
# ERR: error: relocation R_AARCH64_FUNCINIT64 cannot be used against local symbol
8+
.8byte func@FUNCINIT
9+
10+
.data
11+
# ERR: error: relocation R_AARCH64_FUNCINIT64 cannot be used against ifunc symbol 'ifunc'
12+
.8byte ifunc@FUNCINIT
13+
14+
.text
15+
func:
16+
.type ifunc, @gnu_indirect_function
17+
ifunc:
18+
ret

lld/test/ELF/aarch64-funcinit64.s

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# REQUIRES: aarch64
2+
3+
# RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o
4+
# RUN: ld.lld %t.o -o %t
5+
# RUN: llvm-readelf -s -r %t | FileCheck %s
6+
# RUN: ld.lld %t.o -o %t -pie
7+
# RUN: llvm-readelf -s -r %t | FileCheck %s
8+
# RUN: not ld.lld %t.o -o %t -shared 2>&1 | FileCheck --check-prefix=ERR %s
9+
10+
.data
11+
# CHECK: R_AARCH64_IRELATIVE [[FOO:[0-9a-f]*]]
12+
# ERR: relocation R_AARCH64_FUNCINIT64 cannot be used against preemptible symbol 'foo'
13+
.8byte foo@FUNCINIT
14+
15+
.text
16+
# CHECK: {{0*}}[[FOO]] {{.*}} foo
17+
.globl foo
18+
foo:
19+
ret

llvm/include/llvm/BinaryFormat/ELFRelocs/AArch64.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ ELF_RELOC(R_AARCH64_LD64_GOTPAGE_LO15, 0x139)
6262
ELF_RELOC(R_AARCH64_PLT32, 0x13a)
6363
ELF_RELOC(R_AARCH64_GOTPCREL32, 0x13b)
6464
ELF_RELOC(R_AARCH64_PATCHINST, 0x13c)
65+
ELF_RELOC(R_AARCH64_FUNCINIT64, 0x13d)
6566
// General dynamic TLS relocations
6667
ELF_RELOC(R_AARCH64_TLSGD_ADR_PREL21, 0x200)
6768
ELF_RELOC(R_AARCH64_TLSGD_ADR_PAGE21, 0x201)

llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8217,6 +8217,8 @@ bool AArch64AsmParser::parseDataExpr(const MCExpr *&Res) {
82178217
Spec = AArch64::S_GOTPCREL;
82188218
else if (Identifier == "plt")
82198219
Spec = AArch64::S_PLT;
8220+
else if (Identifier == "funcinit")
8221+
Spec = AArch64::S_FUNCINIT;
82208222
}
82218223
if (Spec == AArch64::S_None)
82228224
return Error(Loc, "invalid relocation specifier");

llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ unsigned AArch64ELFObjectWriter::getRelocType(const MCFixup &Fixup,
232232
}
233233
if (RefKind == AArch64::S_AUTH || RefKind == AArch64::S_AUTHADDR)
234234
return ELF::R_AARCH64_AUTH_ABS64;
235+
if (RefKind == AArch64::S_FUNCINIT)
236+
return ELF::R_AARCH64_FUNCINIT64;
235237
return ELF::R_AARCH64_ABS64;
236238
}
237239
case AArch64::fixup_aarch64_add_imm12:

llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCAsmInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const MCAsmInfo::AtSpecifier ELFAtSpecifiers[] = {
4040
{AArch64::S_GOT, "GOT"},
4141
{AArch64::S_GOTPCREL, "GOTPCREL"},
4242
{AArch64::S_PLT, "PLT"},
43+
{AArch64::S_FUNCINIT, "FUNCINIT"},
4344
};
4445

4546
const MCAsmInfo::AtSpecifier MachOAtSpecifiers[] = {

llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCAsmInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ enum {
164164
// ELF relocation specifiers in data directives:
165165
S_PLT = 0x400,
166166
S_GOTPCREL,
167+
S_FUNCINIT,
167168

168169
// Mach-O @ relocation specifiers:
169170
S_MACHO_GOT,

0 commit comments

Comments
 (0)