https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71021
Bug ID: 71021 Summary: [libatomic testsuite] Test program compilation fail (missing -pthread flag) Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: testsuite Assignee: unassigned at gcc dot gnu.org Reporter: romain.geissler at amadeus dot com Target Milestone: --- Created attachment 38452 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38452&action=edit Add "-pthread" flag when compiling libatomic test programs Hi, I am currently building up the Amadeus toolchain and I have trouble running the testsuite with libatomic. All test fails because the compilation of the test program fails. This happens in the specific case of our own toolchain because we build and install glibc/binutils/gcc in a custom prefix "/opt/1A/toolchain/x86_64-2.6.32-v2-6/". It also fails since the default system glibc (found in /lib) is different from the Amadeus toolchain glibc against which we link both binutils and glibc. The toolchain glibc is glibc 2.23 while the system glibc is glibc This happens on Linux x86_64, using gcc 4.9.4. I haven't checked yet if it also happens with gcc 6 but I will check soon. When I run: make check-target-libatomic RUNTESTFLAGS="c.exp=atomic-compare-exchange-1.c -v -v" I can see: Executing on host: /workdir/build/final-system/gcc-build/gcc/xgcc -B/workdir/build/final-system/gcc-build/gcc/ /workdir/src/gcc-4.9.4/libatomic/testsuite/libatomic.c/atomic-compare-exchange-1.c -B/workdir/build/final-system/gcc-build/x86_64-1a-linux-gnu/./libatomic/ -I/workdir/build/final-system/gcc-build/x86_64-1a-linux-gnu/./libatomic -I/workdir/src/gcc-4.9.4/libatomic/testsuite/.. -fmessage-length=0 -fno-inline-atomics -g -L/workdir/build/final-system/gcc-build/x86_64-1a-linux-gnu/./libatomic/.libs -latomic -lm -o ./atomic-compare-exchange-1.exe (timeout = 300) pid is 23832 -23832 waitres is 23832 exp8 0 1 close result is 23832 exp8 0 1 output is /lib/x86_64-linux-gnu/libpthread.so.0: undefined reference to `h_errno@GLIBC_PRIVATE' collect2: error: ld returned 1 exit status If I manually run the link phase with "-Wl,-v,-t" I have this: /workdir/build/final-system/gcc-build/gcc/collect-ld -plugin /workdir/build/final-system/gcc-build/gcc/liblto_plugin.so -plugin-opt=/workdir/build/final-system/gcc-build/gcc/lto-wrapper -plugin-opt=-fresolution=/tmp/ccSu6fuN.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /opt/1A/toolchain/x86_64-2.6.32-v2-6/lib64/ld-linux-x86-64.so.2 -o ./atomic-compare-exchange-1.exe /opt/1A/toolchain/x86_64-2.6.32-v2-6/lib/../lib64/crt1.o /opt/1A/toolchain/x86_64-2.6.32-v2-6/lib/../lib64/crti.o /workdir/build/final-system/gcc-build/gcc/crtbegin.o -L/workdir/build/final-system/gcc-build/x86_64-1a-linux-gnu/./libatomic/.libs -L/workdir/build/final-system/gcc-build/gcc -L/workdir/build/final-system/gcc-build/x86_64-1a-linux-gnu/./libatomic -L/opt/1A/toolchain/x86_64-2.6.32-v2-6/lib/../lib64 -L/opt/1A/toolchain/x86_64-2.6.32-v2-6/lib /tmp/cccwFSDA.o -latomic -lm -v -t -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /workdir/build/final-system/gcc-build/gcc/crtend.o /opt/1A/toolchain/x86_64-2.6.32-v2-6/lib/../lib64/crtn.o GNU ld (GNU Binutils) 2.26.0.20160501 /opt/1A/toolchain/x86_64-2.6.32-v2-6/x86_64-1a-linux-gnu/bin/ld: mode elf_x86_64 /opt/1A/toolchain/x86_64-2.6.32-v2-6/lib/../lib64/crt1.o /opt/1A/toolchain/x86_64-2.6.32-v2-6/lib/../lib64/crti.o /workdir/build/final-system/gcc-build/gcc/crtbegin.o /tmp/cccwFSDA.o -latomic (/workdir/build/final-system/gcc-build/x86_64-1a-linux-gnu/./libatomic/.libs/libatomic.so) /opt/1A/toolchain/x86_64-2.6.32-v2-6/lib/libm.so.6/opt/1A/toolchain/x86_64-2.6.32-v2-6/lib/libmvec.so.1 /opt/1A/toolchain/x86_64-2.6.32-v2-6/lib/libmvec.so.1 -lgcc_s (/workdir/build/final-system/gcc-build/gcc/libgcc_s.so) /opt/1A/toolchain/x86_64-2.6.32-v2-6/lib/libc.so.6 (/opt/1A/toolchain/x86_64-2.6.32-v2-6/lib/libc_nonshared.a)elf-init.oS /opt/1A/toolchain/x86_64-2.6.32-v2-6/lib/ld-linux-x86-64.so.2 /opt/1A/toolchain/x86_64-2.6.32-v2-6/lib/ld-linux-x86-64.so.2 -lgcc_s (/workdir/build/final-system/gcc-build/gcc/libgcc_s.so) /workdir/build/final-system/gcc-build/gcc/crtend.o /opt/1A/toolchain/x86_64-2.6.32-v2-6/lib/../lib64/crtn.o /lib/x86_64-linux-gnu/libpthread.so.0: undefined reference to `h_errno@GLIBC_PRIVATE' /opt/1A/toolchain/x86_64-2.6.32-v2-6/x86_64-1a-linux-gnu/bin/ld: link errors found, deleting executable `./atomic-compare-exchange-1.exe' collect2: error: ld returned 1 exit status So it clearly shows there is a conflict between the glibc in /opt/1A/toolchain/x86_64-2.6.32-v2-6/ and the one in /lib. The linker uses by default the one in /lib because libatomic depends on libpthread, but the test binary was *NOT* built with either "-pthread" or "-lpthread" while it should. This is an issue inside the libatomic test framework. I have fixed it using the attached patch (by adding "-pthread" to "ALWAYS_CFLAGS" in "libatomic/testsuite/lib/libatomic.exp". However I am not sure this patch is correct for all different target that gcc is compatible with. Cheers, Romain