[lld] r189307 - Treat entry point symbol as an undefined atom.

Rui Ueyama ruiu at google.com
Mon Aug 26 20:18:12 PDT 2013


Author: ruiu
Date: Mon Aug 26 22:18:11 2013
New Revision: 189307

URL: http://llvm.org/viewvc/llvm-project?rev=189307&view=rev
Log:
Treat entry point symbol as an undefined atom.

With this patch the entry symbol is treated as an undefined symbol, to force
the resolver to resolve the entry symbol.

Differential Revision: http://llvm-reviews.chandlerc.com/D1524

Modified:
    lld/trunk/include/lld/Core/LinkingContext.h
    lld/trunk/lib/Driver/WinLinkDriver.cpp
    lld/trunk/test/pecoff/Inputs/main.obj.yaml
    lld/trunk/test/pecoff/drectve.test
    lld/trunk/test/pecoff/imagebase.test
    lld/trunk/test/pecoff/importlib.test
    lld/trunk/test/pecoff/lib.test
    lld/trunk/test/pecoff/multi.test
    lld/trunk/test/pecoff/trivial.test
    lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp

Modified: lld/trunk/include/lld/Core/LinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/LinkingContext.h?rev=189307&r1=189306&r2=189307&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/LinkingContext.h (original)
+++ lld/trunk/include/lld/Core/LinkingContext.h Mon Aug 26 22:18:11 2013
@@ -77,6 +77,13 @@ public:
     return _deadStripRoots;
   }
 
+  /// Add the given symbol name to the dead strip root set. Only used if
+  /// deadStrip() returns true.
+  void addDeadStripRoot(StringRef symbolName) {
+    assert(_deadStrip && "only applicable when deadstripping enabled");
+    _deadStripRoots.push_back(symbolName);
+  }
+
   /// Archive files (aka static libraries) are normally lazily loaded.  That is,
   /// object files within an archive are only loaded and linked in, if the
   /// object file contains a DefinedAtom which will replace an existing
@@ -178,7 +185,16 @@ public:
   /// \name Methods used by Drivers to configure TargetInfo
   /// @{
   void setOutputPath(StringRef str) { _outputPath = str; }
-  void setEntrySymbolName(StringRef name) { _entrySymbolName = name; }
+
+  // Set the entry symbol name. You may also need to call addDeadStripRoot() for
+  // the symbol if your platform supports dead-stripping, so that the symbol
+  // will not be removed from the output.
+  void setEntrySymbolName(StringRef name) {
+    // Entry function have to be resolved as an undefined symbol.
+    addInitialUndefinedSymbol(name);
+    _entrySymbolName = name;
+  }
+
   void setDeadStripping(bool enable) { _deadStrip = enable; }
   void setGlobalsAreDeadStripRoots(bool v) { _globalsAreDeadStripRoots = v; }
   void setSearchArchivesToOverrideTentativeDefinitions(bool search) {
@@ -214,9 +230,11 @@ public:
   }
   virtual InputGraph &inputGraph() const { return *_inputGraph; }
 
-  /// This method adds undefined symbols specified by the -u option to the
-  /// to the list of undefined symbols known to the linker. This option
-  /// essentially forces an undefined symbol to be create.
+  /// This method adds undefined symbols specified by the -u option to the to
+  /// the list of undefined symbols known to the linker. This option essentially
+  /// forces an undefined symbol to be create. You may also need to call
+  /// addDeadStripRoot() for the symbol if your platform supports dead
+  /// stripping, so that the symbol will not be removed from the output.
   void addInitialUndefinedSymbol(StringRef symbolName) {
     _initialUndefinedSymbols.push_back(symbolName);
   }

Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=189307&r1=189306&r2=189307&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Mon Aug 26 22:18:11 2013
@@ -422,7 +422,7 @@ bool WinLinkDriver::parse(int argc, cons
   }
 
   // Use the default entry name if /entry option is not given.
-  if (!parsedArgs->getLastArg(OPT_entry))
+  if (ctx.entrySymbolName().empty())
     setDefaultEntrySymbolName(ctx);
 
   // Arguments after "--" are interpreted as filenames even if they

Modified: lld/trunk/test/pecoff/Inputs/main.obj.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/main.obj.yaml?rev=189307&r1=189306&r2=189307&view=diff
==============================================================================
--- lld/trunk/test/pecoff/Inputs/main.obj.yaml (original)
+++ lld/trunk/test/pecoff/Inputs/main.obj.yaml Mon Aug 26 22:18:11 2013
@@ -22,10 +22,6 @@ sections:
     Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
     Alignment:       1
     SectionData:     04000000F10000006E0000003300011100000000433A5C63796777696E5C686F6D655C727569755C7374617469635C7374617469632D696D706F72742E6F626A0037003C1103020000030000000000000000000A0000001B9D01004D6963726F736F667420285229204D6163726F20417373656D626C657200000000
