Skip to content

Commit 4e3b7df

Browse files
authored
MC: Introduce R_AARCH64_FUNCINIT64 relocation type.
R_AARCH64_FUNCINIT64 is a dynamic relocation type for relocating word-sized data in the output file using the return value of a function. An R_AARCH64_FUNCINIT64 shall be relocated as an R_AARCH64_IRELATIVE with the target symbol address if the target symbol is non-preemptible, and it shall be a usage error to relocate an R_AARCH64_FUNCINIT64 with a preemptible or STT_GNU_IFUNC target symbol. The initial use case for this relocation type shall be for emitting global variable field initializers for structure protection. With structure protection, the relocation value computation is tied to the compiler implementation in such a way that it would not be reasonable to define a relocation type for it (for example, it may involve computing a hash using a compiler-determined algorithm), hence the need for the computation to be implemented as code in the binary. Part of the AArch64 psABI extension: ARM-software/abi-aa#340 Reviewers: smithp35 Reviewed By: smithp35 Pull Request: #133531
1 parent f5ca0bc commit 4e3b7df

File tree

6 files changed

+10
-0
lines changed

6 files changed

+10
-0
lines changed

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,

llvm/test/MC/AArch64/data-directive-specifier.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ l:
1212
# CHECK-NEXT: 0x8 R_AARCH64_PLT32 extern 0x4
1313
# CHECK-NEXT: 0xC R_AARCH64_PLT32 g 0x8
1414
# CHECK-NEXT: 0x10 R_AARCH64_PLT32 g 0x18
15+
# CHECK-NEXT: 0x14 R_AARCH64_FUNCINIT64 .text 0x0
1516
# CHECK-NEXT: }
1617
.data
1718
.word l@plt - .
@@ -21,6 +22,8 @@ l:
2122
.word g@plt - . + 8
2223
.word g@plt - .data + 8
2324

25+
.quad l@funcinit
26+
2427
# CHECK: Section ({{.*}}) .rela.data1 {
2528
# CHECK-NEXT: 0x0 R_AARCH64_GOTPCREL32 data1 0x0
2629
# CHECK-NEXT: 0x4 R_AARCH64_GOTPCREL32 extern 0x4

0 commit comments

Comments
 (0)