Skip to content

Commit 449b649

Browse files
committed
Revert "[ELF] Parallelize initializeLocalSymbols"
This reverts commit 09602d3.
1 parent 86e6030 commit 449b649

File tree

4 files changed

+37
-68
lines changed

4 files changed

+37
-68
lines changed

lld/ELF/Driver.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,25 +2316,6 @@ static uint32_t getAndFeatures() {
23162316
return ret;
23172317
}
23182318

2319-
static void initializeLocalSymbols(ELFFileBase *file) {
2320-
switch (config->ekind) {
2321-
case ELF32LEKind:
2322-
cast<ObjFile<ELF32LE>>(file)->initializeLocalSymbols();
2323-
break;
2324-
case ELF32BEKind:
2325-
cast<ObjFile<ELF32BE>>(file)->initializeLocalSymbols();
2326-
break;
2327-
case ELF64LEKind:
2328-
cast<ObjFile<ELF64LE>>(file)->initializeLocalSymbols();
2329-
break;
2330-
case ELF64BEKind:
2331-
cast<ObjFile<ELF64BE>>(file)->initializeLocalSymbols();
2332-
break;
2333-
default:
2334-
llvm_unreachable("");
2335-
}
2336-
}
2337-
23382319
static void postParseObjectFile(ELFFileBase *file) {
23392320
switch (config->ekind) {
23402321
case ELF32LEKind:
@@ -2473,7 +2454,6 @@ void LinkerDriver::link(opt::InputArgList &args) {
24732454

24742455
// No more lazy bitcode can be extracted at this point. Do post parse work
24752456
// like checking duplicate symbols.
2476-
parallelForEach(objectFiles, initializeLocalSymbols);
24772457
parallelForEach(objectFiles, postParseObjectFile);
24782458
parallelForEach(bitcodeFiles, [](BitcodeFile *file) { file->postParse(); });
24792459

@@ -2548,7 +2528,6 @@ void LinkerDriver::link(opt::InputArgList &args) {
25482528
// compileBitcodeFiles may have produced lto.tmp object files. After this, no
25492529
// more file will be added.
25502530
auto newObjectFiles = makeArrayRef(objectFiles).slice(numObjsBeforeLTO);
2551-
parallelForEach(newObjectFiles, initializeLocalSymbols);
25522531
parallelForEach(newObjectFiles, postParseObjectFile);
25532532

25542533
// Handle --exclude-libs again because lto.tmp may reference additional

lld/ELF/InputFiles.cpp

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,41 @@ void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
10211021

10221022
ArrayRef<Elf_Sym> eSyms = this->getELFSyms<ELFT>();
10231023
symbols.resize(eSyms.size());
1024+
SymbolUnion *locals =
1025+
firstGlobal == 0
1026+
? nullptr
1027+
: getSpecificAllocSingleton<SymbolUnion>().Allocate(firstGlobal);
1028+
1029+
for (size_t i = 0, end = firstGlobal; i != end; ++i) {
1030+
const Elf_Sym &eSym = eSyms[i];
1031+
uint32_t secIdx = eSym.st_shndx;
1032+
if (LLVM_UNLIKELY(secIdx == SHN_XINDEX))
1033+
secIdx = check(getExtendedSymbolTableIndex<ELFT>(eSym, i, shndxTable));
1034+
else if (secIdx >= SHN_LORESERVE)
1035+
secIdx = 0;
1036+
if (LLVM_UNLIKELY(secIdx >= sections.size()))
1037+
fatal(toString(this) + ": invalid section index: " + Twine(secIdx));
1038+
if (LLVM_UNLIKELY(eSym.getBinding() != STB_LOCAL))
1039+
error(toString(this) + ": non-local symbol (" + Twine(i) +
1040+
") found at index < .symtab's sh_info (" + Twine(end) + ")");
1041+
1042+
InputSectionBase *sec = sections[secIdx];
1043+
uint8_t type = eSym.getType();
1044+
if (type == STT_FILE)
1045+
sourceFile = CHECK(eSym.getName(stringTable), this);
1046+
if (LLVM_UNLIKELY(stringTable.size() <= eSym.st_name))
1047+
fatal(toString(this) + ": invalid symbol name offset");
1048+
StringRef name(stringTable.data() + eSym.st_name);
1049+
1050+
symbols[i] = reinterpret_cast<Symbol *>(locals + i);
1051+
if (eSym.st_shndx == SHN_UNDEF || sec == &InputSection::discarded)
1052+
new (symbols[i]) Undefined(this, name, STB_LOCAL, eSym.st_other, type,
1053+
/*discardedSecIdx=*/secIdx);
1054+
else
1055+
new (symbols[i]) Defined(this, name, STB_LOCAL, eSym.st_other, type,
1056+
eSym.st_value, eSym.st_size, sec);
1057+
symbols[i]->isUsedInRegularObj = true;
1058+
}
10241059

10251060
// Some entries have been filled by LazyObjFile.
10261061
for (size_t i = firstGlobal, end = eSyms.size(); i != end; ++i)
@@ -1114,45 +1149,6 @@ void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
11141149
}
11151150
}
11161151

1117-
template <class ELFT> void ObjFile<ELFT>::initializeLocalSymbols() {
1118-
if (!firstGlobal)
1119-
return;
1120-
localSymStorage = std::make_unique<SymbolUnion[]>(firstGlobal);
1121-
SymbolUnion *locals = localSymStorage.get();
1122-
1123-
ArrayRef<Elf_Sym> eSyms = this->getELFSyms<ELFT>();
1124-
for (size_t i = 0, end = firstGlobal; i != end; ++i) {
1125-
const Elf_Sym &eSym = eSyms[i];
1126-
uint32_t secIdx = eSym.st_shndx;
1127-
if (LLVM_UNLIKELY(secIdx == SHN_XINDEX))
1128-
secIdx = check(getExtendedSymbolTableIndex<ELFT>(eSym, i, shndxTable));
1129-
else if (secIdx >= SHN_LORESERVE)
1130-
secIdx = 0;
1131-
if (LLVM_UNLIKELY(secIdx >= sections.size()))
1132-
fatal(toString(this) + ": invalid section index: " + Twine(secIdx));
1133-
if (LLVM_UNLIKELY(eSym.getBinding() != STB_LOCAL))
1134-
error(toString(this) + ": non-local symbol (" + Twine(i) +
1135-
") found at index < .symtab's sh_info (" + Twine(end) + ")");
1136-
1137-
InputSectionBase *sec = sections[secIdx];
1138-
uint8_t type = eSym.getType();
1139-
if (type == STT_FILE)
1140-
sourceFile = CHECK(eSym.getName(stringTable), this);
1141-
if (LLVM_UNLIKELY(stringTable.size() <= eSym.st_name))
1142-
fatal(toString(this) + ": invalid symbol name offset");
1143-
StringRef name(stringTable.data() + eSym.st_name);
1144-
1145-
symbols[i] = reinterpret_cast<Symbol *>(locals + i);
1146-
if (eSym.st_shndx == SHN_UNDEF || sec == &InputSection::discarded)
1147-
new (symbols[i]) Undefined(this, name, STB_LOCAL, eSym.st_other, type,
1148-
/*discardedSecIdx=*/secIdx);
1149-
else
1150-
new (symbols[i]) Defined(this, name, STB_LOCAL, eSym.st_other, type,
1151-
eSym.st_value, eSym.st_size, sec);
1152-
symbols[i]->isUsedInRegularObj = true;
1153-
}
1154-
}
1155-
11561152
// Called after all ObjFile::parse is called for all ObjFiles. This checks
11571153
// duplicate symbols and may do symbol property merge in the future.
11581154
template <class ELFT> void ObjFile<ELFT>::postParse() {

lld/ELF/InputFiles.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#define LLD_ELF_INPUT_FILES_H
1111

1212
#include "Config.h"
13-
#include "Symbols.h"
1413
#include "lld/Common/ErrorHandler.h"
1514
#include "lld/Common/LLVM.h"
1615
#include "lld/Common/Reproduce.h"
@@ -274,7 +273,6 @@ template <class ELFT> class ObjFile : public ELFFileBase {
274273
// Get cached DWARF information.
275274
DWARFCache *getDwarf();
276275

277-
void initializeLocalSymbols();
278276
void postParse();
279277

280278
private:
@@ -304,9 +302,6 @@ template <class ELFT> class ObjFile : public ELFFileBase {
304302
// If the section does not exist (which is common), the array is empty.
305303
ArrayRef<Elf_Word> shndxTable;
306304

307-
// Storage for local symbols.
308-
std::unique_ptr<SymbolUnion[]> localSymStorage;
309-
310305
// Debugging information to retrieve source file and line for error
311306
// reporting. Linker may find reasonable number of errors in a
312307
// single object file, so we cache debugging information in order to

lld/ELF/InputSection.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,9 @@ std::string InputSectionBase::getObjMsg(uint64_t off) {
297297
if (!file->archiveName.empty())
298298
archive = (" in archive " + file->archiveName).str();
299299

300-
// Find a symbol that encloses a given location. getObjMsg may be called
301-
// before ObjFile::initializeLocalSymbols where local symbols are initialized.
300+
// Find a symbol that encloses a given location.
302301
for (Symbol *b : file->getSymbols())
303-
if (auto *d = dyn_cast_or_null<Defined>(b))
302+
if (auto *d = dyn_cast<Defined>(b))
304303
if (d->section == this && d->value <= off && off < d->value + d->size)
305304
return filename + ":(" + toString(*d) + ")" + archive;
306305

0 commit comments

Comments
 (0)