@@ -109,6 +109,7 @@ void Ctx::reset() {
109109
110110 in.reset ();
111111 sym = ElfSym{};
112+ symtab = std::make_unique<SymbolTable>();
112113
113114 memoryBuffers.clear ();
114115 objectFiles.clear ();
@@ -155,7 +156,6 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
155156 context->e .cleanupCallback = []() {
156157 elf::ctx.reset ();
157158 elf::ctx.partitions .emplace_back ();
158- symtab = SymbolTable ();
159159
160160 SharedFile::vernauxNum = 0 ;
161161 };
@@ -167,6 +167,7 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
167167 LinkerScript script (ctx);
168168 ctx.script = &script;
169169 ctx.symAux .emplace_back ();
170+ ctx.symtab = std::make_unique<SymbolTable>();
170171
171172 ctx.partitions .clear ();
172173 ctx.partitions .emplace_back ();
@@ -2194,7 +2195,7 @@ static void handleUndefinedGlob(Ctx &ctx, StringRef arg) {
21942195 // Calling sym->extract() in the loop is not safe because it may add new
21952196 // symbols to the symbol table, invalidating the current iterator.
21962197 SmallVector<Symbol *, 0 > syms;
2197- for (Symbol *sym : symtab. getSymbols ())
2198+ for (Symbol *sym : ctx. symtab -> getSymbols ())
21982199 if (!sym->isPlaceholder () && pat->match (sym->getName ()))
21992200 syms.push_back (sym);
22002201
@@ -2203,7 +2204,7 @@ static void handleUndefinedGlob(Ctx &ctx, StringRef arg) {
22032204}
22042205
22052206static void handleLibcall (Ctx &ctx, StringRef name) {
2206- Symbol *sym = symtab. find (name);
2207+ Symbol *sym = ctx. symtab -> find (name);
22072208 if (sym && sym->isLazy () && isa<BitcodeFile>(sym->file )) {
22082209 if (!ctx.arg .whyExtract .empty ())
22092210 ctx.whyExtractRecords .emplace_back (" <libcall>" , sym->file , *sym);
@@ -2390,7 +2391,7 @@ template <class ELFT>
23902391static void findKeepUniqueSections (Ctx &ctx, opt::InputArgList &args) {
23912392 for (auto *arg : args.filtered (OPT_keep_unique)) {
23922393 StringRef name = arg->getValue ();
2393- auto *d = dyn_cast_or_null<Defined>(symtab. find (name));
2394+ auto *d = dyn_cast_or_null<Defined>(ctx. symtab -> find (name));
23942395 if (!d || !d->section ) {
23952396 warn (" could not find symbol " + name + " to keep unique" );
23962397 continue ;
@@ -2405,7 +2406,7 @@ static void findKeepUniqueSections(Ctx &ctx, opt::InputArgList &args) {
24052406
24062407 // Symbols in the dynsym could be address-significant in other executables
24072408 // or DSOs, so we conservatively mark them as address-significant.
2408- for (Symbol *sym : symtab. getSymbols ())
2409+ for (Symbol *sym : ctx. symtab -> getSymbols ())
24092410 if (sym->includeInDynsym ())
24102411 markAddrsig (sym);
24112412
@@ -2574,24 +2575,24 @@ static std::vector<WrappedSymbol> addWrappedSymbols(opt::InputArgList &args) {
25742575 if (!seen.insert (name).second )
25752576 continue ;
25762577
2577- Symbol *sym = symtab. find (name);
2578+ Symbol *sym = ctx. symtab -> find (name);
25782579 if (!sym)
25792580 continue ;
25802581
2581- Symbol *wrap =
2582- symtab. addUnusedUndefined ( saver ().save (" __wrap_" + name), sym->binding );
2582+ Symbol *wrap = ctx. symtab -> addUnusedUndefined (
2583+ saver ().save (" __wrap_" + name), sym->binding );
25832584
25842585 // If __real_ is referenced, pull in the symbol if it is lazy. Do this after
25852586 // processing __wrap_ as that may have referenced __real_.
25862587 StringRef realName = saver ().save (" __real_" + name);
2587- if (Symbol *real = symtab. find (realName)) {
2588- symtab. addUnusedUndefined (name, sym->binding );
2588+ if (Symbol *real = ctx. symtab -> find (realName)) {
2589+ ctx. symtab -> addUnusedUndefined (name, sym->binding );
25892590 // Update sym's binding, which will replace real's later in
25902591 // SymbolTable::wrap.
25912592 sym->binding = real->binding ;
25922593 }
25932594
2594- Symbol *real = symtab. addUnusedUndefined (realName);
2595+ Symbol *real = ctx. symtab -> addUnusedUndefined (realName);
25952596 v.push_back ({sym, real, wrap});
25962597
25972598 // We want to tell LTO not to inline symbols to be overwritten
@@ -2626,7 +2627,7 @@ static void combineVersionedSymbol(Symbol &sym,
26262627 //
26272628 // * There is a definition of foo@v1 and foo@@v1.
26282629 // * There is a definition of foo@v1 and foo.
2629- Defined *sym2 = dyn_cast_or_null<Defined>(symtab. find (sym.getName ()));
2630+ Defined *sym2 = dyn_cast_or_null<Defined>(ctx. symtab -> find (sym.getName ()));
26302631 if (!sym2)
26312632 return ;
26322633 const char *suffix2 = sym2->getVersionSuffix ();
@@ -2681,7 +2682,7 @@ static void redirectSymbols(Ctx &ctx, ArrayRef<WrappedSymbol> wrapped) {
26812682 // symbols with a non-default version (foo@v1) and check whether it should be
26822683 // combined with foo or foo@@v1.
26832684 if (ctx.arg .versionDefinitions .size () > 2 )
2684- for (Symbol *sym : symtab. getSymbols ())
2685+ for (Symbol *sym : ctx. symtab -> getSymbols ())
26852686 if (sym->hasVersionSuffix )
26862687 combineVersionedSymbol (*sym, map);
26872688
@@ -2697,7 +2698,7 @@ static void redirectSymbols(Ctx &ctx, ArrayRef<WrappedSymbol> wrapped) {
26972698
26982699 // Update pointers in the symbol table.
26992700 for (const WrappedSymbol &w : wrapped)
2700- symtab. wrap (w.sym , w.real , w.wrap );
2701+ ctx. symtab -> wrap (w.sym , w.real , w.wrap );
27012702}
27022703
27032704static void reportMissingFeature (StringRef config, const Twine &report) {
@@ -2861,22 +2862,22 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
28612862
28622863 // Handle --trace-symbol.
28632864 for (auto *arg : args.filtered (OPT_trace_symbol))
2864- symtab. insert (arg->getValue ())->traced = true ;
2865+ ctx. symtab -> insert (arg->getValue ())->traced = true ;
28652866
28662867 ctx.internalFile = createInternalFile (" <internal>" );
28672868
28682869 // Handle -u/--undefined before input files. If both a.a and b.so define foo,
28692870 // -u foo a.a b.so will extract a.a.
28702871 for (StringRef name : ctx.arg .undefined )
2871- symtab. addUnusedUndefined (name)->referenced = true ;
2872+ ctx. symtab -> addUnusedUndefined (name)->referenced = true ;
28722873
28732874 parseFiles (files, armCmseImpLib);
28742875
28752876 // Create dynamic sections for dynamic linking and static PIE.
28762877 ctx.arg .hasDynSymTab = !ctx.sharedFiles .empty () || ctx.arg .isPic ;
28772878
28782879 // If an entry symbol is in a static archive, pull out that file now.
2879- if (Symbol *sym = symtab. find (ctx.arg .entry ))
2880+ if (Symbol *sym = ctx. symtab -> find (ctx.arg .entry ))
28802881 handleUndefined (ctx, sym, " --entry" );
28812882
28822883 // Handle the `--undefined-glob <pattern>` options.
@@ -2890,13 +2891,13 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
28902891
28912892 // Prevent LTO from removing any definition referenced by -u.
28922893 for (StringRef name : ctx.arg .undefined )
2893- if (Defined *sym = dyn_cast_or_null<Defined>(symtab. find (name)))
2894+ if (Defined *sym = dyn_cast_or_null<Defined>(ctx. symtab -> find (name)))
28942895 sym->isUsedInRegularObj = true ;
28952896
28962897 // Mark -init and -fini symbols so that the LTO doesn't eliminate them.
2897- if (Symbol *sym = dyn_cast_or_null<Defined>(symtab. find (ctx.arg .init )))
2898+ if (Symbol *sym = dyn_cast_or_null<Defined>(ctx. symtab -> find (ctx.arg .init )))
28982899 sym->isUsedInRegularObj = true ;
2899- if (Symbol *sym = dyn_cast_or_null<Defined>(symtab. find (ctx.arg .fini )))
2900+ if (Symbol *sym = dyn_cast_or_null<Defined>(ctx. symtab -> find (ctx.arg .fini )))
29002901 sym->isUsedInRegularObj = true ;
29012902
29022903 // If any of our inputs are bitcode files, the LTO code generator may create
@@ -2977,7 +2978,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
29772978 // name "foo@ver1") rather do harm, so we don't call this if -r is given.
29782979 if (!ctx.arg .relocatable ) {
29792980 llvm::TimeTraceScope timeScope (" Process symbol versions" );
2980- symtab. scanVersionScript ();
2981+ ctx. symtab -> scanVersionScript ();
29812982 }
29822983
29832984 // Skip the normal linked output if some LTO options are specified.
0 commit comments