diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -1922,7 +1922,13 @@ // Tell LTO not to eliminate these symbols. sym->isUsedInRegularObj = true; - if (sym->referenced) + // If sym is referenced in any object file, bitcode file or shared object, + // retain wrap which is the redirection target of sym. If the object file + // defining sym has sym references, we cannot easily distinguish the case + // from cases where sym is not referenced. Retain wrap because we choose to + // wrap sym references regardless of whether sym is defined + // (https://sourceware.org/bugzilla/show_bug.cgi?id=26358). + if (sym->referenced || sym->isDefined()) wrap->isUsedInRegularObj = true; } return v; diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td --- a/lld/ELF/Options.td +++ b/lld/ELF/Options.td @@ -473,8 +473,9 @@ "Force load of all members in a static library", "Do not force load of all members in a static library (default)">; -defm wrap: Eq<"wrap", "Use wrapper functions for symbol">, - MetaVarName<"">; +defm wrap : Eq<"wrap", "Redirect symbol references to __wrap_symbol and " + "__real_symbol references to symbol">, + MetaVarName<"">; def z: JoinedOrSeparate<["-"], "z">, MetaVarName<"