Skip to content

Commit 8898a50

Browse files
MaskRaysujianIBM
authored andcommitted
[AArch64] Fix relative vtable PLT/GOTPCREL specifiers to use MCSpecifierExpr (llvm#184393)
PR llvm#155776 changed S_PLT/S_GOTPCREL printing to %pltpcrel(x)/%gotpcrel(x) syntax via MCSpecifierExpr, but lowerSymbolDifference and getIndirectSymViaGOTPCRel still created MCSymbolRefExpr with these specifiers, which prints via the @-specifier table as @PLT/@GOTPCREL, leading to incorrect relocation types. Fixes: bed8997 (AArch64: Replace @plt/%gotpcrel in data directives with %pltpcrel %gotpcrel (llvm#155776)) Add llvm/test/CodeGen/AArch64/dso_local_equivalent.ll
1 parent 3ff38e4 commit 8898a50

4 files changed

Lines changed: 56 additions & 19 deletions

File tree

‎llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using namespace dwarf;
2525
void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx,
2626
const TargetMachine &TM) {
2727
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
28-
PLTRelativeSpecifier = AArch64::S_PLT;
28+
PLTPCRelativeSpecifier = AArch64::S_PLT;
2929
SupportIndirectSymViaGOTPCRel = true;
3030

3131
// AARCH64 ELF ABI does not define static relocation type for TLS offset
@@ -59,11 +59,12 @@ void AArch64_ELFTargetObjectFile::emitPersonalityValueImpl(
5959
const MCExpr *AArch64_ELFTargetObjectFile::getIndirectSymViaGOTPCRel(
6060
const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV,
6161
int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const {
62-
int64_t FinalOffset = Offset + MV.getConstant();
63-
const MCExpr *Res =
64-
MCSymbolRefExpr::create(Sym, AArch64::S_GOTPCREL, getContext());
65-
const MCExpr *Off = MCConstantExpr::create(FinalOffset, getContext());
66-
return MCBinaryExpr::createAdd(Res, Off, getContext());
62+
auto &Ctx = getContext();
63+
const MCExpr *Res = MCSymbolRefExpr::create(Sym, Ctx);
64+
if (int64_t FinalOffset = Offset + MV.getConstant())
65+
Res = MCBinaryExpr::createAdd(Res, MCConstantExpr::create(FinalOffset, Ctx),
66+
Ctx);
67+
return MCSpecifierExpr::create(Res, AArch64::S_GOTPCREL, Ctx);
6768
}
6869

6970
AArch64_MachoTargetObjectFile::AArch64_MachoTargetObjectFile() {

‎llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCAsmInfo.cpp‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ const MCAsmInfo::AtSpecifier COFFAtSpecifiers[] = {
3838

3939
const MCAsmInfo::AtSpecifier ELFAtSpecifiers[] = {
4040
{AArch64::S_GOT, "GOT"},
41-
{AArch64::S_GOTPCREL, "GOTPCREL"},
42-
{AArch64::S_PLT, "PLT"},
43-
{AArch64::S_FUNCINIT, "FUNCINIT"},
4441
};
4542

4643
const MCAsmInfo::AtSpecifier MachOAtSpecifiers[] = {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
; RUN: llc -mtriple=aarch64 < %s | FileCheck %s --match-full-lines
2+
3+
declare void @extern_func()
4+
5+
; CHECK-LABEL: const:
6+
; CHECK-NEXT: .word %pltpcrel(extern_func)
7+
8+
@const = dso_local constant i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @extern_func to i64), i64 ptrtoint (ptr @const to i64)) to i32)
9+
10+
@_ZTV1B = dso_local constant { [7 x i32] } { [7 x i32] [
11+
i32 0,
12+
i32 0,
13+
i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @f0 to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [7 x i32] }, ptr @_ZTV1B, i32 0, i32 0, i32 2) to i64)) to i32),
14+
i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @f1 to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [7 x i32] }, ptr @_ZTV1B, i32 0, i32 0, i32 2) to i64)) to i32),
15+
i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @f2 to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [7 x i32] }, ptr @_ZTV1B, i32 0, i32 0, i32 2) to i64)) to i32),
16+
i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @f3 to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [7 x i32] }, ptr @_ZTV1B, i32 0, i32 0, i32 2) to i64)) to i32),
17+
i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @f4 to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [7 x i32] }, ptr @_ZTV1B, i32 0, i32 0, i32 2) to i64)) to i32)
18+
] }, align 4
19+
20+
; CHECK-LABEL: _ZTV1B:
21+
; CHECK-NEXT: .word 0 // 0x0
22+
; CHECK-NEXT: .word 0 // 0x0
23+
; CHECK-NEXT: .word %pltpcrel(f0)
24+
; CHECK-NEXT: .word %pltpcrel(f1+4)
25+
; CHECK-NEXT: .word %pltpcrel(f2+8)
26+
; CHECK-NEXT: .word %pltpcrel(f3+12)
27+
; CHECK-NEXT: .word %pltpcrel(f4+16)
28+
; CHECK-NEXT: .size _ZTV1B, 28
29+
declare void @f0()
30+
declare void @f1()
31+
define dso_local void @f2() {
32+
ret void
33+
}
34+
define void @f3() {
35+
ret void
36+
}
37+
define hidden void @f4() {
38+
ret void
39+
}

