atomic_ops_stack.c:142: undefined reference to `AO_pause'
xantares opened this issue · 4 comments
hello,
I encountered a link error to AO_pause in libatomic_ops_gpl on mingw-w64 for x86_64 target (i686 is fine):
libtool: link: x86_64-w64-mingw32-gcc -shared .libs/atomic_ops_stack.o .libs/atomic_ops_malloc.o -O2 -g -o .libs/libatomic_ops_gpl-1.dll -Wl,--enable-auto-image-base -Xlinker --out-implib -Xlinker .libs/libatomic_ops_gpl.dll.a
.libs/atomic_ops_stack.o: In function `AO_stack_pop_explicit_aux_acquire':
/home/xantares/projects/aur-scripts/mingw-w64-libatomic_ops/src/libatomic_ops-libatomic_ops-7_4_2/build-x86_64-w64-mingw32/src/../../src/atomic_ops_stack.c:142: undefined reference to `AO_pause'
collect2: error: ld returned 1 exit status
Makefile:547: recipe for target 'libatomic_ops_gpl.la' failed
If I add atomic_ops.c where AO_pause is defined to the list of sources fils of libatomic_ops_gpl it goes fine:
libatomic_ops_gpl_la_SOURCES = atomic_ops.c atomic_ops_stack.c atomic_ops_malloc.c
here's the full log:
configure: WARNING: you should use --build, --host, --target
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-w64-mingw32
checking target system type... x86_64-w64-mingw32
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for x86_64-w64-mingw32-strip... x86_64-w64-mingw32-strip
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking for style of include used by make... GNU
checking for x86_64-w64-mingw32-gcc... x86_64-w64-mingw32-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.exe
checking for suffix of executables... .exe
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether x86_64-w64-mingw32-gcc accepts -g... yes
checking for x86_64-w64-mingw32-gcc option to accept ISO C89... none needed
checking whether x86_64-w64-mingw32-gcc understands -c and -o together... yes
checking dependency style of x86_64-w64-mingw32-gcc... gcc3
checking dependency style of x86_64-w64-mingw32-gcc... gcc3
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by x86_64-w64-mingw32-gcc... /usr/x86_64-w64-mingw32/bin/ld
checking if the linker (/usr/x86_64-w64-mingw32/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/x86_64-w64-mingw32-nm -B
checking the name lister (/usr/bin/x86_64-w64-mingw32-nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-unknown-linux-gnu file names to x86_64-w64-mingw32 format... func_convert_file_nix_to_w32
checking how to convert x86_64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/x86_64-w64-mingw32/bin/ld option to reload object files... -r
checking for x86_64-w64-mingw32-objdump... x86_64-w64-mingw32-objdump
checking how to recognize dependent libraries... file_magic ^x86 archive import|^x86 DLL
checking for x86_64-w64-mingw32-dlltool... x86_64-w64-mingw32-dlltool
checking how to associate runtime and link libraries... func_cygming_dll_for_implib
checking for x86_64-w64-mingw32-ar... x86_64-w64-mingw32-ar
checking for archiver @FILE support... @
checking for x86_64-w64-mingw32-strip... (cached) x86_64-w64-mingw32-strip
checking for x86_64-w64-mingw32-ranlib... x86_64-w64-mingw32-ranlib
checking command to parse /usr/bin/x86_64-w64-mingw32-nm -B output from x86_64-w64-mingw32-gcc object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for x86_64-w64-mingw32-mt... no
checking for mt... no
checking if : is a manifest tool... no
checking how to run the C preprocessor... x86_64-w64-mingw32-gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if x86_64-w64-mingw32-gcc supports -fno-rtti -fno-exceptions... no
checking for x86_64-w64-mingw32-gcc option to produce PIC... -DDLL_EXPORT -DPIC
checking if x86_64-w64-mingw32-gcc PIC flag -DDLL_EXPORT -DPIC works... yes
checking if x86_64-w64-mingw32-gcc static flag -static works... yes
checking if x86_64-w64-mingw32-gcc supports -c -o file.o... yes
checking if x86_64-w64-mingw32-gcc supports -c -o file.o... (cached) yes
checking whether the x86_64-w64-mingw32-gcc linker (/usr/x86_64-w64-mingw32/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... yes
checking dynamic linker characteristics... Win32 ld.exe
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking for stdlib.h... (cached) yes
checking for unistd.h... (cached) yes
checking for sys/param.h... yes
checking for getpagesize... yes
checking for working mmap... no
checking for PIC compiler flag... "<none>"
checking for gcc -Wextra... yes
checking for pthread_self in -lpthread... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating doc/Makefile
config.status: creating src/Makefile
config.status: creating tests/Makefile
config.status: creating pkgconfig/atomic_ops.pc
config.status: creating pkgconfig/atomic_ops-uninstalled.pc
config.status: creating src/config.h
config.status: executing depfiles commands
config.status: executing libtool commands
config.status: executing default commands
Making all in src
make[1]: Entering directory '/home/xantares/projects/aur-scripts/mingw-w64-libatomic_ops/src/libatomic_ops-libatomic_ops-7_4_2/build-x86_64-w64-mingw32/src'
make all-am
make[2]: Entering directory '/home/xantares/projects/aur-scripts/mingw-w64-libatomic_ops/src/libatomic_ops-libatomic_ops-7_4_2/build-x86_64-w64-mingw32/src'
/bin/sh ../libtool --tag=CC --mode=compile x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I../src -I../../src -Wall -Wextra -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 -MT atomic_ops.lo -MD -MP -MF .deps/atomic_ops.Tpo -c -o atomic_ops.lo ../../src/atomic_ops.c
/bin/sh ../libtool --tag=CC --mode=compile x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I../src -I../../src -Wall -Wextra -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 -MT atomic_ops_stack.lo -MD -MP -MF .deps/atomic_ops_stack.Tpo -c -o atomic_ops_stack.lo ../../src/atomic_ops_stack.c
libtool: compile: x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I../src -I../../src -Wall -Wextra -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 -MT atomic_ops_stack.lo -MD -MP -MF .deps/atomic_ops_stack.Tpo -c ../../src/atomic_ops_stack.c -DDLL_EXPORT -DPIC -o .libs/atomic_ops_stack.o
libtool: compile: x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I../src -I../../src -Wall -Wextra -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 -MT atomic_ops.lo -MD -MP -MF .deps/atomic_ops.Tpo -c ../../src/atomic_ops.c -DDLL_EXPORT -DPIC -o .libs/atomic_ops.o
libtool: compile: x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I../src -I../../src -Wall -Wextra -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 -MT atomic_ops_stack.lo -MD -MP -MF .deps/atomic_ops_stack.Tpo -c ../../src/atomic_ops_stack.c -o atomic_ops_stack.o >/dev/null 2>&1
mv -f .deps/atomic_ops_stack.Tpo .deps/atomic_ops_stack.Plo
/bin/sh ../libtool --tag=CC --mode=compile x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I../src -I../../src -Wall -Wextra -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 -MT atomic_ops_malloc.lo -MD -MP -MF .deps/atomic_ops_malloc.Tpo -c -o atomic_ops_malloc.lo ../../src/atomic_ops_malloc.c
libtool: compile: x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I../src -I../../src -Wall -Wextra -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 -MT atomic_ops_malloc.lo -MD -MP -MF .deps/atomic_ops_malloc.Tpo -c ../../src/atomic_ops_malloc.c -DDLL_EXPORT -DPIC -o .libs/atomic_ops_malloc.o
libtool: compile: x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I../src -I../../src -Wall -Wextra -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 -MT atomic_ops_malloc.lo -MD -MP -MF .deps/atomic_ops_malloc.Tpo -c ../../src/atomic_ops_malloc.c -o atomic_ops_malloc.o >/dev/null 2>&1
mv -f .deps/atomic_ops_malloc.Tpo .deps/atomic_ops_malloc.Plo
/bin/sh ../libtool --tag=CC --mode=link x86_64-w64-mingw32-gcc -Wall -Wextra -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 -version-info 1:3:0 -no-undefined -o libatomic_ops_gpl.la -rpath /usr/x86_64-w64-mingw32/lib atomic_ops_stack.lo atomic_ops_malloc.lo
libtool: link: x86_64-w64-mingw32-gcc -shared .libs/atomic_ops_stack.o .libs/atomic_ops_malloc.o -O2 -g -o .libs/libatomic_ops_gpl-1.dll -Wl,--enable-auto-image-base -Xlinker --out-implib -Xlinker .libs/libatomic_ops_gpl.dll.a
.libs/atomic_ops_stack.o: In function `AO_stack_pop_explicit_aux_acquire':
/home/xantares/projects/aur-scripts/mingw-w64-libatomic_ops/src/libatomic_ops-libatomic_ops-7_4_2/build-x86_64-w64-mingw32/src/../../src/atomic_ops_stack.c:142: undefined reference to `AO_pause'
collect2: error: ld returned 1 exit status
Makefile:547: recipe for target 'libatomic_ops_gpl.la' failed
make[2]: *** [libatomic_ops_gpl.la] Error 1
make[2]: *** Waiting for unfinished jobs....
libtool: compile: x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I../src -I../../src -Wall -Wextra -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 -MT atomic_ops.lo -MD -MP -MF .deps/atomic_ops.Tpo -c ../../src/atomic_ops.c -o atomic_ops.o >/dev/null 2>&1
mv -f .deps/atomic_ops.Tpo .deps/atomic_ops.Plo
make[2]: Leaving directory '/home/xantares/projects/aur-scripts/mingw-w64-libatomic_ops/src/libatomic_ops-libatomic_ops-7_4_2/build-x86_64-w64-mingw32/src'
Makefile:459: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/home/xantares/projects/aur-scripts/mingw-w64-libatomic_ops/src/libatomic_ops-libatomic_ops-7_4_2/build-x86_64-w64-mingw32/src'
Makefile:473: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1
I see the issue: AO_pause is required for AO_stack implementation if double-wide CAS is not available on the target (generic x86_64 in this case); unlike .so library, when making a dll (libatomic_ops_gpl) one all symbols should be defined (e.g.imported from other library), so -llibatomic_ops should be passed to libtool link. Adding file with AO_pause to libatomic_ops_gpl should solve this issue but should also create issue of duplicated symbols during linking in some build variants (not to mention duplication of code).
The proper fix is to make libtool to pass -llibatomic_ops during libatomic_ops_gpl linking; src/Makefile.am already contains "libatomic_ops_gpl_la_LIBADD = libatomic_ops.la" but it turns out that it does not help.
I don't have immediate solution of this (how to specify the dependency). If you know how to fix it, please contribute.
PS. Potential quick workaround for you is to build the library for a more recent CPU, e.g. CFLAGS=-march=core2