Index: lld/MinGW/Driver.cpp =================================================================== --- lld/MinGW/Driver.cpp +++ lld/MinGW/Driver.cpp @@ -219,10 +219,19 @@ StringRef majSubSysVer = args.getLastArgValue(OPT_major_subsystem_version, "6"); StringRef minSubSysVer = args.getLastArgValue(OPT_minor_subsystem_version, "0"); StringRef subSys = args.getLastArgValue(OPT_subs, "default"); + StringRef subSysName, subSysVer; + std::tie(subSysName, subSysVer) = subSys.split(':'); add("-osversion:" + majOSVer + "." + minOSVer); - add("-subsystem:" + subSys + "," + majSubSysVer + "." + minSubSysVer); - } else if (auto *a = args.getLastArg(OPT_subs)) { - add("-subsystem:" + StringRef(a->getValue())); + if (subSysVer.empty()) + add("-subsystem:" + subSysName + "," + majSubSysVer + "." + minSubSysVer); + else // The version from --subsystem takes precedence, if both are specified + add("-subsystem:" + subSysName + "," + subSysVer); + } else if (args.hasArg(OPT_subs)) { + StringRef subSys = args.getLastArgValue(OPT_subs, "default"); + StringRef subSysName, subSysVer; + std::tie(subSysName, subSysVer) = subSys.split(':'); + StringRef sep = subSysVer.empty() ? "" : ","; + add("-subsystem:" + subSysName + sep + subSysVer); } if (auto *a = args.getLastArg(OPT_out_implib)) Index: lld/test/MinGW/driver.test =================================================================== --- lld/test/MinGW/driver.test +++ lld/test/MinGW/driver.test @@ -78,6 +78,9 @@ SUBSYSTEM_DEFAULT_MINOR: -subsystem:default,7.0 RUN: ld.lld -### foo.o -m i386pep --subsystem windows --major-subsystem-version 7 --minor-subsystem-version 8 | FileCheck -check-prefix=SUBSYSTEM_WINDOWS %s +RUN: ld.lld -### foo.o -m i386pep --subsystem windows:7.8 | FileCheck -check-prefix=SUBSYSTEM_WINDOWS %s +RUN: ld.lld -### foo.o -m i386pep --subsystem windows:7.8 --major-subsystem-version 2 --minor-subsystem-version 3 | FileCheck -check-prefix=SUBSYSTEM_WINDOWS %s +RUN: ld.lld -### foo.o -m i386pep --subsystem windows:7.8 | FileCheck -check-prefix=SUBSYSTEM_WINDOWS %s SUBSYSTEM_WINDOWS: -subsystem:windows,7.8 RUN: ld.lld -### foo.o -m i386pep -stack 4194304,8192 | FileCheck -check-prefix=STACK %s