+ /// The alignment of the symbol, if it is 'common', or -1.
+ //
+ // FIXME: Pack this in with other fields?
+ unsigned CommonAlign = -1U;
+
+ /// The Flags field is used by object file implementations to store
+ /// additional per symbol information which is not easily classified.
+ mutable uint32_t Flags = 0;
+
+protected: // MCContext creates and uniques these.
+ friend class MCExpr;
+ friend class MCContext;
+ 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),
+ IsELF(IsELF) {
+ Offset = 0;
+ }
+
+private:
+ MCSymbol(const MCSymbol &) = delete;
+ void operator=(const MCSymbol &) = delete;
+ MCSection *getSectionPtr() const {
+ if (MCFragment *F = getFragment())
+ return F->getParent();
+ assert(!HasFragment);
+ if (Section || !Value)
+ return Section;
+ return Section = Value->findAssociatedSection();
+ }
+
+public:
+ /// getName - Get the symbol name.
+ StringRef getName() const { return Name ? Name->first() : ""; }
+
+ bool isRegistered() const { return IsRegistered; }
+ void setIsRegistered(bool Value) const { IsRegistered = Value; }
+
+ /// \name Accessors
+ /// @{
+
+ /// isTemporary - Check if this is an assembler temporary symbol.
+ bool isTemporary() const { return IsTemporary; }
+
+ /// isUsed - Check if this is used.
+ bool isUsed() const { return IsUsed; }
+ void setUsed(bool Value) const { IsUsed = Value; }
+
+ /// \brief Check if this symbol is redefinable.
+ bool isRedefinable() const { return IsRedefinable; }
+ /// \brief Mark this symbol as redefinable.
+ void setRedefinable(bool Value) { IsRedefinable = Value; }
+ /// \brief Prepare this symbol to be redefined.
+ void redefineIfPossible() {
+ if (IsRedefinable) {
+ Value = nullptr;
+ Section = nullptr;
+ HasFragment = false;
+ IsRedefinable = false;
+ }
+ }
+
+ /// @}
+ /// \name Associated Sections
+ /// @{
+
+ /// isDefined - Check if this symbol is defined (i.e., it has an address).
+ ///
+ /// Defined symbols are either absolute or in some section.
+ bool isDefined() const { return getSectionPtr() != nullptr; }
+
+ /// isInSection - Check if this symbol is defined in some section (i.e., it
+ /// is defined but not absolute).
+ bool isInSection() const { return isDefined() && !isAbsolute(); }
+
+ /// isUndefined - Check if this symbol undefined (i.e., implicitly defined).
+ bool isUndefined() const { return !isDefined(); }
+
+ /// isAbsolute - Check if this is an absolute symbol.
+ bool isAbsolute() const { return getSectionPtr() == AbsolutePseudoSection; }
+
+ /// Get the section associated with a defined, non-absolute symbol.
+ MCSection &getSection() const {
+ assert(isInSection() && "Invalid accessor!");
+ return *getSectionPtr();
+ }
+
+ /// Mark the symbol as defined in the section \p S.
+ void setSection(MCSection &S) {
+ assert(!isVariable() && "Cannot set section of variable");
+ assert(!HasFragment);
+ Section = &S;
+ }
+
+ /// Mark the symbol as undefined.
+ void setUndefined() {
+ HasFragment = false;
+ Section = nullptr;