MCSymbol *Begin, const MCSectionELF *Associated)
: MCSection(SV_ELF, K, Begin), SectionName(Section), Type(type),
Flags(flags), UniqueID(UniqueID), EntrySize(entrySize), Group(group),
- Associated(Associated) {}
+ Associated(Associated) {
+ if (Group)
+ Group->setIsSignature();
+ }
~MCSectionELF() override;
void setSectionName(StringRef Name) { SectionName = Name; }
mutable unsigned BindingSet : 1;
mutable unsigned UsedInReloc : 1;
+ mutable unsigned IsSignature : 1;
public:
MCSymbolELF(const StringMapEntry<bool> *Name, bool isTemporary)
void setUsedInReloc() const;
bool isUsedInReloc() const;
+ void setIsSignature() const;
+ bool isSignature() const;
+
static bool classof(const MCSymbol *S) { return S->isELF(); }
};
}
static uint64_t SymbolValue(const MCSymbol &Sym, const MCAsmLayout &Layout);
static bool isInSymtab(const MCAsmLayout &Layout, const MCSymbolELF &Symbol,
bool Used, bool Renamed);
- static bool isLocal(const MCSymbolELF &Symbol, bool IsSignature);
/// Helper struct for containing some precomputed information on symbols.
struct ELFSymbolData {
return true;
}
-bool ELFObjectWriter::isLocal(const MCSymbolELF &Symbol, bool IsSignature) {
- if (Symbol.isExternal())
- return false;
-
- if (Symbol.isDefined())
- return true;
-
- if (Symbol.isUsedInReloc())
- return false;
-
- return IsSignature;
-}
-
void ELFObjectWriter::computeSymbolTable(
MCAssembler &Asm, const MCAsmLayout &Layout,
const SectionIndexMapTy &SectionIndexMap, const RevGroupMapTy &RevGroupMap,
const auto &Symbol = cast<MCSymbolELF>(S);
bool Used = Symbol.isUsedInReloc();
bool WeakrefUsed = WeakrefUsedInReloc.count(&Symbol);
- bool isSignature = RevGroupMap.count(&Symbol);
+ bool isSignature = Symbol.isSignature();
if (!isInSymtab(Layout, Symbol, Used || WeakrefUsed || isSignature,
Renames.count(&Symbol)))
ELFSymbolData MSD;
MSD.Symbol = cast<MCSymbolELF>(&Symbol);
- // Undefined symbols are global, but this is the first place we
- // are able to set it.
- bool Local = isLocal(Symbol, isSignature);
- if (!Local && Symbol.getBinding() == ELF::STB_LOCAL)
- Symbol.setBinding(ELF::STB_GLOBAL);
-
+ bool Local = Symbol.getBinding() == ELF::STB_LOCAL;
if (Symbol.isAbsolute()) {
MSD.SectionIndex = ELF::SHN_ABS;
} else if (Symbol.isCommon()) {
}
unsigned MCSymbolELF::getBinding() const {
- uint32_t Binding = (getFlags() & (0xf << ELF_STB_Shift)) >> ELF_STB_Shift;
- assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
- Binding == ELF::STB_WEAK || Binding == ELF::STB_GNU_UNIQUE);
- return Binding;
+ if (isBindingSet()) {
+ uint32_t Binding = (getFlags() & (0xf << ELF_STB_Shift)) >> ELF_STB_Shift;
+ assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
+ Binding == ELF::STB_WEAK || Binding == ELF::STB_GNU_UNIQUE);
+ return Binding;
+ }
+
+ if (isDefined())
+ return ELF::STB_LOCAL;
+ if (isUsedInReloc())
+ return ELF::STB_GLOBAL;
+ if (isSignature())
+ return ELF::STB_LOCAL;
+ return ELF::STB_GLOBAL;
}
void MCSymbolELF::setType(unsigned Type) const {
return UsedInReloc;
}
+void MCSymbolELF::setIsSignature() const { IsSignature = true; }
+
+bool MCSymbolELF::isSignature() const { return IsSignature; }
}