‎llvm/test/MC/ELF/rtti-proxy-gotpcrel.ll‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; REQUIRES: x86-registered-target && aarch64-registered-target && riscv-registered-target
22
; RUN: llc %s -mtriple=x86_64 -o - | FileCheck %s
3-
; RUN: llc %s -mtriple=aarch64 -o - | FileCheck %s
4-
; RUN: llc %s -mtriple=riscv64 -o - | FileCheck %s --check-prefix=RISCV
3+
; RUN: llc %s -mtriple=aarch64 -o - | FileCheck %s --check-prefix=SPECIFIER
4+
; RUN: llc %s -mtriple=riscv64 -o - | FileCheck %s --check-prefix=SPECIFIER
55

66
@vtable = dso_local unnamed_addr constant i32 trunc (i64 sub (i64 ptrtoint (ptr @rtti.proxy to i64), i64 ptrtoint (ptr @vtable to i64)) to i32), align 4
77
@vtable_with_offset = dso_local unnamed_addr constant [2 x i32] [i32 0, i32 trunc (i64 sub (i64 ptrtoint (ptr @rtti.proxy to i64), i64 ptrtoint (ptr @vtable_with_offset to i64)) to i32)], align 4
@@ -29,11 +29,11 @@
2929
; CHECK-NEXT: .{{word|long}} rtti@GOTPCREL-4{{$}}
3030
; CHECK-NEXT: .{{word|long}} 0
3131

32-
; RISCV-LABEL: vtable:
33-
; RISCV-NEXT: .word %gotpcrel(rtti+0)
34-
; RISCV-LABEL: vtable_with_offset:
35-
; RISCV-NEXT: .word 0
36-
; RISCV-NEXT: .word %gotpcrel(rtti+4)
37-
; RISCV-LABEL: vtable_with_negative_offset:
38-
; RISCV-NEXT: .word %gotpcrel(rtti-4)
39-
; RISCV-NEXT: .word 0
32+
; SPECIFIER-LABEL: vtable:
33+
; SPECIFIER-NEXT: .word %gotpcrel(rtti{{(\+0)?}})
34+
; SPECIFIER-LABEL: vtable_with_offset:
35+
; SPECIFIER-NEXT: .word 0
36+
; SPECIFIER-NEXT: .word %gotpcrel(rtti+4)
37+
; SPECIFIER-LABEL: vtable_with_negative_offset:
38+
; SPECIFIER-NEXT: .word %gotpcrel(rtti-4)
39+
; SPECIFIER-NEXT: .word 0

0 commit comments

Comments
 (0)