[lld] r331780 - Refactor BitcodeCompiler::add(). NFC.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue May 8 10:50:54 PDT 2018


Author: ruiu
Date: Tue May  8 10:50:54 2018
New Revision: 331780

URL: http://llvm.org/viewvc/llvm-project?rev=331780&view=rev
Log:
Refactor BitcodeCompiler::add(). NFC.

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

Modified:
    lld/trunk/ELF/LTO.cpp

Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=331780&r1=331779&r2=331780&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Tue May  8 10:50:54 2018
@@ -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




More information about the llvm-commits mailing list