[PATCH] D124143: [lld-macho] Allow dead_strip to work with autohide symbols that cannot be exported

Vincent Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 20 20:12:42 PDT 2022


thevinster created this revision.
Herald added projects: lld-macho, All.
Herald added a reviewer: lld-macho.
thevinster retitled this revision from "[lld-macho] Allow dead_strip on autohide symbols" to "[lld-macho] Allow dead_strip to work with autohide symbols that cannot be exported".
thevinster edited the summary of this revision.
thevinster edited the summary of this revision.
thevinster edited the summary of this revision.
thevinster edited the summary of this revision.
thevinster published this revision for review.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

It seems like we are overly asserting when running `-dead_strip` with 
exported symbols. ld64 links successfully (or at least no-ops) with 
`-dead_strip`  when a symbol cannot be exported. Loosen the assert 
to match ld64's behavior.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124143

Files:
  lld/MachO/MarkLive.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
@@ -133,7 +133,7 @@
 # RUN: llvm-nm -g %t/exp-autohide.dylib | FileCheck %s --check-prefix=EXP-AUTOHIDE
 
 # RUN: not %lld -dylib -exported_symbol "_foo" %t/autohide-private-extern.o \
-# RUN: -o /dev/null  2>&1 | FileCheck %s --check-prefix=AUTOHIDE-PRIVATE
+# RUN:   -o /dev/null  2>&1 | FileCheck %s --check-prefix=AUTOHIDE-PRIVATE
 
 # RUN: not %lld -dylib -exported_symbol "_foo" %t/autohide.o \
 # RUN:   %t/glob-private-extern.o -o /dev/null 2>&1 | \
@@ -143,8 +143,22 @@
 # RUN:   %t/weak-private-extern.o -o /dev/null 2>&1 | \
 # RUN:   FileCheck %s --check-prefix=AUTOHIDE-PRIVATE
 
+## Test that dead_strip does not crash when we cannot export the autohide symbol
+# RUN: %no-fatal-warnings-lld -dylib -exported_symbol "_foo" %t/autohide-private-extern.o \
+# RUN:   -dead_strip -o %t/no_crash
+# RUN: llvm-nm -m %t/no_crash | FileCheck %s --check-prefix=NO-CRASH
+
+# RUN: %no-fatal-warnings-lld -dylib -exported_symbol "_foo" %t/autohide.o \
+# RUN:   -dead_strip %t/glob-private-extern.o -o %t/no_crash
+# RUN: llvm-nm -m %t/no_crash | FileCheck %s --check-prefix=NO-CRASH
+
+# RUN: %no-fatal-warnings-lld -dylib -exported_symbol "_foo" %t/autohide.o \
+# RUN:   -dead_strip %t/weak-private-extern.o -o %t/no_crash
+# RUN: llvm-nm -m %t/no_crash | FileCheck %s --check-prefix=NO-CRASH
+
 # EXP-AUTOHIDE: T _foo
 # AUTOHIDE-PRIVATE: error: cannot export hidden symbol _foo
+# NO-CRASH: (__TEXT,__text) non-external (was a private external) _foo
 
 #--- default.s
 
Index: lld/MachO/MarkLive.cpp
===================================================================
--- lld/MachO/MarkLive.cpp
+++ lld/MachO/MarkLive.cpp
@@ -231,8 +231,6 @@
         // 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 &&
-               "should have been rejected by driver");
         marker->addSym(defined);
         continue;
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124143.424084.patch
Type: text/x-patch
Size: 2213 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220421/c68ce5cf/attachment.bin>


More information about the llvm-commits mailing list