class MCExpr;
class MCSection;
class MCSymbol;
+ class MCSymbolELF;
class MCLabel;
struct MCDwarfFile;
class MCDwarfLoc;
/// ELF sections can have a corresponding symbol. This maps one to the
/// other.
- DenseMap<const MCSectionELF *, MCSymbol *> SectionSymbols;
+ DenseMap<const MCSectionELF *, MCSymbolELF *> SectionSymbols;
/// A mapping from a local label number and an instance count to a symbol.
/// For example, in the assembly
/// Do automatic reset in destructor
bool AutoReset;
+ MCSymbol *createSymbolImpl(const StringMapEntry<bool> *Name,
+ bool IsTemporary);
MCSymbol *CreateSymbol(StringRef Name, bool AlwaysAddSuffix);
MCSymbol *getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
/// \param Name - The symbol name, which must be unique across all symbols.
MCSymbol *getOrCreateSymbol(const Twine &Name);
- MCSymbol *getOrCreateSectionSymbol(const MCSectionELF &Section);
+ MCSymbolELF *getOrCreateSectionSymbol(const MCSectionELF &Section);
/// Gets a symbol that will be defined to the final stack offset of a local
/// variable after codegen.
class MCCodeEmitter;
class MCExpr;
class MCInst;
-class MCSymbol;
class raw_ostream;
class MCELFStreamer : public MCObjectStreamer {
void EmitCOFFSymbolType(int Type) override;
void EndCOFFSymbolDef() override;
- void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) override;
+ void emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) override;
void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) override;
class MCSection;
class MCStreamer;
class MCSymbol;
+class MCSymbolELF;
class MCSymbolRefExpr;
class MCSubtargetInfo;
class StringRef;
///
/// This corresponds to an assembler statement such as:
/// .size symbol, expression
- virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
+ virtual void emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value);
/// \brief Emit a Linker Optimization Hint (LOH) directive.
/// \param Args - Arguments of the LOH.
mutable unsigned HasFragment : 1;
+ unsigned IsELF : 1;
+
/// Index field, for use by the object file implementation.
mutable uint32_t Index = 0;
- /// An expression describing how to calculate the size of a symbol. If a
- /// symbol has no size this field will be NULL.
- const MCExpr *SymbolSize = nullptr;
-
union {
/// The offset to apply to the fragment address to form this symbol's value.
uint64_t Offset;
/// additional per symbol information which is not easily classified.
mutable uint32_t Flags = 0;
-private: // MCContext creates and uniques these.
+protected: // MCContext creates and uniques these.
friend class MCExpr;
friend class MCContext;
- MCSymbol(const StringMapEntry<bool> *Name, bool isTemporary)
+ MCSymbol(bool IsELF, const StringMapEntry<bool> *Name, bool isTemporary)
: Name(Name), Section(nullptr), Value(nullptr), IsTemporary(isTemporary),
IsRedefinable(false), IsUsed(false), IsRegistered(false),
- IsExternal(false), IsPrivateExtern(false), HasFragment(false) {
+ IsExternal(false), IsPrivateExtern(false), HasFragment(false),
+ IsELF(IsELF) {
Offset = 0;
}
+private:
MCSymbol(const MCSymbol &) = delete;
void operator=(const MCSymbol &) = delete;
MCSection *getSectionPtr() const {
Section = nullptr;
}
+ bool isELF() const { return IsELF; }
+
/// @}
/// \name Variable Symbols
/// @{
Index = Value;
}
- void setSize(const MCExpr *SS) { SymbolSize = SS; }
-
- const MCExpr *getSize() const { return SymbolSize; }
-
uint64_t getOffset() const {
assert(!isCommon());
return Offset;
--- /dev/null
+//===- MCSymbolELF.h - -----------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_MC_MCSYMBOLELF_H
+#define LLVM_MC_MCSYMBOLELF_H
+
+#include "llvm/MC/MCSymbol.h"
+
+namespace llvm {
+class MCSymbolELF : public MCSymbol {
+ /// An expression describing how to calculate the size of a symbol. If a
+ /// symbol has no size this field will be NULL.
+ const MCExpr *SymbolSize = nullptr;
+
+public:
+ MCSymbolELF(const StringMapEntry<bool> *Name, bool isTemporary)
+ : MCSymbol(true, Name, isTemporary) {}
+ void setSize(const MCExpr *SS) { SymbolSize = SS; }
+
+ const MCExpr *getSize() const { return SymbolSize; }
+
+ static bool classof(const MCSymbol *S) { return S->isELF(); }
+};
+}
+
+#endif
void EmitCOFFSafeSEH(MCSymbol const *Symbol) override;
void EmitCOFFSectionIndex(MCSymbol const *Symbol) override;
void EmitCOFFSecRel32(MCSymbol const *Symbol) override;
- void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) override;
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) override;
void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCStreamer.h"
-#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCSymbolELF.h"
#include "llvm/MC/MCValue.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
if (MAI->hasDotTypeDotSizeDirective())
// .size foo, 42
- OutStreamer->EmitELFSize(GVSym, MCConstantExpr::create(Size, OutContext));
+ OutStreamer->emitELFSize(cast<MCSymbolELF>(GVSym),
+ MCConstantExpr::create(Size, OutContext));
OutStreamer->AddBlankLine();
}
MCSymbolRefExpr::create(CurrentFnSymForSize,
OutContext),
OutContext);
- OutStreamer->EmitELFSize(CurrentFnSym, SizeExp);
+ OutStreamer->emitELFSize(cast<MCSymbolELF>(CurrentFnSym), SizeExp);
}
for (const HandlerInfo &HI : Handlers) {
#include "llvm/MC/MCSectionELF.h"
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/MC/MCStreamer.h"
-#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCSymbolELF.h"
#include "llvm/MC/MCValue.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/ELF.h"
const MCSymbol *Sym) const {
SmallString<64> NameData("DW.ref.");
NameData += Sym->getName();
- MCSymbol *Label = getContext().getOrCreateSymbol(NameData);
+ MCSymbolELF *Label =
+ cast<MCSymbolELF>(getContext().getOrCreateSymbol(NameData));
Streamer.EmitSymbolAttribute(Label, MCSA_Hidden);
Streamer.EmitSymbolAttribute(Label, MCSA_Weak);
StringRef Prefix = ".data.";
Streamer.EmitValueToAlignment(TM.getDataLayout()->getPointerABIAlignment());
Streamer.EmitSymbolAttribute(Label, MCSA_ELF_TypeObject);
const MCExpr *E = MCConstantExpr::create(Size, getContext());
- Streamer.EmitELFSize(Label, E);
+ Streamer.emitELFSize(Label, E);
Streamer.EmitLabel(Label);
Streamer.EmitSymbolValue(Sym, Size);
#include "llvm/MC/MCFixupKindInfo.h"
#include "llvm/MC/MCObjectWriter.h"
#include "llvm/MC/MCSectionELF.h"
+#include "llvm/MC/MCSymbolELF.h"
#include "llvm/MC/MCValue.h"
#include "llvm/MC/StringTableBuilder.h"
#include "llvm/Support/Compression.h"
/// Helper struct for containing some precomputed information on symbols.
struct ELFSymbolData {
- const MCSymbol *Symbol;
+ const MCSymbolELF *Symbol;
uint32_t SectionIndex;
StringRef Name;
assert((!Symbol.getFragment() ||
(Symbol.getFragment()->getParent() == &Symbol.getSection())) &&
"The symbol's section doesn't match the fragment's symbol");
- const MCSymbol *Base = Layout.getBaseSymbol(Symbol);
+ const MCSymbolELF *Base =
+ cast_or_null<MCSymbolELF>(Layout.getBaseSymbol(Symbol));
// This has to be in sync with when computeSymbolTable uses SHN_ABS or
// SHN_COMMON.
continue;
ELFSymbolData MSD;
- MSD.Symbol = &Symbol;
+ MSD.Symbol = cast<MCSymbolELF>(&Symbol);
// Undefined symbols are global, but this is the first place we
// are able to set it.
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSectionCOFF.h"
#include "llvm/MC/MCSectionMachO.h"
-#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCSymbolELF.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
void EmitCOFFSafeSEH(MCSymbol const *Symbol) override;
void EmitCOFFSectionIndex(MCSymbol const *Symbol) override;
void EmitCOFFSecRel32(MCSymbol const *Symbol) override;
- void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) override;
+ void emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) override;
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) override;
EmitEOL();
}
-void MCAsmStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
+void MCAsmStreamer::emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) {
assert(MAI->hasDotTypeDotSizeDirective());
OS << "\t.size\t" << *Symbol << ", " << *Value << '\n';
}
#include "llvm/MC/MCSectionELF.h"
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/MC/MCStreamer.h"
-#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCSymbolELF.h"
#include "llvm/Support/ELF.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
return Sym;
}
-MCSymbol *MCContext::getOrCreateSectionSymbol(const MCSectionELF &Section) {
- MCSymbol *&Sym = SectionSymbols[&Section];
+MCSymbolELF *MCContext::getOrCreateSectionSymbol(const MCSectionELF &Section) {
+ MCSymbolELF *&Sym = SectionSymbols[&Section];
if (Sym)
return Sym;
MCSymbol *&OldSym = Symbols[Name];
if (OldSym && OldSym->isUndefined()) {
- Sym = OldSym;
- return OldSym;
+ Sym = cast<MCSymbolELF>(OldSym);
+ return Sym;
}
auto NameIter = UsedNames.insert(std::make_pair(Name, true)).first;
- Sym = new (*this) MCSymbol(&*NameIter, /*isTemporary*/ false);
+ Sym = new (*this) MCSymbolELF(&*NameIter, /*isTemporary*/ false);
if (!OldSym)
OldSym = Sym;
FuncName);
}
+MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
+ bool IsTemporary) {
+ bool IsELF = MOFI && MOFI->getObjectFileType() == MCObjectFileInfo::IsELF;
+ if (IsELF)
+ return new (*this) MCSymbolELF(Name, IsTemporary);
+ return new (*this) MCSymbol(false, Name, IsTemporary);
+}
+
MCSymbol *MCContext::CreateSymbol(StringRef Name, bool AlwaysAddSuffix) {
// Determine whether this is an assembler temporary or normal label, if used.
bool IsTemporary = false;
IsTemporary = Name.startswith(MAI->getPrivateGlobalPrefix());
if (IsTemporary && AlwaysAddSuffix && !UseNamesOnTempLabels)
- return new (*this) MCSymbol(nullptr, true);
+ return createSymbolImpl(nullptr, true);
SmallString<128> NewName = Name;
bool AddSuffix = AlwaysAddSuffix;
if (NameEntry.second) {
// Ok, we found a name. Have the MCSymbol object itself refer to the copy
// of the string that is embedded in the UsedNames entry.
- MCSymbol *Result = new (*this) MCSymbol(&*NameEntry.first, IsTemporary);
- return Result;
+ return createSymbolImpl(&*NameEntry.first, IsTemporary);
}
assert(IsTemporary && "Cannot rename non-temporary symbols");
AddSuffix = true;
#include "llvm/MC/MCObjectStreamer.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCSectionELF.h"
+#include "llvm/MC/MCSymbolELF.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCValue.h"
#include "llvm/Support/Debug.h"
Symbol->setCommon(Size, ByteAlignment);
}
- Symbol->setSize(MCConstantExpr::create(Size, getContext()));
+ cast<MCSymbolELF>(Symbol)
+ ->setSize(MCConstantExpr::create(Size, getContext()));
}
-void MCELFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
+void MCELFStreamer::emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) {
Symbol->setSize(Value);
}
void EndCOFFSymbolDef() override {
llvm_unreachable("macho doesn't support this directive");
}
- void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) override {
- llvm_unreachable("macho doesn't support this directive");
- }
void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) override;
void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
#include "llvm/MC/MCParser/MCAsmLexer.h"
#include "llvm/MC/MCSectionELF.h"
#include "llvm/MC/MCStreamer.h"
-#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCSymbolELF.h"
#include "llvm/Support/ELF.h"
using namespace llvm;
StringRef Name;
if (getParser().parseIdentifier(Name))
return TokError("expected identifier in directive");
- MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
+ MCSymbolELF *Sym = cast<MCSymbolELF>(getContext().getOrCreateSymbol(Name));
if (getLexer().isNot(AsmToken::Comma))
return TokError("unexpected token in directive");
if (getLexer().isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in directive");
- getStreamer().EmitELFSize(Sym, Expr);
+ getStreamer().emitELFSize(Sym, Expr);
return false;
}
void MCStreamer::EmitFileDirective(StringRef Filename) {}
void MCStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {}
void MCStreamer::EmitCOFFSymbolType(int Type) {}
-void MCStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {}
+void MCStreamer::emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) {}
void MCStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) {}
void MCStreamer::EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
DF->getContents().resize(DF->getContents().size() + 4, 0);
}
-void MCWinCOFFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
- llvm_unreachable("not supported");
-}
-
void MCWinCOFFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) {
assert((!Symbol->isInSection() ||
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCSectionELF.h"
-#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCSymbolELF.h"
#include "llvm/Support/ELF.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/raw_ostream.h"
// __call_stub_fp_xxxx:
//
std::string x = "__call_stub_fp_" + std::string(Symbol);
- MCSymbol *Stub = OutContext.getOrCreateSymbol(StringRef(x));
+ MCSymbolELF *Stub =
+ cast<MCSymbolELF>(OutContext.getOrCreateSymbol(StringRef(x)));
TS.emitDirectiveEnt(*Stub);
MCSymbol *MType =
OutContext.getOrCreateSymbol("__call_stub_fp_" + Twine(Symbol));
const MCSymbolRefExpr *E = MCSymbolRefExpr::create(Stub, OutContext);
const MCSymbolRefExpr *T = MCSymbolRefExpr::create(Tmp, OutContext);
const MCExpr *T_min_E = MCBinaryExpr::createSub(T, E, OutContext);
- OutStreamer->EmitELFSize(Stub, T_min_E);
+ OutStreamer->emitELFSize(Stub, T_min_E);
TS.emitDirectiveEnd(x);
OutStreamer->PopSection();
}
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCStreamer.h"
-#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCSymbolELF.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/raw_ostream.h"
unsigned Size = TD->getTypeAllocSize(C->getType());
if (MAI->hasDotTypeDotSizeDirective()) {
OutStreamer->EmitSymbolAttribute(GVSym, MCSA_ELF_TypeObject);
- OutStreamer->EmitELFSize(GVSym, MCConstantExpr::create(Size, OutContext));
+ OutStreamer->emitELFSize(cast<MCSymbolELF>(GVSym),
+ MCConstantExpr::create(Size, OutContext));
}
OutStreamer->EmitLabel(GVSym);