-->

Unable to run windows binary compiled with clang/l

2019-08-10 01:50发布

问题:

I have downloaded and installed clang on windows 10 from http://releases.llvm.org/download.html and mingw from https://sourceforge.net/projects/mingw-w64/

I am trying to compile a very basic C program using clang/lld/mingw:

int main(int argc, char* argv[argc + 1])
{
  return 0;
}

To compile I invoke:

clang.exe -target x86_64-windows-gnu -fuse-ld=lld.exe -g -gcodeview -Wl,/debug,/pdb:example.pdb example.c -o example.exe

This creates an exe which faults on startup in mainCRTStartup (__security_init_cookie to be precise).

However, running with default ld from binutils is successful:

clang.exe -target x86_64-windows-gnu example.c -o example.exe

Please note that I wish to use mingw headers, not msvc.

In total I tried:

  • x86_64-8.1.0-posix-seh-rt_v6-rev0
  • x86_64-7.3.0-posix-seh-rt_v5-rev0
  • x86_64-8.1.0-win32-seh-rt_v6-rev0
  • x86_64-8.1.0-win32-sjlj-rt_v6-rev0

without any luck producing a functional program.

So I am wondering, is there something obvious I am doing wrong here?

EDIT: I have also tried with msys2 to no avail. Specifically:

pacman -S mingw-w64-x86_64-clang mingw-w64-x86_64-lld

回答1:

According to https://bugs.llvm.org/show_bug.cgi?id=40568

Linking against mingw import libraries from a normal mingw installation is a new feature, first present in LLD 8.

Unless wanting to compile a pre-release version of lld, have to wait for binary release of llvm 8.0.0. This will hopefully be sometime in March.