Skip to content

Commit a922731

Browse files
committed
MC: Introduce R_AARCH64_PATCHINST relocation type.
The R_AARCH64_PATCHINST relocation type is to support deactivation symbols. For more information, see the RFC: https://discourse.llvm.org/t/rfc-deactivation-symbols/85556 Part of the AArch64 psABI extension: ARM-software/abi-aa#340
1 parent e0f5e28 commit a922731

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ ELF_RELOC(R_AARCH64_LD64_GOT_LO12_NC, 0x138)
6161
ELF_RELOC(R_AARCH64_LD64_GOTPAGE_LO15, 0x139)
6262
ELF_RELOC(R_AARCH64_PLT32, 0x13a)
6363
ELF_RELOC(R_AARCH64_GOTPCREL32, 0x13b)
64+
ELF_RELOC(R_AARCH64_PATCHINST, 0x13c)
6465
// General dynamic TLS relocations
6566
ELF_RELOC(R_AARCH64_TLSGD_ADR_PREL21, 0x200)
6667
ELF_RELOC(R_AARCH64_TLSGD_ADR_PAGE21, 0x201)

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class AArch64ELFObjectWriter : public MCELFObjectTargetWriter {
4040
bool IsPCRel) const override;
4141
bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
4242
bool isNonILP32reloc(const MCFixup &Fixup, AArch64::Specifier RefKind) const;
43+
void sortRelocs(std::vector<ELFRelocationEntry> &Relocs) override;
4344

4445
bool IsILP32;
4546
};
@@ -498,6 +499,17 @@ bool AArch64ELFObjectWriter::needsRelocateWithSymbol(const MCValue &Val,
498499
Val.getSpecifier());
499500
}
500501

502+
void AArch64ELFObjectWriter::sortRelocs(
503+
std::vector<ELFRelocationEntry> &Relocs) {
504+
// PATCHINST relocations should be applied last because they may overwrite the
505+
// whole instruction and so should take precedence over other relocations that
506+
// modify operands of the original instruction.
507+
std::stable_partition(Relocs.begin(), Relocs.end(),
508+
[](const ELFRelocationEntry &R) {
509+
return R.Type != ELF::R_AARCH64_PATCHINST;
510+
});
511+
}
512+
501513
std::unique_ptr<MCObjectTargetWriter>
502514
llvm::createAArch64ELFObjectWriter(uint8_t OSABI, bool IsILP32) {
503515
return std::make_unique<AArch64ELFObjectWriter>(OSABI, IsILP32);

llvm/test/MC/AArch64/patchinst.s

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: llvm-mc -triple aarch64-elf -filetype=obj %s -o - | llvm-objdump -r - | FileCheck %s
2+
3+
// Test that PATCHINST appears after JUMP26.
4+
// CHECK: R_AARCH64_JUMP26
5+
// CHECK-NEXT: R_AARCH64_PATCHINST
6+
.reloc ., R_AARCH64_PATCHINST, ds
7+
b f1

llvm/test/tools/llvm-readobj/ELF/reloc-types-aarch64.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
# CHECK: Type: R_AARCH64_LD64_GOT_LO12_NC (312)
5858
# CHECK: Type: R_AARCH64_LD64_GOTPAGE_LO15 (313)
5959
# CHECK: Type: R_AARCH64_PLT32 (314)
60+
# CHECK: Type: R_AARCH64_PATCHINST (316)
6061
# CHECK: Type: R_AARCH64_TLSGD_ADR_PREL21 (512)
6162
# CHECK: Type: R_AARCH64_TLSGD_ADR_PAGE21 (513)
6263
# CHECK: Type: R_AARCH64_TLSGD_ADD_LO12_NC (514)
@@ -214,6 +215,7 @@ Sections:
214215
- Type: R_AARCH64_LD64_GOT_LO12_NC
215216
- Type: R_AARCH64_LD64_GOTPAGE_LO15
216217
- Type: R_AARCH64_PLT32
218+
- Type: R_AARCH64_PATCHINST
217219
- Type: R_AARCH64_TLSGD_ADR_PREL21
218220
- Type: R_AARCH64_TLSGD_ADR_PAGE21
219221
- Type: R_AARCH64_TLSGD_ADD_LO12_NC

0 commit comments

Comments
 (0)