[PATCH] D63248: [LLD] [COFF] Allow setting subsystem versions while inferring the subsystem type implicitly

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 13 03:46:24 PDT 2019


mstorsjo created this revision.
mstorsjo added reviewers: ruiu, rnk.
Herald added a project: LLVM.
mstorsjo retitled this revision from "[COFF] Allow setting subsystem versions while inferring the subsystem type implicitly" to "[LLD] [COFF] Allow setting subsystem versions while inferring the subsystem type implicitly".

Lead-up to a fix for PR42218.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D63248

Files:
  COFF/DriverUtils.cpp
  test/COFF/subsystem-inference.test
  test/COFF/subsystem.test


Index: test/COFF/subsystem.test
===================================================================
--- test/COFF/subsystem.test
+++ test/COFF/subsystem.test
@@ -17,3 +17,12 @@
 CHECK2: MajorSubsystemVersion: 8
 CHECK2: MinorSubsystemVersion: 9
 CHECK2: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_GUI
+
+# RUN: lld-link /entry:main /out:%t.exe /subsystem:default,8.9 \
+# RUN:   %p/Inputs/ret42.obj
+# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=CHECK3 %s
+
+CHECK3: MajorOperatingSystemVersion: 8
+CHECK3: MinorOperatingSystemVersion: 9
+CHECK3: MajorSubsystemVersion: 8
+CHECK3: MinorSubsystemVersion: 9
Index: test/COFF/subsystem-inference.test
===================================================================
--- test/COFF/subsystem-inference.test
+++ test/COFF/subsystem-inference.test
@@ -1,6 +1,8 @@
 # RUN: sed -e s/ENTRYNAME/main/ %s | yaml2obj > %t.obj
 # RUN: lld-link /out:%t.exe %t.obj
 # RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=MAIN %s
+# RUN: lld-link /out:%t.exe %t.obj /subsystem:default,6.0
+# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=MAIN %s
 
 # RUN: sed s/ENTRYNAME/wmain/ %s | yaml2obj > %t.obj
 # RUN: lld-link /out:%t.exe %t.obj
@@ -9,6 +11,8 @@
 # RUN: sed s/ENTRYNAME/WinMain/ %s | yaml2obj > %t.obj
 # RUN: lld-link /out:%t.exe %t.obj
 # RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=WINMAIN %s
+# RUN: lld-link /out:%t.exe %t.obj /subsystem:default,6.0
+# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=WINMAIN %s
 
 # RUN: sed s/ENTRYNAME/wWinMain/ %s | yaml2obj > %t.obj
 # RUN: lld-link /out:%t.exe %t.obj
Index: COFF/DriverUtils.cpp
===================================================================
--- COFF/DriverUtils.cpp
+++ COFF/DriverUtils.cpp
@@ -114,9 +114,11 @@
                     uint32_t *Minor) {
   StringRef SysStr, Ver;
   std::tie(SysStr, Ver) = Arg.split(',');
-  *Sys = StringSwitch<WindowsSubsystem>(SysStr.lower())
+  std::string SysStrLower = SysStr.lower();
+  *Sys = StringSwitch<WindowsSubsystem>(SysStrLower)
     .Case("boot_application", IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION)
     .Case("console", IMAGE_SUBSYSTEM_WINDOWS_CUI)
+    .Case("default", IMAGE_SUBSYSTEM_UNKNOWN)
     .Case("efi_application", IMAGE_SUBSYSTEM_EFI_APPLICATION)
     .Case("efi_boot_service_driver", IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER)
     .Case("efi_rom", IMAGE_SUBSYSTEM_EFI_ROM)
@@ -125,7 +127,7 @@
     .Case("posix", IMAGE_SUBSYSTEM_POSIX_CUI)
     .Case("windows", IMAGE_SUBSYSTEM_WINDOWS_GUI)
     .Default(IMAGE_SUBSYSTEM_UNKNOWN);
-  if (*Sys == IMAGE_SUBSYSTEM_UNKNOWN)
+  if (*Sys == IMAGE_SUBSYSTEM_UNKNOWN && SysStrLower != "default")
     fatal("unknown subsystem: " + SysStr);
   if (!Ver.empty())
     parseVersion(Ver, Major, Minor);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63248.204476.patch
Type: text/x-patch
Size: 2805 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190613/2701a334/attachment.bin>


More information about the llvm-commits mailing list