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

[Bug]: Can't link using riscv64 toolchain #1702

Open
Mizux opened this issue Jul 5, 2024 · 0 comments
Open

[Bug]: Can't link using riscv64 toolchain #1702

Mizux opened this issue Jul 5, 2024 · 0 comments

Comments

@Mizux
Copy link
Contributor

Mizux commented Jul 5, 2024

Describe the issue

When using the bootlin cross_toolchain
ref: https://toolchains.bootlin.com/

I got the trace:

[ 79%] Linking CXX executable ../../bin/protoc-gen-upb
/home/project/build_cross/archives/riscv64/bin/../lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/../../../../riscv64-buildroot-linux-gnu/bin/ld: ../../lib/libabsl_log_internal_message.so.2401.0.0: undefined reference to `__atomic_compare_exchange_1'
/home/project/build_cross/archives/riscv64/bin/../lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/../../../../riscv64-buildroot-linux-gnu/bin/ld: ../../lib/libabsl_log_internal_globals.so.2401.0.0: undefined reference to `__atomic_exchange_1'
collect2: error: ld returned 1 exit status
gmake[2]: *** [_deps/protobuf-build/CMakeFiles/protoc-gen-upb.dir/build.make:257: bin/protoc-gen-upb-27.2.0] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:4663: _deps/protobuf-build/CMakeFiles/protoc-gen-upb.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2

Steps to reproduce the problem

I'm using my pet project mizux/cmake-cpp:

git clone -b main ssh://git@github.com/Mizux/cmake-cpp
cd cmake-cpp

# use my "makefile based" script to build inside an ubuntu container using the cross-toolchain
make --directory=ci riscv64_build
...
error

note: to debug inside the container you can do:

# build the container until the devel stage then docker run an instance in it
$ make --directory=ci sh_riscv64_devel
...
# inside the container try to build using the tools/cross_compile.sh script
root@corentinl:/home/project# ./tools/cross_compile.sh riscv64
...
/home/project/build_cross/archives/riscv64/bin/riscv64-linux-ranlib ../../lib/libprotoc.a
gmake[2]: Leaving directory '/home/project/build_cross/riscv64'
[100%] Built target libprotoc
gmake[1]: Leaving directory '/home/project/build_cross/riscv64'
gmake: *** [Makefile:146: all] Error 2


