[lld] r216213 - [mach-o] Fix initial live atoms with -dead_strip

Nick Kledzik kledzik at apple.com
Thu Aug 21 13:25:50 PDT 2014


Author: kledzik
Date: Thu Aug 21 15:25:50 2014
New Revision: 216213

URL: http://llvm.org/viewvc/llvm-project?rev=216213&view=rev
Log:
[mach-o] Fix initial live atoms with -dead_strip

When -dead_strip is used with -exported_symbols_list the initial set of
live atoms are those in the export list.

Modified:
    lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
    lld/trunk/test/mach-o/exported_symbols_list-dylib.yaml
    lld/trunk/test/mach-o/hello-world-x86_64.yaml
    lld/trunk/unittests/DriverTests/DarwinLdDriverTest.cpp

Modified: lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp?rev=216213&r1=216212&r2=216213&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp Thu Aug 21 15:25:50 2014
@@ -455,6 +455,22 @@ bool MachOLinkingContext::validateImpl(r
       addInitialUndefinedSymbol(symbol.getKey());
   }
 
+  // If -dead_strip, set up initial live symbols.
+  if (deadStrip()) {
+    // Entry point is live.
+    if (outputTypeHasEntry())
+      addDeadStripRoot(entrySymbolName());
+    // Lazy binding helper is live.
+    if (needsStubsPass())
+      addDeadStripRoot(binderSymbolName());
+    // If using -exported_symbols_list, make all exported symbols live.
+    if (_exportMode == ExportMode::whiteList) {
+      _globalsAreDeadStripRoots = false;
+      for (const auto &symbol : _exportedSymbols)
+        addDeadStripRoot(symbol.getKey());
+    }
+  }
+
   return true;
 }
 

Modified: lld/trunk/test/mach-o/exported_symbols_list-dylib.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/exported_symbols_list-dylib.yaml?rev=216213&r1=216212&r2=216213&view=diff
==============================================================================
--- lld/trunk/test/mach-o/exported_symbols_list-dylib.yaml (original)
+++ lld/trunk/test/mach-o/exported_symbols_list-dylib.yaml Thu Aug 21 15:25:50 2014
@@ -13,6 +13,11 @@
 # RUN:      -unexported_symbol _bar -unexported_symbol _a  && \
 # RUN: llvm-nm -m %t3 | FileCheck %s
 #
+# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 -dylib \
+# RUN:      %s %p/Inputs/libSystem.yaml -dead_strip -o %t \
+# RUN:      -exported_symbols_list %p/Inputs/exported_symbols_list.exp && \
+# RUN: llvm-nm -m %t | FileCheck -check-prefix=CHECK_DEAD %s
+#
 # Test -exported_symbols_list and -exported_symbol properly changes visibility.
 #
 
@@ -65,3 +70,8 @@ global-symbols:
 # CHECK: (__DATA,__data) external _b
 # CHECK: (__TEXT,__text) non-external (was a private external) _bar
 # CHECK: (__TEXT,__text) external _foo
+
+# CHECK_DEAD-NOT:  (__DATA,__data) non-external (was a private external) _a
+# CHECK_DEAD:      (__DATA,__data) external _b
+# CHECK_DEAD-NOT:  (__TEXT,__text) non-external (was a private external) _bar
+# CHECK_DEAD:      (__TEXT,__text) external _foo

Modified: lld/trunk/test/mach-o/hello-world-x86_64.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/hello-world-x86_64.yaml?rev=216213&r1=216212&r2=216213&view=diff
==============================================================================
--- lld/trunk/test/mach-o/hello-world-x86_64.yaml (original)
+++ lld/trunk/test/mach-o/hello-world-x86_64.yaml Thu Aug 21 15:25:50 2014
@@ -1,6 +1,9 @@
 # RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -o %t  && \
 # RUN: llvm-nm -m -n %t | FileCheck %s
 #
+# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -dead_strip \
+# RUN:  -o %t2 &&  llvm-nm -m -n %t2 | FileCheck %s
+#
 # Test that x86_64 hello-world can be linked into a mach-o executable
 #
 

Modified: lld/trunk/unittests/DriverTests/DarwinLdDriverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/DarwinLdDriverTest.cpp?rev=216213&r1=216212&r2=216213&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/DarwinLdDriverTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/DarwinLdDriverTest.cpp Thu Aug 21 15:25:50 2014
@@ -79,17 +79,18 @@ TEST_F(DarwinLdParserTest, OutputPath) {
 }
 
 TEST_F(DarwinLdParserTest, DeadStrip) {
-  EXPECT_TRUE(parse("ld", "-dead_strip", "foo.o", nullptr));
+  EXPECT_TRUE(parse("ld", "-arch", "x86_64", "-dead_strip", "foo.o", nullptr));
   EXPECT_TRUE(_context.deadStrip());
 }
 
 TEST_F(DarwinLdParserTest, DeadStripRootsExe) {
-  EXPECT_TRUE(parse("ld", "-dead_strip", "foo.o", nullptr));
+  EXPECT_TRUE(parse("ld", "-arch", "x86_64", "-dead_strip", "foo.o", nullptr));
   EXPECT_FALSE(_context.globalsAreDeadStripRoots());
 }
 
 TEST_F(DarwinLdParserTest, DeadStripRootsDylib) {
-  EXPECT_TRUE(parse("ld", "-dylib", "-dead_strip", "foo.o", nullptr));
+  EXPECT_TRUE(parse("ld", "-arch", "x86_64", "-dylib", "-dead_strip", "foo.o",
+                    nullptr));
   EXPECT_TRUE(_context.globalsAreDeadStripRoots());
 }
 





More information about the llvm-commits mailing list