[PATCH] D81446: [llvm][ELF][AArch64] Handle R_AARCH64_PLT32 relocation
Leonard Chan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 8 19:55:46 PDT 2020
leonardchan created this revision.
leonardchan added reviewers: espindola, MaskRay, psmith, mcgrathr, pcc.
leonardchan added a project: LLVM.
Herald added subscribers: danielkiss, phosek, hiraditya, kristof.beyls.
This patch allows for usage of the `@PLT` modifier in AArch64 assembly which lowers to an `R_AARCH64_PLT32` relocation. See D81184 <https://reviews.llvm.org/D81184> for handling this relocation in lld.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D81446
Files:
llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
llvm/lib/Target/AArch64/AArch64TargetObjectFile.h
llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
llvm/test/MC/AArch64/elf-reloc-plt32.s
Index: llvm/test/MC/AArch64/elf-reloc-plt32.s
===================================================================
--- /dev/null
+++ llvm/test/MC/AArch64/elf-reloc-plt32.s
@@ -0,0 +1,10 @@
+// RUN: llvm-mc -triple=aarch64-none-fuchsia -filetype=obj %s -o - | \
+// RUN: llvm-readobj -r | FileCheck %s
+
+ .section .data
+this:
+ .word extern_func at PLT - this + 4
+
+// CHECK: Relocations
+// CHECK: Section (4) .rela.data
+// CHECK-NEXT: 0x0 R_AARCH64_PLT32 extern_func 0x4
Index: llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
===================================================================
--- llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
+++ llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
@@ -115,7 +115,8 @@
bool IsNC = AArch64MCExpr::isNotChecked(RefKind);
assert((!Target.getSymA() ||
- Target.getSymA()->getKind() == MCSymbolRefExpr::VK_None) &&
+ Target.getSymA()->getKind() == MCSymbolRefExpr::VK_None ||
+ Target.getSymA()->getKind() == MCSymbolRefExpr::VK_PLT) &&
"Should only be expression-level modifiers here");
assert((!Target.getSymB() ||
@@ -129,8 +130,11 @@
return ELF::R_AARCH64_NONE;
case FK_Data_2:
return R_CLS(PREL16);
- case FK_Data_4:
- return R_CLS(PREL32);
+ case FK_Data_4: {
+ return Target.getAccessVariant() == MCSymbolRefExpr::VK_PLT
+ ? R_CLS(PLT32)
+ : R_CLS(PREL32);
+ }
case FK_Data_8:
if (IsILP32) {
Ctx.reportError(Fixup.getLoc(),
Index: llvm/lib/Target/AArch64/AArch64TargetObjectFile.h
===================================================================
--- llvm/lib/Target/AArch64/AArch64TargetObjectFile.h
+++ llvm/lib/Target/AArch64/AArch64TargetObjectFile.h
@@ -18,6 +18,11 @@
/// This implementation is used for AArch64 ELF targets (Linux in particular).
class AArch64_ELFTargetObjectFile : public TargetLoweringObjectFileELF {
void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
+
+public:
+ AArch64_ELFTargetObjectFile() {
+ PLTRelativeVariantKind = MCSymbolRefExpr::VK_PLT;
+ }
};
/// AArch64_MachoTargetObjectFile - This TLOF implementation is used for Darwin.
Index: llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
===================================================================
--- llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
+++ llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
@@ -399,6 +399,7 @@
case ELF::R_AARCH64_ABS64:
write(isBE, TargetPtr, Value + Addend);
break;
+ case ELF::R_AARCH64_PLT32:
case ELF::R_AARCH64_PREL32: {
uint64_t Result = Value + Addend - FinalAddress;
assert(static_cast<int64_t>(Result) >= INT32_MIN &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81446.269404.patch
Type: text/x-patch
Size: 2799 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200609/02d4b8ce/attachment.bin>
More information about the llvm-commits
mailing list