[lld] r201895 - [PECOFF] Driver support for /SAFESEH option.

Rui Ueyama ruiu at google.com
Fri Feb 21 14:30:43 PST 2014


Author: ruiu
Date: Fri Feb 21 16:30:43 2014
New Revision: 201895

URL: http://llvm.org/viewvc/llvm-project?rev=201895&view=rev
Log:
[PECOFF] Driver support for /SAFESEH option.

Syntactically /SAFESEH is a boolean flag -- you can pass /SAFESEH or /SAFESEH:no.

The meaning of /SAFESEH is as follows.

 - If /SAFESEH is specified, the linker will produce an executable with SEH table.
   If any input files are not compatible with SEH, it's an error.
 - If /SAFESEH:no is specified, the linker will not emit SEH table even if all
   input files are compatible with SEH.
 - If no option is specified, the linker emits SEH table if all input files are
   compatible with SEH.

Modified:
    lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
    lld/trunk/lib/Driver/WinLinkDriver.cpp
    lld/trunk/lib/Driver/WinLinkOptions.td
    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=201895&r1=201894&r2=201895&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h Fri Feb 21 16:30:43 2014
@@ -46,7 +46,8 @@ public:
         _terminalServerAware(true), _dynamicBaseEnabled(true),
         _createManifest(true), _embedManifest(false), _manifestId(1),
         _manifestLevel("'asInvoker'"), _manifestUiAccess("'false'"),
-        _isDll(false), _dosStub(llvm::makeArrayRef(DEFAULT_DOS_STUB)) {
+        _isDll(false), _requireSEH(false), _noSEH(false),
+        _dosStub(llvm::makeArrayRef(DEFAULT_DOS_STUB)) {
     setDeadStripping(true);
   }
 
@@ -194,6 +195,15 @@ public:
   void setIsDll(bool val) { _isDll = val; }
   bool isDll() const { return _isDll; }
 
+  void setSafeSEH(bool val) {
+    if (val)
+      _requireSEH = true;
+    else
+      _noSEH = true;
+  }
+  bool requireSEH() const { return _requireSEH; }
+  bool noSEH() const { return _noSEH; }
+
   StringRef getOutputSectionName(StringRef sectionName) const;
   bool addSectionRenaming(raw_ostream &diagnostics,
                           StringRef from, StringRef to);
@@ -288,6 +298,16 @@ private:
   std::string _manifestDependency;
   bool _isDll;
 
+  // True if /SAFESEH option is specified. Valid only for x86. If true, LLD will
+  // produce an image with SEH table. If any modules were not compatible with
+  // SEH, LLD will exit with an error.
+  bool _requireSEH;
+
+  // True if /SAFESEH:no option is specified. Valid only for x86. If true, LLD
+  // will not produce an image with SEH table even if all input object files are
+  // compatible with SEH.
+  bool _noSEH;
+
   // The set to store /nodefaultlib arguments.
   std::set<std::string> _noDefaultLibs;
 

Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=201895&r1=201894&r2=201895&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Fri Feb 21 16:30:43 2014
@@ -1047,6 +1047,7 @@ WinLinkDriver::parse(int argc, const cha
     DEFINE_BOOLEAN_FLAG(allowisolation, setAllowIsolation);
     DEFINE_BOOLEAN_FLAG(dynamicbase, setDynamicBaseEnabled);
     DEFINE_BOOLEAN_FLAG(tsaware, setTerminalServerAware);
+    DEFINE_BOOLEAN_FLAG(safeseh, setSafeSEH);
 
 #undef DEFINE_BOOLEAN_FLAG
 

Modified: lld/trunk/lib/Driver/WinLinkOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkOptions.td?rev=201895&r1=201894&r2=201895&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkOptions.td (original)
+++ lld/trunk/lib/Driver/WinLinkOptions.td Fri Feb 21 16:30:43 2014
@@ -78,6 +78,7 @@ defm tsaware  : B<"tsaware", "Create non
 defm allowisolation : B<"allowisolation", "Set NO_ISOLATION bit">;
 defm dynamicbase : B<"dynamicbase",
      "Disable address space layout randomization">;
+defm safeseh : B<"safeseh", "Produce an image with Safe Exception Handler">;
 
 def help : F<"help">;
 def help_q : Flag<["/?", "-?"], "">, Alias<help>;
@@ -113,4 +114,3 @@ def tlbout : QF<"tlbout">;
 def verbose_all : QF<"verbose">;
 
 defm wx : QB<"wx">;
-defm safeseh : QB<"safeseh">;

Modified: lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp?rev=201895&r1=201894&r2=201895&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp Fri Feb 21 16:30:43 2014
@@ -443,6 +443,22 @@ TEST_F(WinLinkParserTest, NoEntryError)
 }
 
 //
+// Tests for SEH.
+//
+
+TEST_F(WinLinkParserTest, SafeSEH) {
+  EXPECT_TRUE(parse("link.exe", "/safeseh", "a.obj", nullptr));
+  EXPECT_TRUE(_context.requireSEH());
+  EXPECT_FALSE(_context.noSEH());
+}
+
+TEST_F(WinLinkParserTest, NoSafeSEH) {
+  EXPECT_TRUE(parse("link.exe", "/safeseh:no", "a.obj", nullptr));
+  EXPECT_FALSE(_context.requireSEH());
+  EXPECT_TRUE(_context.noSEH());
+}
+
+//
 // Tests for boolean flags.
 //
 





More information about the llvm-commits mailing list