[lld] r189308 - [PECOFF] Enable dead-stripping by default to match link.exe behavior.

Rui Ueyama ruiu at google.com
Mon Aug 26 20:38:19 PDT 2013


Author: ruiu
Date: Mon Aug 26 22:38:18 2013
New Revision: 189308

URL: http://llvm.org/viewvc/llvm-project?rev=189308&view=rev
Log:
[PECOFF] Enable dead-stripping by default to match link.exe behavior.

Modified:
    lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
    lld/trunk/lib/Driver/WinLinkDriver.cpp
    lld/trunk/lib/Driver/WinLinkOptions.td
    lld/trunk/test/pecoff/base-reloc.test
    lld/trunk/test/pecoff/bss-section.test
    lld/trunk/test/pecoff/common-symbol.test
    lld/trunk/test/pecoff/grouped-sections.test
    lld/trunk/test/pecoff/hello.test
    lld/trunk/test/pecoff/imagebase.test
    lld/trunk/test/pecoff/importlib.test
    lld/trunk/test/pecoff/include.test
    lld/trunk/test/pecoff/lib.test
    lld/trunk/test/pecoff/multi.test
    lld/trunk/test/pecoff/reloc.test
    lld/trunk/test/pecoff/trivial.test
    lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp

Modified: lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h?rev=189308&r1=189307&r2=189308&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h Mon Aug 26 22:38:18 2013
@@ -30,7 +30,9 @@ public:
         _subsystem(llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN), _minOSVersion(6, 0),
         _nxCompat(true), _largeAddressAware(false),
         _baseRelocationEnabled(true), _terminalServerAware(true),
