[all-commits] [llvm/llvm-project] c5a20b: [llvm-libgcc] initial commit
Christopher Di Bella via All-commits
all-commits at lists.llvm.org
Wed Feb 16 09:07:42 PST 2022
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: c5a20b518203613497fa864867fc232648006068
https://github.com/llvm/llvm-project/commit/c5a20b518203613497fa864867fc232648006068
Author: Christopher Di Bella <cjdb at google.com>
Date: 2022-02-16 (Wed, 16 Feb 2022)
Changed paths:
M compiler-rt/cmake/Modules/AddCompilerRT.cmake
A llvm-libgcc/CMakeLists.txt
A llvm-libgcc/docs/LLVMLibgcc.rst
A llvm-libgcc/generate_version_script.py
A llvm-libgcc/lib/CMakeLists.txt
A llvm-libgcc/lib/blank.c
A llvm-libgcc/lib/gcc_s.ver
M runtimes/CMakeLists.txt
Log Message:
-----------
[llvm-libgcc] initial commit
Note: the term "libgcc" refers to the all of `libgcc.a`, `libgcc_eh.a`,
and `libgcc_s.so`.
Enabling libunwind as a replacement for libgcc on Linux has proven to be
challenging since libgcc_s.so is a required dependency in the [Linux
standard base][5]. Some software is transitively dependent on libgcc
because glibc makes hardcoded calls to functions in libgcc_s. For example,
the function `__GI___backtrace` eventually makes its way to a [hardcoded
dlopen to libgcc_s' _Unwind_Backtrace][1]. Since libgcc_{eh.a,s.so} and
libunwind have the same ABI, but different implementations, the two
libraries end up [cross-talking, which ultimately results in a
segfault][2].
To solve this problem, libunwind needs to build a “libgcc”. That is, link
the necessary functions from compiler-rt and libunwind into an archive
and shared object that advertise themselves as `libgcc.a`, `libgcc_eh.a`,
and `libgcc_s.so`, so that glibc’s baked calls are diverted to the
correct objects in memory. Fortunately for us, compiler-rt and libunwind
use the same ABI as the libgcc family, so the problem is solvable at the
llvm-project configuration level: no program source needs to be edited.
Thus, the end result is for a user to configure their LLVM build with a
flag that indicates they want to archive compiler-rt/unwind as libgcc.
We achieve this by compiling libunwind with all the symbols necessary
for compiler-rt to emulate the libgcc family, and then generate symlinks
named for our "libgcc" that point to their corresponding libunwind
counterparts.
We alternatively considered patching glibc so that the source doesn't
directly refer to libgcc, but rather _defaults_ to libgcc, so that a
system preferring compiler-rt/libunwind can point to these libraries
at the config stage instead. Even if we modified the Linux standard
base, this alternative won't work because binaries that are built using
libgcc will still end up having crosstalk between the differing
implementations.
This problem has been solved in this manner for [FreeBSD][3], and this
CL has been tested against [Chrome OS][4].
[1]: https://github.com/bminor/glibc/blob/master/sysdeps/arm/backtrace.c#L68
[2]: https://bugs.chromium.org/p/chromium/issues/detail?id=1162190#c16
[3]: https://github.com/freebsd/freebsd-src/tree/main/lib/libgcc_s
[4]: https://chromium-review.googlesource.com/c/chromiumos/overlays/chromiumos-overlay/+/2945947
[5]: https://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/libgcc-s.html
Differential Revision: https://reviews.llvm.org/D108416
More information about the All-commits
mailing list