@@ -149,6 +149,7 @@ static Defined *addOptionalRegular(Ctx &ctx, StringRef name, SectionBase *sec,
149
149
if (!s || s->isDefined () || s->isCommon ())
150
150
return nullptr ;
151
151
152
+ ctx.synthesizedSymbols .push_back (s);
152
153
s->resolve (ctx, Defined{ctx, ctx.internalFile , StringRef (), STB_GLOBAL,
153
154
stOther, STT_NOTYPE, val,
154
155
/* size=*/ 0 , sec});
@@ -282,6 +283,7 @@ static void demoteDefined(Defined &sym, DenseMap<SectionBase *, size_t> &map) {
282
283
static void demoteSymbolsAndComputeIsPreemptible (Ctx &ctx) {
283
284
llvm::TimeTraceScope timeScope (" Demote symbols" );
284
285
DenseMap<InputFile *, DenseMap<SectionBase *, size_t >> sectionIndexMap;
286
+ bool hasDynSymTab = ctx.arg .hasDynSymTab ;
285
287
for (Symbol *sym : ctx.symtab ->getSymbols ()) {
286
288
if (auto *d = dyn_cast<Defined>(sym)) {
287
289
if (d->section && !d->section ->isLive ())
@@ -294,11 +296,12 @@ static void demoteSymbolsAndComputeIsPreemptible(Ctx &ctx) {
294
296
sym->type )
295
297
.overwrite (*sym);
296
298
sym->versionId = VER_NDX_GLOBAL;
299
+ if (sym->includeInDynsym (ctx))
300
+ sym->isExported = true ;
297
301
}
298
302
}
299
303
300
- sym->isExported = sym->includeInDynsym (ctx);
301
- if (ctx.arg .hasDynSymTab )
304
+ if (hasDynSymTab)
302
305
sym->isPreemptible = sym->isExported && computeIsPreemptible (ctx, *sym);
303
306
}
304
307
}
@@ -1846,6 +1849,11 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
1846
1849
}
1847
1850
}
1848
1851
1852
+ // If the previous code block defines any non-hidden symbols (e.g.
1853
+ // __global_pointer$), they may be exported.
1854
+ for (Symbol *sym : ctx.synthesizedSymbols )
1855
+ sym->isExported = sym->includeInDynsym (ctx);
1856
+
1849
1857
demoteSymbolsAndComputeIsPreemptible (ctx);
1850
1858
1851
1859
if (ctx.arg .copyRelocs && ctx.arg .discard != DiscardPolicy::None)
0 commit comments