Refactor BitcodeCompiler::add(). NFC.

This change makes it explicit that the main loop iterates over a
parallel array, Syms and ObjSyms.

llvm-svn: 331780
This commit is contained in:
Rui Ueyama 2018-05-08 17:50:54 +00:00
parent 2f9fa42892
commit d31b54b3c1
1 changed files with 7 additions and 8 deletions

View File

@ -165,6 +165,7 @@ static void undefine(Symbol *S) {
void BitcodeCompiler::add(BitcodeFile &F) {
lto::InputFile &Obj = *F.Obj;
bool IsExec = !Config->Shared && !Config->Relocatable;
// Create the empty files which, if indexed, will be overwritten later.
if (Config->ThinLTOIndexOnly) {
@ -175,17 +176,15 @@ void BitcodeCompiler::add(BitcodeFile &F) {
openFile(Path + ".imports");
}
unsigned SymNum = 0;
ArrayRef<Symbol *> Syms = F.getSymbols();
ArrayRef<lto::InputFile::Symbol> ObjSyms = Obj.symbols();
std::vector<lto::SymbolResolution> Resols(Syms.size());
bool IsExecutable = !Config->Shared && !Config->Relocatable;
// Provide a resolution to the LTO API for each symbol.
for (const lto::InputFile::Symbol &ObjSym : Obj.symbols()) {
Symbol *Sym = Syms[SymNum];
lto::SymbolResolution &R = Resols[SymNum];
++SymNum;
for (size_t I = 0, E = Syms.size(); I != E; ++I) {
Symbol *Sym = Syms[I];
const lto::InputFile::Symbol &ObjSym = ObjSyms[I];
lto::SymbolResolution &R = Resols[I];
// Ideally we shouldn't check for SF_Undefined but currently IRObjectFile
// reports two symbols for module ASM defined. Without this check, lld
@ -205,7 +204,7 @@ void BitcodeCompiler::add(BitcodeFile &F) {
UsedStartStop.count(ObjSym.getSectionName());
const auto *DR = dyn_cast<Defined>(Sym);
R.FinalDefinitionInLinkageUnit =
(IsExecutable || Sym->Visibility != STV_DEFAULT) && DR &&
(IsExec || Sym->Visibility != STV_DEFAULT) && DR &&
// Skip absolute symbols from ELF objects, otherwise PC-rel relocations
// will be generated by for them, triggering linker errors.
// Symbol section is always null for bitcode symbols, hence the check