forked from OSchip/llvm-project
Add range access to MCAssembler's symbol collection.
llvm-svn: 206631
This commit is contained in:
parent
d861811e46
commit
583a31c976
|
@ -834,6 +834,9 @@ public:
|
|||
typedef SymbolDataListType::const_iterator const_symbol_iterator;
|
||||
typedef SymbolDataListType::iterator symbol_iterator;
|
||||
|
||||
typedef iterator_range<symbol_iterator> symbol_range;
|
||||
typedef iterator_range<const_symbol_iterator> const_symbol_range;
|
||||
|
||||
typedef std::vector<std::string> FileNameVectorType;
|
||||
typedef FileNameVectorType::const_iterator const_file_name_iterator;
|
||||
|
||||
|
@ -1099,6 +1102,9 @@ public:
|
|||
symbol_iterator symbol_end() { return Symbols.end(); }
|
||||
const_symbol_iterator symbol_end() const { return Symbols.end(); }
|
||||
|
||||
symbol_range symbols() { return make_range(symbol_begin(), symbol_end()); }
|
||||
const_symbol_range symbols() const { return make_range(symbol_begin(), symbol_end()); }
|
||||
|
||||
size_t symbol_size() const { return Symbols.size(); }
|
||||
|
||||
/// @}
|
||||
|
|
|
@ -530,9 +530,8 @@ void ELFObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm,
|
|||
// The presence of symbol versions causes undefined symbols and
|
||||
// versions declared with @@@ to be renamed.
|
||||
|
||||
for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
|
||||
ie = Asm.symbol_end(); it != ie; ++it) {
|
||||
const MCSymbol &Alias = it->getSymbol();
|
||||
for (MCSymbolData &OriginalData : Asm.symbols()) {
|
||||
const MCSymbol &Alias = OriginalData.getSymbol();
|
||||
const MCSymbol &Symbol = Alias.AliasedSymbol();
|
||||
MCSymbolData &SD = Asm.getSymbolData(Symbol);
|
||||
|
||||
|
@ -547,8 +546,8 @@ void ELFObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm,
|
|||
|
||||
// Aliases defined with .symvar copy the binding from the symbol they alias.
|
||||
// This is the first place we are able to copy this information.
|
||||
it->setExternal(SD.isExternal());
|
||||
MCELF::SetBinding(*it, MCELF::GetBinding(SD));
|
||||
OriginalData.setExternal(SD.isExternal());
|
||||
MCELF::SetBinding(OriginalData, MCELF::GetBinding(SD));
|
||||
|
||||
StringRef Rest = AliasName.substr(Pos);
|
||||
if (!Symbol.isUndefined() && !Rest.startswith("@@@"))
|
||||
|
@ -1046,36 +1045,35 @@ ELFObjectWriter::computeSymbolTable(MCAssembler &Asm, const MCAsmLayout &Layout,
|
|||
}
|
||||
|
||||
// Add the data for the symbols.
|
||||
for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
|
||||
ie = Asm.symbol_end(); it != ie; ++it) {
|
||||
const MCSymbol &Symbol = it->getSymbol();
|
||||
for (MCSymbolData &SD : Asm.symbols()) {
|
||||
const MCSymbol &Symbol = SD.getSymbol();
|
||||
|
||||
bool Used = UsedInReloc.count(&Symbol);
|
||||
bool WeakrefUsed = WeakrefUsedInReloc.count(&Symbol);
|
||||
bool isSignature = RevGroupMap.count(&Symbol);
|
||||
|
||||
if (!isInSymtab(Asm, *it,
|
||||
if (!isInSymtab(Asm, SD,
|
||||
Used || WeakrefUsed || isSignature,
|
||||
Renames.count(&Symbol)))
|
||||
continue;
|
||||
|
||||
ELFSymbolData MSD;
|
||||
MSD.SymbolData = it;
|
||||
MSD.SymbolData = &SD;
|
||||
const MCSymbol *BaseSymbol = getBaseSymbol(Layout, Symbol);
|
||||
|
||||
// Undefined symbols are global, but this is the first place we
|
||||
// are able to set it.
|
||||
bool Local = isLocal(*it, isSignature, Used);
|
||||
if (!Local && MCELF::GetBinding(*it) == ELF::STB_LOCAL) {
|
||||
bool Local = isLocal(SD, isSignature, Used);
|
||||
if (!Local && MCELF::GetBinding(SD) == ELF::STB_LOCAL) {
|
||||
assert(BaseSymbol);
|
||||
MCSymbolData &SD = Asm.getSymbolData(*BaseSymbol);
|
||||
MCELF::SetBinding(*it, ELF::STB_GLOBAL);
|
||||
MCSymbolData &BaseData = Asm.getSymbolData(*BaseSymbol);
|
||||
MCELF::SetBinding(SD, ELF::STB_GLOBAL);
|
||||
MCELF::SetBinding(BaseData, ELF::STB_GLOBAL);
|
||||
}
|
||||
|
||||
if (!BaseSymbol) {
|
||||
MSD.SectionIndex = ELF::SHN_ABS;
|
||||
} else if (it->isCommon()) {
|
||||
} else if (SD.isCommon()) {
|
||||
assert(!Local);
|
||||
MSD.SectionIndex = ELF::SHN_COMMON;
|
||||
} else if (BaseSymbol->isUndefined()) {
|
||||
|
@ -1084,7 +1082,7 @@ ELFObjectWriter::computeSymbolTable(MCAssembler &Asm, const MCAsmLayout &Layout,
|
|||
else
|
||||
MSD.SectionIndex = ELF::SHN_UNDEF;
|
||||
if (!Used && WeakrefUsed)
|
||||
MCELF::SetBinding(*it, ELF::STB_WEAK);
|
||||
MCELF::SetBinding(SD, ELF::STB_WEAK);
|
||||
} else {
|
||||
const MCSectionELF &Section =
|
||||
static_cast<const MCSectionELF&>(BaseSymbol->getSection());
|
||||
|
|
|
@ -430,13 +430,12 @@ void MCMachOStreamer::FinishImpl() {
|
|||
// First, scan the symbol table to build a lookup table from fragments to
|
||||
// defining symbols.
|
||||
DenseMap<const MCFragment*, MCSymbolData*> DefiningSymbolMap;
|
||||
for (MCAssembler::symbol_iterator it = getAssembler().symbol_begin(),
|
||||
ie = getAssembler().symbol_end(); it != ie; ++it) {
|
||||
if (getAssembler().isSymbolLinkerVisible(it->getSymbol()) &&
|
||||
it->getFragment()) {
|
||||
for (MCSymbolData &SD : getAssembler().symbols()) {
|
||||
if (getAssembler().isSymbolLinkerVisible(SD.getSymbol()) &&
|
||||
SD.getFragment()) {
|
||||
// An atom defining symbol should never be internal to a fragment.
|
||||
assert(it->getOffset() == 0 && "Invalid offset in atom defining symbol!");
|
||||
DefiningSymbolMap[it->getFragment()] = it;
|
||||
assert(SD.getOffset() == 0 && "Invalid offset in atom defining symbol!");
|
||||
DefiningSymbolMap[SD.getFragment()] = &SD;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -516,15 +516,14 @@ ComputeSymbolTable(MCAssembler &Asm, SmallString<256> &StringTable,
|
|||
// table, then sort the symbols is chosen to match 'as'. Even though it
|
||||
// doesn't matter for correctness, this is important for letting us diff .o
|
||||
// files.
|
||||
for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
|
||||
ie = Asm.symbol_end(); it != ie; ++it) {
|
||||
const MCSymbol &Symbol = it->getSymbol();
|
||||
for (MCSymbolData &SD : Asm.symbols()) {
|
||||
const MCSymbol &Symbol = SD.getSymbol();
|
||||
|
||||
// Ignore non-linker visible symbols.
|
||||
if (!Asm.isSymbolLinkerVisible(it->getSymbol()))
|
||||
if (!Asm.isSymbolLinkerVisible(SD.getSymbol()))
|
||||
continue;
|
||||
|
||||
if (!it->isExternal() && !Symbol.isUndefined())
|
||||
if (!SD.isExternal() && !Symbol.isUndefined())
|
||||
continue;
|
||||
|
||||
uint64_t &Entry = StringIndexMap[Symbol.getName()];
|
||||
|
@ -535,7 +534,7 @@ ComputeSymbolTable(MCAssembler &Asm, SmallString<256> &StringTable,
|
|||
}
|
||||
|
||||
MachSymbolData MSD;
|
||||
MSD.SymbolData = it;
|
||||
MSD.SymbolData = &SD;
|
||||
MSD.StringIndex = Entry;
|
||||
|
||||
if (Symbol.isUndefined()) {
|
||||
|
@ -552,15 +551,14 @@ ComputeSymbolTable(MCAssembler &Asm, SmallString<256> &StringTable,
|
|||
}
|
||||
|
||||
// Now add the data for local symbols.
|
||||
for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
|
||||
ie = Asm.symbol_end(); it != ie; ++it) {
|
||||
const MCSymbol &Symbol = it->getSymbol();
|
||||
for (MCSymbolData &SD : Asm.symbols()) {
|
||||
const MCSymbol &Symbol = SD.getSymbol();
|
||||
|
||||
// Ignore non-linker visible symbols.
|
||||
if (!Asm.isSymbolLinkerVisible(it->getSymbol()))
|
||||
if (!Asm.isSymbolLinkerVisible(SD.getSymbol()))
|
||||
continue;
|
||||
|
||||
if (it->isExternal() || Symbol.isUndefined())
|
||||
if (SD.isExternal() || Symbol.isUndefined())
|
||||
continue;
|
||||
|
||||
uint64_t &Entry = StringIndexMap[Symbol.getName()];
|
||||
|
@ -571,7 +569,7 @@ ComputeSymbolTable(MCAssembler &Asm, SmallString<256> &StringTable,
|
|||
}
|
||||
|
||||
MachSymbolData MSD;
|
||||
MSD.SymbolData = it;
|
||||
MSD.SymbolData = &SD;
|
||||
MSD.StringIndex = Entry;
|
||||
|
||||
if (Symbol.isAbsolute()) {
|
||||
|
@ -621,10 +619,7 @@ void MachObjectWriter::computeSectionAddresses(const MCAssembler &Asm,
|
|||
|
||||
void MachObjectWriter::markAbsoluteVariableSymbols(MCAssembler &Asm,
|
||||
const MCAsmLayout &Layout) {
|
||||
for (MCAssembler::symbol_iterator i = Asm.symbol_begin(),
|
||||
e = Asm.symbol_end();
|
||||
i != e; ++i) {
|
||||
MCSymbolData &SD = *i;
|
||||
for (MCSymbolData &SD : Asm.symbols()) {
|
||||
if (!SD.getSymbol().isVariable())
|
||||
continue;
|
||||
|
||||
|
|
|
@ -665,13 +665,9 @@ void WinCOFFObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm,
|
|||
for (MCAssembler::const_iterator i = Asm.begin(), e = Asm.end(); i != e; i++)
|
||||
DefineSection(*i);
|
||||
|
||||
for (MCAssembler::const_symbol_iterator i = Asm.symbol_begin(),
|
||||
e = Asm.symbol_end();
|
||||
i != e; i++) {
|
||||
if (ExportSymbol(*i, Asm)) {
|
||||
DefineSymbol(*i, Asm, Layout);
|
||||
}
|
||||
}
|
||||
for (MCSymbolData &SD : Asm.symbols())
|
||||
if (ExportSymbol(SD, Asm))
|
||||
DefineSymbol(SD, Asm, Layout);
|
||||
}
|
||||
|
||||
void WinCOFFObjectWriter::RecordRelocation(const MCAssembler &Asm,
|
||||
|
|
Loading…
Reference in New Issue