# rerun the cmake build to get the error
root@corentinl:/home/project# cmake --build build_cross/riscv64/ -v
...
[ 79%] Linking CXX executable ../../bin/protoc-gen-upb
cd /home/project/build_cross/riscv64/_deps/protobuf-build && /usr/local/bin/cmake -E cmake_link_script CMakeFiles/protoc-gen-upb.dir/link.txt --verbose=1
/home/project/build_cross/archives/riscv64/bin/riscv64-linux-g++ --sysroot=/home/project/build_cross/archives/riscv64/riscv64-buildroot-linux-gnu/sysroot  -L/home/project/build_cross/archives/riscv64/riscv64-buildroot-linux-gnu/sysroot/lib -O3 -DNDEBUG "CMakeFiles/protoc-gen-upb.dir/upb_generator/common.cc.o" "CMakeFiles/protoc-gen-upb.dir/upb_generator/file_layout.cc.o" "CMakeFiles/protoc-gen-upb.dir/upb_generator/mangle.cc.o" "CMakeFiles/protoc-gen-upb.dir/upb_generator/names.cc.o" "CMakeFiles/protoc-gen-upb.dir/upb_generator/protoc-gen-upb.cc.o" "CMakeFiles/protoc-gen-upb.dir/upb_generator/cmake/google/protobuf/compiler/plugin.upb_minitable.c.o" -o ../../bin/protoc-gen-upb-27.2.0  -Wl,-rpath,"\$ORIGIN/../lib" ../../lib/libprotobuf.a ../../lib/libupb.a ../../lib/libabsl_die_if_null.so.2401.0.0 ../../lib/libabsl_log_initialize.so.2401.0.0 ../../lib/libabsl_statusor.so.2401.0.0 ../../lib/libabsl_log_internal_check_op.so.2401.0.0 ../../lib/libabsl_leak_check.so.2401.0.0 ../../lib/libabsl_log_internal_conditions.so.2401.0.0 ../../lib/libabsl_log_internal_message.so.2401.0.0 ../../lib/libabsl_log_internal_nullguard.so.2401.0.0 ../../lib/libabsl_examine_stack.so.2401.0.0 ../../lib/libabsl_log_internal_format.so.2401.0.0 ../../lib/libabsl_log_internal_proto.so.2401.0.0 ../../lib/libabsl_log_internal_log_sink_set.so.2401.0.0 ../../lib/libabsl_log_sink.so.2401.0.0 ../../lib/libabsl_log_entry.so.2401.0.0 ../../lib/libabsl_flags_internal.so.2401.0.0 ../../lib/libabsl_flags_marshalling.so.2401.0.0 ../../lib/libabsl_flags_reflection.so.2401.0.0 ../../lib/libabsl_flags_config.so.2401.0.0 ../../lib/libabsl_flags_program_name.so.2401.0.0 ../../lib/libabsl_flags_private_handle_accessor.so.2401.0.0 ../../lib/libabsl_flags_commandlineflag.so.2401.0.0 ../../lib/libabsl_flags_commandlineflag_internal.so.2401.0.0 ../../lib/libabsl_log_internal_globals.so.2401.0.0 ../../lib/libabsl_log_globals.so.2401.0.0 ../../lib/libabsl_vlog_config_internal.so.2401.0.0 ../../lib/libabsl_log_internal_fnmatch.so.2401.0.0 ../../lib/libabsl_raw_hash_set.so.2401.0.0 ../../lib/libabsl_hash.so.2401.0.0 ../../lib/libabsl_city.so.2401.0.0 ../../lib/libabsl_low_level_hash.so.2401.0.0 ../../lib/libabsl_hashtablez_sampler.so.2401.0.0 ../../lib/libabsl_random_distributions.so.2401.0.0 ../../lib/libabsl_random_seed_sequences.so.2401.0.0 ../../lib/libabsl_random_internal_pool_urbg.so.2401.0.0 ../../lib/libabsl_random_internal_randen.so.2401.0.0 ../../lib/libabsl_random_internal_randen_hwaes.so.2401.0.0 ../../lib/libabsl_random_internal_randen_hwaes_impl.so.2401.0.0 ../../lib/libabsl_random_internal_randen_slow.so.2401.0.0 ../../lib/libabsl_random_internal_platform.so.2401.0.0 ../../lib/libabsl_random_internal_seed_material.so.2401.0.0 ../../lib/libabsl_random_seed_gen_exception.so.2401.0.0 ../../lib/libabsl_status.so.2401.0.0 ../../lib/libabsl_cord.so.2401.0.0 ../../lib/libabsl_cordz_info.so.2401.0.0 ../../lib/libabsl_cord_internal.so.2401.0.0 ../../lib/libabsl_cordz_functions.so.2401.0.0 ../../lib/libabsl_exponential_biased.so.2401.0.0 ../../lib/libabsl_cordz_handle.so.2401.0.0 ../../lib/libabsl_crc_cord_state.so.2401.0.0 ../../lib/libabsl_crc32c.so.2401.0.0 ../../lib/libabsl_crc_internal.so.2401.0.0 ../../lib/libabsl_crc_cpu_detect.so.2401.0.0 ../../lib/libabsl_bad_optional_access.so.2401.0.0 ../../lib/libabsl_strerror.so.2401.0.0 ../../lib/libabsl_str_format_internal.so.2401.0.0 ../../lib/libabsl_synchronization.so.2401.0.0 ../../lib/libabsl_stacktrace.so.2401.0.0 ../../lib/libabsl_symbolize.so.2401.0.0 ../../lib/libabsl_debugging_internal.so.2401.0.0 ../../lib/libabsl_demangle_internal.so.2401.0.0 ../../lib/libabsl_graphcycles_internal.so.2401.0.0 ../../lib/libabsl_kernel_timeout_internal.so.2401.0.0 ../../lib/libabsl_malloc_internal.so.2401.0.0 ../../lib/libabsl_time.so.2401.0.0 ../../lib/libabsl_civil_time.so.2401.0.0 ../../lib/libabsl_time_zone.so.2401.0.0 ../../lib/libabsl_bad_variant_access.so.2401.0.0 ../../lib/libutf8_validity.a ../../lib/libabsl_strings.so.2401.0.0 ../../lib/libabsl_int128.so.2401.0.0 ../../lib/libabsl_strings_internal.so.2401.0.0 ../../lib/libabsl_string_view.so.2401.0.0 ../../lib/libabsl_base.so.2401.0.0 ../../lib/libabsl_spinlock_wait.so.2401.0.0 ../../lib/libabsl_throw_delegate.so.2401.0.0 ../../lib/libabsl_raw_logging_internal.so.2401.0.0 ../../lib/libabsl_log_severity.so.2401.0.0 ../../lib/libutf8_range.a 
/home/project/build_cross/archives/riscv64/bin/../lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/../../../../riscv64-buildroot-linux-gnu/bin/ld: ../../lib/libabsl_log_internal_message.so.2401.0.0: undefined reference to `__atomic_compare_exchange_1'
/home/project/build_cross/archives/riscv64/bin/../lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/../../../../riscv64-buildroot-linux-gnu/bin/ld: ../../lib/libabsl_log_internal_globals.so.2401.0.0: undefined reference to `__atomic_exchange_1'
collect2: error: ld returned 1 exit status
gmake[2]: *** [_deps/protobuf-build/CMakeFiles/protoc-gen-upb.dir/build.make:257: bin/protoc-gen-upb-27.2.0] Error 1
gmake[2]: Leaving directory '/home/project/build_cross/riscv64'
gmake[1]: *** [CMakeFiles/Makefile2:4663: _deps/protobuf-build/CMakeFiles/protoc-gen-upb.dir/all] Error 2
gmake[1]: Leaving directory '/home/project/build_cross/riscv64'
gmake: *** [Makefile:146: all] Error 2