-  - Name:            .drectve
-    Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
-    Alignment:       2147483648
-    SectionData:     2F656E7472793A6D61696E20
 symbols:
   - Name:            "@comp.id"
     Value:           10394907
@@ -75,12 +71,4 @@ symbols:
     SimpleType:      IMAGE_SYM_TYPE_NULL
     ComplexType:     IMAGE_SYM_DTYPE_NULL
     StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
-  - Name:            .drectve
-    Value:           0
-    SectionNumber:   4
-    SimpleType:      IMAGE_SYM_TYPE_NULL
-    ComplexType:     IMAGE_SYM_DTYPE_NULL
-    StorageClass:    IMAGE_SYM_CLASS_STATIC
-    NumberOfAuxSymbols: 1
-    AuxiliaryData:   0C0000000000000000000000000000000000
 ...

Modified: lld/trunk/test/pecoff/drectve.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/drectve.test?rev=189307&r1=189306&r2=189307&view=diff
==============================================================================
--- lld/trunk/test/pecoff/drectve.test (original)
+++ lld/trunk/test/pecoff/drectve.test Mon Aug 26 22:18:11 2013
@@ -4,7 +4,7 @@
 
 # RUN: yaml2obj %p/Inputs/drectve.obj.yaml > %t.obj
 #
-# RUN: lld -flavor link /out:%t1 /entry:start -- %t.obj \
+# RUN: lld -flavor link /out:%t1 /entry:_start -- %t.obj \
 # RUN:   && llvm-readobj -file-headers %t1 | FileCheck %s
 
 CHECK: MajorOperatingSystemVersion: 42

Modified: lld/trunk/test/pecoff/imagebase.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/imagebase.test?rev=189307&r1=189306&r2=189307&view=diff
==============================================================================
--- lld/trunk/test/pecoff/imagebase.test (original)
+++ lld/trunk/test/pecoff/imagebase.test Mon Aug 26 22:18:11 2013
@@ -1,9 +1,10 @@
 # RUN: yaml2obj %p/Inputs/imagebase.obj.yaml > %t.obj
 #
-# RUN: lld -flavor link /out:%t1 /subsystem:console -- %t.obj \
+# RUN: lld -flavor link /out:%t1 /subsystem:console /entry:__start -- %t.obj \
 # RUN:   && llvm-objdump -disassemble %t1 | FileCheck -check-prefix=CHECK1 %s
 #
-# RUN: lld -flavor link /out:%t1 /subsystem:console /base:65536 -- %t.obj \
+# RUN: lld -flavor link /out:%t1 /subsystem:console /entry:__start /base:65536 \
+# RUN:   -- %t.obj \
 # RUN:   && llvm-objdump -disassemble %t1 | FileCheck -check-prefix=CHECK2 %s
 
 CHECK1: a1 00 20 40 00    movl    4202496, %eax

Modified: lld/trunk/test/pecoff/importlib.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/importlib.test?rev=189307&r1=189306&r2=189307&view=diff
==============================================================================
--- lld/trunk/test/pecoff/importlib.test (original)
+++ lld/trunk/test/pecoff/importlib.test Mon Aug 26 22:18:11 2013
@@ -3,20 +3,23 @@
 #
 # RUN: yaml2obj %p/Inputs/vars-main.obj.yaml > %t.obj
 #
-# RUN: lld -flavor link /out:%t1 /subsystem:console -- %t.obj \
+# RUN: lld -flavor link /out:%t1 /subsystem:console /entry:_main -- %t.obj \
 # RUN:    %p/Inputs/vars.lib && llvm-objdump -d %t1 | FileCheck %s
 #
-# RUN: lld -flavor link /out:%t1 /subsystem:console /libpath:%p/Inputs \
-# RUN:    -- %t.obj vars.lib && llvm-objdump -d %t1 | FileCheck %s
-#
-# RUN: lld -flavor link /out:%t1 /subsystem:console /libpath:%p/Inputs \
-# RUN:    /defaultlib:vars.lib -- %t.obj && llvm-objdump -d %t1 | FileCheck %s
+# RUN: lld -flavor link /out:%t1 /subsystem:console /entry:_main \
+# RUN:    /libpath:%p/Inputs -- %t.obj vars.lib && llvm-objdump -d %t1 \
+# RUN:    | FileCheck %s
+#
+# RUN: lld -flavor link /out:%t1 /subsystem:console /entry:_main \
+# RUN:    /libpath:%p/Inputs /defaultlib:vars.lib -- %t.obj \
+# RUN:    && llvm-objdump -d %t1 | FileCheck %s
 #
 # RUN: env LIB=%p/Inputs lld -flavor link /out:%t1 /subsystem:console \
