This is an archive of the discontinued LLVM Phabricator instance.

Fixes majorOSVersion and majorSubsystemVersion being set into too large values
Needs ReviewPublic

Authored by KOLANICH on Oct 19 2021, 1:05 PM.

Details

Summary

https://bugs.llvm.org/show_bug.cgi?id=52227

Added support of Windows XP for the files generated by Clang and lld. The too high values in these fields cause inability to run the programs compiled with Clang (using MinGW-w64 free and open source runtime) on Windows XP and ReactOS. I have implemented the patch intended to fix that. This patch sets the version to 4.0 - the one used in MinGW shared libs. I haven't tested this patch myself, because compiling llvm is time- and resource-consuming proccess, but I have implemented a stopgap tool in python for patching PE headers, https://github.com/KOLANICH-tools/PEHeaderFixer.py , and used it to patch the binaries generated by LLD 14 + CLang 14. The resulting binaries have worked on XP and ReactOS.

Diff Detail

Event Timeline

KOLANICH created this revision.Oct 19 2021, 1:05 PM
KOLANICH requested review of this revision.Oct 19 2021, 1:05 PM

Overall, many things assume Windows 7 these days, so I don't think it's an entirely unreasonable default - you can always set a lower target if you want to, by passing e.g. --major-os-version 4 to the linker. I don't think the default of the main COFF linker should be lowered.

But I guess one could argue whether the mingw frontend should set the default target lower - then one doesn't have to change the main default in lld/COFF/Config.h, but tweak the logic in lld/MinGW/Driver.cpp. It currently has to keep a hardcoded default version for some cases, but defaults to the COFF linker's default in some cases. We could make it always pass a version number.

What do @mati865 or @jeremyd2019 think about this?

I never had to dig into subsystem versions and what do the mean but looking at subsystem docs 4.0 stands for kernel mode drivers which looks wrong to me. They also specify 5.01 as 32-bit, 5.02 as 64-bit and 6.0 as being either 32-bit or 64-bit.

I'm not sure if major OS version actually means anything but I agree 6.0 which stands for long gone Vista is reasonable. I would not mind changing it however.

rnk added a comment.Oct 20 2021, 10:47 AM

I don't think the default of the main COFF linker should be lowered.

But I guess one could argue whether the mingw frontend should set the default target lower - then one doesn't have to change the main default in lld/COFF/Config.h, but tweak the logic in lld/MinGW/Driver.cpp. It currently has to keep a hardcoded default version for some cases, but defaults to the COFF linker's default in some cases. We could make it always pass a version number.

What do @mati865 or @jeremyd2019 think about this?

I agree, I think LLD has the right default. Both drivers have flags if you need to pick a different OS or subsystem version. If we want to change the mingw default to be lower, that seems OK to me.

I also think 6.0 is fine for a default.

KOLANICH updated this revision to Diff 382534.Oct 26 2021, 11:54 PM

Replaced 6 to 4 in more places (tests), as a try to resolve the issues with the tests failing.

you can always set a lower target if you want to, by passing e.g. --major-os-version 4 to the linker.

Thanks for the info, I'll incorporate that in my CMake toolchain fikes.

About 6.0 being reasanoble or not. I think that we should keep it as low as possible, otherwise it would create issues for the users of of old OSes out of thin air. Defaults rule the world, so if we set the version too high the majority of software would become incompatible to XP even if it is de-facto compatible. I think that instead of lowering the version on per-target-basis it should be increased on per-target-basis, when a linker is completely sure that the runtime is incompatible to the OS. It can do it by examining the fields within the libs it links an executable to, including C runtime libs.

KOLANICH updated this revision to Diff 435930.Jun 10 2022, 8:39 AM

Some tests fixes.

Herald added a project: Restricted Project. · View Herald TranscriptJun 10 2022, 8:39 AM
Herald added a subscriber: StephenFan. · View Herald Transcript