Description of problem: After upgrading glibc to version 2.31 clang fails to link an app using exp2/pow/etc. functions from libm when -ffast-math is used and optimizations are turned off (-O0, the default). This applies to both clang-9 and clang-10; gcc doesn't suffer from this issue. Version-Release number of selected component (if applicable): clang-9.0.0-1.fc31 or clang-10.0.0-0.1.rc1.fc32 glibc-2.31-1.fc32 How reproducible: always Steps to Reproduce: $ cat > test.c << EOF #include <stdio.h> #include <math.h> int main(void) { printf("Hello %lf, %lf\n", exp2(2.0), pow(2.0, 3.0)); return 0; } EOF $ clang -o test test.c -lm -ffast-math Actual results: ## Without optimizations (clang-9) $ clang -o test test.c -lm -ffast-math /usr/bin/ld: /tmp/test-0dc25f.o: in function `main': test.c:(.text+0x18): undefined reference to `__exp2_finite' /usr/bin/ld: test.c:(.text+0x38): undefined reference to `__pow_finite' clang-9: error: linker command failed with exit code 1 (use -v to see invocation) ## Without optimizations (clang-10) $ clang -o test test.c -lm -ffast-math /usr/bin/ld: /tmp/test-e3abbe.o: in function `main': test.c:(.text+0x18): undefined reference to `__exp2_finite' /usr/bin/ld: test.c:(.text+0x38): undefined reference to `__pow_finite' clang-10: error: linker command failed with exit code 1 (use -v to see invocation) ## With optimizations (-O1 and higher, both clang-9 and clang-10) $ clang -o test test.c -lm -ffast-math -O1 $ echo $? 0 $ ./test Hello 4.000000, 8.000000 Expected results: Compilation should succeed. ## Without optimizations (gcc-10) $ gcc -o test test.c -lm -ffast-math $ echo $? 0 $ ./test Hello 4.000000, 8.000000 Additional info: The issue is not present with glibc-2.30-5.fc31. The same issue appears on Arch Linux with clang-9 and glibc-2.31-1. ## clang-10 verbose output $ clang -o test test.c -lm -ffast-math -v clang version 10.0.0 (Fedora 10.0.0-0.1.rc1.fc32) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /usr/bin Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/9 Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9 Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/9 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Selected multilib: .;@m64 (in-process) "/usr/bin/clang-10" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.c -mrelocation-model static -mthread-model posix -mframe-pointer=all -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -v -resource-dir /usr/lib64/clang/10.0.0 -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/10.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir / -ferror-limit 19 -fmessage-length 0 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -faddrsig -o /tmp/test-5d05c7.o -x c test.c clang -cc1 version 10.0.0 based upon LLVM 10.0.0 default target x86_64-unknown-linux-gnu ignoring nonexistent directory "/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include /usr/lib64/clang/10.0.0/include /usr/include End of search list. "/usr/bin/ld" --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o test /usr/bin/../lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crt1.o /usr/bin/../lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crti.o /usr/bin/../lib/gcc/x86_64-redhat-linux/9/crtbegin.o /usr/bin/../lib/gcc/x86_64-redhat-linux/9/crtfastmath.o -L/usr/bin/../lib/gcc/x86_64-redhat-linux/9 -L/usr/bin/../lib/gcc/x86_64-redhat-linux/9/../../../../lib64 -L/usr/bin/../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/bin/../lib/gcc/x86_64-redhat-linux/9/../../.. -L/usr/bin/../lib -L/lib -L/usr/lib /tmp/test-5d05c7.o -lm -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/bin/../lib/gcc/x86_64-redhat-linux/9/crtend.o /usr/bin/../lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crtn.o /usr/bin/ld: /tmp/test-5d05c7.o: in function `main': test.c:(.text+0x18): undefined reference to `__exp2_finite' /usr/bin/ld: test.c:(.text+0x38): undefined reference to `__pow_finite' clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
Since https://sourceware.org/git/?p=glibc.git;a=commit;h=7bdb921d70bf9f93948e2e311fef9ef439314e41, glibc no longer provides acces to these symbols, this is a bug in upstream clang. I'll provide a patch upstream.
Upstream review: https://reviews.llvm.org/D74712
Fixed upstream as of 6d15c4deab51498b70825fb6cefbbfe8f3d9bdcf
Fixed in llvm-10.0.0-0.2.rc2.fc33