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