llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.83k stars 11.01k forks source link

Clang on windows with target i386-none-elf error: program is not executable. #59587

Open SzateX opened 1 year ago

SzateX commented 1 year ago

Hi! I got and issue while try to use clang on my home-brew OS development.

When I try to compile this empty file (It is a minimum thing to reproduce, because I'm trying to compose CMake file):

int kmain(){
    while(1);
    return 0;
}

I got this result:

$ clang .\kernel.c -target i386-none-elf -march=i386 -ffreestanding -v
clang version 15.0.6
Target: i386-none-unknown-elf
Thread model: posix
InstalledDir: E:\LLVM\bin    
 "E:\\LLVM\\bin\\clang.exe" -cc1 -triple i386-none-unknown-elf -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name kernel.c -mrelocation-mode
l static -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -ffreestanding -target-cpu i386 -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v "-fcoverage-compilation-dir=E:
\\OptimaX" -resource-dir "E:\\LLVM\\lib\\clang\\15.0.6" "-fdebug-compilation-dir=E:\\OptimaX" -ferror-limit 19 -fmessage-length=232 -fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig -o "C:\\Users\\jaksz\\AppData\\Local\\Temp\\kerne
l-02f466.o" -x c ".\\kernel.c"
clang -cc1 version 15.0.6 based upon LLVM 15.0.6 default target x86_64-pc-windows-msvc
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 E:\LLVM\lib\clang\15.0.6\include
End of search list.
 "gcc" -m32 -o a.out "C:\\Users\\jaksz\\AppData\\Local\\Temp\\kernel-02f466.o"
clang: error: unable to execute command: program not executable
clang: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)

I have no idea why it try to search in Linux-like directories, and try to issue GCC.

I will be very glad for your quick response :)

llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-driver

alvinhochun commented 1 year ago

Try adding -fuse-ld=lld to the clang command line for linking.

SzateX commented 1 year ago

Try adding -fuse-ld=lld to the clang command line for linking.

Still the same problem. I have tried it also on Apline Docker Image, and it doesn't work also until I install gcc.

clang .\kernel.c -fuse-ld=lld -target i386-pc-none-elf -march=i386 -ffreestanding -nostdlib -v
clang version 15.0.6
Target: i386-pc-none-elf
Thread model: posix
InstalledDir: E:\LLVM\bin
 "E:\\LLVM\\bin\\clang.exe" -cc1 -triple i386-pc-none-elf -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name kernel.c -mrelocation-model sta
tic -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -ffreestanding -target-cpu i386 -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v "-fcoverage-compilation-dir=E:\\Opt
imaX" -resource-dir "E:\\LLVM\\lib\\clang\\15.0.6" "-fdebug-compilation-dir=E:\\OptimaX" -ferror-limit 19 -fmessage-length=232 -fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig -o "C:\\Users\\jaksz\\AppData\\Local\\Temp\\kernel-b25
365.o" -x c ".\\kernel.c"
clang -cc1 version 15.0.6 based upon LLVM 15.0.6 default target x86_64-pc-windows-msvc
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 E:\LLVM\lib\clang\15.0.6\include
End of search list.
 "gcc" -fuse-ld=lld -nostdlib -m32 -o a.out "C:\\Users\\jaksz\\AppData\\Local\\Temp\\kernel-b25365.o"
clang: error: unable to execute command: program not executable
clang: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)