Skip to content

Commit e87f33d

Browse files
authored
[RISCV][MC] Pass MCSubtargetInfo down to shouldForceRelocation and evaluateTargetFixup. (llvm#73721)
Instead of using the STI stored in RISCVAsmBackend, try to get it from the MCFragment. This addresses the issue raised here https://discourse.llvm.org/t/possible-problem-related-to-subtarget-usage/75283
1 parent ab4d6cd commit e87f33d

File tree

22 files changed

+75
-46
lines changed

22 files changed

+75
-46
lines changed

llvm/include/llvm/MC/MCAsmBackend.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ class MCAsmBackend {
101101
/// Hook to check if a relocation is needed for some target specific reason.
102102
virtual bool shouldForceRelocation(const MCAssembler &Asm,
103103
const MCFixup &Fixup,
104-
const MCValue &Target) {
104+
const MCValue &Target,
105+
const MCSubtargetInfo *STI) {
105106
return false;
106107
}
107108

@@ -124,7 +125,8 @@ class MCAsmBackend {
124125
virtual bool evaluateTargetFixup(const MCAssembler &Asm,
125126
const MCAsmLayout &Layout,
126127
const MCFixup &Fixup, const MCFragment *DF,
127-
const MCValue &Target, uint64_t &Value,
128+
const MCValue &Target,
129+
const MCSubtargetInfo *STI, uint64_t &Value,
128130
bool &WasForced) {
129131
llvm_unreachable("Need to implement hook if target has custom fixups");
130132
}

llvm/include/llvm/MC/MCAssembler.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ class MCAssembler {
185185
/// relocation.
186186
bool evaluateFixup(const MCAsmLayout &Layout, const MCFixup &Fixup,
187187
const MCFragment *DF, MCValue &Target,
188-
uint64_t &Value, bool &WasForced) const;
188+
const MCSubtargetInfo *STI, uint64_t &Value,
189+
bool &WasForced) const;
189190

190191
/// Check whether a fixup can be satisfied, or whether it needs to be relaxed
191192
/// (increased in size, in order to hold its value correctly).
@@ -221,8 +222,10 @@ class MCAssembler {
221222
/// finishLayout - Finalize a layout, including fragment lowering.
222223
void finishLayout(MCAsmLayout &Layout);
223224

224-
std::tuple<MCValue, uint64_t, bool>
225-
handleFixup(const MCAsmLayout &Layout, MCFragment &F, const MCFixup &Fixup);
225+
std::tuple<MCValue, uint64_t, bool> handleFixup(const MCAsmLayout &Layout,
226+
MCFragment &F,
227+
const MCFixup &Fixup,
228+
const MCSubtargetInfo *STI);
226229

227230
public:
228231
struct Symver {

llvm/lib/MC/MCAssembler.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ const MCSymbol *MCAssembler::getAtom(const MCSymbol &S) const {
193193
return S.getFragment()->getAtom();
194194
}
195195

196-
bool MCAssembler::evaluateFixup(const MCAsmLayout &Layout,
197-
const MCFixup &Fixup, const MCFragment *DF,
198-
MCValue &Target, uint64_t &Value,
196+
bool MCAssembler::evaluateFixup(const MCAsmLayout &Layout, const MCFixup &Fixup,
197+
const MCFragment *DF, MCValue &Target,
198+
const MCSubtargetInfo *STI, uint64_t &Value,
199199
bool &WasForced) const {
200200
++stats::evaluateFixup;
201201

@@ -227,7 +227,7 @@ bool MCAssembler::evaluateFixup(const MCAsmLayout &Layout,
227227

228228
if (IsTarget)
229229
return getBackend().evaluateTargetFixup(*this, Layout, Fixup, DF, Target,
230-
Value, WasForced);
230+
STI, Value, WasForced);
231231

232232
unsigned FixupFlags = getBackendPtr()->getFixupKindInfo(Fixup.getKind()).Flags;
233233
bool IsPCRel = getBackendPtr()->getFixupKindInfo(Fixup.getKind()).Flags &
@@ -282,7 +282,8 @@ bool MCAssembler::evaluateFixup(const MCAsmLayout &Layout,
282282
}
283283

284284
// Let the backend force a relocation if needed.
285-
if (IsResolved && getBackend().shouldForceRelocation(*this, Fixup, Target)) {
285+
if (IsResolved &&
286+
getBackend().shouldForceRelocation(*this, Fixup, Target, STI)) {
286287
IsResolved = false;
287288
WasForced = true;
288289
}
@@ -796,13 +797,13 @@ void MCAssembler::writeSectionData(raw_ostream &OS, const MCSection *Sec,
796797

797798
std::tuple<MCValue, uint64_t, bool>
798799
MCAssembler::handleFixup(const MCAsmLayout &Layout, MCFragment &F,
799-
const MCFixup &Fixup) {
800+
const MCFixup &Fixup, const MCSubtargetInfo *STI) {
800801
// Evaluate the fixup.
801802
MCValue Target;
802803
uint64_t FixedValue;
803804
bool WasForced;
804-
bool IsResolved = evaluateFixup(Layout, Fixup, &F, Target, FixedValue,
805-
WasForced);
805+
bool IsResolved =
806+
evaluateFixup(Layout, Fixup, &F, Target, STI, FixedValue, WasForced);
806807
if (!IsResolved) {
807808
// The fixup was unresolved, we need a relocation. Inform the object
808809
// writer of the relocation, and give it an opportunity to adjust the
@@ -936,7 +937,7 @@ void MCAssembler::layout(MCAsmLayout &Layout) {
936937
bool IsResolved;
937938
MCValue Target;
938939
std::tie(Target, FixedValue, IsResolved) =
939-
handleFixup(Layout, Frag, Fixup);
940+
handleFixup(Layout, Frag, Fixup, STI);
940941
getBackend().applyFixup(*this, Fixup, Target, Contents, FixedValue,
941942
IsResolved, STI);
942943
}
@@ -960,7 +961,8 @@ bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
960961
MCValue Target;
961962
uint64_t Value;
962963
bool WasForced;
963-
bool Resolved = evaluateFixup(Layout, Fixup, DF, Target, Value, WasForced);
964+
bool Resolved = evaluateFixup(Layout, Fixup, DF, Target,
965+
DF->getSubtargetInfo(), Value, WasForced);
964966
if (Target.getSymA() &&
965967
Target.getSymA()->getKind() == MCSymbolRefExpr::VK_X86_ABS8 &&
966968
Fixup.getKind() == FK_Data_1)

llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ class AArch64AsmBackend : public MCAsmBackend {
100100
unsigned getFixupKindContainereSizeInBytes(unsigned Kind) const;
101101

102102
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
103-
const MCValue &Target) override;
103+
const MCValue &Target,
104+
const MCSubtargetInfo *STI) override;
104105
};
105106

106107
} // end anonymous namespace
@@ -499,7 +500,8 @@ bool AArch64AsmBackend::writeNopData(raw_ostream &OS, uint64_t Count,
499500

500501
bool AArch64AsmBackend::shouldForceRelocation(const MCAssembler &Asm,
501502
const MCFixup &Fixup,
502-
const MCValue &Target) {
503+
const MCValue &Target,
504+
const MCSubtargetInfo *STI) {
503505
unsigned Kind = Fixup.getKind();
504506
if (Kind >= FirstLiteralRelocationKind)
505507
return true;

llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class AMDGPUAsmBackend : public MCAsmBackend {
5353
std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
5454
const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
5555
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
56-
const MCValue &Target) override;
56+
const MCValue &Target,
57+
const MCSubtargetInfo *STI) override;
5758
};
5859

5960
} //End anonymous namespace
@@ -192,7 +193,8 @@ const MCFixupKindInfo &AMDGPUAsmBackend::getFixupKindInfo(
192193

193194
bool AMDGPUAsmBackend::shouldForceRelocation(const MCAssembler &,
194195
const MCFixup &Fixup,
195-
const MCValue &) {
196+
const MCValue &,
197+
const MCSubtargetInfo *STI) {
196198
return Fixup.getKind() >= FirstLiteralRelocationKind;
197199
}
198200

llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,8 @@ unsigned ARMAsmBackend::adjustFixupValue(const MCAssembler &Asm,
908908

909909
bool ARMAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
910910
const MCFixup &Fixup,
911-
const MCValue &Target) {
911+
const MCValue &Target,
912+
const MCSubtargetInfo *STI) {
912913
const MCSymbolRefExpr *A = Target.getSymA();
913914
const MCSymbol *Sym = A ? &A->getSymbol() : nullptr;
914915
const unsigned FixupKind = Fixup.getKind();

llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class ARMAsmBackend : public MCAsmBackend {
3636
const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
3737

3838
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
39-
const MCValue &Target) override;
39+
const MCValue &Target,
40+
const MCSubtargetInfo *STI) override;
4041

4142
unsigned adjustFixupValue(const MCAssembler &Asm, const MCFixup &Fixup,
4243
const MCValue &Target, uint64_t Value,

llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,8 @@ bool AVRAsmBackend::writeNopData(raw_ostream &OS, uint64_t Count,
507507

508508
bool AVRAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
509509
const MCFixup &Fixup,
510-
const MCValue &Target) {
510+
const MCValue &Target,
511+
const MCSubtargetInfo *STI) {
511512
switch ((unsigned)Fixup.getKind()) {
512513
default:
513514
return Fixup.getKind() >= FirstLiteralRelocationKind;

llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ class AVRAsmBackend : public MCAsmBackend {
6060
const MCSubtargetInfo *STI) const override;
6161

6262
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
63-
const MCValue &Target) override;
63+
const MCValue &Target,
64+
const MCSubtargetInfo *STI) override;
6465

6566
private:
6667
Triple::OSType OSType;

llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ class HexagonAsmBackend : public MCAsmBackend {
202202
}
203203

204204
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
205-
const MCValue &Target) override {
205+
const MCValue &Target,
206+
const MCSubtargetInfo *STI) override {
206207
switch(Fixup.getTargetKind()) {
207208
default:
208209
llvm_unreachable("Unknown Fixup Kind!");

0 commit comments

Comments
 (0)