@@ -333,10 +333,13 @@ bool elf::computeIsPreemptible(Ctx &ctx, const Symbol &sym) {
333333 if (sym.visibility () != STV_DEFAULT)
334334 return false ;
335335
336- // At this point copy relocations have not been created yet, so any
337- // symbol that is not defined locally is preemptible.
336+ // At this point copy relocations have not been created yet.
337+ // Shared symbols are preemptible. Undefined symbols are preemptible
338+ // when zDynamicUndefined (default in dynamic linking). Weakness is not
339+ // checked, though undefined non-weak would typically trigger relocation
340+ // errors unless options like -z undefs are used.
338341 if (!sym.isDefined ())
339- return true ;
342+ return !sym. isUndefined () || ctx. arg . zDynamicUndefined ;
340343
341344 if (!ctx.arg .shared )
342345 return false ;
@@ -360,7 +363,6 @@ void elf::parseVersionAndComputeIsPreemptible(Ctx &ctx) {
360363 // can contain versions in the form of <name>@<version>.
361364 // Let them parse and update their names to exclude version suffix.
362365 // In addition, compute isExported and isPreemptible.
363- bool maybePreemptible = ctx.sharedFiles .size () || ctx.arg .shared ;
364366 for (Symbol *sym : ctx.symtab ->getSymbols ()) {
365367 if (sym->hasVersionSuffix )
366368 sym->parseSymbolVersion (ctx);
@@ -369,11 +371,11 @@ void elf::parseVersionAndComputeIsPreemptible(Ctx &ctx) {
369371 continue ;
370372 }
371373 if (!sym->isDefined () && !sym->isCommon ()) {
372- sym->isPreemptible = maybePreemptible && computeIsPreemptible (ctx, *sym);
374+ sym->isPreemptible = computeIsPreemptible (ctx, *sym);
373375 } else if (ctx.arg .exportDynamic &&
374376 (sym->isUsedInRegularObj || !sym->ltoCanOmit )) {
375377 sym->isExported = true ;
376- sym->isPreemptible = maybePreemptible && computeIsPreemptible (ctx, *sym);
378+ sym->isPreemptible = computeIsPreemptible (ctx, *sym);
377379 }
378380 }
379381}
0 commit comments