Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: building the downstream C-binding library using the Solana SDK #22725

Closed
johhnsmmith198 opened this issue Jan 25, 2022 · 0 comments
Closed
Labels
stale [bot only] Added to stale content; results in auto-close after a week.

Comments

@johhnsmmith198
Copy link

johhnsmmith198 commented Jan 25, 2022

Problem

The environment variable passed to the downstream cmake library are not enough to build the library correctly.
Also I noticed that the -fuse-ld=lld was missing.
Even if I add it manually the compilation keeps failing for some reason.

I am just adding this dependency to the example-helloworld program to trigger this issue

h3ron = { git = "https://github.com/nmandery/h3ron.git"}

this is the result of running npm run build:program-rust

> helloworld@0.0.1 build:program-rust /home/pc/Documents/funspace/crypto-world/lab/solanaworkspace/example-helloworld
> cargo build-bpf --manifest-path=./src/program-rust/Cargo.toml --bpf-out-dir=dist/program

BPF SDK: /home/pc/.local/share/solana/install/releases/1.9.4/solana-release/bin/sdk/bpf
cargo-build-bpf child: rustup toolchain list -v
cargo-build-bpf child: cargo +bpf build --target bpfel-unknown-unknown --release
Error: Function _ZN6robust13incircleadapt17hcd08b205f8290514E Stack offset of 24392 exceeded max offset of 4096 by 20296 bytes, please minimize large stack variables
   Compiling as-slice v0.1.5
   Compiling digest v0.9.0
   Compiling block-buffer v0.9.0
   Compiling proc-macro-crate v0.1.5
   Compiling h3ron-h3-sys v0.12.0 (https://github.com/nmandery/h3ron.git#ab3a27f3)
   Compiling sha2 v0.9.5
   Compiling sha3 v0.9.1
error: failed to run custom build command for `h3ron-h3-sys v0.12.0 (https://github.com/nmandery/h3ron.git#ab3a27f3)`

Caused by:
  process didn't exit successfully: `/home/pc/Documents/funspace/crypto-world/lab/solanaworkspace/example-helloworld/src/program-rust/target/release/build/h3ron-h3-sys-1ab6cd26d7e5abe9/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-changed=libh3
  CMAKE_TOOLCHAIN_FILE_bpfel-unknown-unknown = None
  CMAKE_TOOLCHAIN_FILE_bpfel_unknown_unknown = None
  TARGET_CMAKE_TOOLCHAIN_FILE = None
  CMAKE_TOOLCHAIN_FILE = None
  CMAKE_GENERATOR_bpfel-unknown-unknown = None
  CMAKE_GENERATOR_bpfel_unknown_unknown = None
  TARGET_CMAKE_GENERATOR = None
  CMAKE_GENERATOR = None
  CMAKE_PREFIX_PATH_bpfel-unknown-unknown = None
  CMAKE_PREFIX_PATH_bpfel_unknown_unknown = None
  TARGET_CMAKE_PREFIX_PATH = None
  CMAKE_PREFIX_PATH = None
  CMAKE_bpfel-unknown-unknown = None
  CMAKE_bpfel_unknown_unknown = None
  TARGET_CMAKE = None
  CMAKE = None
  running: "cmake" "/home/pc/.cargo/git/checkouts/h3ron-31217b227e8cd3a6/ab3a27f/h3ron-h3-sys/libh3" "-DBUILD_BENCHMARKS=OFF" "-DBUILD_FILTERS=OFF" "-DBUILD_GENERATORS=OFF" "-DBUILD_TESTING=OFF" "-DENABLE_COVERAGE=OFF" "-DENABLE_DOCS=OFF" "-DENABLE_FORMAT=OFF" "-DENABLE_LINTING=OFF" "-DCMAKE_INSTALL_PREFIX=/home/pc/Documents/funspace/crypto-world/lab/solanaworkspace/example-helloworld/src/program-rust/target/bpfel-unknown-unknown/release/build/h3ron-h3-sys-df478ba73015eab9/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC --target=bpfel-unknown-unknown" "-DCMAKE_C_COMPILER=/home/pc/.local/share/solana/install/releases/1.9.4/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin/clang" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC" "-DCMAKE_CXX_COMPILER=/usr/bin/c++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC --target=bpfel-unknown-unknown" "-DCMAKE_ASM_COMPILER=/home/pc/.local/share/solana/install/releases/1.9.4/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin/clang" "-DCMAKE_BUILD_TYPE=Release"
  -- The C compiler identification is Clang 13.0.0
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - failed
  -- Check for working C compiler: /home/pc/.local/share/solana/install/releases/1.9.4/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin/clang
  -- Check for working C compiler: /home/pc/.local/share/solana/install/releases/1.9.4/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin/clang - broken
  -- Configuring incomplete, errors occurred!
  See also "/home/pc/Documents/funspace/crypto-world/lab/solanaworkspace/example-helloworld/src/program-rust/target/bpfel-unknown-unknown/release/build/h3ron-h3-sys-df478ba73015eab9/out/build/CMakeFiles/CMakeOutput.log".
  See also "/home/pc/Documents/funspace/crypto-world/lab/solanaworkspace/example-helloworld/src/program-rust/target/bpfel-unknown-unknown/release/build/h3ron-h3-sys-df478ba73015eab9/out/build/CMakeFiles/CMakeError.log".

  --- stderr
  CMake Error at /usr/local/share/cmake-3.22/Modules/CMakeTestCCompiler.cmake:69 (message):
    The C compiler

      "/home/pc/.local/share/solana/install/releases/1.9.4/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin/clang"

    is not able to compile a simple test program.

    It fails with the following output:

      Change Dir: /home/pc/Documents/funspace/crypto-world/lab/solanaworkspace/example-helloworld/src/program-rust/target/bpfel-unknown-unknown/release/build/h3ron-h3-sys-df478ba73015eab9/out/build/CMakeFiles/CMakeTmp

      Run Build Command(s):/usr/bin/make -f Makefile cmTC_b71ce/fast && /usr/bin/make  -f CMakeFiles/cmTC_b71ce.dir/build.make CMakeFiles/cmTC_b71ce.dir/build
      make[1]: Entering directory '/home/pc/Documents/funspace/crypto-world/lab/solanaworkspace/example-helloworld/src/program-rust/target/bpfel-unknown-unknown/release/build/h3ron-h3-sys-df478ba73015eab9/out/build/CMakeFiles/CMakeTmp'
      Building C object CMakeFiles/cmTC_b71ce.dir/testCCompiler.c.o
      /home/pc/.local/share/solana/install/releases/1.9.4/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin/clang   -ffunction-sections -fdata-sections -fPIC --target=bpfel-unknown-unknown  -std=gnu99 -MD -MT CMakeFiles/cmTC_b71ce.dir/testCCompiler.c.o -MF CMakeFiles/cmTC_b71ce.dir/testCCompiler.c.o.d -o CMakeFiles/cmTC_b71ce.dir/testCCompiler.c.o -c /home/pc/Documents/funspace/crypto-world/lab/solanaworkspace/example-helloworld/src/program-rust/target/bpfel-unknown-unknown/release/build/h3ron-h3-sys-df478ba73015eab9/out/build/CMakeFiles/CMakeTmp/testCCompiler.c
      Linking C executable cmTC_b71ce
      /usr/local/bin/cmake -E cmake_link_script CMakeFiles/cmTC_b71ce.dir/link.txt --verbose=1
      /home/pc/.local/share/solana/install/releases/1.9.4/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin/clang  -ffunction-sections -fdata-sections -fPIC --target=bpfel-unknown-unknown  -rdynamic CMakeFiles/cmTC_b71ce.dir/testCCompiler.c.o -o cmTC_b71ce
      /usr/bin/ld: unknown architecture of input file `CMakeFiles/cmTC_b71ce.dir/testCCompiler.c.o' is incompatible with i386:x86-64 output
      collect2: error: ld returned 1 exit status
      clang-13: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
      make[1]: *** [CMakeFiles/cmTC_b71ce.dir/build.make:100: cmTC_b71ce] Error 1
      make[1]: Leaving directory '/home/pc/Documents/funspace/crypto-world/lab/solanaworkspace/example-helloworld/src/program-rust/target/bpfel-unknown-unknown/release/build/h3ron-h3-sys-df478ba73015eab9/out/build/CMakeFiles/CMakeTmp'
      make: *** [Makefile:127: cmTC_b71ce/fast] Error 2





    CMake will not be able to correctly generate this project.
  Call Stack (most recent call first):
    CMakeLists.txt:59 (project)


  thread 'main' panicked at '
  command did not execute successfully, got: exit status: 1

  build script failed, must exit now', /home/pc/.cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.46/src/lib.rs:974:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed

I think the important bit is /usr/bin/ld: unknown architecture of input file CMakeFiles/cmTC_b71ce.dir/testCCompiler.c.o' is incompatible with i386:x86-64 output
We see here that the /usr/bin/ld is being used.
Instead I tried to copy-paste the cmake command and try to run it myself on the c source code of the h3ron library.
adding -v -fuse-ld=lld

export PATH="/home/pc/.local/share/solana/install/releases/1.9.4/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin/:$PATH"

"cmake" "../h3ron-h3-sys/libh3" \
"-DBUILD_BENCHMARKS=OFF" \
"-DBUILD_FILTERS=OFF" \
"-DBUILD_GENERATORS=OFF" \
"-DBUILD_TESTING=OFF" \
"-DENABLE_COVERAGE=OFF" \
"-DENABLE_DOCS=OFF" \
"-DENABLE_FORMAT=OFF" \
"-DENABLE_LINTING=OFF" \
"-DCMAKE_INSTALL_PREFIX=./h3ron-h3-sys-df478ba73015eab9/out" \
"-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC --target=bpfel-unknown-unknown -v -fuse-ld=lld" \
"-DCMAKE_C_COMPILER=/home/pc/.local/share/solana/install/releases/1.9.4/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin/clang" \
"-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -v" \
"-DCMAKE_CXX_COMPILER=/usr/bin/c++" \
"-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC --target=bpfel-unknown-unknown -v" \
"-DCMAKE_ASM_COMPILER=/home/pc/.local/share/solana/install/releases/1.9.4/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin/clang" \
"-DCMAKE_BUILD_TYPE=Release"

but getting a slightly different error with

CMake Error at /usr/local/share/cmake-3.22/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    "/home/pc/.local/share/solana/install/releases/1.9.4/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin/clang"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/pc/Documents/funspace/h3ron/build/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/bin/make -f Makefile cmTC_1ce4d/fast && /usr/bin/make  -f CMakeFiles/cmTC_1ce4d.dir/build.make CMakeFiles/cmTC_1ce4d.dir/build
    make[1]: Entering directory '/home/pc/Documents/funspace/h3ron/build/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_1ce4d.dir/testCCompiler.c.o
    /home/pc/.local/share/solana/install/releases/1.9.4/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin/clang   -ffunction-sections -fdata-sections -fPIC --target=bpfel-unknown-unknown -v -fuse-ld=lld  -std=gnu99 -MD -MT CMakeFiles/cmTC_1ce4d.dir/testCCompiler.c.o -MF CMakeFiles/cmTC_1ce4d.dir/testCCompiler.c.o.d -o CMakeFiles/cmTC_1ce4d.dir/testCCompiler.c.o -c /home/pc/Documents/funspace/h3ron/build/CMakeFiles/CMakeTmp/testCCompiler.c
    clang version 13.0.0 (https://github.com/solana-labs/llvm-project.git 9a51f4037220994af74488ba064efc4e96ee08c0)
    Target: bpfel-unknown-unknown
    Thread model: posix
    InstalledDir: /home/pc/.local/share/solana/install/releases/1.9.4/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin
    clang-13: warning: argument unused during compilation: '-fuse-ld=lld' [-Wunused-command-line-argument]
     (in-process)
     "/home/pc/.cache/solana/v1.21/bpf-tools/llvm/bin/clang-13" -cc1 -triple bpfel-unknown-unknown -emit-obj -mrelax-all --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name testCCompiler.c -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -debugger-tuning=gdb -v -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/home/pc/Documents/funspace/h3ron/build/CMakeFiles/CMakeTmp -resource-dir /home/pc/.cache/solana/v1.21/bpf-tools/llvm/lib/clang/13.0.0 -dependency-file CMakeFiles/cmTC_1ce4d.dir/testCCompiler.c.o.d -MT CMakeFiles/cmTC_1ce4d.dir/testCCompiler.c.o -sys-header-deps -std=gnu99 -fdebug-compilation-dir=/home/pc/Documents/funspace/h3ron/build/CMakeFiles/CMakeTmp -ferror-limit 19 -fgnuc-version=4.2.1 -faddrsig -o CMakeFiles/cmTC_1ce4d.dir/testCCompiler.c.o -x c /home/pc/Documents/funspace/h3ron/build/CMakeFiles/CMakeTmp/testCCompiler.c
    clang -cc1 version 13.0.0 based upon LLVM 13.0.0-rust-dev default target x86_64-unknown-linux-gnu
    #include "..." search starts here:
    #include <...> search starts here:
     /usr/local/include
     /home/pc/.cache/solana/v1.21/bpf-tools/llvm/lib/clang/13.0.0/include
     /usr/include
    End of search list.
    Linking C executable cmTC_1ce4d
    /usr/local/bin/cmake -E cmake_link_script CMakeFiles/cmTC_1ce4d.dir/link.txt --verbose=1
    /home/pc/.local/share/solana/install/releases/1.9.4/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin/clang  -ffunction-sections -fdata-sections -fPIC --target=bpfel-unknown-unknown -v -fuse-ld=lld  -rdynamic CMakeFiles/cmTC_1ce4d.dir/testCCompiler.c.o -o cmTC_1ce4d
    clang version 13.0.0 (https://github.com/solana-labs/llvm-project.git 9a51f4037220994af74488ba064efc4e96ee08c0)
    Target: bpfel-unknown-unknown
    Thread model: posix
    InstalledDir: /home/pc/.local/share/solana/install/releases/1.9.4/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin
     "/usr/bin/gcc" -fuse-ld=lld -rdynamic -o cmTC_1ce4d CMakeFiles/cmTC_1ce4d.dir/testCCompiler.c.o
    ld.lld: error: CMakeFiles/cmTC_1ce4d.dir/testCCompiler.c.o is incompatible with elf64-x86-64
    collect2: error: ld returned 1 exit status
    clang-13: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
    make[1]: *** [CMakeFiles/cmTC_1ce4d.dir/build.make:100: cmTC_1ce4d] Error 1
    make[1]: Leaving directory '/home/pc/Documents/funspace/h3ron/build/CMakeFiles/CMakeTmp'
    make: *** [Makefile:127: cmTC_1ce4d/fast] Error 2

using the solana lld is now returning: ld.lld: error: CMakeFiles/cmTC_1ce4d.dir/testCCompiler.c.o is incompatible with elf64-x86-64

Proposed Solution

I don't know I am really trying to figure it out.
We have been digging into it on this issue here: nmandery/h3ron#30

@github-actions github-actions bot added the stale [bot only] Added to stale content; results in auto-close after a week. label Jan 26, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale [bot only] Added to stale content; results in auto-close after a week.
Projects
None yet
Development

No branches or pull requests

1 participant