[clang] [RFC] [clang][Toolchain] Treat "pc"/"unknown" vendor interchangeable (PR #97802)

Azat Khuzhin via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 5 11:15:22 PDT 2024


azat wrote:

>How is Rust built? If the system compiler-rt libraries are installed to /usr/lib/llvm-18/lib/clang/18/lib/x86_64-pc-linux-gnu, which means that LLVM_DEFAULT_TARGET_TRIPLE=x86_64-pc-linux-gnu, the Rust build should also use x86_64-pc-linux-gnu.

The problem is not only with Rust, it is any invocation with non-default `--target` (`--target` != `LLVM_DEFAULT_TARGET_TRIPLE`), and I was fixing a C++ issue not a Rust issue, but I guess it will be covered

Here is an example of a problem (assuming `LLVM_DEFAULT_TARGET_TRIPLE` is `x86_64-pc-linux-gnu` (in packages from apt.llvm.org)):

- without explicit `-target` - everything is correct, it uses `/usr/lib/llvm-18/lib/clang/18/lib/x86_64-pc-linux-gnu/libclang_rt.asan.a`

```
$ docker run --rm -it clickhouse/binary-builder:9e5aa3a43749 clang-18 -### -xc - -fsanitize=address
Ubuntu clang version 18.1.8 (++20240615103753+3b5b5c1ec4a3-1~exp1~20240615223858.136)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
 "/usr/lib/llvm-18/bin/clang" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-obj" "-mrelax-all" "-dumpdir" "a-" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "-" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/workdir" "-fcoverage-compilation-dir=/workdir" "-resource-dir" "/usr/lib/llvm-18/lib/clang/18" "-internal-isystem" "/usr/lib/llvm-18/lib/clang/18/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-ferror-limit" "19" "-fmessage-length=295" "-fsanitize=address" "-fsanitize-system-ignorelist=/usr/lib/llvm-18/lib/clang/18/share/asan_ignorelist.txt" "-fno-sanitize-memory-param-retval" "-fsanitize-address-use-after-scope" "-fsanitize-address-globals-dead-stripping" "-fno-assume-sane-operator-new" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf" "-fcolor-diagnostics" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "/tmp/--ed21dd.o" "-x" "c" "-"
 "/usr/bin/ld" "-z" "relro" "--hash-style=gnu" "--build-id" "--eh-frame-hdr" "-m" "elf_x86_64" "-pie" "-dynamic-linker" "/lib64/ld-linux-x86-64.so.2" "-o" "a.out" "/lib/x86_64-linux-gnu/Scrt1.o" "/lib/x86_64-linux-gnu/crti.o" "/usr/bin/../lib/gcc/x86_64-linux-gnu/11/crtbeginS.o" "-L/usr/lib/llvm-18/lib/clang/18/lib/x86_64-pc-linux-gnu" "-L/usr/bin/../lib/gcc/x86_64-linux-gnu/11" "-L/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../lib64" "-L/lib/x86_64-linux-gnu" "-L/lib/../lib64" "-L/usr/lib/x86_64-linux-gnu" "-L/usr/lib/../lib64" "-L/lib" "-L/usr/lib" "--whole-archive" "/usr/lib/llvm-18/lib/clang/18/lib/x86_64-pc-linux-gnu/libclang_rt.asan_static.a" "--no-whole-archive" "--whole-archive" "/usr/lib/llvm-18/lib/clang/18/lib/x86_64-pc-linux-gnu/libclang_rt.asan.a" "--no-whole-archive" "--dynamic-list=/usr/lib/llvm-18/lib/clang/18/lib/x86_64-pc-linux-gnu/libclang_rt.asan.a.syms" "/tmp/--ed21dd.o" "--no-as-needed" "-lpthread" "-lrt" "-lm" "-ldl" "-lresolv" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "/usr/bin/../lib/gcc/x86_64-linux-gnu/11/crtendS.o" "/lib/x86_64-linux-gnu/crtn.o"
```

- but with explicit `-target=x86_64-unknown-linux-gnu`, it try to use `/usr/lib/llvm-18/lib/clang/18/lib/linux/libclang_rt.asan-x86_64.a` (because there is no such file `/usr/lib/llvm-18/lib/clang/18/lib/x86_64-unknown-linux-gnu/libclang_rt.asan.a`), which obviously does not exists, and it will fail eventually

```
$ docker run --rm -it clickhouse/binary-builder:9e5aa3a43749 clang-18 -target x86_64-unknown-linux-gnu -### -xc - -fsanitize=address
Ubuntu clang version 18.1.8 (++20240615103753+3b5b5c1ec4a3-1~exp1~20240615223858.136)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
 "/usr/lib/llvm-18/bin/clang" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-mrelax-all" "-dumpdir" "a-" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "-" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/workdir" "-fcoverage-compilation-dir=/workdir" "-resource-dir" "/usr/lib/llvm-18/lib/clang/18" "-internal-isystem" "/usr/lib/llvm-18/lib/clang/18/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-ferror-limit" "19" "-fmessage-length=295" "-fsanitize=address" "-fsanitize-system-ignorelist=/usr/lib/llvm-18/lib/clang/18/share/asan_ignorelist.txt" "-fno-sanitize-memory-param-retval" "-fsanitize-address-use-after-scope" "-fsanitize-address-globals-dead-stripping" "-fno-assume-sane-operator-new" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf" "-fcolor-diagnostics" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "/tmp/--85ef6b.o" "-x" "c" "-"
 "/usr/bin/ld" "-z" "relro" "--hash-style=gnu" "--build-id" "--eh-frame-hdr" "-m" "elf_x86_64" "-pie" "-dynamic-linker" "/lib64/ld-linux-x86-64.so.2" "-o" "a.out" "/lib/x86_64-linux-gnu/Scrt1.o" "/lib/x86_64-linux-gnu/crti.o" "/usr/bin/../lib/gcc/x86_64-linux-gnu/11/crtbeginS.o" "-L/usr/bin/../lib/gcc/x86_64-linux-gnu/11" "-L/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../lib64" "-L/lib/x86_64-linux-gnu" "-L/lib/../lib64" "-L/usr/lib/x86_64-linux-gnu" "-L/usr/lib/../lib64" "-L/lib" "-L/usr/lib" "--whole-archive" "/usr/lib/llvm-18/lib/clang/18/lib/linux/libclang_rt.asan_static-x86_64.a" "--no-whole-archive" "--whole-archive" "/usr/lib/llvm-18/lib/clang/18/lib/linux/libclang_rt.asan-x86_64.a" "--no-whole-archive" "--export-dynamic" "/tmp/--85ef6b.o" "--no-as-needed" "-lpthread" "-lrt" "-lm" "-ldl" "-lresolv" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "/usr/bin/../lib/gcc/x86_64-linux-gnu/11/crtendS.o" "/lib/x86_64-linux-gnu/crtn.o"
```

Maybe you have better/proper idea on how this should be addressed?

https://github.com/llvm/llvm-project/pull/97802


More information about the cfe-commits mailing list