Revert "[ELF] Parallelize initializeLocalSymbols"
This reverts commit 09602d3b47.
			
			
This commit is contained in:
		
							parent
							
								
									86e6030ee8
								
							
						
					
					
						commit
						449b649fec
					
				| 
						 | 
					@ -2316,25 +2316,6 @@ static uint32_t getAndFeatures() {
 | 
				
			||||||
  return ret;
 | 
					  return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void initializeLocalSymbols(ELFFileBase *file) {
 | 
					 | 
				
			||||||
  switch (config->ekind) {
 | 
					 | 
				
			||||||
  case ELF32LEKind:
 | 
					 | 
				
			||||||
    cast<ObjFile<ELF32LE>>(file)->initializeLocalSymbols();
 | 
					 | 
				
			||||||
    break;
 | 
					 | 
				
			||||||
  case ELF32BEKind:
 | 
					 | 
				
			||||||
    cast<ObjFile<ELF32BE>>(file)->initializeLocalSymbols();
 | 
					 | 
				
			||||||
    break;
 | 
					 | 
				
			||||||
  case ELF64LEKind:
 | 
					 | 
				
			||||||
    cast<ObjFile<ELF64LE>>(file)->initializeLocalSymbols();
 | 
					 | 
				
			||||||
    break;
 | 
					 | 
				
			||||||
  case ELF64BEKind:
 | 
					 | 
				
			||||||
    cast<ObjFile<ELF64BE>>(file)->initializeLocalSymbols();
 | 
					 | 
				
			||||||
    break;
 | 
					 | 
				
			||||||
  default:
 | 
					 | 
				
			||||||
    llvm_unreachable("");
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void postParseObjectFile(ELFFileBase *file) {
 | 
					static void postParseObjectFile(ELFFileBase *file) {
 | 
				
			||||||
  switch (config->ekind) {
 | 
					  switch (config->ekind) {
 | 
				
			||||||
  case ELF32LEKind:
 | 
					  case ELF32LEKind:
 | 
				
			||||||
| 
						 | 
					@ -2473,7 +2454,6 @@ void LinkerDriver::link(opt::InputArgList &args) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // No more lazy bitcode can be extracted at this point. Do post parse work
 | 
					  // No more lazy bitcode can be extracted at this point. Do post parse work
 | 
				
			||||||
  // like checking duplicate symbols.
 | 
					  // like checking duplicate symbols.
 | 
				
			||||||
  parallelForEach(objectFiles, initializeLocalSymbols);
 | 
					 | 
				
			||||||
  parallelForEach(objectFiles, postParseObjectFile);
 | 
					  parallelForEach(objectFiles, postParseObjectFile);
 | 
				
			||||||
  parallelForEach(bitcodeFiles, [](BitcodeFile *file) { file->postParse(); });
 | 
					  parallelForEach(bitcodeFiles, [](BitcodeFile *file) { file->postParse(); });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2548,7 +2528,6 @@ void LinkerDriver::link(opt::InputArgList &args) {
 | 
				
			||||||
  // compileBitcodeFiles may have produced lto.tmp object files. After this, no
 | 
					  // compileBitcodeFiles may have produced lto.tmp object files. After this, no
 | 
				
			||||||
  // more file will be added.
 | 
					  // more file will be added.
 | 
				
			||||||
  auto newObjectFiles = makeArrayRef(objectFiles).slice(numObjsBeforeLTO);
 | 
					  auto newObjectFiles = makeArrayRef(objectFiles).slice(numObjsBeforeLTO);
 | 
				
			||||||
  parallelForEach(newObjectFiles, initializeLocalSymbols);
 | 
					 | 
				
			||||||
  parallelForEach(newObjectFiles, postParseObjectFile);
 | 
					  parallelForEach(newObjectFiles, postParseObjectFile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Handle --exclude-libs again because lto.tmp may reference additional
 | 
					  // Handle --exclude-libs again because lto.tmp may reference additional
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1021,6 +1021,41 @@ void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ArrayRef<Elf_Sym> eSyms = this->getELFSyms<ELFT>();
 | 
					  ArrayRef<Elf_Sym> eSyms = this->getELFSyms<ELFT>();
 | 
				
			||||||
  symbols.resize(eSyms.size());
 | 
					  symbols.resize(eSyms.size());
 | 
				
			||||||
 | 
					  SymbolUnion *locals =
 | 
				
			||||||
 | 
					      firstGlobal == 0
 | 
				
			||||||
 | 
					          ? nullptr
 | 
				
			||||||
 | 
					          : getSpecificAllocSingleton<SymbolUnion>().Allocate(firstGlobal);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  for (size_t i = 0, end = firstGlobal; i != end; ++i) {
 | 
				
			||||||
 | 
					    const Elf_Sym &eSym = eSyms[i];
 | 
				
			||||||
 | 
					    uint32_t secIdx = eSym.st_shndx;
 | 
				
			||||||
 | 
					    if (LLVM_UNLIKELY(secIdx == SHN_XINDEX))
 | 
				
			||||||
 | 
					      secIdx = check(getExtendedSymbolTableIndex<ELFT>(eSym, i, shndxTable));
 | 
				
			||||||
 | 
					    else if (secIdx >= SHN_LORESERVE)
 | 
				
			||||||
 | 
					      secIdx = 0;
 | 
				
			||||||
 | 
					    if (LLVM_UNLIKELY(secIdx >= sections.size()))
 | 
				
			||||||
 | 
					      fatal(toString(this) + ": invalid section index: " + Twine(secIdx));
 | 
				
			||||||
 | 
					    if (LLVM_UNLIKELY(eSym.getBinding() != STB_LOCAL))
 | 
				
			||||||
 | 
					      error(toString(this) + ": non-local symbol (" + Twine(i) +
 | 
				
			||||||
 | 
					            ") found at index < .symtab's sh_info (" + Twine(end) + ")");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    InputSectionBase *sec = sections[secIdx];
 | 
				
			||||||
 | 
					    uint8_t type = eSym.getType();
 | 
				
			||||||
 | 
					    if (type == STT_FILE)
 | 
				
			||||||
 | 
					      sourceFile = CHECK(eSym.getName(stringTable), this);
 | 
				
			||||||
 | 
					    if (LLVM_UNLIKELY(stringTable.size() <= eSym.st_name))
 | 
				
			||||||
 | 
					      fatal(toString(this) + ": invalid symbol name offset");
 | 
				
			||||||
 | 
					    StringRef name(stringTable.data() + eSym.st_name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    symbols[i] = reinterpret_cast<Symbol *>(locals + i);
 | 
				
			||||||
 | 
					    if (eSym.st_shndx == SHN_UNDEF || sec == &InputSection::discarded)
 | 
				
			||||||
 | 
					      new (symbols[i]) Undefined(this, name, STB_LOCAL, eSym.st_other, type,
 | 
				
			||||||
 | 
					                                 /*discardedSecIdx=*/secIdx);
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      new (symbols[i]) Defined(this, name, STB_LOCAL, eSym.st_other, type,
 | 
				
			||||||
 | 
					                               eSym.st_value, eSym.st_size, sec);
 | 
				
			||||||
 | 
					    symbols[i]->isUsedInRegularObj = true;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Some entries have been filled by LazyObjFile.
 | 
					  // Some entries have been filled by LazyObjFile.
 | 
				
			||||||
  for (size_t i = firstGlobal, end = eSyms.size(); i != end; ++i)
 | 
					  for (size_t i = firstGlobal, end = eSyms.size(); i != end; ++i)
 | 
				
			||||||
| 
						 | 
					@ -1114,45 +1149,6 @@ void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template <class ELFT> void ObjFile<ELFT>::initializeLocalSymbols() {
 | 
					 | 
				
			||||||
  if (!firstGlobal)
 | 
					 | 
				
			||||||
    return;
 | 
					 | 
				
			||||||
  localSymStorage = std::make_unique<SymbolUnion[]>(firstGlobal);
 | 
					 | 
				
			||||||
  SymbolUnion *locals = localSymStorage.get();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  ArrayRef<Elf_Sym> eSyms = this->getELFSyms<ELFT>();
 | 
					 | 
				
			||||||
  for (size_t i = 0, end = firstGlobal; i != end; ++i) {
 | 
					 | 
				
			||||||
    const Elf_Sym &eSym = eSyms[i];
 | 
					 | 
				
			||||||
    uint32_t secIdx = eSym.st_shndx;
 | 
					 | 
				
			||||||
    if (LLVM_UNLIKELY(secIdx == SHN_XINDEX))
 | 
					 | 
				
			||||||
      secIdx = check(getExtendedSymbolTableIndex<ELFT>(eSym, i, shndxTable));
 | 
					 | 
				
			||||||
    else if (secIdx >= SHN_LORESERVE)
 | 
					 | 
				
			||||||
      secIdx = 0;
 | 
					 | 
				
			||||||
    if (LLVM_UNLIKELY(secIdx >= sections.size()))
 | 
					 | 
				
			||||||
      fatal(toString(this) + ": invalid section index: " + Twine(secIdx));
 | 
					 | 
				
			||||||
    if (LLVM_UNLIKELY(eSym.getBinding() != STB_LOCAL))
 | 
					 | 
				
			||||||
      error(toString(this) + ": non-local symbol (" + Twine(i) +
 | 
					 | 
				
			||||||
            ") found at index < .symtab's sh_info (" + Twine(end) + ")");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    InputSectionBase *sec = sections[secIdx];
 | 
					 | 
				
			||||||
    uint8_t type = eSym.getType();
 | 
					 | 
				
			||||||
    if (type == STT_FILE)
 | 
					 | 
				
			||||||
      sourceFile = CHECK(eSym.getName(stringTable), this);
 | 
					 | 
				
			||||||
    if (LLVM_UNLIKELY(stringTable.size() <= eSym.st_name))
 | 
					 | 
				
			||||||
      fatal(toString(this) + ": invalid symbol name offset");
 | 
					 | 
				
			||||||
    StringRef name(stringTable.data() + eSym.st_name);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    symbols[i] = reinterpret_cast<Symbol *>(locals + i);
 | 
					 | 
				
			||||||
    if (eSym.st_shndx == SHN_UNDEF || sec == &InputSection::discarded)
 | 
					 | 
				
			||||||
      new (symbols[i]) Undefined(this, name, STB_LOCAL, eSym.st_other, type,
 | 
					 | 
				
			||||||
                                 /*discardedSecIdx=*/secIdx);
 | 
					 | 
				
			||||||
    else
 | 
					 | 
				
			||||||
      new (symbols[i]) Defined(this, name, STB_LOCAL, eSym.st_other, type,
 | 
					 | 
				
			||||||
                               eSym.st_value, eSym.st_size, sec);
 | 
					 | 
				
			||||||
    symbols[i]->isUsedInRegularObj = true;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Called after all ObjFile::parse is called for all ObjFiles. This checks
 | 
					// Called after all ObjFile::parse is called for all ObjFiles. This checks
 | 
				
			||||||
// duplicate symbols and may do symbol property merge in the future.
 | 
					// duplicate symbols and may do symbol property merge in the future.
 | 
				
			||||||
template <class ELFT> void ObjFile<ELFT>::postParse() {
 | 
					template <class ELFT> void ObjFile<ELFT>::postParse() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,7 +10,6 @@
 | 
				
			||||||
#define LLD_ELF_INPUT_FILES_H
 | 
					#define LLD_ELF_INPUT_FILES_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "Config.h"
 | 
					#include "Config.h"
 | 
				
			||||||
#include "Symbols.h"
 | 
					 | 
				
			||||||
#include "lld/Common/ErrorHandler.h"
 | 
					#include "lld/Common/ErrorHandler.h"
 | 
				
			||||||
#include "lld/Common/LLVM.h"
 | 
					#include "lld/Common/LLVM.h"
 | 
				
			||||||
#include "lld/Common/Reproduce.h"
 | 
					#include "lld/Common/Reproduce.h"
 | 
				
			||||||
| 
						 | 
					@ -274,7 +273,6 @@ public:
 | 
				
			||||||
  // Get cached DWARF information.
 | 
					  // Get cached DWARF information.
 | 
				
			||||||
  DWARFCache *getDwarf();
 | 
					  DWARFCache *getDwarf();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void initializeLocalSymbols();
 | 
					 | 
				
			||||||
  void postParse();
 | 
					  void postParse();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
| 
						 | 
					@ -304,9 +302,6 @@ private:
 | 
				
			||||||
  // If the section does not exist (which is common), the array is empty.
 | 
					  // If the section does not exist (which is common), the array is empty.
 | 
				
			||||||
  ArrayRef<Elf_Word> shndxTable;
 | 
					  ArrayRef<Elf_Word> shndxTable;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Storage for local symbols.
 | 
					 | 
				
			||||||
  std::unique_ptr<SymbolUnion[]> localSymStorage;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Debugging information to retrieve source file and line for error
 | 
					  // Debugging information to retrieve source file and line for error
 | 
				
			||||||
  // reporting. Linker may find reasonable number of errors in a
 | 
					  // reporting. Linker may find reasonable number of errors in a
 | 
				
			||||||
  // single object file, so we cache debugging information in order to
 | 
					  // single object file, so we cache debugging information in order to
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -297,10 +297,9 @@ std::string InputSectionBase::getObjMsg(uint64_t off) {
 | 
				
			||||||
  if (!file->archiveName.empty())
 | 
					  if (!file->archiveName.empty())
 | 
				
			||||||
    archive = (" in archive " + file->archiveName).str();
 | 
					    archive = (" in archive " + file->archiveName).str();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Find a symbol that encloses a given location. getObjMsg may be called
 | 
					  // Find a symbol that encloses a given location.
 | 
				
			||||||
  // before ObjFile::initializeLocalSymbols where local symbols are initialized.
 | 
					 | 
				
			||||||
  for (Symbol *b : file->getSymbols())
 | 
					  for (Symbol *b : file->getSymbols())
 | 
				
			||||||
    if (auto *d = dyn_cast_or_null<Defined>(b))
 | 
					    if (auto *d = dyn_cast<Defined>(b))
 | 
				
			||||||
      if (d->section == this && d->value <= off && off < d->value + d->size)
 | 
					      if (d->section == this && d->value <= off && off < d->value + d->size)
 | 
				
			||||||
        return filename + ":(" + toString(*d) + ")" + archive;
 | 
					        return filename + ":(" + toString(*d) + ")" + archive;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue