[PATCH] Entry point function should never be dead-stripped.

Rui Ueyama ruiu at google.com
Mon Aug 12 10:44:57 PDT 2013


Hi shankarke,

Currently we do not have this logic, so the entry point function can be
dead-stripped, which is wrong.

http://llvm-reviews.chandlerc.com/D1366

Files:
  include/lld/Core/LinkingContext.h
  test/dead-strip-basic.objtxt

Index: include/lld/Core/LinkingContext.h
===================================================================
--- include/lld/Core/LinkingContext.h
+++ include/lld/Core/LinkingContext.h
@@ -176,7 +176,13 @@
   /// \name Methods used by Drivers to configure LinkingContext
   /// @{
   void setOutputPath(StringRef str) { _outputPath = str; }
-  void setEntrySymbolName(StringRef name) { _entrySymbolName = name; }
+
+  void setEntrySymbolName(StringRef name) {
+    // Entry function should never be dead-stripped.
+    _deadStripRoots.push_back(name);
+    _entrySymbolName = name;
+  }
+
   void setDeadStripping(bool enable) { _deadStrip = enable; }
   void setGlobalsAreDeadStripRoots(bool v) { _globalsAreDeadStripRoots = v; }
   void setSearchArchivesToOverrideTentativeDefinitions(bool search) {
Index: test/dead-strip-basic.objtxt
===================================================================
--- test/dead-strip-basic.objtxt
+++ test/dead-strip-basic.objtxt
@@ -1,5 +1,6 @@
-# RUN: lld -core --dead-strip  %s | FileCheck -check-prefix=CHK1 %s
-# RUN: lld -core  %s | FileCheck -check-prefix=CHK2 %s
+# RUN: lld -core --dead-strip %s | FileCheck -check-prefix=CHK1 %s
+# RUN: lld -core --dead-strip -e mydead1 %s | FileCheck -check-prefix=CHK2 %s
+# RUN: lld -core %s | FileCheck -check-prefix=CHK3 %s
 
 #
 # Test that -dead-strip removes unreachable code and data
@@ -55,8 +56,16 @@
 
 # CHK2:       name: entry
 # CHK2:       name: mydead1
-# CHK2:       name: mydead2
 # CHK2:       name: bar
+# CHK2-NOT:   name: mydead2
 # CHK2:       name: baz
-# CHK2:       name: mydead3
+# CHK2-NOT:   name: mydead3
 # CHK2:       ...
+
+# CHK3:       name: entry
+# CHK3:       name: mydead1
+# CHK3:       name: mydead2
+# CHK3:       name: bar
+# CHK3:       name: baz
+# CHK3:       name: mydead3
+# CHK3:       ...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1366.1.patch
Type: text/x-patch
Size: 1826 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130812/41ffbd22/attachment.bin>


More information about the llvm-commits mailing list