Glibc - "undefined symbol: __sfp_handle_exceptions"
NR
nroycea+gnu@gmail.com
Wed Jun 11 11:39:28 GMT 2025
On Tue, Jun 10, 2025 at 3:44 PM Adhemerval Zanella Netto
<adhemerval.zanella@linaro.org> wrote:
>
>
>
> On 09/06/25 15:50, NR wrote:
> > On Mon, Jun 9, 2025 at 1:03 PM Adhemerval Zanella Netto
> > <adhemerval.zanella@linaro.org> wrote:
> >> On 09/06/25 12:16, NR wrote:
> >>> 1) Install kernel headers into empty directory
> >>> 2) Install glibc headers (and "touch" "<sysroot>/usr/include/gnu/stubs.h")
> >>> 3) Install LLVM runtime builtins
> >>> 4) Build glibc against sysroot
> >>>
> >>> ```
> >>> /<pathTo>/toolchain/bin/clang -shared -static-libgcc -Wl,-O1
> >>> -Wl,-z,defs -Wl,-dynamic-linker=/lib64/ld-linux-x86-64.so.2
> >>> -Wl,-z,pack-relative-relocs -B/<pathTo>/build/csu/
> >>> -Wl,--version-script=/<pathTo>/build/libm.map -Wl,--undefined-version
> >>> -Wl,-soname=libm.so.6 -Wl,-z,relro -Wl,-z,now -L/<pathTo>/build
> >>> -L/<pathTo>/build/math -L/<pathTo>/build/elf -L/<pathTo>/build/dlfcn
> >>> -L/<pathTo>/build/nss -L/<pathTo>/build/nis -L/<pathTo>/build/rt
> >>> -L/<pathTo>/build/resolv -L/<pathTo>/build/mathvec
> >>> -L/<pathTo>/build/support -L/<pathTo>/build/misc
> >>> -L/<pathTo>/build/debug -L/<pathTo>/build/nptl
> >>> -Wl,-rpath-link=/<pathTo>/build:/<pathTo>/build/math:/<pathTo>/build/elf:/<pathTo>/build/dlfcn:/<pathTo>/build/nss:/<pathTo>/build/nis:/<pathTo>/build/rt:/<pathTo>/build/resolv:/<pathTo>/build/mathvec:/<pathTo>/build/support:/<pathTo>/build/misc:/<pathTo>/build/debug:/<pathTo>/build/nptl
> >>> -o /<pathTo>/build/math/libm.so /<pathTo>/build/csu/abi-note.o
> >>> -Wl,--whole-archive /<pathTo>/build/math/libm_pic.a
> >>> -Wl,--no-whole-archive -Wl,--start-group /<pathTo>/build/libc.so
> >>> /<pathTo>/build/libc_nonshared.a -Wl,--as-needed
> >>> /<pathTo>/build/elf/ld.so -Wl,--no-as-needed -Wl,--end-group
> >>> ld.lld: warning: attempt to reassign symbol 'exp2l' of version
> >>> 'GLIBC_2.2.5' to version 'GLIBC_2.4'
> >>> ld.lld: error: undefined symbol: __sfp_handle_exceptions
> >>>>>> referenced by e_sqrtf128.c
> >>>>>> e_sqrtf128.os:(__ieee754_sqrtf128) in archive /<pathTo>/build/math/libm_pic.a
> >>> clang: error: linker command failed with exit code 1
> >>> ```
> >>>
> >>> I also found it odd that even though I set "LDFLAGS" to include
> >>> sysroot and "-v", it didn't produce ld.lld verbose output (only
> >>> clang). It does with other projects.
> >>> My CFLAGS were included in "config.make", but no LDFLAGS.
> >>>
> >>> I was trying to think where I've seen "undefined symbol" before and
> >>> just now remembered it was when I stripped binaries for musl and ended
> >>> up finding out the entry "_start" was ripped out.
> >>> That doesn't apply here I don't think, as no install even happened yet.
> >>>
> >>> I see other "attempt to reassign symbol" warnings and read about using
> >>> "-Wl,--undefined-version" to LDFLAGS, but that didn't make any
> >>> difference (not sure why it would since they aren't "undefined").
> >>>
> >>> A search led me to
> >>> https://inbox.sourceware.org/glibc-cvs/?t=20240410130446 with some
> >>> "sfp" related stuff.
> >>> I don't know when `sysdeps/x86_64/configure` ends up occurring.
> >>>
> >>
> >> The __sfp_handle_exceptions is used internally by x86_64 and powerpc64le for
> >> the soft-fp implementation (soft-fp/), used to implement float128
> >> support (or for the case of powerpc64le with -mabi=ieeelongdouble, the
> >> long double), and it is provided by *libgcc*. Afaiu, this was a deliberate
> >> decision since glibc is/was the main source for the soft-fp implementation;
> >> and for some targets glibc still supports such symbols as compat one, and
> >> using libgcc will result in duplicated symbol and required some hacks to
> >> make the build correct (like .wrap we do for sparc).
> >>
> >> The last time I tried to check glibc build with clang and llvm runtime I noted
> >> that compiler-rt does not provide __sfp_handle_exceptions, nor its soft-fp routines
> >> (for long double / _Float128) support floating point rounding mode different than
> >> default (FE_TONEAREST) nor floating point exceptions for some operation (like
> >> overflow/underflow or invalid operations). I think this is true even for
> >> today.
> >>
> >> In this experiment I used a glibc where I copied the gcc implementation
> >> (libgcc/config/i386/sfp-exceptions.c). Sometime ago I tried to add a SSE
> >> only implementation on glibc (460ee50de054396cc9791ff4cfdc2f5029fb923d),
> >> but I had to revert it (f721171632d67f397e712db52b9ce36bb46fdd96).
> >>
> >> I think we recent minimum gcc version required to build glibc we can instead
> >> link against libgcc instead of resorting to our own soft-fp implementation.
> >> This would require some make changes to avoid doing this for some target
> >> (like powerpc).
> >>
> >> Another possibility would just to copy __sfp_handle_exceptions from libgcc
> >> to glibc for the ABI that requires it.
> >>
> >> On llvm side, one possibility would be to add __sfp_handle_exceptions for
> >> llvm-libgcc runtime.
> >
> > Okay, so from what I'm gathering, the azanella/clang branch is
> > expected to NOT build successfully without libgcc being installed
> > first. So, my options are:
> > a) I build `libgcc` first (easiest route (supposedly))
> > b) I copy `https://github.com/gcc-mirror/gcc/blob/master/libgcc/config/ia64/sfp-exceptions.c`
> > to `sysdeps/x86/fpu/` and add it somewhere in the `Makefile`
> > (shouldn't this just already be done in the azanella/clang branch
> > itself?)
>
> It should be libgcc/config/*i386*/sfp-exceptions (ia64 is a defunct
> architecture not supported by glibc anymore).
>
> And I have not added it yet because I got stalled on other projects,
> and my focus now is to at least get clang+glibc is a workable state
> with libgcc.
>
> > c) I copy `https://github.com/gcc-mirror/gcc/blob/master/libgcc/config/ia64/sfp-exceptions.c`
> > to `llvm-project/llvm-libgcc/` and add it somewhere in
> > `CMakeLists.txt` (probably not since I'd doubt llvm would want to
> > accept such a PR)
>
> I doubt as well, since __sfp_handle_exceptions is really and implementation
> detail for the soft-fp support on GNU systems. I am not sure why it was
> not copied on glibc at first place, since most of the other soft-fp were.
>
> > d) It's dead-in-the-water, and I should give musl another look (was in
> > a fiery discussion regarding it and systemd, but yocto seems made for
> > it)
> >
> > I'll start with exploring b) when I'm rested, but am welcoming of
> > insight if I'm mistaken in any of my assumptions, or any further
> > advice.
>
> Could you check https://github.com/zatrazz/glibc/tree/azanella/clang-rtlib ?
>
> I have added a patch to build a __sfp_handle_exceptions if the selected
> compiler runtime does not provide it. The glibc now builds with
>
> -target x86_64-linux-gnu -Wno-unused-command-line-argument --rtlib=compiler-rt
>
> Although some tests still fails because of missing _Unwind_Backtrace (which
> was the original required support that motivated llvm-libgcc runtime). I have
> not check the C++ supports, neither if it has any regression (which mostly
> likely it does).
I had moved this to the correct ML (though I don't know if it should
be taken back out since we're working on your branch/repo).
In any case, yes, your change worked (also saw you've been busy with a
whole bunch of commits over the past day).
On the flip side (and may warrant a separate report (to your repo?)),
I tried using a different arch (armv6) and needed to add a flag to
counter:
```
error: overriding currently unsupported rounding mode on this target
[-Werror,-Wunsupported-floating-point-opt]
error: overriding currently unsupported use of floating point
exceptions on this target [-Werror,-Wunsupported-floating-point-opt]
```
Added `-Wno-unsupported-floating-point-opt` to CFLAGS.
Later, I found the triple for the `build` (as opposed to the
`--host=`) system was being used when building an Assembly file:
```
/<pathTo>/toolchain/bin/clang ../sysdeps/unix/sysv/linux/arm/sysdep.S
-c -v -I../include -I/<pathTo>/build/csu -I/<pathTo>/build
-I../sysdeps/unix/sysv/linux/arm/le -I../sysdeps/unix/sysv/linux/arm
-I../sysdeps/arm/nptl -I../sysdeps/unix/sysv/linux/include
-I../sysdeps/unix/sysv/linux -I../sysdeps/nptl -I../sysdeps/pthread
-I../sysdeps/gnu -I../sysdeps/unix/inet -I../sysdeps/unix/sysv
-I../sysdeps/unix/arm -I../sysdeps/unix -I../sysdeps/posix
-I../sysdeps/arm/le/armv6 -I../sysdeps/arm/armv6
-I../sysdeps/arm/le/nofpu -I../sysdeps/arm/nofpu
-I../sysdeps/ieee754/soft-fp -I../sysdeps/arm/le
-I../sysdeps/arm/include -I../sysdeps/arm -I../sysdeps/wordsize-32
-I../sysdeps/ieee754/flt-32 -I../sysdeps/ieee754/dbl-64
-I../sysdeps/ieee754 -I../sysdeps/generic -I.. -I../libio -I.
-D_LIBC_REENTRANT -include /<pathTo>/build/libc-modules.h
-DMODULE_NAME=libc -include ../include/libc-symbols.h -DPIC
-DTOP_NAMESPACE=glibc -DASSEMBLER -I/<pathTo>/build/csu/.
-Werror=undef -o /<pathTo>/build/csu/sysdep.o -MD -MP -MF
/<pathTo>/build/csu/sysdep.o.dt -MT /<pathTo>/build/csu/sysdep.o
clang version 21.0.0git
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /<pathTo>/toolchain/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1
Found candidate GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/14.2.1
Selected GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/14.2.1
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
"/<pathTo>/toolchain/bin/clang-21" -cc1 -triple
x86_64-unknown-linux-gnu -E -disable-free -clear-ast-before-backend
-disable-llvm-verifier -discard-value-names -main-file-name sysdep.S
-mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all
-fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases
-funwind-tables=2 -target-cpu x86-64 -tune-cpu generic
-debugger-tuning=gdb -fdebug-compilation-dir=/<pathTo>/glibc/csu -v
-fcoverage-compilation-dir=/<pathTo>/glibc/csu -resource-dir
/<pathTo>/toolchain/lib/clang/21 -dependency-file
/<pathTo>/build/csu/sysdep.o.dt -MT /<pathTo>/build/csu/sysdep.o
-sys-header-deps -MP -include /<pathTo>/build/libc-modules.h -include
../include/libc-symbols.h -I ../include -I /<pathTo>/build/csu -I
/<pathTo>/build -I ../sysdeps/unix/sysv/linux/arm/le -I
../sysdeps/unix/sysv/linux/arm -I ../sysdeps/arm/nptl -I
../sysdeps/unix/sysv/linux/include -I ../sysdeps/unix/sysv/linux -I
../sysdeps/nptl -I ../sysdeps/pthread -I ../sysdeps/gnu -I
../sysdeps/unix/inet -I ../sysdeps/unix/sysv -I ../sysdeps/unix/arm -I
../sysdeps/unix -I ../sysdeps/posix -I ../sysdeps/arm/le/armv6 -I
../sysdeps/arm/armv6 -I ../sysdeps/arm/le/nofpu -I
../sysdeps/arm/nofpu -I ../sysdeps/ieee754/soft-fp -I
../sysdeps/arm/le -I ../sysdeps/arm/include -I ../sysdeps/arm -I
../sysdeps/wordsize-32 -I ../sysdeps/ieee754/flt-32 -I
../sysdeps/ieee754/dbl-64 -I ../sysdeps/ieee754 -I ../sysdeps/generic
-I .. -I ../libio -I . -D _LIBC_REENTRANT -D MODULE_NAME=libc -D PIC
-D TOP_NAMESPACE=glibc -D ASSEMBLER -I /<pathTo>/build/csu/.
-internal-isystem /<pathTo>/toolchain/lib/clang/21/include
-internal-isystem /usr/local/include -internal-isystem
/usr/lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../x86_64-pc-linux-gnu/include
-internal-externc-isystem /include -internal-externc-isystem
/usr/include -Werror=undef -ferror-limit 19 -fgnuc-version=4.2.1
-fskip-odr-check-in-gmf -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o
/tmp/sysdep-f5bf6d.s -x assembler-with-cpp
../sysdeps/unix/sysv/linux/arm/sysdep.S
clang -cc1 version 21.0.0git based upon LLVM 21.0.0git default target
x86_64-unknown-linux-gnu
ignoring nonexistent directory
"/usr/lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../x86_64-pc-linux-gnu/include"
ignoring nonexistent directory "/include"
ignoring duplicate directory "/<pathTo>/build/csu/."
#include "..." search starts here:
#include <...> search starts here:
../include
/<pathTo>/build/csu
/<pathTo>/build
../sysdeps/unix/sysv/linux/arm/le
../sysdeps/unix/sysv/linux/arm
../sysdeps/arm/nptl
../sysdeps/unix/sysv/linux/include
../sysdeps/unix/sysv/linux
../sysdeps/nptl
../sysdeps/pthread
../sysdeps/gnu
../sysdeps/unix/inet
../sysdeps/unix/sysv
../sysdeps/unix/arm
../sysdeps/unix
../sysdeps/posix
../sysdeps/arm/le/armv6
../sysdeps/arm/armv6
../sysdeps/arm/le/nofpu
../sysdeps/arm/nofpu
../sysdeps/ieee754/soft-fp
../sysdeps/arm/le
../sysdeps/arm/include
../sysdeps/arm
../sysdeps/wordsize-32
../sysdeps/ieee754/flt-32
../sysdeps/ieee754/dbl-64
../sysdeps/ieee754
../sysdeps/generic
..
../libio
.
/<pathTo>/toolchain/lib/clang/21/include
/usr/local/include
/usr/include
End of search list.
In file included from ../sysdeps/unix/sysv/linux/arm/sysdep.S:18:
In file included from ../sysdeps/unix/sysv/linux/arm/sysdep.h:23:
In file included from ../sysdeps/unix/arm/sysdep.h:19:
../sysdeps/arm/sysdep.h:49:4: error: unknown arm architecture
49 | # error unknown arm architecture
| ^
../sysdeps/arm/sysdep.h:53:5: error: '__ARM_ARCH' is not defined,
evaluates to 0 [-Werror,-Wundef]
53 | #if __ARM_ARCH > 4 || defined (__ARM_ARCH_4T__)
| ^
../sysdeps/arm/sysdep.h:56:5: error: '__ARM_ARCH' is not defined,
evaluates to 0 [-Werror,-Wundef]
56 | #if __ARM_ARCH > 4
| ^
../sysdeps/arm/sysdep.h:59:5: error: '__ARM_ARCH' is not defined,
evaluates to 0 [-Werror,-Wundef]
59 | #if __ARM_ARCH > 6 || defined (__ARM_ARCH_6K__) || defined
(__ARM_ARCH_6ZK__)
| ^
../sysdeps/arm/sysdep.h:62:5: error: '__ARM_ARCH' is not defined,
evaluates to 0 [-Werror,-Wundef]
62 | #if __ARM_ARCH > 6 || defined (__ARM_ARCH_6T2__)
| ^
5 errors generated.
make[2]: *** [/<pathTo>/build/sysd-rules:41:
/<pathTo>/build/csu/sysdep.o] Error 1
make[2]: Leaving directory '/<pathTo>/glibc/csu'
make[1]: *** [Makefile:484: csu/subdir_lib] Error 2
make[1]: Leaving directory '/<pathTo>/glibc'
make: *** [Makefile:20: all] Error 2
```
You can see `-triple x86_64-unknown-linux-gnu` being used even though
`--target=armv6-pc-linux-gnueabi` is set in CFLAGS.
I didn't notice any ASFLAGS in `--help`, but set it anyway with no
difference in the result.
I see mention of `ASFLAGS_config` in `configure.ac`
In `config.make`, I see:
```
cflags-cpu =
asflags-cpu =
CFLAGS = <my stuff>
ASFLAGS-config = -Wa,--noexecstack
```
That seems relevant/important that the *-cpu isn't set, and my
`ASFLAGS` wasn't used.
More information about the Libc-help
mailing list