abseil / abseil/abseil-cpp

Some libraries need -latomic on GCC ARM32

Đang mở
#836 0 bình luận 3 reaction 1 người được giao Được @derekmauro nhận Xem trên GitHub
bug
Ngôn ngữ chính
C++
Star
18.1k
Fork
3.2k
Merge trung bình
20 giờ 36 phút
Pull request đã merge (30 ngày)
1

Mô tả

When compiling some of Abseil’s libraries on 32-bit ARM, GCC emits calls to functions contained in libatomic rather than in the compiler runtime. However, Abseil’s CMake build scripts do not set `-latomic` when building shared libraries (or when building against static ones). This results in link failures in reverse dependencies:

```console
$ uname -m
armv7l
$ cat stuff.cc
#include

int main() {
absl::InstallFailureSignalHandler(absl::FailureSignalHandlerOptions());
}
$ g++ -o stuff stuff.cc -labsl_failure_signal_handler
/usr/bin/ld: /usr/lib/arm-linux-gnueabi/libabsl_debugging_internal.so.20200923: undefined reference to `__atomic_compare_exchange_8'
/usr/bin/ld: /usr/lib/arm-linux-gnueabi/libabsl_spinlock_wait.so.20200923: undefined reference to `__atomic_load_8'
/usr/bin/ld: /usr/lib/arm-linux-gnueabi/libabsl_spinlock_wait.so.20200923: undefined reference to `__atomic_store_8'
collect2: error: ld returned 1 exit status
```

A similar failure occurs when taking an Abseil dependency via CMake. Explicitly linking against libatomic solves the issue:
```console
$ g++ -o stuff stuff.cc -l:libabsl_{failure_signal_handler,stacktrace,examine_stack,symbolize,malloc_internal,demangle_internal,debugging_internal,base,spinlock_wait,raw_logging_internal}.a -pthread -lm -latomic
```

This problem does not appear when using Clang, since Clang includes the atomic functions in compiler-rt rather than in a separate shared library.

I think this can be solved by sticking `-Wl,--as-needed -latomic -Wl,--no-as-needed` in appropriate places in the CMake files. This would give shared libraries a `DT_NEEDED` entry on libatomic.so on architectures where that’s necessary, and reverse dependencies linking static libraries would pick up the `-latomic` from abslTargets.cmake. I don’t think the Bazel rules need to change – this seems like the sort of thing that should go in a crosstool rather than individual BUILD files, especially given that it only applies to GCC.

**What version of Abseil are you using?**

20200923.1 LTS

**What operating system and version are you using**

Debian GNU/Linux, unstable, armel

**What compiler and version are you using?**

GCC 10.2.0:

```console
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabi/10/lto-wrapper
Target: arm-linux-gnueabi
Configured with: ../src/configure -v --with-pkgversion='Debian 10.2.0-16' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-10 --program-prefix=arm-linux-gnueabi- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-sjlj-exceptions --with-arch=armv5te --with-float=soft --disable-werror --enable-checking=yes,extra,rtl --build=arm-linux-gnueabi --host=arm-linux-gnueabi --target=arm-linux-gnueabi
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (Debian 10.2.0-16)
```

**What build system are you using?**

CMake

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.