- /// IsTemporary - True if this is an assembler temporary label, which
- /// typically does not survive in the .o file's symbol table. Usually
- /// "Lfoo" or ".foo".
- unsigned IsTemporary : 1;
-
- /// \brief True if this symbol can be redefined.
- unsigned IsRedefinable : 1;
-
- /// IsUsed - True if this symbol has been used.
- mutable unsigned IsUsed : 1;
-
- private: // MCContext creates and uniques these.
- friend class MCExpr;
- friend class MCContext;
- MCSymbol(StringRef name, bool isTemporary)
- : Name(name), Section(nullptr), Value(nullptr),
- IsTemporary(isTemporary), IsRedefinable(false), IsUsed(false) {}
-
- MCSymbol(const MCSymbol&) = delete;
- void operator=(const MCSymbol&) = delete;
- const MCSection *getSectionPtr() const {
- if (Section || !Value)
- return Section;
- return Section = Value->FindAssociatedSection();
- }
+protected: // MCContext creates and uniques these.
+ friend class MCExpr;
+ friend class MCContext;
+
+ /// \brief The name for a symbol.
+ /// MCSymbol contains a uint64_t so is probably aligned to 8. On a 32-bit
+ /// system, the name is a pointer so isn't going to satisfy the 8 byte
+ /// alignment of uint64_t. Account for that here.
+ typedef union {
+ const StringMapEntry<bool> *NameEntry;
+ uint64_t AlignmentPadding;
+ } NameEntryStorageTy;
+
+ MCSymbol(SymbolKind Kind, const StringMapEntry<bool> *Name, bool isTemporary)
+ : IsTemporary(isTemporary), IsRedefinable(false), IsUsed(false),
+ IsRegistered(false), IsExternal(false), IsPrivateExtern(false),
+ Kind(Kind), IsUsedInReloc(false), SymbolContents(SymContentsUnset),
+ CommonAlignLog2(0), Flags(0) {
+ Offset = 0;
+ SectionOrFragmentAndHasName.setInt(!!Name);
+ if (Name)
+ getNameEntryPtr() = Name;
+ }
+
+ // Provide custom new/delete as we will only allocate space for a name
+ // if we need one.
+ void *operator new(size_t s, const StringMapEntry<bool> *Name,
+ MCContext &Ctx);
+
+private:
+
+ void operator delete(void *);
+ /// \brief Placement delete - required by std, but never called.
+ void operator delete(void*, unsigned) {
+ llvm_unreachable("Constructor throws?");
+ }
+ /// \brief Placement delete - required by std, but never called.
+ void operator delete(void*, unsigned, bool) {
+ llvm_unreachable("Constructor throws?");
+ }
+
+ MCSymbol(const MCSymbol &) = delete;
+ void operator=(const MCSymbol &) = delete;
+ MCSection *getSectionPtr(bool SetUsed = true) const {
+ if (MCFragment *F = getFragment())
+ return F->getParent();
+ const auto &SectionOrFragment = SectionOrFragmentAndHasName.getPointer();
+ assert(!SectionOrFragment.is<MCFragment *>() && "Section or null expected");
+ MCSection *Section = SectionOrFragment.dyn_cast<MCSection *>();
+ if (Section || !isVariable())
+ return Section;
+ return Section = getVariableValue(SetUsed)->findAssociatedSection();
+ }
+
+ /// \brief Get a reference to the name field. Requires that we have a name
+ const StringMapEntry<bool> *&getNameEntryPtr() {
+ assert(SectionOrFragmentAndHasName.getInt() && "Name is required");
+ NameEntryStorageTy *Name = reinterpret_cast<NameEntryStorageTy *>(this);
+ return (*(Name - 1)).NameEntry;
+ }
+ const StringMapEntry<bool> *&getNameEntryPtr() const {
+ return const_cast<MCSymbol*>(this)->getNameEntryPtr();
+ }