Skip to content

Commit 2a26292

Browse files
committed
[ELF] Make isExported accurate early
LTO compilation might define symbols not in the symbol table (e.g. __emutls_v.x in test/ELF/lto/wrap-unreferenced-before-codegen.test). These symbols have a false `isExported` until `demoteSymbolsAndComputeIsPreemptible`. This is usually benign as we do not reference `isExported` that early. Ensure that `isExported` is correct early. This helps remove a redundant `isExported` computation in `demoteSymbolsAndComputeIsPreemptible`.
1 parent 0e6b582 commit 2a26292

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

lld/ELF/Driver.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,9 +2157,12 @@ static void excludeLibs(Ctx &ctx, opt::InputArgList &args) {
21572157
ArrayRef<Symbol *> symbols = file->getSymbols();
21582158
if (isa<ELFFileBase>(file))
21592159
symbols = cast<ELFFileBase>(file)->getGlobalSymbols();
2160-
for (Symbol *sym : symbols)
2161-
if (!sym->isUndefined() && sym->file == file)
2160+
for (Symbol *sym : symbols) {
2161+
if (!sym->isUndefined() && sym->file == file) {
21622162
sym->versionId = VER_NDX_LOCAL;
2163+
sym->isExported = false;
2164+
}
2165+
}
21632166
};
21642167

21652168
for (ELFFileBase *file : ctx.objectFiles)
@@ -2545,11 +2548,17 @@ void LinkerDriver::compileBitcodeFiles(bool skipLinkedOutput) {
25452548
auto *obj = cast<ObjFile<ELFT>>(file.get());
25462549
obj->parse(/*ignoreComdats=*/true);
25472550

2548-
// Parse '@' in symbol names for non-relocatable output.
2551+
// For defined symbols in non-relocatable output,
2552+
// compute isExported and parse '@'.
25492553
if (!ctx.arg.relocatable)
2550-
for (Symbol *sym : obj->getGlobalSymbols())
2554+
for (Symbol *sym : obj->getGlobalSymbols()) {
2555+
if (!sym->isDefined())
2556+
continue;
2557+
if (sym->includeInDynsym(ctx))
2558+
sym->isExported = true;
25512559
if (sym->hasVersionSuffix)
25522560
sym->parseSymbolVersion(ctx);
2561+
}
25532562
ctx.objectFiles.push_back(obj);
25542563
}
25552564
}
@@ -3061,7 +3070,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
30613070

30623071
// Handle --exclude-libs again because lto.tmp may reference additional
30633072
// libcalls symbols defined in an excluded archive. This may override
3064-
// versionId set by scanVersionScript().
3073+
// versionId set by scanVersionScript() and isExported.
30653074
if (args.hasArg(OPT_exclude_libs))
30663075
excludeLibs(ctx, args);
30673076

0 commit comments

Comments
 (0)