[lld] r299728 - COFF: support the /appcontainer flag

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 6 16:07:53 PDT 2017


Author: compnerd
Date: Thu Apr  6 18:07:53 2017
New Revision: 299728

URL: http://llvm.org/viewvc/llvm-project?rev=299728&view=rev
Log:
COFF: support the /appcontainer flag

The /appcontainer flag indicates that the module may only be used inside
an application container (for isolation).  This has been supported by
link.exe since Windows 8.0.  It sets an additional bit in the PE DLL
Characteristics flag to indicate the behavioural change.

Modified:
    lld/trunk/COFF/Config.h
    lld/trunk/COFF/Driver.cpp
    lld/trunk/COFF/Options.td
    lld/trunk/COFF/Writer.cpp
    lld/trunk/test/COFF/hello32.test

Modified: lld/trunk/COFF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=299728&r1=299727&r2=299728&view=diff
==============================================================================
--- lld/trunk/COFF/Config.h (original)
+++ lld/trunk/COFF/Config.h Thu Apr  6 18:07:53 2017
@@ -160,6 +160,7 @@ struct Configuration {
   bool TerminalServerAware = true;
   bool LargeAddressAware = false;
   bool HighEntropyVA = false;
+  bool AppContainer = false;
 
   // This is for debugging.
   bool DebugPdb = false;

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=299728&r1=299727&r2=299728&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Thu Apr  6 18:07:53 2017
@@ -674,6 +674,9 @@ void LinkerDriver::link(ArrayRef<const c
     }
   }
 
+  if (Args.hasArg(OPT_appcontainer))
+    Config->AppContainer = true;
+
   // Handle /machine
   if (auto *Arg = Args.getLastArg(OPT_machine))
     Config->Machine = getMachineType(Arg->getValue());

Modified: lld/trunk/COFF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Options.td?rev=299728&r1=299727&r2=299728&view=diff
==============================================================================
--- lld/trunk/COFF/Options.td (original)
+++ lld/trunk/COFF/Options.td Thu Apr  6 18:07:53 2017
@@ -82,6 +82,8 @@ def force_unresolved : F<"force:unresolv
 
 defm allowbind: B<"allowbind", "Disable DLL binding">;
 defm allowisolation : B<"allowisolation", "Set NO_ISOLATION bit">;
+defm appcontainer : B<"appcontainer",
+                      "Image can only be run in an app container">;
 defm dynamicbase : B<"dynamicbase",
                      "Disable address space layout randomization">;
 defm fixed    : B<"fixed", "Enable base relocations">;

Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=299728&r1=299727&r2=299728&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Thu Apr  6 18:07:53 2017
@@ -602,6 +602,8 @@ template <typename PEHeaderTy> void Writ
   PE->SizeOfStackCommit = Config->StackCommit;
   PE->SizeOfHeapReserve = Config->HeapReserve;
   PE->SizeOfHeapCommit = Config->HeapCommit;
+  if (Config->AppContainer)
+    PE->DLLCharacteristics |= IMAGE_DLL_CHARACTERISTICS_APPCONTAINER;
   if (Config->DynamicBase)
     PE->DLLCharacteristics |= IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE;
   if (Config->HighEntropyVA)

Modified: lld/trunk/test/COFF/hello32.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/hello32.test?rev=299728&r1=299727&r2=299728&view=diff
==============================================================================
--- lld/trunk/test/COFF/hello32.test (original)
+++ lld/trunk/test/COFF/hello32.test Thu Apr  6 18:07:53 2017
@@ -1,6 +1,6 @@
 # RUN: yaml2obj < %p/Inputs/hello32.yaml > %t.obj
 # RUN: lld-link %t.obj %p/Inputs/std32.lib /subsystem:console \
-# RUN:   /entry:main at 0 /out:%t.exe
+# RUN:   /entry:main at 0 /out:%t.exe /appcontainer
 # RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=HEADER %s
 # RUN: llvm-readobj -coff-imports %t.exe | FileCheck -check-prefix=IMPORTS %s
 # RUN: llvm-readobj -coff-basereloc %t.exe | FileCheck -check-prefix=BASEREL %s
@@ -41,7 +41,8 @@ HEADER-NEXT:   MinorSubsystemVersion: 0
 HEADER-NEXT:   SizeOfImage: 16896
 HEADER-NEXT:   SizeOfHeaders: 512
 HEADER-NEXT:   Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI (0x3)
-HEADER-NEXT:   Characteristics [ (0x8140)
+HEADER-NEXT:   Characteristics [ (0x9140)
+HEADER-NEXT:     IMAGE_DLL_CHARACTERISTICS_APPCONTAINER (0x1000)
 HEADER-NEXT:     IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE (0x40)
 HEADER-NEXT:     IMAGE_DLL_CHARACTERISTICS_NX_COMPAT (0x100)
 HEADER-NEXT:     IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE (0x8000)




More information about the llvm-commits mailing list