Skip to content

Commit 769b0e6

Browse files
committed
XCOFF: Simplify R_REF and remove a MCFragment::addFixup use
Simplify the code added by https://reviews.llvm.org/D144356
1 parent b103311 commit 769b0e6

File tree

4 files changed

+5
-27
lines changed

4 files changed

+5
-27
lines changed

llvm/lib/MC/MCXCOFFStreamer.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,8 @@ void MCXCOFFStreamer::emitXCOFFSymbolLinkageWithVisibility(
103103
void MCXCOFFStreamer::emitXCOFFRefDirective(const MCSymbol *Symbol) {
104104
// Add a Fixup here to later record a relocation of type R_REF to prevent the
105105
// ref symbol from being garbage collected (by the binder).
106-
MCFragment *DF = getCurrentFragment();
107-
const MCSymbolRefExpr *SRE = MCSymbolRefExpr::create(Symbol, getContext());
108-
std::optional<MCFixupKind> MaybeKind =
109-
getAssembler().getBackend().getFixupKind("R_REF");
110-
if (!MaybeKind)
111-
report_fatal_error("failed to get fixup kind for R_REF relocation");
112-
113-
MCFixupKind Kind = *MaybeKind;
114-
MCFixup Fixup = MCFixup::create(DF->getContents().size(), SRE, Kind);
115-
DF->addFixup(Fixup);
106+
addFixup(MCSymbolRefExpr::create(Symbol, getContext()),
107+
XCOFF::RelocationType::R_REF);
116108
}
117109

118110
void MCXCOFFStreamer::emitXCOFFRenameDirective(const MCSymbol *Name,

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,6 @@ class XCOFFPPCAsmBackend : public PPCAsmBackend {
243243
createObjectTargetWriter() const override {
244244
return createPPCXCOFFObjectWriter(TT.isArch64Bit());
245245
}
246-
247-
std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
248246
};
249247

250248
} // end anonymous namespace
@@ -279,13 +277,6 @@ ELFPPCAsmBackend::getFixupKind(StringRef Name) const {
279277
return std::nullopt;
280278
}
281279

282-
std::optional<MCFixupKind>
283-
XCOFFPPCAsmBackend::getFixupKind(StringRef Name) const {
284-
return StringSwitch<std::optional<MCFixupKind>>(Name)
285-
.Case("R_REF", PPC::fixup_ppc_nofixup)
286-
.Default(std::nullopt);
287-
}
288-
289280
MCAsmBackend *llvm::createPPCAsmBackend(const Target &T,
290281
const MCSubtargetInfo &STI,
291282
const MCRegisterInfo &MRI,

llvm/lib/Target/PowerPC/MCTargetDesc/PPCFixupKinds.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ enum Fixups {
4848

4949
/// Not a true fixup, but ties a symbol to a call to __tls_get_addr for the
5050
/// TLS general and local dynamic models, or inserts the thread-pointer
51-
/// register number. It can also be used to tie the ref symbol to prevent it
52-
/// from being garbage collected on AIX.
51+
/// register number.
5352
fixup_ppc_nofixup,
5453

5554
/// A 16-bit fixup corresponding to lo16(_foo) with implied 3 zero bits for

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ std::pair<uint8_t, uint8_t> PPCXCOFFObjectWriter::getRelocTypeAndSignSize(
5656
switch ((unsigned)Fixup.getKind()) {
5757
default:
5858
report_fatal_error("Unimplemented fixup kind.");
59+
case XCOFF::RelocationType::R_REF:
60+
return {XCOFF::RelocationType::R_REF, 0};
5961
case PPC::fixup_ppc_half16: {
6062
const uint8_t SignAndSizeForHalf16 = EncodedSignednessIndicator | 15;
6163
switch (Specifier) {
@@ -96,12 +98,6 @@ std::pair<uint8_t, uint8_t> PPCXCOFFObjectWriter::getRelocTypeAndSignSize(
9698
return {XCOFF::RelocationType::R_RBR, EncodedSignednessIndicator | 25};
9799
case PPC::fixup_ppc_br24abs:
98100
return {XCOFF::RelocationType::R_RBA, EncodedSignednessIndicator | 25};
99-
case PPC::fixup_ppc_nofixup: {
100-
if (Specifier == PPC::S_None)
101-
return {XCOFF::RelocationType::R_REF, 0};
102-
else
103-
llvm_unreachable("Unsupported Modifier");
104-
} break;
105101
case FK_Data_4:
106102
case FK_Data_8:
107103
const uint8_t SignAndSizeForFKData =

0 commit comments

Comments
 (0)