diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -1472,8 +1472,15 @@ StringRef symbolName = defined->getName(); if (config->exportedSymbols.match(symbolName)) { if (defined->privateExtern) { - warn("cannot export hidden symbol " + symbolName + - "\n>>> defined in " + toString(defined->getFile())); + // If it's a weak, it's not "hidden". + if (!defined->isWeakDef()) + warn("cannot export hidden symbol " + symbolName + + "\n>>> defined in " + toString(defined->getFile())); + else + // When a weakdef private extern symbol is exported, + // it becomes "non-private. + // This matches LD64's behaviour. + defined->privateExtern = false; } } else { defined->privateExtern = true; diff --git a/lld/MachO/MarkLive.cpp b/lld/MachO/MarkLive.cpp --- a/lld/MachO/MarkLive.cpp +++ b/lld/MachO/MarkLive.cpp @@ -67,7 +67,7 @@ // FIXME: Instead of doing this here, maybe the Driver code doing // the matching should add them to explicitUndefineds? Then the // explicitUndefineds code below would handle this automatically. - assert(!defined->privateExtern && + assert((!defined->privateExtern || defined->isWeakDef()) && "should have been rejected by driver"); addSym(defined); continue;