Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug build of Clang built with MinGW on Windows 10 cannot be run

I have built Clang with MinGW on Windows with the target triple x86_64-w64-windows-gnu. The executables clang.exe and clang++.exe work as expected if I build them in release mode (they compile programs without error), however when building in debug mode I cannot run them and get this error - "This app can't run on your PC". Other executables from the same build such as clang-check.exe do not display this error and run correctly.

It seems as though this could be an issue with the file size as both clang.exe and clang++.exe are > 2GB in size whereas the other executables are smaller but I was under the impression that the file size limit on 64-bit Windows is 4GB.

Has anyone else run into a similar issue? If the file size is the problem, is it possible to get LLVM to put the debug symbols in a separate file to reduce the size of the executable?

EDIT: I've tried to reduce the executable size by dumping the debug symbols to a separate file using the -gsplit-dwarf flag when building LLVM but it doesn't have any effect.

like image 329
ed95 Avatar asked Sep 08 '17 15:09

ed95


1 Answers

Yes, file size is a pretty good hint of having this problem. The IMAGE_OPTIONAL_HEADER64.SizeOfImage field is a DWORD, suggesting a 4 GB maximum size. But there is another limit that kicks in first, the OS loader maps the entire .exe or .dll file into memory with a memory-mapped file. The view on the MMF can never be larger than 2 GB. This is a hard technical limitation, it even applies to x64. More about this problem in this post.

Debug info is no doubt the reason why the image file blows up so badly. For comparison, the clang build that is included with VS2017 needs 27MB for the front end and 32MB for the x64 back end. Why -gsplit-dwarf cannot solve your problem is visible from this project page:

Fission is implemented in GCC 4.7, and requires support from recent versions of objcopy and the gold linker.

MinGW cannot provide you with the gold linker. They made no attempt at porting it since it can only generate ELF images. Cold hard facts, as long as you depend on MinGW then you're up a creek without a good paddle.

Something drastic is needed. I'll hesitantly mention Cygwin. Do consider another compiler, like using Clang to build Clang :) Or MSVC++. The community edition is a free download. Also be sure to take a look at the Clang port, they did a lot of work to make it ABI compatible.

like image 147
Hans Passant Avatar answered Nov 14 '22 23:11

Hans Passant