From fbf576370820f710e8c90a8f4125eb3ffd0d882a Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Tue, 23 Jul 2013 17:17:19 +0000 Subject: [PATCH] [PECOFF] Support -tsaware:no command line option. llvm-svn: 186957 --- lld/include/lld/ReaderWriter/PECOFFTargetInfo.h | 9 +++++++-- lld/lib/Driver/WinLinkDriver.cpp | 4 ++++ lld/lib/Driver/WinLinkOptions.td | 5 +++++ lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp | 8 +++++--- lld/unittests/DriverTests/WinLinkDriverTest.cpp | 15 +++++++++++++-- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/lld/include/lld/ReaderWriter/PECOFFTargetInfo.h b/lld/include/lld/ReaderWriter/PECOFFTargetInfo.h index 5194d1f269c1..f9a1729d0133 100644 --- a/lld/include/lld/ReaderWriter/PECOFFTargetInfo.h +++ b/lld/include/lld/ReaderWriter/PECOFFTargetInfo.h @@ -28,7 +28,8 @@ public: : _baseAddress(0x400000), _stackReserve(1024 * 1024), _stackCommit(4096), _heapReserve(1024 * 1024), _heapCommit(4096), _subsystem(llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN), _minOSVersion(6, 0), - _nxCompat(true), _largeAddressAware(false), _baseRelocationEnabled(true) {} + _nxCompat(true), _largeAddressAware(false), _baseRelocationEnabled(true), + _terminalServerAware(true) {} struct OSVersion { OSVersion(int v1, int v2) : majorVersion(v1), minorVersion(v2) {} @@ -76,7 +77,7 @@ public: OSVersion getMinOSVersion() const { return _minOSVersion; } void setNxCompat(bool nxCompat) { _nxCompat = nxCompat; } - bool getNxCompat() const { return _nxCompat; } + bool isNxCompat() const { return _nxCompat; } void setLargeAddressAware(bool val) { _largeAddressAware = val; } bool getLargeAddressAware() const { return _largeAddressAware; } @@ -84,6 +85,9 @@ public: void setBaseRelocationEnabled(bool val) { _baseRelocationEnabled = val; } bool getBaseRelocationEnabled() const { return _baseRelocationEnabled; } + void setTerminalServerAware(bool val) { _terminalServerAware = val; } + bool isTerminalServerAware() const { return _terminalServerAware; } + virtual ErrorOr relocKindFromString(StringRef str) const; virtual ErrorOr stringFromRelocKind(Reference::Kind kind) const; @@ -108,6 +112,7 @@ private: bool _nxCompat; bool _largeAddressAware; bool _baseRelocationEnabled; + bool _terminalServerAware; std::vector _inputSearchPaths; mutable std::unique_ptr _reader; diff --git a/lld/lib/Driver/WinLinkDriver.cpp b/lld/lib/Driver/WinLinkDriver.cpp index 33689b35d93d..8b235d332795 100644 --- a/lld/lib/Driver/WinLinkDriver.cpp +++ b/lld/lib/Driver/WinLinkDriver.cpp @@ -347,6 +347,10 @@ bool WinLinkDriver::parse(int argc, const char *argv[], if (parsedArgs->getLastArg(OPT_fixed)) info.setBaseRelocationEnabled(false); + // Handle -tsaware:no + if (parsedArgs->getLastArg(OPT_no_tsaware)) + info.setTerminalServerAware(false); + // Handle -out if (llvm::opt::Arg *outpath = parsedArgs->getLastArg(OPT_out)) info.setOutputPath(outpath->getValue()); diff --git a/lld/lib/Driver/WinLinkOptions.td b/lld/lib/Driver/WinLinkOptions.td index f6ef1a82279b..f130230b539b 100644 --- a/lld/lib/Driver/WinLinkOptions.td +++ b/lld/lib/Driver/WinLinkOptions.td @@ -55,5 +55,10 @@ def fixed : Flag<["-", "/"], "fixed">, def no_fixed : Flag<["-", "/"], "fixed:no">, HelpText<"Enable base relocations">; +def tsaware : Flag<["-", "/"], "tsaware">, + HelpText<"Create Terminal Server aware executable">; +def no_tsaware : Flag<["-", "/"], "tsaware:no">, + HelpText<"Create non-Terminal Server aware executable">; + def help : Flag<["-", "/"], "help">; def help_q : Flag<["-", "/"], "?">, Alias; diff --git a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp index 2c08b10830e4..53e82c4cc15b 100644 --- a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp +++ b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp @@ -196,9 +196,11 @@ public: // them. uint16_t dllCharacteristics = llvm::COFF::IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE | - llvm::COFF::IMAGE_DLL_CHARACTERISTICS_NO_SEH | - llvm::COFF::IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE; - if (targetInfo.getNxCompat()) + llvm::COFF::IMAGE_DLL_CHARACTERISTICS_NO_SEH; + if (targetInfo.isTerminalServerAware()) + dllCharacteristics |= + llvm::COFF::IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE; + if (targetInfo.isNxCompat()) dllCharacteristics |= llvm::COFF::IMAGE_DLL_CHARACTERISTICS_NX_COMPAT; _peHeader.DLLCharacteristics = dllCharacteristics; diff --git a/lld/unittests/DriverTests/WinLinkDriverTest.cpp b/lld/unittests/DriverTests/WinLinkDriverTest.cpp index 1070399c4073..80e797d912ba 100644 --- a/lld/unittests/DriverTests/WinLinkDriverTest.cpp +++ b/lld/unittests/DriverTests/WinLinkDriverTest.cpp @@ -50,9 +50,10 @@ TEST_F(WinLinkParserTest, Basic) { EXPECT_EQ(1024 * 1024ULL, _info.getStackReserve()); EXPECT_EQ(4096ULL, _info.getStackCommit()); EXPECT_FALSE(_info.allowRemainingUndefines()); - EXPECT_TRUE(_info.getNxCompat()); + EXPECT_TRUE(_info.isNxCompat()); EXPECT_FALSE(_info.getLargeAddressAware()); EXPECT_TRUE(_info.getBaseRelocationEnabled()); + EXPECT_TRUE(_info.isTerminalServerAware()); } TEST_F(WinLinkParserTest, WindowsStyleOption) { @@ -138,7 +139,7 @@ TEST_F(WinLinkParserTest, Force) { TEST_F(WinLinkParserTest, NoNxCompat) { EXPECT_FALSE(parse("link.exe", "-nxcompat:no", "a.obj", nullptr)); - EXPECT_FALSE(_info.getNxCompat()); + EXPECT_FALSE(_info.isNxCompat()); } TEST_F(WinLinkParserTest, LargeAddressAware) { @@ -161,6 +162,16 @@ TEST_F(WinLinkParserTest, NoFixed) { EXPECT_TRUE(_info.getBaseRelocationEnabled()); } +TEST_F(WinLinkParserTest, TerminalServerAware) { + EXPECT_FALSE(parse("link.exe", "-tsaware", "a.out", nullptr)); + EXPECT_TRUE(_info.isTerminalServerAware()); +} + +TEST_F(WinLinkParserTest, NoTerminalServerAware) { + EXPECT_FALSE(parse("link.exe", "-tsaware:no", "a.out", nullptr)); + EXPECT_FALSE(_info.isTerminalServerAware()); +} + TEST_F(WinLinkParserTest, NoInputFiles) { EXPECT_TRUE(parse("link.exe", nullptr)); EXPECT_EQ("No input files\n", errorMessage());