Skip to content

Commit 3e48c5f

Browse files
committed
[MC] Don't pass MCSubtargetInfo down to shouldForceRelocation and evaluateTargetFixup
This reverts the code change in commit e87f33d (llvm#73721) but keeps its test. llvm#73721, a workaround to generate necessary relocations in mixed non-relax/relax code, is no longer necessary after llvm#140692 fixed the root issue (whether two locations are separated by a fragment with indeterminate size due to linker relaxation).
1 parent bb03cdc commit 3e48c5f

File tree

22 files changed

+34
-53
lines changed

22 files changed

+34
-53
lines changed

llvm/include/llvm/MC/MCAsmBackend.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class MCAsmBackend {
9090

9191
// Hook used by the default `addReloc` to check if a relocation is needed.
9292
virtual bool shouldForceRelocation(const MCAssembler &, const MCFixup &,
93-
const MCValue &, const MCSubtargetInfo *) {
93+
const MCValue &) {
9494
return false;
9595
}
9696

@@ -111,7 +111,6 @@ class MCAsmBackend {
111111

112112
virtual bool evaluateTargetFixup(const MCAssembler &Asm, const MCFixup &Fixup,
113113
const MCFragment *DF, const MCValue &Target,
114-
const MCSubtargetInfo *STI,
115114
uint64_t &Value) {
116115
llvm_unreachable("Need to implement hook if target has custom fixups");
117116
}

llvm/lib/MC/MCAsmBackend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ bool MCAsmBackend::addReloc(MCAssembler &Asm, const MCFragment &F,
122122
const MCFixup &Fixup, const MCValue &Target,
123123
uint64_t &FixedValue, bool IsResolved,
124124
const MCSubtargetInfo *STI) {
125-
if (IsResolved && shouldForceRelocation(Asm, Fixup, Target, STI))
125+
if (IsResolved && shouldForceRelocation(Asm, Fixup, Target))
126126
IsResolved = false;
127127
if (!IsResolved)
128128
Asm.getWriter().recordRelocation(Asm, &F, Fixup, Target, FixedValue);

llvm/lib/MC/MCAssembler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ bool MCAssembler::evaluateFixup(const MCFixup &Fixup, const MCFragment *DF,
160160
unsigned FixupFlags = getBackend().getFixupKindInfo(Fixup.getKind()).Flags;
161161
if (FixupFlags & MCFixupKindInfo::FKF_IsTarget) {
162162
IsResolved =
163-
getBackend().evaluateTargetFixup(*this, Fixup, DF, Target, STI, Value);
163+
getBackend().evaluateTargetFixup(*this, Fixup, DF, Target, Value);
164164
} else {
165165
const MCSymbol *Add = Target.getAddSym();
166166
const MCSymbol *Sub = Target.getSubSym();

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

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

9898
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
99-
const MCValue &Target,
100-
const MCSubtargetInfo *STI) override;
99+
const MCValue &Target) override;
101100
};
102101

103102
} // end anonymous namespace
@@ -523,8 +522,7 @@ bool AArch64AsmBackend::writeNopData(raw_ostream &OS, uint64_t Count,
523522

524523
bool AArch64AsmBackend::shouldForceRelocation(const MCAssembler &Asm,
525524
const MCFixup &Fixup,
526-
const MCValue &Target,
527-
const MCSubtargetInfo *STI) {
525+
const MCValue &Target) {
528526
// The ADRP instruction adds some multiple of 0x1000 to the current PC &
529527
// ~0xfff. This means that the required offset to reach a symbol can vary by
530528
// up to one step depending on where the ADRP is in memory. For example:

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

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

5959
} //End anonymous namespace
@@ -194,8 +194,7 @@ MCFixupKindInfo AMDGPUAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
194194

195195
bool AMDGPUAsmBackend::shouldForceRelocation(const MCAssembler &,
196196
const MCFixup &,
197-
const MCValue &Target,
198-
const MCSubtargetInfo *) {
197+
const MCValue &Target) {
199198
return Target.getSpecifier();
200199
}
201200

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -971,8 +971,7 @@ unsigned ARMAsmBackend::adjustFixupValue(const MCAssembler &Asm,
971971

972972
bool ARMAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
973973
const MCFixup &Fixup,
974-
const MCValue &Target,
975-
const MCSubtargetInfo *STI) {
974+
const MCValue &Target) {
976975
const MCSymbol *Sym = Target.getAddSym();
977976
const unsigned FixupKind = Fixup.getKind();
978977
if (FixupKind == ARM::fixup_arm_thumb_bl) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ class ARMAsmBackend : public MCAsmBackend {
3131
MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const override;
3232

3333
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
34-
const MCValue &Target,
35-
const MCSubtargetInfo *STI) override;
34+
const MCValue &Target) override;
3635

3736
unsigned adjustFixupValue(const MCAssembler &Asm, const MCFixup &Fixup,
3837
const MCValue &Target, uint64_t Value,

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ bool AVRAsmBackend::addReloc(MCAssembler &Asm, const MCFragment &F,
377377
if (IsResolved) {
378378
auto TargetVal = MCValue::get(Target.getAddSym(), Target.getSubSym(),
379379
FixedValue, Target.getSpecifier());
380-
if (shouldForceRelocation(Asm, Fixup, TargetVal, STI))
380+
if (forceRelocation(Asm, Fixup, TargetVal, STI))
381381
IsResolved = false;
382382
}
383383
if (!IsResolved)
@@ -515,10 +515,9 @@ bool AVRAsmBackend::writeNopData(raw_ostream &OS, uint64_t Count,
515515
return true;
516516
}
517517

518-
bool AVRAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
519-
const MCFixup &Fixup,
520-
const MCValue &Target,
521-
const MCSubtargetInfo *STI) {
518+
bool AVRAsmBackend::forceRelocation(const MCAssembler &Asm,
519+
const MCFixup &Fixup, const MCValue &Target,
520+
const MCSubtargetInfo *STI) {
522521
switch ((unsigned)Fixup.getKind()) {
523522
default:
524523
return false;

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ class AVRAsmBackend : public MCAsmBackend {
5252
bool writeNopData(raw_ostream &OS, uint64_t Count,
5353
const MCSubtargetInfo *STI) const override;
5454

55-
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
56-
const MCValue &Target,
57-
const MCSubtargetInfo *STI) override;
55+
bool forceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
56+
const MCValue &Target, const MCSubtargetInfo *);
5857

5958
private:
6059
Triple::OSType OSType;

llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ bool CSKYAsmBackend::mayNeedRelaxation(const MCInst &Inst,
253253

254254
bool CSKYAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
255255
const MCFixup &Fixup,
256-
const MCValue &Target,
257-
const MCSubtargetInfo * /*STI*/) {
256+
const MCValue &Target /*STI*/) {
258257
if (Target.getSpecifier())
259258
return true;
260259
switch (Fixup.getTargetKind()) {

llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ class CSKYAsmBackend : public MCAsmBackend {
4747
const MCSubtargetInfo *STI) const override;
4848

4949
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
50-
const MCValue &Target,
51-
const MCSubtargetInfo *STI) override;
50+
const MCValue &Target) override;
5251

5352
std::unique_ptr<MCObjectTargetWriter>
5453
createObjectTargetWriter() const override;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ class HexagonAsmBackend : public MCAsmBackend {
199199
}
200200

201201
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
202-
const MCValue &Target,
203-
const MCSubtargetInfo *STI) override {
202+
const MCValue &Target) override {
204203
switch(Fixup.getTargetKind()) {
205204
default:
206205
llvm_unreachable("Unknown Fixup Kind!");

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,10 @@ bool LoongArchAsmBackend::shouldInsertFixupForCodeAlign(MCAssembler &Asm,
246246

247247
bool LoongArchAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
248248
const MCFixup &Fixup,
249-
const MCValue &Target,
250-
const MCSubtargetInfo *STI) {
249+
const MCValue &Target) {
251250
switch (Fixup.getTargetKind()) {
252251
default:
253-
return STI->hasFeature(LoongArch::FeatureRelax);
252+
return STI.hasFeature(LoongArch::FeatureRelax);
254253
case FK_Data_1:
255254
case FK_Data_2:
256255
case FK_Data_4:

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ class LoongArchAsmBackend : public MCAsmBackend {
5353
MCAlignFragment &AF) override;
5454

5555
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
56-
const MCValue &Target,
57-
const MCSubtargetInfo *STI) override;
58-
56+
const MCValue &Target) override;
5957

6058
std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
6159

llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,7 @@ bool MipsAsmBackend::writeNopData(raw_ostream &OS, uint64_t Count,
559559

560560
bool MipsAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
561561
const MCFixup &Fixup,
562-
const MCValue &Target,
563-
const MCSubtargetInfo *STI) {
562+
const MCValue &Target) {
564563
const unsigned FixupKind = Fixup.getKind();
565564
switch (FixupKind) {
566565
default:

llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ class MipsAsmBackend : public MCAsmBackend {
5151
const MCSubtargetInfo *STI) const override;
5252

5353
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
54-
const MCValue &Target,
55-
const MCSubtargetInfo *STI) override;
54+
const MCValue &Target) override;
5655
}; // class MipsAsmBackend
5756

5857
} // namespace

llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ class PPCAsmBackend : public MCAsmBackend {
170170
}
171171

172172
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
173-
const MCValue &Target,
174-
const MCSubtargetInfo *STI) override {
173+
const MCValue &Target) override {
175174
// If there is a @ specifier, unless it is optimized out (e.g. constant @l),
176175
// force a relocation.
177176
if (Target.getSpecifier())

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,11 @@ bool RISCVAsmBackend::isPCRelFixupResolved(const MCAssembler &Asm,
569569
return !Res.getSubSym();
570570
}
571571

572-
bool RISCVAsmBackend::evaluateTargetFixup(
573-
const MCAssembler &Asm, const MCFixup &Fixup, const MCFragment *DF,
574-
const MCValue &Target, const MCSubtargetInfo *STI, uint64_t &Value) {
572+
bool RISCVAsmBackend::evaluateTargetFixup(const MCAssembler &Asm,
573+
const MCFixup &Fixup,
574+
const MCFragment *DF,
575+
const MCValue &Target,
576+
uint64_t &Value) {
575577
const MCFixup *AUIPCFixup;
576578
const MCFragment *AUIPCDF;
577579
MCValue AUIPCTarget;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class RISCVAsmBackend : public MCAsmBackend {
4747

4848
bool evaluateTargetFixup(const MCAssembler &Asm, const MCFixup &Fixup,
4949
const MCFragment *DF, const MCValue &Target,
50-
const MCSubtargetInfo *STI,
5150
uint64_t &Value) override;
5251

5352
bool addReloc(MCAssembler &Asm, const MCFragment &F, const MCFixup &Fixup,

llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmBackend.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class SystemZMCAsmBackend : public MCAsmBackend {
114114
std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
115115
MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const override;
116116
bool shouldForceRelocation(const MCAssembler &, const MCFixup &,
117-
const MCValue &, const MCSubtargetInfo *) override;
117+
const MCValue &) override;
118118
void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
119119
const MCValue &Target, MutableArrayRef<char> Data,
120120
uint64_t Value, bool IsResolved,
@@ -157,8 +157,7 @@ MCFixupKindInfo SystemZMCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
157157

158158
bool SystemZMCAsmBackend::shouldForceRelocation(const MCAssembler &,
159159
const MCFixup &,
160-
const MCValue &Target,
161-
const MCSubtargetInfo *) {
160+
const MCValue &Target) {
162161
return Target.getSpecifier();
163162
}
164163

llvm/lib/Target/VE/MCTargetDesc/VEAsmBackend.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ class VEAsmBackend : public MCAsmBackend {
130130
}
131131

132132
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
133-
const MCValue &Target,
134-
const MCSubtargetInfo *STI) override {
133+
const MCValue &Target) override {
135134
switch ((VE::Fixups)Fixup.getKind()) {
136135
default:
137136
return false;

llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class X86AsmBackend : public MCAsmBackend {
170170
MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const override;
171171

172172
bool shouldForceRelocation(const MCAssembler &, const MCFixup &,
173-
const MCValue &, const MCSubtargetInfo *) override;
173+
const MCValue &) override;
174174

175175
void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
176176
const MCValue &Target, MutableArrayRef<char> Data,
@@ -693,8 +693,7 @@ static unsigned getFixupKindSize(unsigned Kind) {
693693
// Force relocation when there is a specifier. This might be too conservative -
694694
// GAS doesn't emit a relocation for call local@plt; local:.
695695
bool X86AsmBackend::shouldForceRelocation(const MCAssembler &, const MCFixup &,
696-
const MCValue &Target,
697-
const MCSubtargetInfo *) {
696+
const MCValue &Target) {
698697
return Target.getSpecifier();
699698
}
700699

0 commit comments

Comments
 (0)