Skip to content

Commit ccc18ca

Browse files
committed
[RISCV] Move VK_GOTPCREL and VK_PLT to RISCVMCExpr::Specifier
to migrate away from the deprecated MCSymbolRefExpr::VariantKind. In the future, @GOTPCREL and @plt in data directives should be encoded as part of RISCVMCExpr instead of MCSymbolRefExpr.
1 parent 868c89f commit ccc18ca

File tree

8 files changed

+22
-12
lines changed

8 files changed

+22
-12
lines changed

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2343,7 +2343,7 @@ ParseStatus RISCVAsmParser::parsePseudoJumpSymbol(OperandVector &Operands) {
23432343
return ParseStatus::Failure;
23442344

23452345
if (Res->getKind() != MCExpr::ExprKind::SymbolRef ||
2346-
cast<MCSymbolRefExpr>(Res)->getKind() == MCSymbolRefExpr::VK_PLT)
2346+
getSpecifier(cast<MCSymbolRefExpr>(Res)) == RISCVMCExpr::VK_PLT)
23472347
return Error(S, "operand must be a valid jump target");
23482348

23492349
Res = RISCVMCExpr::create(Res, RISCVMCExpr::VK_CALL, getContext());

llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ bool RISCVAsmBackend::evaluateTargetFixup(const MCAssembler &Asm,
556556

557557
const MCSymbolRefExpr *A = AUIPCTarget.getSymA();
558558
const MCSymbolELF &SA = cast<MCSymbolELF>(A->getSymbol());
559-
if (A->getKind() != MCSymbolRefExpr::VK_None || SA.isUndefined())
559+
if (getSpecifier(A) != RISCVMCExpr::VK_None || SA.isUndefined())
560560
return false;
561561

562562
bool IsResolved = &SA.getSection() == AUIPCDF->getParent() &&

llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ unsigned RISCVELFObjectWriter::getRelocType(MCContext &Ctx,
7373
return ELF::R_RISCV_NONE;
7474
case FK_Data_4:
7575
case FK_PCRel_4:
76-
return Target.getAccessVariant() == MCSymbolRefExpr::VK_PLT
76+
return uint8_t(Target.getAccessVariant()) == RISCVMCExpr::VK_PLT
7777
? ELF::R_RISCV_PLT32
7878
: ELF::R_RISCV_32_PCREL;
7979
case RISCV::fixup_riscv_pcrel_hi20:
@@ -132,7 +132,7 @@ unsigned RISCVELFObjectWriter::getRelocType(MCContext &Ctx,
132132
if (Expr->getKind() == MCExpr::Target &&
133133
cast<RISCVMCExpr>(Expr)->getSpecifier() == RISCVMCExpr::VK_32_PCREL)
134134
return ELF::R_RISCV_32_PCREL;
135-
if (Target.getSymA()->getKind() == MCSymbolRefExpr::VK_GOTPCREL)
135+
if (getSpecifier(Target.getSymA()) == RISCVMCExpr::VK_GOTPCREL)
136136
return ELF::R_RISCV_GOT32_PCREL;
137137
return ELF::R_RISCV_32;
138138
case FK_Data_8:

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
using namespace llvm;
2020

2121
const MCAsmInfo::VariantKindDesc variantKindDescs[] = {
22-
{MCSymbolRefExpr::VK_GOTPCREL, "GOTPCREL"},
23-
{MCSymbolRefExpr::VK_PLT, "PLT"},
22+
{RISCVMCExpr::VK_GOTPCREL, "GOTPCREL"},
23+
{RISCVMCExpr::VK_PLT, "PLT"},
2424
};
2525

2626
void RISCVMCAsmInfo::anchor() {}

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,9 @@ uint64_t RISCVMCCodeEmitter::getImmOpValue(const MCInst &MI, unsigned OpNo,
478478
switch (RVExpr->getSpecifier()) {
479479
case RISCVMCExpr::VK_None:
480480
case RISCVMCExpr::VK_32_PCREL:
481-
llvm_unreachable("Unhandled fixup kind!");
481+
case RISCVMCExpr::VK_GOTPCREL:
482+
case RISCVMCExpr::VK_PLT:
483+
llvm_unreachable("unhandled specifier");
482484
case RISCVMCExpr::VK_TPREL_ADD:
483485
// tprel_add is only used to indicate that a relocation should be emitted
484486
// for an add instruction used in TP-relative addressing. It should not be
@@ -556,8 +558,8 @@ uint64_t RISCVMCCodeEmitter::getImmOpValue(const MCInst &MI, unsigned OpNo,
556558
break;
557559
}
558560
} else if ((Kind == MCExpr::SymbolRef &&
559-
cast<MCSymbolRefExpr>(Expr)->getKind() ==
560-
MCSymbolRefExpr::VK_None) ||
561+
getSpecifier(cast<MCSymbolRefExpr>(Expr)) ==
562+
RISCVMCExpr::VK_None) ||
561563
Kind == MCExpr::Binary) {
562564
// FIXME: Sub kind binary exprs have chance of underflow.
563565
if (MIFrm == RISCVII::InstFormatJ) {

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ RISCVMCExpr::getSpecifierForName(StringRef name) {
125125
StringRef RISCVMCExpr::getSpecifierName(Specifier S) {
126126
switch (S) {
127127
case VK_None:
128-
llvm_unreachable("Invalid ELF symbol kind");
128+
case VK_PLT:
129+
case VK_GOTPCREL:
130+
llvm_unreachable("not used as %specifier()");
129131
case VK_LO:
130132
return "lo";
131133
case VK_HI:

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class RISCVMCExpr : public MCTargetExpr {
3737
VK_CALL,
3838
VK_CALL_PLT,
3939
VK_32_PCREL,
40+
VK_GOTPCREL,
41+
VK_PLT,
4042
VK_TLSDESC_HI,
4143
VK_TLSDESC_LOAD_LO,
4244
VK_TLSDESC_ADD_LO,
@@ -85,6 +87,9 @@ class RISCVMCExpr : public MCTargetExpr {
8587
static StringRef getSpecifierName(Specifier Kind);
8688
};
8789

90+
static inline RISCVMCExpr::Specifier getSpecifier(const MCSymbolRefExpr *SRE) {
91+
return RISCVMCExpr::Specifier(SRE->getKind());
92+
}
8893
} // end namespace llvm.
8994

9095
#endif

llvm/lib/Target/RISCV/RISCVTargetObjectFile.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "RISCVTargetObjectFile.h"
10+
#include "MCTargetDesc/RISCVMCExpr.h"
1011
#include "MCTargetDesc/RISCVMCObjectFileInfo.h"
1112
#include "RISCVTargetMachine.h"
1213
#include "llvm/BinaryFormat/ELF.h"
@@ -26,7 +27,7 @@ void RISCVELFTargetObjectFile::Initialize(MCContext &Ctx,
2627
const TargetMachine &TM) {
2728
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
2829

29-
PLTRelativeSpecifier = MCSymbolRefExpr::VK_PLT;
30+
PLTRelativeSpecifier = RISCVMCExpr::VK_PLT;
3031
SupportIndirectSymViaGOTPCRel = true;
3132

3233
SmallDataSection = getContext().getELFSection(
@@ -50,7 +51,7 @@ const MCExpr *RISCVELFTargetObjectFile::getIndirectSymViaGOTPCRel(
5051
int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const {
5152
int64_t FinalOffset = Offset + MV.getConstant();
5253
const MCExpr *Res =
53-
MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOTPCREL, getContext());
54+
MCSymbolRefExpr::create(Sym, RISCVMCExpr::VK_GOTPCREL, getContext());
5455
const MCExpr *Off = MCConstantExpr::create(FinalOffset, getContext());
5556
return MCBinaryExpr::createAdd(Res, Off, getContext());
5657
}

0 commit comments

Comments
 (0)