[LLD] [MinGW] Support setting the subsystem version via the subsystem argument

If a version is specified both with --{major,minor}-subsystem-version and
with --subsystem <name>:<version>, the one specified last (that actually
sets a version) takes precedance in GNU ld; thus doing the same here.

Differential Revision: https://reviews.llvm.org/D88804
This commit is contained in:
Martin Storsjö 2020-10-04 17:59:33 +03:00
parent bc8f3b424c
commit 61e2f9fa2e
2 changed files with 40 additions and 6 deletions

View File

@ -216,13 +216,41 @@ bool mingw::link(ArrayRef<const char *> argsArr, bool canExitEarly,
OPT_major_subsystem_version, OPT_minor_subsystem_version)) {
StringRef majOSVer = args.getLastArgValue(OPT_major_os_version, "6");
StringRef minOSVer = args.getLastArgValue(OPT_minor_os_version, "0");
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 majSubSysVer = "6";
StringRef minSubSysVer = "0";
StringRef subSysName = "default";
StringRef subSysVer;
// Iterate over --{major,minor}-subsystem-version and --subsystem, and pick
// the version number components from the last one of them that specifies
// a version.
for (auto *a : args.filtered(OPT_major_subsystem_version,
OPT_minor_subsystem_version, OPT_subs)) {
switch (a->getOption().getID()) {
case OPT_major_subsystem_version:
majSubSysVer = a->getValue();
break;
case OPT_minor_subsystem_version:
minSubSysVer = a->getValue();
break;
case OPT_subs:
std::tie(subSysName, subSysVer) = StringRef(a->getValue()).split(':');
if (!subSysVer.empty()) {
if (subSysVer.contains('.'))
std::tie(majSubSysVer, minSubSysVer) = subSysVer.split('.');
else
majSubSysVer = subSysVer;
}
break;
}
}
add("-osversion:" + majOSVer + "." + minOSVer);
add("-subsystem:" + subSys + "," + majSubSysVer + "." + minSubSysVer);
} else if (auto *a = args.getLastArg(OPT_subs)) {
add("-subsystem:" + StringRef(a->getValue()));
add("-subsystem:" + subSysName + "," + majSubSysVer + "." + minSubSysVer);
} 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))

View File

@ -78,6 +78,12 @@ RUN: ld.lld -### foo.o -m i386pep --major-subsystem-version 7 | FileCheck -check
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 --major-subsystem-version 7 --minor-subsystem-version 8 --subsystem windows | 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:2.3 --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 --major-subsystem-version 2 --minor-subsystem-version 3 --subsystem windows:7.8 | FileCheck -check-prefix=SUBSYSTEM_WINDOWS %s
RUN: ld.lld -### foo.o -m i386pep --major-subsystem-version 2 --minor-subsystem-version 8 --subsystem windows:7 | 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