From de266ce4f9f2dfc989d2f9f82017229be5f535eb Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 23 Apr 2021 22:55:05 -0400 Subject: [PATCH] [lld/mac] Don't assert when using -exported_symbol with private symbol When I added this assert in D93609, it asserted that a symbol that is privateExtern is also isExternal(). In D98381 the privateExtern check moved into shouldExportSymbol() but the assert didn't -- now it checked that _every_ non-exported symbol is isExternal(), which isn't true. Move the assert into the privateExtern check where it used to be. Fixes PR50098. Differential Revision: https://reviews.llvm.org/D101223 --- lld/MachO/SyntheticSections.cpp | 5 +++-- lld/test/MachO/export-options.s | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp index 8b1616f..387bfc2 100644 --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -585,8 +585,10 @@ static void validateExportSymbol(const Defined *defined) { } static bool shouldExportSymbol(const Defined *defined) { - if (defined->privateExtern) + if (defined->privateExtern) { + assert(defined->isExternal() && "invalid input file"); return false; + } // TODO: Is this a performance bottleneck? If a build has mostly // global symbols in the input but uses -exported_symbols to filter // out most of them, then it would be better to set the value of @@ -844,7 +846,6 @@ template void SymtabSectionImpl::writeTo(uint8_t *buf) const { if (!shouldExportSymbol(defined)) { // Private external -- dylib scoped symbol. // Promote to non-external at link time. - assert(defined->isExternal() && "invalid input file"); scope = N_PEXT; } else if (defined->isExternal()) { // Normal global symbol. diff --git a/lld/test/MachO/export-options.s b/lld/test/MachO/export-options.s index f219dfa..d7c904e 100644 --- a/lld/test/MachO/export-options.s +++ b/lld/test/MachO/export-options.s @@ -38,6 +38,8 @@ _hide_globl: .private_extern _private_extern _private_extern: retq +_private: + retq ## Check that the export trie is unaltered # RUN: %lld -dylib %t/default.o -o %t/default -- 2.7.4