KyleMayes / clang-sys

Rust bindings for libclang.
Apache License 2.0
128 stars 65 forks source link

Support for cray-clang #143

Closed jedbrown closed 1 year ago

jedbrown commented 1 year ago

I'm working on adding rsmpi support for Cray environments and have reduced the problem to this with clang-sys. Cray compilers are clang-based with some custom optimization passes and more static than upstream defaults.

$ cc --version
Cray clang version 14.0.1  (3a8780657c742829e80f36338fb6ec6578642bb7)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/cray/pe/cce/14.0.1/cce-clang/x86_64/share/../bin
$ cargo build
   Compiling glob v0.3.0
   Compiling libc v0.2.126
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "/tmp/rustc7Esbmp/symbols.o" "/global/u1/j/jedbrow/clang-sys/target/debug/build/libc-7bee6741a0fd2270/build_script_build-7bee6741a0fd2270.build_script_build.753a8059-cgu
.0.rcgu.o" "/global/u1/j/jedbrow/clang-sys/target/debug/build/libc-7bee6741a0fd2270/build_script_build-7bee6741a0fd2270.build_script_build.753a8059-cgu.1.rcgu.o" "/global/u1/j/jedbrow/clang-s
ys/target/debug/build/libc-7bee6741a0fd2270/build_script_build-7bee6741a0fd2270.build_script_build.753a8059-cgu.10.rcgu.o" "/global/u1/j/jedbrow/clang-sys/target/debug/build/libc-7bee6741a0fd
2270/build_script_build-7bee6741a0fd2270.build_script_build.753a8059-cgu.11.rcgu.o" "/global/u1/j/jedbrow/clang-sys/target/debug/build/libc-7bee6741a0fd2270/build_script_build-7bee6741a0fd227
0.build_script_build.753a8059-cgu.12.rcgu.o" "/global/u1/j/jedbrow/clang-sys/target/debug/build/libc-7bee6741a0fd2270/build_script_build-7bee6741a0fd2270.build_script_build.753a8059-cgu.13.rc
gu.o" "/global/u1/j/jedbrow/clang-sys/target/debug/build/libc-7bee6741a0fd2270/build_script_build-7bee6741a0fd2270.build_script_build.753a8059-cgu.14.rcgu.o" "/global/u1/j/jedbrow/clang-sys/t
arget/debug/build/libc-7bee6741a0fd2270/build_script_build-7bee6741a0fd2270.build_script_build.753a8059-cgu.15.rcgu.o" "/global/u1/j/jedbrow/clang-sys/target/debug/build/libc-7bee6741a0fd2270
/build_script_build-7bee6741a0fd2270.build_script_build.753a8059-cgu.2.rcgu.o" "/global/u1/j/jedbrow/clang-sys/target/debug/build/libc-7bee6741a0fd2270/build_script_build-7bee6741a0fd2270.bui
ld_script_build.753a8059-cgu.3.rcgu.o" "/global/u1/j/jedbrow/clang-sys/target/debug/build/libc-7bee6741a0fd2270/build_script_build-7bee6741a0fd2270.build_script_build.753a8059-cgu.4.rcgu.o" "
/global/u1/j/jedbrow/clang-sys/target/debug/build/libc-7bee6741a0fd2270/build_script_build-7bee6741a0fd2270.build_script_build.753a8059-cgu.5.rcgu.o" "/global/u1/j/jedbrow/clang-sys/target/de
bug/build/libc-7bee6741a0fd2270/build_script_build-7bee6741a0fd2270.build_script_build.753a8059-cgu.6.rcgu.o" "/global/u1/j/jedbrow/clang-sys/target/debug/build/libc-7bee6741a0fd2270/build_sc
ript_build-7bee6741a0fd2270.build_script_build.753a8059-cgu.7.rcgu.o" "/global/u1/j/jedbrow/clang-sys/target/debug/build/libc-7bee6741a0fd2270/build_script_build-7bee6741a0fd2270.build_script
_build.753a8059-cgu.8.rcgu.o" "/global/u1/j/jedbrow/clang-sys/target/debug/build/libc-7bee6741a0fd2270/build_script_build-7bee6741a0fd2270.build_script_build.753a8059-cgu.9.rcgu.o" "/global/u
1/j/jedbrow/clang-sys/target/debug/build/libc-7bee6741a0fd2270/build_script_build-7bee6741a0fd2270.59vyy2qd9mqaxnfe.rcgu.o" "-Wl,--as-needed" "-L" "/global/u1/j/jedbrow/clang-sys/target/debug
/deps" "-L" "/global/u1/j/jedbrow/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/global/u1/j/jedbrow/.rustup
/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-69edc9ac8de4d39c.rlib" "/global/u1/j/jedbrow/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib
/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-254ac8a4d96ed89e.rlib" "/global/u1/j/jedbrow/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/
libobject-8bed7ede368468ef.rlib" "/global/u1/j/jedbrow/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-9da1150e6aeada6b.rlib" "/global/u1
/j/jedbrow/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-dec39a40a22b358c.rlib" "/global/u1/j/jedbrow/.rustup/toolchains/stable-x86_
64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-7a90882341200e38.rlib" "/global/u1/j/jedbrow/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unkno
wn-linux-gnu/lib/librustc_demangle-6a5da46a37549d0a.rlib" "/global/u1/j/jedbrow/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-6dc3d
1df7e408d5b.rlib" "/global/u1/j/jedbrow/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-9d89ad14c568d44a.rlib" "/global/u1/j/jedbrow/.
rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-ecbdf47025adae10.rlib" "/global/u1/j/jedbrow/.rustup/toolchains/stable-x86_64-unknown
-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-29db3ffec771ef22.rlib" "/global/u1/j/jedbrow/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-g
nu/lib/librustc_std_workspace_alloc-8b55ad9e1a2080d1.rlib" "/global/u1/j/jedbrow/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-f37a5594
1b8b3bbd.rlib" "/global/u1/j/jedbrow/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-c1d45d3d6971ce0d.rlib" "/global/u1/j/jedbrow/.rustup
/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-18ac7cbb154ecd62.rlib" "/global/u1/j/jedbrow/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/li
b/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-80c5909c82700e85.rlib" "/global/u1/j/jedbrow/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librus
tc_std_workspace_core-aa7f747e2f6af7d5.rlib" "/global/u1/j/jedbrow/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-60d544c9f51ce476.rlib" "
-Wl,--end-group" "/global/u1/j/jedbrow/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-d1bd89f2a607e488.rlib" "-Wl,-Bdynamic"
"-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/global/u1/j/jedbrow/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86
_64-unknown-linux-gnu/lib" "-o" "/global/u1/j/jedbrow/clang-sys/target/debug/build/libc-7bee6741a0fd2270/build_script_build-7bee6741a0fd2270" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-
nodefaultlibs"
  = note: ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
          >>> defined in /opt/cray/pe/cce/14.0.1/cce/x86_64/lib/no_mmap.o
          >>> referenced by no_mmap.c
          >>>               /opt/cray/pe/cce/14.0.1/cce/x86_64/lib/no_mmap.o:(__no_mmap_for_malloc)

          ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
          >>> defined in /opt/cray/pe/cce/14.0.1/cce/x86_64/lib/no_mmap.o
          >>> referenced by no_mmap.c
          >>>               /opt/cray/pe/cce/14.0.1/cce/x86_64/lib/no_mmap.o:(__no_mmap_for_malloc)

          ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
          >>> defined in /opt/cray/pe/cce/14.0.1/cce/x86_64/lib/no_mmap.o
          >>> referenced by no_mmap.c
          >>>               /opt/cray/pe/cce/14.0.1/cce/x86_64/lib/no_mmap.o:(__no_mmap_for_malloc)
          clang-14: error: linker command failed with exit code 1 (use -v to see invocation)

error: could not compile `libc` due to previous error
warning: build failed, waiting for other jobs to finish...

I get almost identical errors when trying cargo build --no-default-features --features clang_13_0,static. Do you have suggestions for how to fix this?

I was able to module swap PrgEnv-cray PrgEnv-aocc (AMD compilers) and get successful cargo build (default features) on this machine (NERSC Perlmutter), so that may be a workaround for others encountering this issue.

$ cc --version
AMD clang version 13.0.0 (CLANG: AOCC_3.2.0-Build#128 2021_11_12) (based on LLVM Mirror.Version.13.0.0)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/AMD/aocc-compiler-3.2.0/include/../bin