Skip to content

Commit 712264b

Browse files
committed
[ELF] Merge parseSymbolVersion and computeIspreemptible
ICF needs isPreemptible, which can be combined with parseSymbolVersion.
1 parent 18538e2 commit 712264b

File tree

6 files changed

+25
-18
lines changed

6 files changed

+25
-18
lines changed

lld/ELF/Driver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2987,6 +2987,8 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
29872987
if (!ctx.arg.relocatable) {
29882988
llvm::TimeTraceScope timeScope("Process symbol versions");
29892989
ctx.symtab->scanVersionScript();
2990+
2991+
parseVersionAndComputeIsPreemptible(ctx);
29902992
}
29912993

29922994
// Skip the normal linked output if some LTO options are specified.

lld/ELF/ICF.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -461,13 +461,6 @@ static void combineRelocHashes(unsigned cnt, InputSection *isec,
461461

462462
// The main function of ICF.
463463
template <class ELFT> void ICF<ELFT>::run() {
464-
// Compute isPreemptible early. We may add more symbols later, so this loop
465-
// cannot be merged with the later computeIsPreemptible() pass which is used
466-
// by scanRelocations().
467-
if (ctx.arg.hasDynSymTab)
468-
for (Symbol *sym : ctx.symtab->getSymbols())
469-
sym->isPreemptible = computeIsPreemptible(ctx, *sym);
470-
471464
// Two text sections may have identical content and relocations but different
472465
// LSDA, e.g. the two functions may have catch blocks of different types. If a
473466
// text section is referenced by a .eh_frame FDE with LSDA, it is not

lld/ELF/SymbolTable.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,6 @@ void SymbolTable::scanVersionScript() {
350350
assignAsterisk(pat, &v, true);
351351
}
352352

353-
// Symbol themselves might know their versions because symbols
354-
// can contain versions in the form of <name>@<version>.
355-
// Let them parse and update their names to exclude version suffix.
356-
for (Symbol *sym : symVector)
357-
if (sym->hasVersionSuffix)
358-
sym->parseSymbolVersion(ctx);
359-
360353
// isPreemptible is false at this point. To correctly compute the binding of a
361354
// Defined (which is used by includeInDynsym(ctx)), we need to know if it is
362355
// VER_NDX_LOCAL or not. Compute symbol versions before handling

lld/ELF/Symbols.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "InputFiles.h"
1212
#include "InputSection.h"
1313
#include "OutputSections.h"
14+
#include "SymbolTable.h"
1415
#include "SyntheticSections.h"
1516
#include "Target.h"
1617
#include "Writer.h"
@@ -345,7 +346,7 @@ bool elf::computeIsPreemptible(Ctx &ctx, const Symbol &sym) {
345346

346347
// Only symbols with default visibility that appear in dynsym can be
347348
// preempted. Symbols with protected visibility cannot be preempted.
348-
if (!sym.includeInDynsym(ctx) || sym.visibility() != STV_DEFAULT)
349+
if (sym.visibility() != STV_DEFAULT)
349350
return false;
350351

351352
// At this point copy relocations have not been created yet, so any
@@ -370,6 +371,20 @@ bool elf::computeIsPreemptible(Ctx &ctx, const Symbol &sym) {
370371
return true;
371372
}
372373

374+
void elf::parseVersionAndComputeIsPreemptible(Ctx &ctx) {
375+
// Symbol themselves might know their versions because symbols
376+
// can contain versions in the form of <name>@<version>.
377+
// Let them parse and update their names to exclude version suffix.
378+
bool hasDynSymTab = ctx.arg.hasDynSymTab;
379+
for (Symbol *sym : ctx.symtab->getSymbols()) {
380+
if (sym->hasVersionSuffix)
381+
sym->parseSymbolVersion(ctx);
382+
if (hasDynSymTab)
383+
sym->isPreemptible =
384+
sym->includeInDynsym(ctx) && computeIsPreemptible(ctx, *sym);
385+
}
386+
}
387+
373388
// Merge symbol properties.
374389
//
375390
// When we have many symbols of the same name, we choose one of them,

lld/ELF/Symbols.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ void reportDuplicate(Ctx &, const Symbol &sym, const InputFile *newFile,
527527
InputSectionBase *errSec, uint64_t errOffset);
528528
void maybeWarnUnorderableSymbol(Ctx &, const Symbol *sym);
529529
bool computeIsPreemptible(Ctx &, const Symbol &sym);
530+
void parseVersionAndComputeIsPreemptible(Ctx &);
530531

531532
} // namespace lld::elf
532533

lld/ELF/Writer.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,11 @@ static void demoteSymbolsAndComputeIsPreemptible(Ctx &ctx) {
297297
}
298298
}
299299

300-
if (ctx.arg.hasDynSymTab)
301-
sym->isPreemptible = computeIsPreemptible(ctx, *sym);
300+
if (ctx.arg.hasDynSymTab) {
301+
sym->exportDynamic = sym->includeInDynsym(ctx);
302+
sym->isPreemptible =
303+
sym->exportDynamic && computeIsPreemptible(ctx, *sym);
304+
}
302305
}
303306
}
304307

@@ -1888,7 +1891,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
18881891
if (ctx.in.symTab)
18891892
ctx.in.symTab->addSymbol(sym);
18901893

1891-
if (sym->includeInDynsym(ctx)) {
1894+
if (sym->exportDynamic) {
18921895
ctx.partitions[sym->partition - 1].dynSymTab->addSymbol(sym);
18931896
if (auto *file = dyn_cast<SharedFile>(sym->file))
18941897
if (file->isNeeded && !sym->isUndefined())

0 commit comments

Comments
 (0)