Skip to content

[ARM] Move MCStreamer::emitThumbFunc to ARMTargetStreamer #126199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion llvm/include/llvm/MC/MCELFStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class MCELFStreamer : public MCObjectStreamer {
void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCDataFragment &F,
uint64_t Offset) override;
void emitAssemblerFlag(MCAssemblerFlag Flag) override;
void emitThumbFunc(MCSymbol *Func) override;
void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/MC/MCObjectStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class MCObjectStreamer : public MCStreamer {
virtual void emitInstToData(const MCInst &Inst, const MCSubtargetInfo&) = 0;
void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
void emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override;
MCSymbol *emitCFILabel() override;
void emitInstructionImpl(const MCInst &Inst, const MCSubtargetInfo &STI);
void resolvePendingFixups();

Expand All @@ -81,6 +80,7 @@ class MCObjectStreamer : public MCStreamer {
bool isIntegratedAssemblerRequired() const override { return true; }

void emitFrames(MCAsmBackend *MAB);
MCSymbol *emitCFILabel() override;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to check this was intentional. I don't see any problems with it, but at first glance it doesn't look related.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making the function public is intentional as mentioned by the description:

emitCFILabel, called by ARMWinCOFFStreamer.cpp, has to be made public.

In the call site, the previous getParser().getStreamer().emitThumbFunc(Symbol); somehow was able to access emitThumbFunc, despite it being private. Perhaps there was a friend somewhere.

The new getTargetStreamer().emitThumbFunc(Symbol); does require emitThumbFunc to be public.

void emitCFISections(bool EH, bool Debug) override;

void insert(MCFragment *F) {
Expand Down
6 changes: 2 additions & 4 deletions llvm/include/llvm/MC/MCStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ class ARMTargetStreamer : public MCTargetStreamer {

virtual void annotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);

// Note in the output that the specified \p Symbol is a Thumb mode function.
virtual void emitThumbFunc(MCSymbol *Symbol);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we preserve the comment, minus the ARM only part

Note in the output that the specified \p Func is a Thumb mode function.

virtual void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value);

void emitConstantPools() override;
Expand Down Expand Up @@ -501,10 +503,6 @@ class MCStreamer {
const Triple *DarwinTargetVariantTriple,
const VersionTuple &DarwinTargetVariantSDKVersion);

/// Note in the output that the specified \p Func is a Thumb mode
/// function (ARM target only).
virtual void emitThumbFunc(MCSymbol *Func);

/// Emit an assignment of \p Value to \p Symbol.
///
/// This corresponds to an assembler statement such as:
Expand Down
1 change: 0 additions & 1 deletion llvm/include/llvm/MC/MCWasmStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class MCWasmStreamer : public MCObjectStreamer {
void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCDataFragment &F,
uint64_t Offset) override;
void emitAssemblerFlag(MCAssemblerFlag Flag) override;
void emitThumbFunc(MCSymbol *Func) override;
void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
Expand Down
1 change: 0 additions & 1 deletion llvm/include/llvm/MC/MCWinCOFFStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class MCWinCOFFStreamer : public MCObjectStreamer {
void changeSection(MCSection *Section, uint32_t Subsection = 0) override;
void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
void emitAssemblerFlag(MCAssemblerFlag Flag) override;
void emitThumbFunc(MCSymbol *Func) override;
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
void beginCOFFSymbolDef(MCSymbol const *Symbol) override;
Expand Down
13 changes: 0 additions & 13 deletions llvm/lib/MC/MCAsmStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ class MCAsmStreamer final : public MCStreamer {
void emitDarwinTargetVariantBuildVersion(unsigned Platform, unsigned Major,
unsigned Minor, unsigned Update,
VersionTuple SDKVersion) override;
void emitThumbFunc(MCSymbol *Func) override;

void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
void emitConditionalAssignment(MCSymbol *Symbol,
Expand Down Expand Up @@ -697,18 +696,6 @@ void MCAsmStreamer::emitDarwinTargetVariantBuildVersion(
emitBuildVersion(Platform, Major, Minor, Update, SDKVersion);
}

void MCAsmStreamer::emitThumbFunc(MCSymbol *Func) {
// This needs to emit to a temporary string to get properly quoted
// MCSymbols when they have spaces in them.
OS << "\t.thumb_func";
// Only Mach-O hasSubsectionsViaSymbols()
if (MAI->hasSubsectionsViaSymbols()) {
OS << '\t';
Func->print(OS, MAI);
}
EmitEOL();
}

void MCAsmStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
// Do not emit a .set on inlined target assignments.
bool EmitSet = true;
Expand Down
4 changes: 0 additions & 4 deletions llvm/lib/MC/MCELFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,10 +616,6 @@ void MCELFStreamer::finishImpl() {
this->MCObjectStreamer::finishImpl();
}

void MCELFStreamer::emitThumbFunc(MCSymbol *Func) {
llvm_unreachable("Generic ELF doesn't support this directive");
}

void MCELFStreamer::emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
llvm_unreachable("ELF doesn't support this directive");
}
Expand Down
8 changes: 0 additions & 8 deletions llvm/lib/MC/MCMachOStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ class MCMachOStreamer : public MCObjectStreamer {
void emitDarwinTargetVariantBuildVersion(unsigned Platform, unsigned Major,
unsigned Minor, unsigned Update,
VersionTuple SDKVersion) override;
void emitThumbFunc(MCSymbol *Func) override;
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Expand Down Expand Up @@ -269,13 +268,6 @@ void MCMachOStreamer::emitDarwinTargetVariantBuildVersion(
Minor, Update, SDKVersion);
}

void MCMachOStreamer::emitThumbFunc(MCSymbol *Symbol) {
// Remember that the function is a thumb function. Fixup and relocation
// values will need adjusted.
getAssembler().setIsThumbFunc(Symbol);
cast<MCSymbolMachO>(Symbol)->setThumbFunc();
}

bool MCMachOStreamer::emitSymbolAttribute(MCSymbol *Sym,
MCSymbolAttr Attribute) {
MCSymbolMachO *Symbol = cast<MCSymbolMachO>(Sym);
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/MC/MCStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,6 @@ void MCStreamer::emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi,
}

void MCStreamer::emitAssemblerFlag(MCAssemblerFlag Flag) {}
void MCStreamer::emitThumbFunc(MCSymbol *Func) {}
void MCStreamer::emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {}
void MCStreamer::beginCOFFSymbolDef(const MCSymbol *Symbol) {
llvm_unreachable("this directive only supported on COFF targets");
Expand Down
4 changes: 0 additions & 4 deletions llvm/lib/MC/MCWasmStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,6 @@ void MCWasmStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) {
}
}

void MCWasmStreamer::emitThumbFunc(MCSymbol *Func) {
llvm_unreachable("Generic Wasm doesn't support this directive");
}

void MCWasmStreamer::emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
llvm_unreachable("Wasm doesn't support this directive");
}
Expand Down
4 changes: 0 additions & 4 deletions llvm/lib/MC/MCWinCOFFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,6 @@ void MCWinCOFFStreamer::emitAssemblerFlag(MCAssemblerFlag Flag) {
}
}

void MCWinCOFFStreamer::emitThumbFunc(MCSymbol *Func) {
llvm_unreachable("not implemented");
}

bool MCWinCOFFStreamer::emitSymbolAttribute(MCSymbol *S,
MCSymbolAttr Attribute) {
auto *Symbol = cast<MCSymbolCOFF>(S);
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Target/ARM/ARMAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ void ARMAsmPrinter::emitFunctionBodyEnd() {
}

void ARMAsmPrinter::emitFunctionEntryLabel() {
auto &TS =
static_cast<ARMTargetStreamer &>(*OutStreamer->getTargetStreamer());
if (AFI->isThumbFunction()) {
OutStreamer->emitAssemblerFlag(MCAF_Code16);
OutStreamer->emitThumbFunc(CurrentFnSym);
TS.emitThumbFunc(CurrentFnSym);
} else {
OutStreamer->emitAssemblerFlag(MCAF_Code32);
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11712,7 +11712,7 @@ void ARMAsmParser::doBeforeLabelEmit(MCSymbol *Symbol, SMLoc IDLoc) {

void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
if (NextSymbolIsThumb) {
getParser().getStreamer().emitThumbFunc(Symbol);
getTargetStreamer().emitThumbFunc(Symbol);
NextSymbolIsThumb = false;
}
}
Expand All @@ -11732,7 +11732,7 @@ bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Parser.getTok().is(AsmToken::String)) {
MCSymbol *Func = getParser().getContext().getOrCreateSymbol(
Parser.getTok().getIdentifier());
getParser().getStreamer().emitThumbFunc(Func);
getTargetStreamer().emitThumbFunc(Func);
Parser.Lex();
if (parseEOL())
return true;
Expand Down
27 changes: 20 additions & 7 deletions llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class ARMTargetAsmStreamer : public ARMTargetStreamer {
void finishAttributeSection() override;

void annotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE) override;
void emitThumbFunc(MCSymbol *Symbol) override;
void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value) override;

void emitARMWinCFIAllocStack(unsigned Size, bool Wide) override;
Expand Down Expand Up @@ -260,6 +261,17 @@ void ARMTargetAsmStreamer::annotateTLSDescriptorSequence(
OS << "\t.tlsdescseq\t" << S->getSymbol().getName() << "\n";
}

void ARMTargetAsmStreamer::emitThumbFunc(MCSymbol *Symbol) {
const MCAsmInfo *MAI = Streamer.getContext().getAsmInfo();
OS << "\t.thumb_func";
// Only Mach-O hasSubsectionsViaSymbols()
if (MAI->hasSubsectionsViaSymbols()) {
OS << '\t';
Symbol->print(OS, MAI);
}
OS << '\n';
}

void ARMTargetAsmStreamer::emitThumbSet(MCSymbol *Symbol, const MCExpr *Value) {
const MCAsmInfo *MAI = Streamer.getContext().getAsmInfo();

Expand Down Expand Up @@ -422,6 +434,7 @@ class ARMTargetELFStreamer : public ARMTargetStreamer {
void emitLabel(MCSymbol *Symbol) override;

void annotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE) override;
void emitThumbFunc(MCSymbol *Symbol) override;
void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value) override;

// Reset state between object emissions
Expand Down Expand Up @@ -686,11 +699,6 @@ class ARMELFStreamer : public MCELFStreamer {
Symbol->setBinding(ELF::STB_LOCAL);
}

void emitThumbFunc(MCSymbol *Func) override {
getAssembler().setIsThumbFunc(Func);
emitSymbolAttribute(Func, MCSA_ELF_TypeFunction);
}

// Helper functions for ARM exception handling directives
void EHReset();

Expand Down Expand Up @@ -1089,14 +1097,19 @@ void ARMTargetELFStreamer::emitLabel(MCSymbol *Symbol) {
Streamer.getAssembler().registerSymbol(*Symbol);
unsigned Type = cast<MCSymbolELF>(Symbol)->getType();
if (Type == ELF::STT_FUNC || Type == ELF::STT_GNU_IFUNC)
Streamer.emitThumbFunc(Symbol);
emitThumbFunc(Symbol);
}

void ARMTargetELFStreamer::annotateTLSDescriptorSequence(
const MCSymbolRefExpr *S) {
getStreamer().EmitFixup(S, FK_Data_4);
}

void ARMTargetELFStreamer::emitThumbFunc(MCSymbol *Symbol) {
getStreamer().getAssembler().setIsThumbFunc(Symbol);
getStreamer().emitSymbolAttribute(Symbol, MCSA_ELF_TypeFunction);
}

void ARMTargetELFStreamer::emitThumbSet(MCSymbol *Symbol, const MCExpr *Value) {
if (const MCSymbolRefExpr *SRE = dyn_cast<MCSymbolRefExpr>(Value)) {
const MCSymbol &Sym = SRE->getSymbol();
Expand All @@ -1106,7 +1119,7 @@ void ARMTargetELFStreamer::emitThumbSet(MCSymbol *Symbol, const MCExpr *Value) {
}
}

getStreamer().emitThumbFunc(Symbol);
emitThumbFunc(Symbol);
getStreamer().emitAssignment(Symbol, Value);
}

Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ MCTargetStreamer *createARMTargetAsmStreamer(MCStreamer &S,
MCTargetStreamer *createARMObjectTargetStreamer(MCStreamer &S,
const MCSubtargetInfo &STI);
MCTargetStreamer *createARMObjectTargetELFStreamer(MCStreamer &S);
MCTargetStreamer *createARMObjectTargetMachOStreamer(MCStreamer &S);
MCTargetStreamer *createARMObjectTargetWinCOFFStreamer(MCStreamer &S);

MCCodeEmitter *createARMLEMCCodeEmitter(const MCInstrInfo &MCII,
Expand Down
23 changes: 23 additions & 0 deletions llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCFixup.h"
#include "llvm/MC/MCMachObjectWriter.h"
#include "llvm/MC/MCObjectStreamer.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCSymbolMachO.h"
#include "llvm/MC/MCValue.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/ErrorHandling.h"

using namespace llvm;
Expand Down Expand Up @@ -489,3 +492,23 @@ llvm::createARMMachObjectWriter(bool Is64Bit, uint32_t CPUType,
uint32_t CPUSubtype) {
return std::make_unique<ARMMachObjectWriter>(Is64Bit, CPUType, CPUSubtype);
}

namespace {
class ARMTargetMachOStreamer : public ARMTargetStreamer {
public:
ARMTargetMachOStreamer(MCStreamer &S) : ARMTargetStreamer(S) {}
MCObjectStreamer &getStreamer() {
return static_cast<MCObjectStreamer &>(Streamer);
}
void emitThumbFunc(MCSymbol *Symbol) override {
// Remember that the function is a thumb function. Fixup and relocation
// values will need adjusted.
getStreamer().getAssembler().setIsThumbFunc(Symbol);
cast<MCSymbolMachO>(Symbol)->setThumbFunc();
}
};
} // namespace

MCTargetStreamer *llvm::createARMObjectTargetMachOStreamer(MCStreamer &S) {
return new ARMTargetMachOStreamer(S);
}
3 changes: 3 additions & 0 deletions llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ void ARMTargetStreamer::emitFPU(ARM::FPUKind FPU) {}
void ARMTargetStreamer::finishAttributeSection() {}
void ARMTargetStreamer::annotateTLSDescriptorSequence(
const MCSymbolRefExpr *SRE) {}
void ARMTargetStreamer::emitThumbFunc(MCSymbol *Symbol) {}
void ARMTargetStreamer::emitThumbSet(MCSymbol *Symbol, const MCExpr *Value) {}

void ARMTargetStreamer::emitARMWinCFIAllocStack(unsigned Size, bool Wide) {}
Expand Down Expand Up @@ -329,5 +330,7 @@ llvm::createARMObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
return createARMObjectTargetELFStreamer(S);
if (TT.isOSBinFormatCOFF())
return createARMObjectTargetWinCOFFStreamer(S);
if (TT.isOSBinFormatMachO())
return createARMObjectTargetMachOStreamer(S);
return new ARMTargetStreamer(S);
}
14 changes: 9 additions & 5 deletions llvm/lib/Target/ARM/MCTargetDesc/ARMWinCOFFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class ARMWinCOFFStreamer : public MCWinCOFFStreamer {
void emitWindowsUnwindTables() override;
void emitWindowsUnwindTables(WinEH::FrameInfo *Frame) override;

void emitThumbFunc(MCSymbol *Symbol) override;
void finishImpl() override;
};

Expand All @@ -54,10 +53,6 @@ void ARMWinCOFFStreamer::emitWindowsUnwindTables() {
EHStreamer.Emit(*this);
}

void ARMWinCOFFStreamer::emitThumbFunc(MCSymbol *Symbol) {
getAssembler().setIsThumbFunc(Symbol);
}

void ARMWinCOFFStreamer::finishImpl() {
emitFrames(nullptr);
emitWindowsUnwindTables();
Expand All @@ -80,6 +75,11 @@ class ARMTargetWinCOFFStreamer : public llvm::ARMTargetStreamer {
public:
ARMTargetWinCOFFStreamer(llvm::MCStreamer &S) : ARMTargetStreamer(S) {}

ARMWinCOFFStreamer &getStreamer() {
return static_cast<ARMWinCOFFStreamer &>(Streamer);
}
void emitThumbFunc(MCSymbol *Symbol) override;

// The unwind codes on ARM Windows are documented at
// https://docs.microsoft.com/en-us/cpp/build/arm-exception-handling
void emitARMWinCFIAllocStack(unsigned Size, bool Wide) override;
Expand All @@ -97,6 +97,10 @@ class ARMTargetWinCOFFStreamer : public llvm::ARMTargetStreamer {
void emitARMWinUnwindCode(unsigned UnwindCode, int Reg, int Offset);
};

void ARMTargetWinCOFFStreamer::emitThumbFunc(MCSymbol *Symbol) {
getStreamer().getAssembler().setIsThumbFunc(Symbol);
}

// Helper function to common out unwind code setup for those codes that can
// belong to both prolog and epilog.
void ARMTargetWinCOFFStreamer::emitARMWinUnwindCode(unsigned UnwindCode,
Expand Down