-# RUN:    -- %t.obj vars.lib && llvm-objdump -d %t1 | FileCheck %s
+# RUN:    /entry:_main -- %t.obj vars.lib && llvm-objdump -d %t1 | FileCheck %s
 #
-# RUN: env LINK="/out:%t1 /subsystem:console -- %t.obj" lld -flavor link \
-# RUN:    %p/Inputs/vars.lib && llvm-objdump -d %t1 | FileCheck %s
+# RUN: env LINK="/out:%t1 /subsystem:console /entry:_main -- %t.obj" \
+# RUN:    lld -flavor link %p/Inputs/vars.lib && llvm-objdump -d %t1 \
+# RUN:    | FileCheck %s
 
 CHECK: Disassembly of section .text:
 CHECK-NEXT: .text:

Modified: lld/trunk/test/pecoff/lib.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/lib.test?rev=189307&r1=189306&r2=189307&view=diff
==============================================================================
--- lld/trunk/test/pecoff/lib.test (original)
+++ lld/trunk/test/pecoff/lib.test Mon Aug 26 22:18:11 2013
@@ -2,7 +2,7 @@
 #
 # RUN: yaml2obj %p/Inputs/main.obj.yaml > %t.obj
 #
-# RUN: lld -flavor link /out:%t1 /subsystem:console -- %t.obj \
+# RUN: lld -flavor link /out:%t1 /subsystem:console /entry:_main -- %t.obj \
 # RUN:   %p/Inputs/static.lib && llvm-objdump -d %t1 | FileCheck %s
 
 CHECK: Disassembly of section .text:

Modified: lld/trunk/test/pecoff/multi.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/multi.test?rev=189307&r1=189306&r2=189307&view=diff
==============================================================================
--- lld/trunk/test/pecoff/multi.test (original)
+++ lld/trunk/test/pecoff/multi.test Mon Aug 26 22:18:11 2013
@@ -4,8 +4,8 @@
 # RUN: yaml2obj %p/Inputs/static-data1.obj.yaml > %t2.obj
 # RUN: yaml2obj %p/Inputs/static-data2.obj.yaml > %t3.obj
 #
-# RUN: lld -flavor link /out:%t1 /subsystem:console -- %t1.obj %t2.obj %t3.obj \
-# RUN:   && llvm-objdump -d %t1 | FileCheck %s
+# RUN: lld -flavor link /out:%t1 /subsystem:console /entry:_main \
+# RUN:   -- %t1.obj %t2.obj %t3.obj && llvm-objdump -d %t1 | FileCheck %s
 
 CHECK: Disassembly of section .text:
 CHECK: .text:

Modified: lld/trunk/test/pecoff/trivial.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/trivial.test?rev=189307&r1=189306&r2=189307&view=diff
==============================================================================
--- lld/trunk/test/pecoff/trivial.test (original)
+++ lld/trunk/test/pecoff/trivial.test Mon Aug 26 22:18:11 2013
@@ -4,10 +4,11 @@
 #
 # RUN: yaml2obj %p/Inputs/nop.obj.yaml > %t.obj
 #
-# RUN: lld -flavor link /out:%t1 /subsystem:console,3.11 -- %t.obj \
-# RUN:   && llvm-readobj -file-headers %t1 | FileCheck -check-prefix=FILE %s
+# RUN: lld -flavor link /out:%t1 /subsystem:console,3.11 /entry:_start \
+# RUN:   -- %t.obj && llvm-readobj -file-headers %t1 \
+# RUN:   | FileCheck -check-prefix=FILE %s
 #
-# RUN: lld -flavor link /out:%t1 -- %t.obj \
+# RUN: lld -flavor link /out:%t1 /entry:_start -- %t.obj \
 # RUN:   && llvm-readobj -sections %t1 | FileCheck -check-prefix=SECTIONS %s
 
 FILE: Format: COFF-i386

Modified: lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp?rev=189307&r1=189306&r2=189307&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp Mon Aug 26 22:18:11 2013
@@ -54,7 +54,8 @@ TEST_F(WinLinkParserTest, Basic) {
   EXPECT_TRUE(_context.getBaseRelocationEnabled());
   EXPECT_TRUE(_context.isTerminalServerAware());
   EXPECT_TRUE(_context.getDynamicBaseEnabled());
-  EXPECT_TRUE(_context.initialUndefinedSymbols().empty());
+  EXPECT_FALSE(_context.initialUndefinedSymbols().empty());
+  EXPECT_EQ("_start", _context.initialUndefinedSymbols()[0]);
 }
 
 TEST_F(WinLinkParserTest, UnixStyleOption) {





More information about the llvm-commits mailing list