40 bool MCELFStreamer::isBundleLocked()
const {
60 if (RequiredBundlePadding > UINT8_MAX)
63 if (RequiredBundlePadding > 0) {
80 for (
unsigned i = 0, e = EF->
getFixups().size(); i != e; ++i) {
109 auto *
Symbol = cast<MCSymbolELF>(S);
110 assert(
Symbol->isUndefined() &&
"Cannot define a symbol twice!");
147 const MCExpr *Subsection) {
149 if (CurSection && isBundleLocked())
156 const MCSymbol *Grp = SectionELF->getGroup();
162 auto *Begin = cast_or_null<MCSymbolELF>(Section->
getBeginSymbol());
167 if (Begin->isUndefined()) {
200 auto *
Symbol = cast<MCSymbolELF>(S);
242 Symbol->setExternal(
true);
247 Symbol->setExternal(
true);
253 Symbol->setExternal(
true);
258 Symbol->setExternal(
false);
304 auto *
Symbol = cast<MCSymbolELF>(S);
307 if (!
Symbol->isBindingSet()) {
309 Symbol->setExternal(
true);
320 struct LocalCommon L = {
Symbol, Size, ByteAlignment};
321 LocalCommons.push_back(L);
323 if(
Symbol->declareCommon(Size, ByteAlignment))
325 " redeclared as different type");
338 auto *
Symbol = cast<MCSymbolELF>(S);
342 Symbol->setExternal(
false);
348 if (isBundleLocked())
350 fixSymbolsInTLSFixups(Value);
357 unsigned MaxBytesToEmit) {
358 if (isBundleLocked())
361 ValueSize, MaxBytesToEmit);
385 void MCELFStreamer::fixSymbolsInTLSFixups(
const MCExpr *expr) {
388 cast<MCTargetExpr>(expr)->fixELFSymbolsInTLSFixups(
getAssembler());
395 fixSymbolsInTLSFixups(be->
getLHS());
396 fixSymbolsInTLSFixups(be->
getRHS());
462 fixSymbolsInTLSFixups(cast<MCUnaryExpr>(expr)->getSubExpr());
467 void MCELFStreamer::EmitInstToFragment(
const MCInst &Inst,
472 for (
unsigned i = 0, e = F.
getFixups().size(); i != e; ++i)
473 fixSymbolsInTLSFixups(F.
getFixups()[i].getValue());
476 void MCELFStreamer::EmitInstToData(
const MCInst &Inst,
485 for (
unsigned i = 0, e = Fixups.
size(); i != e; ++i)
486 fixSymbolsInTLSFixups(Fixups[i].getValue());
510 DF = BundleGroups.back();
511 else if (Assembler.
getRelaxAll() && !isBundleLocked())
520 else if (!isBundleLocked() && Fixups.
size() == 0) {
548 for (
unsigned i = 0, e = Fixups.
size(); i != e; ++i) {
556 if (!isBundleLocked()) {
564 assert(AlignPow2 <= 30 &&
"Invalid bundle alignment");
581 if (!isBundleLocked())
584 if (
getAssembler().getRelaxAll() && !isBundleLocked()) {
587 BundleGroups.push_back(DF);
600 else if (!isBundleLocked())
609 assert(!BundleGroups.empty() &&
"There are no bundle groups");
616 if (!isBundleLocked()) {
618 BundleGroups.pop_back();
629 for (std::vector<LocalCommon>::const_iterator i = LocalCommons.begin(),
630 e = LocalCommons.end();
633 uint64_t Size = i->Size;
648 LocalCommons.clear();
void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a local common (.lcomm) symbol.
void AssignSection(MCSymbol *Symbol, MCSection *Section)
Sets the symbol's section.
MCSymbolELF * getOrCreateSectionSymbol(const MCSectionELF &Section)
Instances of this class represent a uniqued identifier for a section in the current translation unit...
void Flush() override
Causes any cached state to be written out.
virtual MCObjectWriter * createObjectWriter(raw_pwrite_stream &OS) const =0
Create a new MCObjectWriter instance for use by the assembler backend to emit the final object file...
void EmitBundleAlignMode(unsigned AlignPow2) override
Set the bundle alignment mode from now on in the section.
const MCAsmInfo * getAsmInfo() const
void EmitBytes(StringRef Data) override
Emit the bytes in Data into the output.
const MCSymbol & getSymbol() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
bool hasInstructions() const
void EmitLabel(MCSymbol *Symbol) override
Emit a label for Symbol into the current section.
.type _foo, STT_OBJECT # aka
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
void EmitBundleUnlock() override
Ends a bundle-locked group.
MCSectionELF * getELFSection(StringRef Section, unsigned Type, unsigned Flags)
virtual void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &)
Emit an instruction to a special fragment, because this instruction can change its size during relaxa...
void EmitZerofill(MCSection *Section, MCSymbol *Symbol=nullptr, uint64_t Size=0, unsigned ByteAlignment=0) override
Emit the zerofill section and an optional symbol.
unsigned getBundleAlignSize() const
void setAlignment(unsigned Value)
void writeFragmentPadding(const MCFragment &F, uint64_t FSize, MCObjectWriter *OW) const
Write the necessary bundle padding to the given object writer.
unsigned getFlags() const
void setBundleLockState(BundleLockStateType NewState)
void emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) override
Emit an ELF .size directive.
MCCodeEmitter & getEmitter() const
A raw_ostream that writes to an SmallVector or SmallString.
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
void PushSection()
Save the current and previous section on the section stack.
MCSection * getDataSection() const
This is a compact (memory-size-wise) fragment for holding an encoded instruction (non-relaxable) that...
void EmitCOFFSymbolType(int Type) override
Emit the type of the symbol.
void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override
Emit an weak reference from Alias to Symbol.
std::vector< IndirectSymbolData > & getIndirectSymbols()
bool registerSection(MCSection &Section)
.type _foo, STT_NOTYPE # aka
unsigned getAlignment() const
static std::error_code getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
COFF::SymbolStorageClass StorageClass
void BeginCOFFSymbolDef(const MCSymbol *Symbol) override
Start emitting COFF symbol definition.
MCContext & getContext() const
static unsigned CombineSymbolTypes(unsigned T1, unsigned T2)
Defines the object file and target independent interfaces used by the assembler backend to write nati...
void EmitIdent(StringRef IdentString) override
Emit the "identifiers" directive.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
void InitSections(bool NoExecStack) override
Create the default sections and set the initial one.
MCFragment * getCurrentFragment() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void EmitFileDirective(StringRef Filename) override
Switch to a new logical file.
virtual void encodeInstruction(const MCInst &Inst, raw_ostream &OS, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const =0
EncodeInstruction - Encode the given Inst to bytes on the output stream OS.
void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment=0) override
Emit a thread local bss (.tbss) symbol.
void setRelaxAll(bool Value)
MCSection * getCurrentSectionOnly() const
Base class for the full range of assembler expressions which are needed for parsing.
bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
void EmitLabel(MCSymbol *Symbol) override
Emit a label for Symbol into the current section.
Represent a reference to a symbol from inside an expression.
void setAlignToBundleEnd(bool V)
MCContext & getContext() const
void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override
Set the DescValue for the Symbol.
void EmitValueToAlignment(unsigned, int64_t, unsigned, unsigned) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
void setSubsectionsViaSymbols(bool Value)
Context object for machine code objects.
MCSection * getBSSSection() const
void EmitThumbFunc(MCSymbol *Func) override
Note in the output that the specified Func is a Thumb mode function (ARM target only).
void setHasInstructions(bool V)
.code16 (X86) / .code 16 (ARM)
.type _foo, STT_GNU_IFUNC
void setBundleAlignSize(unsigned Size)
SmallVectorImpl< char > & getContents()
virtual void EmitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers...
Instances of this class represent a single low-level machine instruction.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override
Update streamer for a new active section.
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Streaming machine code generation interface.
.weak_def_can_be_hidden (MachO)
The instances of the Type class are immutable: once they are created, they are never changed...
void insert(MCFragment *F)
void setSize(const MCExpr *SS)
void EmitCodeAlignment(unsigned ByteAlignment, unsigned MaxBytesToEmit=0) override
Emit nops until the byte alignment ByteAlignment is reached.
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
static void setSectionAlignmentForBundling(const MCAssembler &Assembler, MCSection *Section)
MCAssembler & getAssembler()
MCCodeEmitter - Generic instruction encoding interface.
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a common symbol.
SmallVectorImpl< MCFixup > & getFixups()
.subsections_via_symbols (MachO)
void EmitValueImpl(const MCExpr *Value, unsigned Size, const SMLoc &Loc=SMLoc()) override
Emit the expression Value into the output as a native integer of the given Size bytes.
MCSection * getTextSection() const
void EmitFrames(MCAsmBackend *MAB)
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Binary assembler expressions.
void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
uint64_t computeBundlePadding(const MCAssembler &Assembler, const MCFragment *F, uint64_t FOffset, uint64_t FSize)
Compute the amount of padding required before the fragment F to obey bundling restrictions, where FOffset is the fragment's offset in its section and FSize is the fragment's size.
void setFragment(MCFragment *Value) const
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override
Update streamer for a new active section.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool isBundlingEnabled() const
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
.type _foo, STT_TLS # aka
MCSymbol * getBeginSymbol()
MCStreamer * createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB, raw_pwrite_stream &OS, MCCodeEmitter *CE, bool RelaxAll)
Takes ownership of TAB and CE.
void setVariableValue(const MCExpr *Value)
void addFileName(StringRef FileName)
void flushPendingLabels(MCFragment *F, uint64_t FOffset=0)
If any labels have been emitted but not assigned fragments, ensure that they get assigned, either to F if possible or to a new data fragment.
.code32 (X86) / .code 32 (ARM)
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
.type _foo, STT_COMMON # aka
void setBundlePadding(uint8_t N)
Set the padding size for this fragment.
virtual void handleAssemblerFlag(MCAssemblerFlag Flag)
Handle any target-specific assembler flags. By default, do nothing.
void EmitValueImpl(const MCExpr *Value, unsigned Size, const SMLoc &Loc=SMLoc()) override
Emit the expression Value into the output as a native integer of the given Size bytes.
void FinishImpl() override
Streamer specific finalization.
.type _foo, STT_FUNC # aka
MCAsmBackend & getBackend() const
bool isBundleGroupBeforeFirstInst() const
MCSubtargetInfo - Generic base class for all target subtargets.
MCSectionELF - This represents a section on linux, lots of unix variants and some bare metal systems...
References to labels and assigned expressions.
BundleLockStateType getBundleLockState() const
void setBundleGroupBeforeFirstInst(bool IsFirst)
An abstract base class for streams implementations that also support a pwrite operation.
Fragment for data and encoded instructions.
virtual MCSection * getNonexecutableStackSection(MCContext &Ctx) const
Targets can implement this method to specify a section to switch to if the translation unit doesn't h...
VariantKind getKind() const
void EmitBundleLock(bool AlignToEnd) override
The following instructions are a bundle-locked group.
cl::opt< bool > RelaxAll("mc-relax-all", cl::desc("When used with filetype=obj, ""relax all fixups in the emitted object file"))
bool PopSection()
Restore the current and previous section from the section stack.
LLVM Value Representation.
Generic interface to target specific assembler backends.
const MCObjectFileInfo * getObjectFileInfo() const
bool isBundleLocked() const
void EndCOFFSymbolDef() override
Marks the end of the symbol definition.
void EmitAssemblerFlag(MCAssemblerFlag Flag) override
Note in the output the specified Flag.
StringRef - Represent a constant reference to a string, i.e.
Target specific expression.
~MCELFStreamer() override
Represents a location in source code.
void FinishImpl() override
Streamer specific finalization.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
MCDataFragment * getOrCreateDataFragment()
Get a data fragment to write into, creating a new one if the current fragment is not a data fragment...
void EmitCOFFSymbolStorageClass(int StorageClass) override
Emit the storage class of the symbol.
void setBeginSymbol(MCSymbol *Sym)