[PATCH] D101223: [lld/mac] Don't assert when using -exported_symbol with private symbol

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 23 20:00:50 PDT 2021


thakis created this revision.
thakis added a reviewer: lld-macho.
Herald added a reviewer: int3.
Herald added a project: lld-macho.
thakis requested review of this revision.

When I added this assert in D93609 <https://reviews.llvm.org/D93609>, it asserted that a symbol that
is privateExtern is also isExternal().

In D98381 <https://reviews.llvm.org/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.


https://reviews.llvm.org/D101223

Files:
  lld/MachO/SyntheticSections.cpp
  lld/test/MachO/export-options.s


Index: lld/test/MachO/export-options.s
===================================================================
--- lld/test/MachO/export-options.s
+++ lld/test/MachO/export-options.s
@@ -38,6 +38,8 @@
 .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
Index: lld/MachO/SyntheticSections.cpp
===================================================================
--- lld/MachO/SyntheticSections.cpp
+++ lld/MachO/SyntheticSections.cpp
@@ -585,8 +585,10 @@
 }
 
 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 @@
       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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101223.340229.patch
Type: text/x-patch
Size: 1318 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210424/020bda7d/attachment.bin>


More information about the llvm-commits mailing list