[llvm][ELF][AArch64] Handle R_AARCH64_PLT32 relocation

This patch allows for usage of the @PLT modifier in AArch64 assembly which
lowers to an R_AARCH64_PLT32 relocation. See D81184 for handling this
relocation in lld.

Differential Revision: https://reviews.llvm.org/D81446
This commit is contained in:
Leonard Chan 2020-06-10 11:34:16 -07:00
parent 52cae05e08
commit 6adc664b9d
4 changed files with 29 additions and 3 deletions

View File

@ -399,6 +399,13 @@ void RuntimeDyldELF::resolveAArch64Relocation(const SectionEntry &Section,
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));
break;
}
case ELF::R_AARCH64_PREL32: {
uint64_t Result = Value + Addend - FinalAddress;
assert(static_cast<int64_t>(Result) >= INT32_MIN &&

View File

@ -18,6 +18,11 @@ class AArch64TargetMachine;
/// 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.

View File

@ -115,7 +115,8 @@ unsigned AArch64ELFObjectWriter::getRelocType(MCContext &Ctx,
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 @@ unsigned AArch64ELFObjectWriter::getRelocType(MCContext &Ctx,
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(),

View File

@ -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@PLT - this + 4
// CHECK: Section ({{.*}}) .rela.data
// CHECK-NEXT: 0x0 R_AARCH64_PLT32 extern_func 0x4
// CHECK-NEXT: }