[PATCH] D81446: [llvm][ELF][AArch64] Handle R_AARCH64_PLT32 relocation
Leonard Chan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 9 14:21:31 PDT 2020
leonardchan updated this revision to Diff 269656.
leonardchan marked 6 inline comments as done.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D81446/new/
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 -filetype=obj %s -o - | \
+// RUN: llvm-readobj -r | FileCheck %s
+
+ .section .data
+this:
+ .word extern_func at PLT - this + 4
+
+// CHECK: Section ({{.*}}) .rela.data
+// CHECK-NEXT: 0x0 R_AARCH64_PLT32 extern_func 0x4
+// CHECK-NEXT: }
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,13 @@
case ELF::R_AARCH64_ABS64:
write(isBE, TargetPtr, Value + Addend);
break;
+ case ELF::R_AARCH64_PLT32: {
+ uint64_t Result = Value + Addend - FinalAddress;
+ assert(static_cast<int64_t>(Result) >= INT32_MIN &&
+ static_cast<int64_t>(Result) <= INT32_MAX);
+ write(isBE, TargetPtr, static_cast<uint32_t>(Result & 0xffffffffU));
+ break;
+ }
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.269656.patch
Type: text/x-patch
Size: 3036 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200609/fce28f1b/attachment.bin>
More information about the llvm-commits
mailing list