Mintsuki wrote:

Reproducer, on an x86_64 Linux host with LLVM 22.1.8 (main behaves the same
without this patch). Temporary object paths are shortened to `a.o`.

```
$ cat a.c
void _start(void) {}
$ clang --target=loongarch64-unknown-elf -fuse-ld=lld -nostdlib a.c -### 2>&1 | 
tail -1
 "/usr/bin/gcc" "-fuse-ld=lld" "-nostdlib" "-o" "a.out" "a.o"
$ clang --target=loongarch64-unknown-elf -fuse-ld=lld -nostdlib a.c
ld.lld: error: a.o is incompatible with elf_x86_64
collect2: error: ld returned 1 exit status
clang: error: linker (via gcc) command failed with exit code 1 (use -v to see 
invocation)
$ clang --target=loongarch64-unknown-elf -fsyntax-only -v a.c 2>&1 | sed -n 
'/<\.\.\.>/,/^End/p'
#include <...> search starts here:
 /usr/local/include
 /usr/lib/clang/22/include
 /usr/include
End of search list.
```

With this patch, the selected linker is run directly, whether it is LLD or GNU
ld, and only the bare-metal include directories are searched:

```
$ clang --target=loongarch64-unknown-elf -fuse-ld=lld -nostdlib a.c -### 2>&1 | 
tail -1
 "<prefix>/bin/ld.lld" "-Bstatic" "-m" "elf64loongarch" "-X" "-L[...]" "a.o" 
"-o" "a.out"
$ clang --target=loongarch64-unknown-elf -fuse-ld=lld -nostdlib a.c
$ llvm-readelf -h a.out | grep Machine
  Machine:                           LoongArch
$ clang --target=loongarch64-unknown-elf 
--ld-path=/usr/bin/loongarch64-linux-gnu-ld -nostdlib a.c -v 2>&1 | grep -- 
-Bstatic
 "/usr/bin/loongarch64-linux-gnu-ld" -Bstatic -m elf64loongarch -X -L[...] a.o 
-o a.out
$ clang --target=loongarch64-unknown-elf -fsyntax-only -v a.c 2>&1 | sed -n 
'/<\.\.\.>/,/^End/p'
#include <...> search starts here:
 <prefix>/lib/clang/24/include
End of search list.
```

@MaskRay @petrhosek @SixWeining


https://github.com/llvm/llvm-project/pull/223703
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to