[lld] r191276 - [PECOFF] Add /swaprun:{cd,net} options.
Rui Ueyama
ruiu at google.com
Mon Sep 23 21:20:37 PDT 2013
Author: ruiu
Date: Mon Sep 23 23:20:37 2013
New Revision: 191276
URL: http://llvm.org/viewvc/llvm-project?rev=191276&view=rev
Log:
[PECOFF] Add /swaprun:{cd,net} options.
Modified:
lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
lld/trunk/lib/Driver/WinLinkDriver.cpp
lld/trunk/lib/Driver/WinLinkOptions.td
lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
lld/trunk/test/pecoff/options.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=191276&r1=191275&r2=191276&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h Mon Sep 23 23:20:37 2013
@@ -35,7 +35,8 @@ public:
_subsystem(llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN),
_machineType(llvm::COFF::IMAGE_FILE_MACHINE_I386), _imageVersion(0, 0),
_minOSVersion(6, 0), _nxCompat(true), _largeAddressAware(false),
- _allowBind(true), _allowIsolation(true), _baseRelocationEnabled(true),
+ _allowBind(true), _allowIsolation(true), _swapRunFromCD(false),
+ _swapRunFromNet(false), _baseRelocationEnabled(true),
_terminalServerAware(true), _dynamicBaseEnabled(true),
_imageType(ImageType::IMAGE_EXE) {
setDeadStripping(true);
@@ -132,6 +133,12 @@ public:
void setAllowIsolation(bool val) { _allowIsolation = val; }
bool getAllowIsolation() const { return _allowIsolation; }
+ void setSwapRunFromCD(bool val) { _swapRunFromCD = val; }
+ bool getSwapRunFromCD() const { return _swapRunFromCD; }
+
+ void setSwapRunFromNet(bool val) { _swapRunFromNet = val; }
+ bool getSwapRunFromNet() const { return _swapRunFromNet; }
+
void setBaseRelocationEnabled(bool val) { _baseRelocationEnabled = val; }
bool getBaseRelocationEnabled() const { return _baseRelocationEnabled; }
@@ -194,6 +201,8 @@ private:
bool _largeAddressAware;
bool _allowBind;
bool _allowIsolation;
+ bool _swapRunFromCD;
+ bool _swapRunFromNet;
bool _baseRelocationEnabled;
bool _terminalServerAware;
bool _dynamicBaseEnabled;
Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=191276&r1=191275&r2=191276&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Mon Sep 23 23:20:37 2013
@@ -433,6 +433,18 @@ bool WinLinkDriver::parse(int argc, cons
ctx.setDynamicBaseEnabled(false);
break;
+ case OPT_swaprun_cd:
+ // /swaprun:{cd,net} options set IMAGE_FILE_{REMOVABLE,NET}_RUN_FROM_SWAP
+ // bits in the COFF header, respectively. If one of the bits is on, the
+ // Windows loader will copy the entire file to swap area then execute it,
+ // so that the user can eject a CD or disconnect from the network.
+ ctx.setSwapRunFromCD(true);
+ break;
+
+ case OPT_swaprun_net:
+ ctx.setSwapRunFromNet(true);
+ break;
+
case OPT_incl:
ctx.addInitialUndefinedSymbol(ctx.allocateString(inputArg->getValue()));
break;
Modified: lld/trunk/lib/Driver/WinLinkOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkOptions.td?rev=191276&r1=191275&r2=191276&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkOptions.td (original)
+++ lld/trunk/lib/Driver/WinLinkOptions.td Mon Sep 23 23:20:37 2013
@@ -41,6 +41,8 @@ def incl_c : Separate<["/", "-"], "inclu
def nodefaultlib_all : F<"nodefaultlib">;
def debug : F<"debug">;
+def swaprun_cd : F<"swaprun:cd">;
+def swaprun_net : F<"swaprun:net">;
def force : F<"force">,
HelpText<"Allow undefined symbols when creating executables">;
Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp?rev=191276&r1=191275&r2=191276&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Mon Sep 23 23:20:37 2013
@@ -156,6 +156,10 @@ public:
llvm::COFF::IMAGE_FILE_EXECUTABLE_IMAGE;
if (context.getLargeAddressAware())
characteristics |= llvm::COFF::IMAGE_FILE_LARGE_ADDRESS_AWARE;
+ if (context.getSwapRunFromCD())
+ characteristics |= llvm::COFF::IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP;
+ if (context.getSwapRunFromNet())
+ characteristics |= llvm::COFF::IMAGE_FILE_NET_RUN_FROM_SWAP;
if (!context.getBaseRelocationEnabled())
characteristics |= llvm::COFF::IMAGE_FILE_RELOCS_STRIPPED;
Modified: lld/trunk/test/pecoff/options.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/options.test?rev=191276&r1=191275&r2=191276&view=diff
==============================================================================
--- lld/trunk/test/pecoff/options.test (original)
+++ lld/trunk/test/pecoff/options.test Mon Sep 23 23:20:37 2013
@@ -15,3 +15,13 @@ NOBIND: IMAGE_DLL_CHARACTERISTICS_NO_BIN
# RUN: && llvm-readobj -file-headers %t.exe \
# RUN: | FileCheck -check-prefix=NOISOLATION %s
NOISOLATION: IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION
+
+# RUN: lld -flavor link /swaprun:cd /out:%t.exe /entry:start -- %t.obj \
+# RUN: && llvm-readobj -file-headers %t.exe \
+# RUN: | FileCheck -check-prefix=SWAPRUNCD %s
+SWAPRUNCD: IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP
+
+# RUN: lld -flavor link /swaprun:net /out:%t.exe /entry:start -- %t.obj \
+# RUN: && llvm-readobj -file-headers %t.exe \
+# RUN: | FileCheck -check-prefix=SWAPRUNNET %s
+SWAPRUNNET: IMAGE_FILE_NET_RUN_FROM_SWAP
Modified: lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp?rev=191276&r1=191275&r2=191276&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp Mon Sep 23 23:20:37 2013
@@ -55,6 +55,8 @@ TEST_F(WinLinkParserTest, Basic) {
EXPECT_FALSE(_context.getLargeAddressAware());
EXPECT_TRUE(_context.getAllowBind());
EXPECT_TRUE(_context.getAllowIsolation());
+ EXPECT_FALSE(_context.getSwapRunFromCD());
+ EXPECT_FALSE(_context.getSwapRunFromNet());
EXPECT_TRUE(_context.getBaseRelocationEnabled());
EXPECT_TRUE(_context.isTerminalServerAware());
EXPECT_TRUE(_context.getDynamicBaseEnabled());
@@ -304,6 +306,16 @@ TEST_F(WinLinkParserTest, NoAllowIsolati
EXPECT_FALSE(_context.getAllowIsolation());
}
+TEST_F(WinLinkParserTest, SwapRunFromCD) {
+ EXPECT_FALSE(parse("link.exe", "/swaprun:cd", "a.obj", nullptr));
+ EXPECT_TRUE(_context.getSwapRunFromCD());
+}
+
+TEST_F(WinLinkParserTest, SwapRunFromNet) {
+ EXPECT_FALSE(parse("link.exe", "/swaprun:net", "a.obj", nullptr));
+ EXPECT_TRUE(_context.getSwapRunFromNet());
+}
+
TEST_F(WinLinkParserTest, Debug) {
EXPECT_FALSE(parse("link.exe", "/debug", "a.out", nullptr));
EXPECT_FALSE(_context.deadStrip());
More information about the llvm-commits
mailing list