wrappers: For UWP, pass the default -lwindowsapp after user specified options

This matches how the compiler driver normally includes default
linked libraries; the user provided -l flags are passed first,
followed by the compiler's default ones. That allows a user
specified library to override the default ones.

This makes sure that if a user provides -lwindowsappcompat, it
gets linked before -lwindowsapp, which makes a difference for
symbols that are provided in both (such as e.g. LoadLibraryW).
This commit is contained in:
Martin Storsjö committed 2022-10-01 13:28:02 +03:00
1 parent e76e935c7d
commit 56fec2622f
2 files changed
+25 -9

No files matched your search

+14 -6
View File
@@ -50,7 +50,7 @@ int _tmain(int argc, TCHAR* argv[]) {
}
}
int max_arg = argc + 20;
int max_arg = argc + 22;
const TCHAR **exec_argv = malloc((max_arg + 1) * sizeof(*exec_argv));
int arg = 0;
if (getenv("CCACHE"))
@@ -84,11 +84,6 @@ int _tmain(int argc, TCHAR* argv[]) {
exec_argv[arg++] = _T("-DWINAPI_FAMILY=WINAPI_FAMILY_APP");
// the Windows Store API only supports Windows Unicode (some rare ANSI ones are available)
exec_argv[arg++] = _T("-DUNICODE");
// add the minimum runtime to use for UWP targets
exec_argv[arg++] = _T("-Wl,-lwindowsapp");
// This still requires that the toolchain (in particular, libc++.a) has
// been built targeting UCRT originally.
exec_argv[arg++] = _T("-Wl,-lucrtapp");
// force the user of Universal C Runtime
exec_argv[arg++] = _T("-D_UCRT");
}
@@ -104,6 +99,19 @@ int _tmain(int argc, TCHAR* argv[]) {
for (int i = 1; i < argc; i++)
exec_argv[arg++] = argv[i];
if (target_os && !_tcscmp(target_os, _T("mingw32uwp"))) {
// Default linker flags; passed after any user specified -l options,
// to let the user specified libraries take precedence over these.
exec_argv[arg++] = _T("--start-no-unused-arguments");
// add the minimum runtime to use for UWP targets
exec_argv[arg++] = _T("-Wl,-lwindowsapp");
// This still requires that the toolchain (in particular, libc++.a) has
// been built targeting UCRT originally.
exec_argv[arg++] = _T("-Wl,-lucrtapp");
exec_argv[arg++] = _T("--end-no-unused-arguments");
}
exec_argv[arg] = NULL;
if (arg >= max_arg) {
fprintf(stderr, "Too many options added\n");