[lld] r239864 - COFF: Add miscellaneous boolean flags.

Rui Ueyama ruiu at google.com
Tue Jun 16 16:13:00 PDT 2015


Author: ruiu
Date: Tue Jun 16 18:13:00 2015
New Revision: 239864

URL: http://llvm.org/viewvc/llvm-project?rev=239864&view=rev
Log:
COFF: Add miscellaneous boolean flags.

Added:
    lld/trunk/test/COFF/options.test
Modified:
    lld/trunk/COFF/Config.h
    lld/trunk/COFF/Driver.cpp
    lld/trunk/COFF/Writer.cpp

Modified: lld/trunk/COFF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=239864&r1=239863&r2=239864&view=diff
==============================================================================
--- lld/trunk/COFF/Config.h (original)
+++ lld/trunk/COFF/Config.h Tue Jun 16 18:13:00 2015
@@ -51,6 +51,12 @@ public:
   uint32_t MinorImageVersion = 0;
   uint32_t MajorOSVersion = 6;
   uint32_t MinorOSVersion = 0;
+  bool DynamicBase = true;
+  bool HighEntropyVA = true;
+  bool AllowBind = true;
+  bool NxCompat = true;
+  bool AllowIsolation = true;
+  bool TerminalServerAware = true;
 };
 
 extern Configuration *Config;

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=239864&r1=239863&r2=239864&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Tue Jun 16 18:13:00 2015
@@ -226,8 +226,14 @@ bool LinkerDriver::link(int Argc, const
     Config->EntryName = Arg->getValue();
 
   // Handle /fixed
-  if (Args->hasArg(OPT_fixed))
+  if (Args->hasArg(OPT_fixed)) {
+    if (Args->hasArg(OPT_dynamicbase)) {
+      llvm::errs() << "/fixed must not be specified with /dynamicbase\n";
+      return false;
+    }
     Config->Relocatable = false;
+    Config->DynamicBase = false;
+  }
 
   // Handle /machine
   auto MTOrErr = getMachineType(Args.get());
@@ -318,6 +324,14 @@ bool LinkerDriver::link(int Argc, const
     return false;
   }
 
+  // Handle miscellaneous boolean flags.
+  if (Args->hasArg(OPT_allowbind_no))      Config->AllowBind = false;
+  if (Args->hasArg(OPT_allowisolation_no)) Config->AllowIsolation = false;
+  if (Args->hasArg(OPT_dynamicbase_no))    Config->DynamicBase = false;
+  if (Args->hasArg(OPT_highentropyva_no))  Config->HighEntropyVA = false;
+  if (Args->hasArg(OPT_nxcompat_no))       Config->NxCompat = false;
+  if (Args->hasArg(OPT_tsaware_no))        Config->TerminalServerAware = false;
+
   // Create a list of input files. Files can be given as arguments
   // for /defaultlib option.
   std::vector<StringRef> InputPaths;

Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=239864&r1=239863&r2=239864&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Tue Jun 16 18:13:00 2015
@@ -270,8 +270,18 @@ void Writer::writeHeader() {
   PE->SizeOfStackCommit = Config->StackCommit;
   PE->SizeOfHeapReserve = Config->HeapReserve;
   PE->SizeOfHeapCommit = Config->HeapCommit;
-  if (Config->Relocatable)
-    PE->DLLCharacteristics = IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE;
+  if (Config->DynamicBase)
+    PE->DLLCharacteristics |= IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE;
+  if (Config->HighEntropyVA)
+    PE->DLLCharacteristics |= IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA;
+  if (!Config->AllowBind)
+    PE->DLLCharacteristics |= IMAGE_DLL_CHARACTERISTICS_NO_BIND;
+  if (Config->NxCompat)
+    PE->DLLCharacteristics |= IMAGE_DLL_CHARACTERISTICS_NX_COMPAT;
+  if (!Config->AllowIsolation)
+    PE->DLLCharacteristics |= IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION;
+  if (Config->TerminalServerAware)
+    PE->DLLCharacteristics |= IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE;
   PE->NumberOfRvaAndSize = NumberfOfDataDirectory;
   if (OutputSection *Text = findSection(".text")) {
     PE->BaseOfCode = Text->getRVA();

Added: lld/trunk/test/COFF/options.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/options.test?rev=239864&view=auto
==============================================================================
--- lld/trunk/test/COFF/options.test (added)
+++ lld/trunk/test/COFF/options.test Tue Jun 16 18:13:00 2015
@@ -0,0 +1,51 @@
+# RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
+
+# RUN: lld -flavor link /out:%t.exe %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=BIND %s
+# RUN: lld -flavor link /allowbind /out:%t.exe %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=BIND %s
+BIND-NOT: IMAGE_DLL_CHARACTERISTICS_NO_BIND
+
+# RUN: lld -flavor link /allowbind:no /out:%t.exe %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NOBIND %s
+NOBIND: IMAGE_DLL_CHARACTERISTICS_NO_BIND
+
+# RUN: lld -flavor link /out:%t.exe %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=ISO %s
+# RUN: lld -flavor link /allowisolation /out:%t.exe %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=ISO %s
+ISO-NOT: IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION
+
+# RUN: lld -flavor link /allowisolation:no /out:%t.exe %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NOISO %s
+NOISO: IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION
+
+# RUN: lld -flavor link /out:%t.exe %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=ENT %s
+# RUN: lld -flavor link /highentropyva /out:%t.exe %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=ENT %s
+ENT: IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA
+
+# RUN: lld -flavor link /highentropyva:no %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NOENT %s
+NOENT-NOT: IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA
+
+# RUN: lld -flavor link %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NXCOMPAT %s
+# RUN: lld -flavor link /nxcompat %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NXCOMPAT %s
+NXCOMPAT: IMAGE_DLL_CHARACTERISTICS_NX_COMPAT
+
+# RUN: lld -flavor link /nxcompat:no %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NONXCOMPAT %s
+NONXCOMPAT-NOT: IMAGE_DLL_CHARACTERISTICS_NX_COMPAT
+
+# RUN: lld -flavor link %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=TSAWARE %s
+# RUN: lld -flavor link /tsaware %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=TSAWARE %s
+TSAWARE: IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE
+
+# RUN: lld -flavor link /tsaware:no %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NOTSAWARE %s
+NOTSAWARE-NOT: IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE





More information about the llvm-commits mailing list