-        _dynamicBaseEnabled(true), _imageType(ImageType::IMAGE_EXE) {}
+        _dynamicBaseEnabled(true), _imageType(ImageType::IMAGE_EXE) {
+    setDeadStripping(true);
+  }
 
   struct OSVersion {
     OSVersion(int v1, int v2) : majorVersion(v1), minorVersion(v2) {}

Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=189308&r1=189307&r2=189308&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Mon Aug 26 22:38:18 2013
@@ -363,6 +363,11 @@ bool WinLinkDriver::parse(int argc, cons
       ctx.setAllowRemainingUndefines(true);
       break;
 
+    case OPT_no_ref:
+      // Handle /opt:noref
+      ctx.setDeadStripping(false);
+      break;
+
     case OPT_no_nxcompat:
       // handle /nxcompat:no
       ctx.setNxCompat(false);
@@ -425,6 +430,12 @@ bool WinLinkDriver::parse(int argc, cons
   if (ctx.entrySymbolName().empty())
     setDefaultEntrySymbolName(ctx);
 
+  // Specifying both /opt:ref and /opt:noref is an error.
+  if (parsedArgs->getLastArg(OPT_ref) && parsedArgs->getLastArg(OPT_no_ref)) {
+    diagnostics << "/opt:ref must not be specified with /opt:noref\n";
+    return true;
+  }
+
   // Arguments after "--" are interpreted as filenames even if they
   // start with a hypen or a slash. This is not compatible with link.exe
   // but useful for us to test lld on Unix.

Modified: lld/trunk/lib/Driver/WinLinkOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkOptions.td?rev=189308&r1=189307&r2=189308&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkOptions.td (original)
+++ lld/trunk/lib/Driver/WinLinkOptions.td Mon Aug 26 22:38:18 2013
@@ -31,6 +31,10 @@ def incl_c : Separate<["/", "-"], "inclu
 def force : F<"force">,
     HelpText<"Allow undefined symbols when creating executables">;
 
+def ref : F<"opt:ref">;
+def no_ref : F<"opt:noref">,
+    HelpText<"Keep unreferenced symbols to be included to the output">;
+
 def nxcompat : F<"nxcompat">;
 def no_nxcompat : F<"nxcompat:no">,
     HelpText<"Disable data execution provention">;

Modified: lld/trunk/test/pecoff/base-reloc.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/base-reloc.test?rev=189308&r1=189307&r2=189308&view=diff
==============================================================================
--- lld/trunk/test/pecoff/base-reloc.test (original)
+++ lld/trunk/test/pecoff/base-reloc.test Mon Aug 26 22:38:18 2013
@@ -1,9 +1,11 @@
 # RUN: yaml2obj %p/Inputs/hello.obj.yaml > %t.obj
 #
-# RUN: lld -flavor link /out:%t1 /subsystem:console /force -- %t.obj \
+# RUN: lld -flavor link /out:%t1 /subsystem:console /force /opt:noref \
+# RUN:   -- %t.obj \
 # RUN:   && llvm-objdump -s %t1 | FileCheck %s --check-prefix=BASEREL-SECTION
 #
-# RUN: lld -flavor link /out:%t1 /subsystem:console /force /fixed -- %t.obj \
+# RUN: lld -flavor link /out:%t1 /subsystem:console /force /fixed /opt:noref \
+# RUN:    -- %t.obj \
 # RUN:   && llvm-objdump -s %t1 | FileCheck %s --check-prefix=NOBASEREL-SECTION
 
 # Because llvm-objdump cannot pretty-print the contents of .reloc section, we

Modified: lld/trunk/test/pecoff/bss-section.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/bss-section.test?rev=189308&r1=189307&r2=189308&view=diff
==============================================================================
--- lld/trunk/test/pecoff/bss-section.test (original)
+++ lld/trunk/test/pecoff/bss-section.test Mon Aug 26 22:38:18 2013
@@ -1,5 +1,5 @@
-# RUN: lld -flavor link /out:%t /subsystem:console /force -- %p/Inputs/bss.obj \
-# RUN:    && llvm-readobj -sections %t | FileCheck %s
+# RUN: lld -flavor link /out:%t /subsystem:console /force /opt:noref \
+# RUN:    -- %p/Inputs/bss.obj && llvm-readobj -sections %t | FileCheck %s
 
 CHECK:       Section {
 CHECK:         Number: 2

Modified: lld/trunk/test/pecoff/common-symbol.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/common-symbol.test?rev=189308&r1=189307&r2=189308&view=diff
==============================================================================
--- lld/trunk/test/pecoff/common-symbol.test (original)
+++ lld/trunk/test/pecoff/common-symbol.test Mon Aug 26 22:38:18 2013
@@ -1,7 +1,7 @@
 # RUN: yaml2obj %p/Inputs/common-symbol.obj.yaml > %t.obj
 #
-# RUN: lld -flavor link /out:%t /subsystem:console /force -- %t.obj %t.obj \
-# RUN:    && llvm-readobj -sections %t | FileCheck %s
+# RUN: lld -flavor link /out:%t /subsystem:console /force /opt:noref \
+# RUN:    -- %t.obj %t.obj && llvm-readobj -sections %t | FileCheck %s
 
 CHECK:       Section {
 CHECK:         Number: 2

Modified: lld/trunk/test/pecoff/grouped-sections.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/grouped-sections.test?rev=189308&r1=189307&r2=189308&view=diff
==============================================================================
--- lld/trunk/test/pecoff/grouped-sections.test (original)
+++ lld/trunk/test/pecoff/grouped-sections.test Mon Aug 26 22:38:18 2013
@@ -1,7 +1,7 @@
 # RUN: yaml2obj %p/Inputs/grouped-sections.obj.yaml > %t.obj
 #
-# RUN: lld -flavor link /out:%t1 /subsystem:console /force -- %t.obj \
-# RUN:   && llvm-objdump -s %t1 | FileCheck %s
+# RUN: lld -flavor link /out:%t1 /subsystem:console /force /opt:noref \
+# RUN:   -- %t.obj && llvm-objdump -s %t1 | FileCheck %s
 #
 # The file "grouped-sections.obj" has three data sections in the following
 # order:

Modified: lld/trunk/test/pecoff/hello.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/hello.test?rev=189308&r1=189307&r2=189308&view=diff
==============================================================================
--- lld/trunk/test/pecoff/hello.test (original)
+++ lld/trunk/test/pecoff/hello.test Mon Aug 26 22:38:18 2013
@@ -1,13 +1,15 @@
 # RUN: yaml2obj %p/Inputs/hello.obj.yaml > %t.obj
 
-# RUN: lld -flavor link /out:%t1 /subsystem:console /force -- %t.obj \
+# RUN: lld -flavor link /out:%t1 /subsystem:console /force /opt:noref \
+# RUN:   -- %t.obj \
 # RUN:   && llvm-readobj -file-headers %t1 | FileCheck -check-prefix=FILE %s
 
 FILE: ImageOptionalHeader {
 FILE:   SizeOfInitializedData: 512
 FILE: }
 
-# RUN: lld -flavor link /out:%t1 /subsystem:console /force -- %t.obj \
+# RUN: lld -flavor link /out:%t1 /subsystem:console /force /opt:noref \
+# RUN:   -- %t.obj \
 # RUN:   && llvm-readobj -sections %t1 | FileCheck -check-prefix=SECTIONS %s
 
 SECTIONS: Format: COFF-i386

Modified: lld/trunk/test/pecoff/imagebase.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/imagebase.test?rev=189308&r1=189307&r2=189308&view=diff
==============================================================================
--- lld/trunk/test/pecoff/imagebase.test (original)
+++ lld/trunk/test/pecoff/imagebase.test Mon Aug 26 22:38:18 2013
@@ -1,10 +1,11 @@
 # RUN: yaml2obj %p/Inputs/imagebase.obj.yaml > %t.obj
 #
-# RUN: lld -flavor link /out:%t1 /subsystem:console /entry:__start -- %t.obj \
+# RUN: lld -flavor link /out:%t1 /subsystem:console /entry:__start /opt:noref \
+# RUN:   -- %t.obj \
 # RUN:   && llvm-objdump -disassemble %t1 | FileCheck -check-prefix=CHECK1 %s
 #
 # RUN: lld -flavor link /out:%t1 /subsystem:console /entry:__start /base:65536 \
-# RUN:   -- %t.obj \
+# RUN:   /opt:noref -- %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=189308&r1=189307&r2=189308&view=diff
==============================================================================
--- lld/trunk/test/pecoff/importlib.test (original)
+++ lld/trunk/test/pecoff/importlib.test Mon Aug 26 22:38:18 2013
@@ -3,23 +3,24 @@
 #
 # RUN: yaml2obj %p/Inputs/vars-main.obj.yaml > %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 /entry:_main /opt:noref \
+# RUN:    -- %t.obj %p/Inputs/vars.lib && llvm-objdump -d %t1 | FileCheck %s
 #
-# RUN: lld -flavor link /out:%t1 /subsystem:console /entry:_main \
+# RUN: lld -flavor link /out:%t1 /subsystem:console /entry:_main /opt:noref \
 # 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: lld -flavor link /out:%t1 /subsystem:console /entry:_main /opt:noref \
 # 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:    /entry:_main -- %t.obj vars.lib && llvm-objdump -d %t1 | FileCheck %s
+# RUN:    /opt:noref /entry:_main -- %t.obj vars.lib \
+# RUN:    && 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
+# RUN: env LINK="/out:%t1 /subsystem:console /entry:_main /opt:noref \
+# RUN:    -- %t.obj" lld -flavor link %p/Inputs/vars.lib \
+# RUN:    && llvm-objdump -d %t1 | FileCheck %s
 
 CHECK: Disassembly of section .text:
 CHECK-NEXT: .text:

Modified: lld/trunk/test/pecoff/include.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/include.test?rev=189308&r1=189307&r2=189308&view=diff
==============================================================================
--- lld/trunk/test/pecoff/include.test (original)
+++ lld/trunk/test/pecoff/include.test Mon Aug 26 22:38:18 2013
@@ -1,6 +1,6 @@
 # RUN: yaml2obj %p/Inputs/nop.obj.yaml > %t.obj
 #
-# RUN: not lld -flavor link /out:%t1 /subsystem:console \
+# RUN: not lld -flavor link /out:%t1 /subsystem:console /opt:noref \
 # RUN:   /include:sym1 /include:sym2 -- %t.obj 2> %t1
 # RUN: FileCheck %s < %t1
 

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

Modified: lld/trunk/test/pecoff/multi.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/multi.test?rev=189308&r1=189307&r2=189308&view=diff
==============================================================================
--- lld/trunk/test/pecoff/multi.test (original)
+++ lld/trunk/test/pecoff/multi.test Mon Aug 26 22:38:18 2013
@@ -4,7 +4,7 @@
 # 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 /entry:_main \
+# RUN: lld -flavor link /out:%t1 /subsystem:console /entry:_main /opt:noref \
 # RUN:   -- %t1.obj %t2.obj %t3.obj && llvm-objdump -d %t1 | FileCheck %s
 
 CHECK: Disassembly of section .text:

Modified: lld/trunk/test/pecoff/reloc.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/reloc.test?rev=189308&r1=189307&r2=189308&view=diff
==============================================================================
--- lld/trunk/test/pecoff/reloc.test (original)
+++ lld/trunk/test/pecoff/reloc.test Mon Aug 26 22:38:18 2013
@@ -2,8 +2,8 @@
 #
 # RUN: llvm-objdump -d %t.obj | FileCheck -check-prefix=BEFORE %s
 #
-# RUN: lld -flavor link /out:%t1 /subsystem:console /force -- %t.obj \
-# RUN:   && llvm-objdump -d %t1 | FileCheck -check-prefix=AFTER %s
+# RUN: lld -flavor link /out:%t1 /subsystem:console /force /opt:noref \
+# RUN:   -- %t.obj && llvm-objdump -d %t1 | FileCheck -check-prefix=AFTER %s
 
 BEFORE: Disassembly of section .text:
 BEFORE: _main:

Modified: lld/trunk/test/pecoff/trivial.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/trivial.test?rev=189308&r1=189307&r2=189308&view=diff
==============================================================================
--- lld/trunk/test/pecoff/trivial.test (original)
+++ lld/trunk/test/pecoff/trivial.test Mon Aug 26 22:38:18 2013
@@ -5,10 +5,10 @@
 # RUN: yaml2obj %p/Inputs/nop.obj.yaml > %t.obj
 #
 # RUN: lld -flavor link /out:%t1 /subsystem:console,3.11 /entry:_start \
-# RUN:   -- %t.obj && llvm-readobj -file-headers %t1 \
+# RUN:   /opt:noref -- %t.obj && llvm-readobj -file-headers %t1 \
 # RUN:   | FileCheck -check-prefix=FILE %s
 #
-# RUN: lld -flavor link /out:%t1 /entry:_start -- %t.obj \
+# RUN: lld -flavor link /out:%t1 /entry:_start /opt:noref -- %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=189308&r1=189307&r2=189308&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp Mon Aug 26 22:38:18 2013
@@ -54,6 +54,7 @@ TEST_F(WinLinkParserTest, Basic) {
   EXPECT_TRUE(_context.getBaseRelocationEnabled());
   EXPECT_TRUE(_context.isTerminalServerAware());
   EXPECT_TRUE(_context.getDynamicBaseEnabled());
+  EXPECT_TRUE(_context.deadStrip());
   EXPECT_FALSE(_context.initialUndefinedSymbols().empty());
   EXPECT_EQ("_start", _context.initialUndefinedSymbols()[0]);
 }





More information about the llvm-commits mailing list