Skip to content

Commit 6048629

Browse files
committed
[MC] Move MIPS-specific gprel/tprel/dtprel from MCStreamer to MipsTargetStreamer
https://reviews.llvm.org/D23669 inappropriately added MIPS-specific dtprel/tprel directives to MCStreamer. In addition, llvm-mc -filetype=null parsing these directives will crash. This patch moves these functions to MipsTargetStreamer and fixes -filetype=null. gprel32 and gprel64, called by AsmPrinter, are moved to MCTargetStreamer.
1 parent 31bf16a commit 6048629

21 files changed

+174
-295
lines changed

llvm/include/llvm/MC/MCAsmInfo.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -241,24 +241,11 @@ class MCAsmInfo {
241241
/// True if data directives support signed values
242242
bool SupportsSignedData = true;
243243

244-
/// If non-null, a directive that is used to emit a word which should be
245-
/// relocated as a 64-bit GP-relative offset, e.g. .gpdword on Mips. Defaults
246-
/// to nullptr.
247-
const char *GPRel64Directive = nullptr;
248-
249244
/// If non-null, a directive that is used to emit a word which should be
250245
/// relocated as a 32-bit GP-relative offset, e.g. .gpword on Mips or .gprel32
251246
/// on Alpha. Defaults to nullptr.
252247
const char *GPRel32Directive = nullptr;
253248

254-
/// If non-null, directives that are used to emit a word/dword which should
255-
/// be relocated as a 32/64-bit DTP/TP-relative offset, e.g. .dtprelword/
256-
/// .dtpreldword/.tprelword/.tpreldword on Mips.
257-
const char *DTPRel32Directive = nullptr;
258-
const char *DTPRel64Directive = nullptr;
259-
const char *TPRel32Directive = nullptr;
260-
const char *TPRel64Directive = nullptr;
261-
262249
/// This is true if this target uses "Sun Style" syntax for section switching
263250
/// ("#alloc,#write" etc) instead of the normal ELF syntax (,"a,w") in
264251
/// .section directives. Defaults to false.
@@ -463,12 +450,7 @@ class MCAsmInfo {
463450
const char *getData32bitsDirective() const { return Data32bitsDirective; }
464451
const char *getData64bitsDirective() const { return Data64bitsDirective; }
465452
bool supportsSignedData() const { return SupportsSignedData; }
466-
const char *getGPRel64Directive() const { return GPRel64Directive; }
467453
const char *getGPRel32Directive() const { return GPRel32Directive; }
468-
const char *getDTPRel64Directive() const { return DTPRel64Directive; }
469-
const char *getDTPRel32Directive() const { return DTPRel32Directive; }
470-
const char *getTPRel64Directive() const { return TPRel64Directive; }
471-
const char *getTPRel32Directive() const { return TPRel32Directive; }
472454

473455
/// Targets can implement this method to specify a section to switch to if the
474456
/// translation unit doesn't have any trampolines that require an executable

llvm/include/llvm/MC/MCFixup.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ enum MCFixupKind {
2929
FK_PCRel_2, ///< A two-byte pc relative fixup.
3030
FK_PCRel_4, ///< A four-byte pc relative fixup.
3131
FK_PCRel_8, ///< A eight-byte pc relative fixup.
32-
FK_GPRel_1, ///< A one-byte gp relative fixup.
33-
FK_GPRel_2, ///< A two-byte gp relative fixup.
34-
FK_GPRel_4, ///< A four-byte gp relative fixup.
35-
FK_GPRel_8, ///< A eight-byte gp relative fixup.
36-
FK_DTPRel_4, ///< A four-byte dtp relative fixup.
37-
FK_DTPRel_8, ///< A eight-byte dtp relative fixup.
38-
FK_TPRel_4, ///< A four-byte tp relative fixup.
39-
FK_TPRel_8, ///< A eight-byte tp relative fixup.
4032
FK_SecRel_1, ///< A one-byte section relative fixup.
4133
FK_SecRel_2, ///< A two-byte section relative fixup.
4234
FK_SecRel_4, ///< A four-byte section relative fixup.

llvm/include/llvm/MC/MCObjectStreamer.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,6 @@ class MCObjectStreamer : public MCStreamer {
166166
void emitCVStringTableDirective() override;
167167
void emitCVFileChecksumsDirective() override;
168168
void emitCVFileChecksumOffsetDirective(unsigned FileNo) override;
169-
void emitDTPRel32Value(const MCExpr *Value) override;
170-
void emitDTPRel64Value(const MCExpr *Value) override;
171-
void emitTPRel32Value(const MCExpr *Value) override;
172-
void emitTPRel64Value(const MCExpr *Value) override;
173-
void emitGPRel32Value(const MCExpr *Value) override;
174-
void emitGPRel64Value(const MCExpr *Value) override;
175169
std::optional<std::pair<bool, std::string>>
176170
emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr,
177171
SMLoc Loc, const MCSubtargetInfo &STI) override;

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ class MCTargetStreamer {
130130
virtual void emitConstantPools();
131131

132132
virtual void finish();
133+
134+
// MIPS specific functions called by AsmPrinter.
135+
virtual void emitGPRel32Value(const MCExpr *);
136+
virtual void emitGPRel64Value(const MCExpr *);
133137
};
134138

135139
// FIXME: declared here because it is used from
@@ -762,48 +766,6 @@ class MCStreamer {
762766
void emitSymbolValue(const MCSymbol *Sym, unsigned Size,
763767
bool IsSectionRelative = false);
764768

765-
/// Emit the expression \p Value into the output as a dtprel
766-
/// (64-bit DTP relative) value.
767-
///
768-
/// This is used to implement assembler directives such as .dtpreldword on
769-
/// targets that support them.
770-
virtual void emitDTPRel64Value(const MCExpr *Value);
771-
772-
/// Emit the expression \p Value into the output as a dtprel
773-
/// (32-bit DTP relative) value.
774-
///
775-
/// This is used to implement assembler directives such as .dtprelword on
776-
/// targets that support them.
777-
virtual void emitDTPRel32Value(const MCExpr *Value);
778-
779-
/// Emit the expression \p Value into the output as a tprel
780-
/// (64-bit TP relative) value.
781-
///
782-
/// This is used to implement assembler directives such as .tpreldword on
783-
/// targets that support them.
784-
virtual void emitTPRel64Value(const MCExpr *Value);
785-
786-
/// Emit the expression \p Value into the output as a tprel
787-
/// (32-bit TP relative) value.
788-
///
789-
/// This is used to implement assembler directives such as .tprelword on
790-
/// targets that support them.
791-
virtual void emitTPRel32Value(const MCExpr *Value);
792-
793-
/// Emit the expression \p Value into the output as a gprel64 (64-bit
794-
/// GP relative) value.
795-
///
796-
/// This is used to implement assembler directives such as .gpdword on
797-
/// targets that support them.
798-
virtual void emitGPRel64Value(const MCExpr *Value);
799-
800-
/// Emit the expression \p Value into the output as a gprel32 (32-bit
801-
/// GP relative) value.
802-
///
803-
/// This is used to implement assembler directives such as .gprel32 on
804-
/// targets that support them.
805-
virtual void emitGPRel32Value(const MCExpr *Value);
806-
807769
/// Emit NumBytes bytes worth of the value specified by FillValue.
808770
/// This implements directives such as '.space'.
809771
void emitFill(uint64_t NumBytes, uint8_t FillValue);

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3043,7 +3043,8 @@ void AsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo &MJTI,
30433043
// with a relocation as gp-relative, e.g.:
30443044
// .gprel32 LBB123
30453045
MCSymbol *MBBSym = MBB->getSymbol();
3046-
OutStreamer->emitGPRel32Value(MCSymbolRefExpr::create(MBBSym, OutContext));
3046+
OutStreamer->getTargetStreamer()->emitGPRel32Value(
3047+
MCSymbolRefExpr::create(MBBSym, OutContext));
30473048
return;
30483049
}
30493050

@@ -3052,7 +3053,8 @@ void AsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo &MJTI,
30523053
// with a relocation as gp-relative, e.g.:
30533054
// .gpdword LBB123
30543055
MCSymbol *MBBSym = MBB->getSymbol();
3055-
OutStreamer->emitGPRel64Value(MCSymbolRefExpr::create(MBBSym, OutContext));
3056+
OutStreamer->getTargetStreamer()->emitGPRel64Value(
3057+
MCSymbolRefExpr::create(MBBSym, OutContext));
30563058
return;
30573059
}
30583060

llvm/lib/MC/MCAsmBackend.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,6 @@ const MCFixupKindInfo &MCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
9999
{"FK_PCRel_2", 0, 16, MCFixupKindInfo::FKF_IsPCRel},
100100
{"FK_PCRel_4", 0, 32, MCFixupKindInfo::FKF_IsPCRel},
101101
{"FK_PCRel_8", 0, 64, MCFixupKindInfo::FKF_IsPCRel},
102-
{"FK_GPRel_1", 0, 8, 0},
103-
{"FK_GPRel_2", 0, 16, 0},
104-
{"FK_GPRel_4", 0, 32, 0},
105-
{"FK_GPRel_8", 0, 64, 0},
106-
{"FK_DTPRel_4", 0, 32, 0},
107-
{"FK_DTPRel_8", 0, 64, 0},
108-
{"FK_TPRel_4", 0, 32, 0},
109-
{"FK_TPRel_8", 0, 64, 0},
110102
{"FK_SecRel_1", 0, 8, 0},
111103
{"FK_SecRel_2", 0, 16, 0},
112104
{"FK_SecRel_4", 0, 32, 0},

llvm/lib/MC/MCAsmStreamer.cpp

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,6 @@ class MCAsmStreamer final : public MCStreamer {
259259

260260
void emitSLEB128Value(const MCExpr *Value) override;
261261

262-
void emitDTPRel32Value(const MCExpr *Value) override;
263-
void emitDTPRel64Value(const MCExpr *Value) override;
264-
void emitTPRel32Value(const MCExpr *Value) override;
265-
void emitTPRel64Value(const MCExpr *Value) override;
266-
267-
void emitGPRel64Value(const MCExpr *Value) override;
268-
269-
void emitGPRel32Value(const MCExpr *Value) override;
270-
271262
void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
272263
SMLoc Loc = SMLoc()) override;
273264

@@ -1432,48 +1423,6 @@ void MCAsmStreamer::emitSLEB128Value(const MCExpr *Value) {
14321423
EmitEOL();
14331424
}
14341425

1435-
void MCAsmStreamer::emitDTPRel64Value(const MCExpr *Value) {
1436-
assert(MAI->getDTPRel64Directive() != nullptr);
1437-
OS << MAI->getDTPRel64Directive();
1438-
Value->print(OS, MAI);
1439-
EmitEOL();
1440-
}
1441-
1442-
void MCAsmStreamer::emitDTPRel32Value(const MCExpr *Value) {
1443-
assert(MAI->getDTPRel32Directive() != nullptr);
1444-
OS << MAI->getDTPRel32Directive();
1445-
Value->print(OS, MAI);
1446-
EmitEOL();
1447-
}
1448-
1449-
void MCAsmStreamer::emitTPRel64Value(const MCExpr *Value) {
1450-
assert(MAI->getTPRel64Directive() != nullptr);
1451-
OS << MAI->getTPRel64Directive();
1452-
Value->print(OS, MAI);
1453-
EmitEOL();
1454-
}
1455-
1456-
void MCAsmStreamer::emitTPRel32Value(const MCExpr *Value) {
1457-
assert(MAI->getTPRel32Directive() != nullptr);
1458-
OS << MAI->getTPRel32Directive();
1459-
Value->print(OS, MAI);
1460-
EmitEOL();
1461-
}
1462-
1463-
void MCAsmStreamer::emitGPRel64Value(const MCExpr *Value) {
1464-
assert(MAI->getGPRel64Directive() != nullptr);
1465-
OS << MAI->getGPRel64Directive();
1466-
Value->print(OS, MAI);
1467-
EmitEOL();
1468-
}
1469-
1470-
void MCAsmStreamer::emitGPRel32Value(const MCExpr *Value) {
1471-
assert(MAI->getGPRel32Directive() != nullptr);
1472-
OS << MAI->getGPRel32Directive();
1473-
Value->print(OS, MAI);
1474-
EmitEOL();
1475-
}
1476-
14771426
void MCAsmStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
14781427
SMLoc Loc) {
14791428
int64_t IntNumBytes;

llvm/lib/MC/MCNullStreamer.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ namespace {
4141
void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
4242
uint64_t Size = 0, Align ByteAlignment = Align(1),
4343
SMLoc Loc = SMLoc()) override {}
44-
void emitGPRel32Value(const MCExpr *Value) override {}
4544
void beginCOFFSymbolDef(const MCSymbol *Symbol) override {}
4645
void emitCOFFSymbolStorageClass(int StorageClass) override {}
4746
void emitCOFFSymbolType(int Type) override {}

llvm/lib/MC/MCObjectStreamer.cpp

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -581,54 +581,6 @@ void MCObjectStreamer::emitValueToOffset(const MCExpr *Offset,
581581
insert(getContext().allocFragment<MCOrgFragment>(*Offset, Value, Loc));
582582
}
583583

584-
// Associate DTPRel32 fixup with data and resize data area
585-
void MCObjectStreamer::emitDTPRel32Value(const MCExpr *Value) {
586-
MCDataFragment *DF = getOrCreateDataFragment();
587-
DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
588-
Value, FK_DTPRel_4));
589-
DF->appendContents(4, 0);
590-
}
591-
592-
// Associate DTPRel64 fixup with data and resize data area
593-
void MCObjectStreamer::emitDTPRel64Value(const MCExpr *Value) {
594-
MCDataFragment *DF = getOrCreateDataFragment();
595-
DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
596-
Value, FK_DTPRel_8));
597-
DF->appendContents(8, 0);
598-
}
599-
600-
// Associate TPRel32 fixup with data and resize data area
601-
void MCObjectStreamer::emitTPRel32Value(const MCExpr *Value) {
602-
MCDataFragment *DF = getOrCreateDataFragment();
603-
DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
604-
Value, FK_TPRel_4));
605-
DF->appendContents(4, 0);
606-
}
607-
608-
// Associate TPRel64 fixup with data and resize data area
609-
void MCObjectStreamer::emitTPRel64Value(const MCExpr *Value) {
610-
MCDataFragment *DF = getOrCreateDataFragment();
611-
DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
612-
Value, FK_TPRel_8));
613-
DF->appendContents(8, 0);
614-
}
615-
616-
// Associate GPRel32 fixup with data and resize data area
617-
void MCObjectStreamer::emitGPRel32Value(const MCExpr *Value) {
618-
MCDataFragment *DF = getOrCreateDataFragment();
619-
DF->getFixups().push_back(
620-
MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
621-
DF->appendContents(4, 0);
622-
}
623-
624-
// Associate GPRel64 fixup with data and resize data area
625-
void MCObjectStreamer::emitGPRel64Value(const MCExpr *Value) {
626-
MCDataFragment *DF = getOrCreateDataFragment();
627-
DF->getFixups().push_back(
628-
MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
629-
DF->appendContents(8, 0);
630-
}
631-
632584
static std::optional<std::pair<bool, std::string>>
633585
getOffsetAndDataFragment(const MCSymbol &Symbol, uint32_t &RelocOffset,
634586
MCDataFragment *&DF) {

llvm/lib/MC/MCStreamer.cpp

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ void MCTargetStreamer::emitRawBytes(StringRef Data) {
9090

9191
void MCTargetStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {}
9292

93+
void MCTargetStreamer::emitGPRel32Value(const MCExpr *) {
94+
report_fatal_error("unsupported directive");
95+
}
96+
97+
void MCTargetStreamer::emitGPRel64Value(const MCExpr *) {
98+
report_fatal_error("unsupported directive");
99+
}
100+
93101
MCStreamer::MCStreamer(MCContext &Ctx)
94102
: Context(Ctx), CurrentWinFrameInfo(nullptr),
95103
CurrentProcWinFrameInfoStartIndex(0) {
@@ -191,30 +199,6 @@ void MCStreamer::emitSymbolValue(const MCSymbol *Sym, unsigned Size,
191199
emitCOFFSecRel32(Sym, /*Offset=*/0);
192200
}
193201

194-
void MCStreamer::emitDTPRel64Value(const MCExpr *Value) {
195-
report_fatal_error("unsupported directive in streamer");
196-
}
197-
198-
void MCStreamer::emitDTPRel32Value(const MCExpr *Value) {
199-
report_fatal_error("unsupported directive in streamer");
200-
}
201-
202-
void MCStreamer::emitTPRel64Value(const MCExpr *Value) {
203-
report_fatal_error("unsupported directive in streamer");
204-
}
205-
206-
void MCStreamer::emitTPRel32Value(const MCExpr *Value) {
207-
report_fatal_error("unsupported directive in streamer");
208-
}
209-
210-
void MCStreamer::emitGPRel64Value(const MCExpr *Value) {
211-
report_fatal_error("unsupported directive in streamer");
212-
}
213-
214-
void MCStreamer::emitGPRel32Value(const MCExpr *Value) {
215-
report_fatal_error("unsupported directive in streamer");
216-
}
217-
218202
/// Emit NumBytes bytes worth of the value specified by FillValue.
219203
/// This implements directives such as '.space'.
220204
void MCStreamer::emitFill(uint64_t NumBytes, uint8_t FillValue) {

0 commit comments

Comments
 (0)