What version of Abseil are you using?

message(CHECK_START "Fetching Abseil-cpp")
list(APPEND CMAKE_MESSAGE_INDENT "  ")
set(ABSL_USE_SYSTEM_INCLUDES ON)
# We want Abseil to declare what C++ standard it was compiled with.
set(ABSL_PROPAGATE_CXX_STD ON)
# We want Abseil to keep the INSTALL rules enabled, even though it is a
# subproject. Otherwise the install rules in this project break.
set(ABSL_ENABLE_INSTALL ON)
FetchContent_Declare(
  absl
  GIT_REPOSITORY "https://github.com/abseil/abseil-cpp.git"
  GIT_TAG "20240116.2"
  GIT_SHALLOW TRUE
  PATCH_COMMAND git apply --ignore-whitespace "${CMAKE_CURRENT_LIST_DIR}/../patches/abseil-cpp-20240116.2.patch"
  OVERRIDE_FIND_PACKAGE)
FetchContent_MakeAvailable(absl)
list(POP_BACK CMAKE_MESSAGE_INDENT)
message(CHECK_PASS "fetched")

note: the patch is to fix the RUNPATH in all absl shared library since my super project build use CMAKE_BUILD_WITH_INSTALL_RPATH TRUE.
(PR incoming -_-)

What operating system and version are you using?

run inside a docker:

%head -3 ci/docker/toolchain/Dockerfile
# Create a virtual environment with all tools installed
# ref: https://hub.docker.com/_/ubuntu
FROM ubuntu:latest AS env

What compiler and version are you using?

From tools/cross_compile.sh

      local -r TOOLCHAIN_URL="https://toolchains.bootlin.com/downloads/releases/toolchains/riscv64-lp64d/tarballs/riscv64-lp64d--glibc--stable-2022.08-1.tar.bz2"
      local -r GCC_PREFIX="riscv64"

seems to be a gcc version 11.3.0 (Buildroot 2021.11-4428-g6b6741b)

make --directory=ci sh_riscv64_devel
# generate the cmake toolchain file to find the compiler path
root@corentinl:/# ./tools/build_cross.sh riscv64
...
root@corentinl:/home/project# grep "set(tools" build_cross/archives/toolchain_riscv64.cmake 
set(tools /home/project/build_cross/archives/riscv64)
root@corentinl:/home/project# grep "CXX_COMPILER" build_cross/archives/toolchain_riscv64.cmake 
set(CMAKE_CXX_COMPILER ${tools}/bin/riscv64-linux-g++)

