summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/include/lld/ReaderWriter/PECOFFLinkingContext.h4
-rw-r--r--lld/lib/Driver/WinLinkDriver.cpp11
-rw-r--r--lld/lib/Driver/WinLinkOptions.td4
-rw-r--r--lld/test/pecoff/base-reloc.test6
-rw-r--r--lld/test/pecoff/bss-section.test4
-rw-r--r--lld/test/pecoff/common-symbol.test4
-rw-r--r--lld/test/pecoff/grouped-sections.test4
-rw-r--r--lld/test/pecoff/hello.test6
-rw-r--r--lld/test/pecoff/imagebase.test5
-rw-r--r--lld/test/pecoff/importlib.test17
-rw-r--r--lld/test/pecoff/include.test2
-rw-r--r--lld/test/pecoff/lib.test4
-rw-r--r--lld/test/pecoff/multi.test2
-rw-r--r--lld/test/pecoff/reloc.test4
-rw-r--r--lld/test/pecoff/trivial.test4
-rw-r--r--lld/unittests/DriverTests/WinLinkDriverTest.cpp1
16 files changed, 53 insertions, 29 deletions
diff --git a/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h b/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h
index 1b8ae4367b7..ab27327ecca 100644
--- a/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h
+++ b/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h
@@ -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) {}
diff --git a/lld/lib/Driver/WinLinkDriver.cpp b/lld/lib/Driver/WinLinkDriver.cpp
index a312eb2a126..64ad9cba853 100644
--- a/lld/lib/Driver/WinLinkDriver.cpp
+++ b/lld/lib/Driver/WinLinkDriver.cpp
@@ -363,6 +363,11 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
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, const char *argv[],
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.
diff --git a/lld/lib/Driver/WinLinkOptions.td b/lld/lib/Driver/WinLinkOptions.td
index e62676e017b..663a6b571d6 100644
--- a/lld/lib/Driver/WinLinkOptions.td
+++ b/lld/lib/Driver/WinLinkOptions.td
@@ -31,6 +31,10 @@ def incl_c : Separate<["/", "-"], "include">, Alias<incl>;
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">;
diff --git a/lld/test/pecoff/base-reloc.test b/lld/test/pecoff/base-reloc.test
index 5337dbbee9c..e9214f057e4 100644
--- a/lld/test/pecoff/base-reloc.test
+++ b/lld/test/pecoff/base-reloc.test
@@ -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
diff --git a/lld/test/pecoff/bss-section.test b/lld/test/pecoff/bss-section.test
index 3227b71de4f..f686e12d722 100644
--- a/lld/test/pecoff/bss-section.test
+++ b/lld/test/pecoff/bss-section.test
@@ -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
diff --git a/lld/test/pecoff/common-symbol.test b/lld/test/pecoff/common-symbol.test
index bd3c550662f..fb3d14793c9 100644
--- a/lld/test/pecoff/common-symbol.test
+++ b/lld/test/pecoff/common-symbol.test
@@ -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
diff --git a/lld/test/pecoff/grouped-sections.test b/lld/test/pecoff/grouped-sections.test
index d0b1ac9bee4..f45e496622c 100644
--- a/lld/test/pecoff/grouped-sections.test
+++ b/lld/test/pecoff/grouped-sections.test
@@ -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:
diff --git a/lld/test/pecoff/hello.test b/lld/test/pecoff/hello.test
index 9a7c2927bed..cc1e13215e2 100644
--- a/lld/test/pecoff/hello.test
+++ b/lld/test/pecoff/hello.test
@@ -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
diff --git a/lld/test/pecoff/imagebase.test b/lld/test/pecoff/imagebase.test
index 82230ba4366..f691eb9a6e4 100644
--- a/lld/test/pecoff/imagebase.test
+++ b/lld/test/pecoff/imagebase.test
@@ -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
diff --git a/lld/test/pecoff/importlib.test b/lld/test/pecoff/importlib.test
index 11ba4540490..9b00e6a828f 100644
--- a/lld/test/pecoff/importlib.test
+++ b/lld/test/pecoff/importlib.test
@@ -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:
diff --git a/lld/test/pecoff/include.test b/lld/test/pecoff/include.test
index 93793377763..39c319c62bc 100644
--- a/lld/test/pecoff/include.test
+++ b/lld/test/pecoff/include.test
@@ -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
diff --git a/lld/test/pecoff/lib.test b/lld/test/pecoff/lib.test
index 94a7044b7a0..661e32ad15b 100644
--- a/lld/test/pecoff/lib.test
+++ b/lld/test/pecoff/lib.test
@@ -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:
diff --git a/lld/test/pecoff/multi.test b/lld/test/pecoff/multi.test
index 787de318722..8687678ecbc 100644
--- a/lld/test/pecoff/multi.test
+++ b/lld/test/pecoff/multi.test
@@ -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:
diff --git a/lld/test/pecoff/reloc.test b/lld/test/pecoff/reloc.test
index 8dd5c472cb4..bfef4600376 100644
--- a/lld/test/pecoff/reloc.test
+++ b/lld/test/pecoff/reloc.test
@@ -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:
diff --git a/lld/test/pecoff/trivial.test b/lld/test/pecoff/trivial.test
index 536aea0943a..8b8100e3057 100644
--- a/lld/test/pecoff/trivial.test
+++ b/lld/test/pecoff/trivial.test
@@ -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
diff --git a/lld/unittests/DriverTests/WinLinkDriverTest.cpp b/lld/unittests/DriverTests/WinLinkDriverTest.cpp
index 416af38c76b..a70b20b1aed 100644
--- a/lld/unittests/DriverTests/WinLinkDriverTest.cpp
+++ b/lld/unittests/DriverTests/WinLinkDriverTest.cpp
@@ -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]);
}
OpenPOWER on IntegriCloud