root@corentinl:/home/project# /home/project/build_cross/archives/riscv64/bin/riscv64-linux-g++ -v
Using built-in specs.
COLLECT_GCC=/home/project/build_cross/archives/riscv64/bin/riscv64-linux-g++.br_real
COLLECT_LTO_WRAPPER=/home/project/build_cross/archives/riscv64/bin/../libexec/gcc/riscv64-buildroot-linux-gnu/11.3.0/lto-wrapper
Target: riscv64-buildroot-linux-gnu
Configured with: ./configure --prefix=/builds/buildroot.org/toolchains-builder/build/riscv64-lp64d--glibc--stable-2022.08-1 --sysconfdir=/builds/buildroot.org/toolchains-builder/build/riscv64-lp64d--glibc--stable-2022.08-1/etc --enable-static --target=riscv64-buildroot-linux-gnu --with-sysroot=/builds/buildroot.org/toolchains-builder/build/riscv64-lp64d--glibc--stable-2022.08-1/riscv64-buildroot-linux-gnu/sysroot --enable-__cxa_atexit --with-gnu-ld --disable-libssp --disable-multilib --disable-decimal-float --enable-plugins --enable-lto --with-gmp=/builds/buildroot.org/toolchains-builder/build/riscv64-lp64d--glibc--stable-2022.08-1 --with-mpc=/builds/buildroot.org/toolchains-builder/build/riscv64-lp64d--glibc--stable-2022.08-1 --with-mpfr=/builds/buildroot.org/toolchains-builder/build/riscv64-lp64d--glibc--stable-2022.08-1 --with-pkgversion='Buildroot 2021.11-4428-g6b6741b' --with-bugurl=http://bugs.buildroot.net/ --without-zstd --disable-libquadmath --disable-libquadmath-support --enable-tls --enable-threads --without-isl --without-cloog --with-arch=rv64imafd --with-abi=lp64d --enable-languages=c,c++,fortran --with-build-time-tools=/builds/buildroot.org/toolchains-builder/build/riscv64-lp64d--glibc--stable-2022.08-1/riscv64-buildroot-linux-gnu/bin --enable-shared --enable-libgomp
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.3.0 (Buildroot 2021.11-4428-g6b6741b) 
COMPILER_PATH=/home/project/build_cross/archives/riscv64/bin/../libexec/gcc/riscv64-buildroot-linux-gnu/11.3.0/:/home/project/build_cross/archives/riscv64/bin/../libexec/gcc/:/home/project/build_cross/archives/riscv64/bin/../lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/../../../../riscv64-buildroot-linux-gnu/bin/
LIBRARY_PATH=/home/project/build_cross/archives/riscv64/bin/../lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/:/home/project/build_cross/archives/riscv64/bin/../lib/gcc/:/home/project/build_cross/archives/riscv64/bin/../lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/../../../../riscv64-buildroot-linux-gnu/lib/:/home/project/build_cross/archives/riscv64/riscv64-buildroot-linux-gnu/sysroot/lib/:/home/project/build_cross/archives/riscv64/riscv64-buildroot-linux-gnu/sysroot/usr/lib/
COLLECT_GCC_OPTIONS='-fstack-protector-strong' '-fPIE' '-pie' '-v' '-shared-libgcc' '-march=rv64imafd' '-mabi=lp64d' '-misa-spec=2.2' '-march=rv64imafd' '-dumpdir' 'a.'
 /home/project/build_cross/archives/riscv64/bin/../libexec/gcc/riscv64-buildroot-linux-gnu/11.3.0/collect2 -plugin /home/project/build_cross/archives/riscv64/bin/../libexec/gcc/riscv64-buildroot-linux-gnu/11.3.0/liblto_plugin.so -plugin-opt=/home/project/build_cross/archives/riscv64/bin/../libexec/gcc/riscv64-buildroot-linux-gnu/11.3.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccucnLsL.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --sysroot=/home/project/build_cross/archives/riscv64/riscv64-buildroot-linux-gnu/sysroot --eh-frame-hdr -melf64lriscv -dynamic-linker /lib/ld-linux-riscv64-lp64d.so.1 -pie /home/project/build_cross/archives/riscv64/riscv64-buildroot-linux-gnu/sysroot/usr/lib/Scrt1.o /home/project/build_cross/archives/riscv64/bin/../lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/crti.o /home/project/build_cross/archives/riscv64/bin/../lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/crtbeginS.o -L/home/project/build_cross/archives/riscv64/bin/../lib/gcc/riscv64-buildroot-linux-gnu/11.3.0 -L/home/project/build_cross/archives/riscv64/bin/../lib/gcc -L/home/project/build_cross/archives/riscv64/bin/../lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/../../../../riscv64-buildroot-linux-gnu/lib -L/home/project/build_cross/archives/riscv64/riscv64-buildroot-linux-gnu/sysroot/lib -L/home/project/build_cross/archives/riscv64/riscv64-buildroot-linux-gnu/sysroot/usr/lib -z now -z relro -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /home/project/build_cross/archives/riscv64/bin/../lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/crtendS.o /home/project/build_cross/archives/riscv64/bin/../lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/crtn.o
/home/project/build_cross/archives/riscv64/bin/../lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/../../../../riscv64-buildroot-linux-gnu/bin/ld: /home/project/build_cross/archives/riscv64/riscv64-buildroot-linux-gnu/sysroot/usr/lib/Scrt1.o: in function `_start':
(.text+0x8): undefined reference to `main'
collect2: error: ld returned 1 exit status

What build system are you using?

%make --directory=ci sh_riscv64_env         
root@corentinl:/# cmake --version
cmake version 3.28.3

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant