[PATCH 2/2] Avoid adding duplicated symbols into static libraries
Adhemerval Zanella
adhemerval.zanella@linaro.org
Tue Mar 30 19:47:45 GMT 2021
On 11/02/2021 07:19, Siddhesh Poyarekar via Libc-alpha wrote:
> Some math functions (such as __isnan*) are built into both libm and
> libc because they are needed in libc. The symbol gets exported from
> libc.so and not libm.so, because of which dynamic linking works fine;
> the symbols are always resolved from libc.so and libm.so uses its
> internal copy of the same function if needed.
>
> When linking statically though, the libm variants get used throughout
> because the symbols are exported in both archives and libm.a is
> searched first.
>
> This patch removes these duplicate objects from the libm.a archive so
> that programs always link to libc in both, the static and dynamic
> case. The difference this will cause is that libm uses of these
> functions will start using the libc versions in the !SHARED case.
> This is harmless at the moment because the objects are identical
> except for their names.
>
> Some of these duplicates could be removed from libm.so too, but I
> avoided that in the interest of retaining an internal reference if at
> all those functions get used within libm in future.
> ---
> math/Makefile | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/math/Makefile b/math/Makefile
> index 687aa5d510..c4cc1b2068 100644
> --- a/math/Makefile
> +++ b/math/Makefile
> @@ -196,6 +196,9 @@ calls = s_isinfF s_isnanF s_finiteF s_copysignF s_modfF s_scalbnF s_frexpF \
> gen-calls = s_ldexpF
> generated += $(foreach s,.c .S,$(call type-foreach, $(calls:s_%=m_%$(s))))
> routines = $(call type-foreach, $(calls))
> +# The $(calls) that are shared between libm and libc are not included in static
> +# libm so the symbols end up in exactly one place.
> +libm-shared-only-routines = $(call type-foreach, $(calls:s_%=m_%))
>
> ifeq ($(build-mathvec),yes)
> # We need to install libm.so and libm.a as linker scripts
>
This broke powerpc64le static math tests:
powerpc64le-linux-gnu]$ make math/tests
[...]
/home/azanella/toolchain/install/compilers/powerpc64le-linux-gnu/bin/powerpc64le-glibc-linux-gnu-gcc -nostdlib -nostartfiles -static -o /home/azanella/glibc/build/powerpc64le-linux-gnu/math/test-signgam-uchar-static /home/azanella/glibc/build/powerpc64le-linux-gnu/csu/crt1.o /home/azanella/glibc/build/powerpc64le-linux-gnu/csu/crti.o `/home/azanella/toolchain/install/compilers/powerpc64le-linux-gnu/bin/powerpc64le-glibc-linux-gnu-gcc --print-file-name=crtbeginT.o` /home/azanella/glibc/build/powerpc64le-linux-gnu/math/test-signgam-uchar-static.o /home/azanella/glibc/build/powerpc64le-linux-gnu/support/libsupport_nonshared.a /home/azanella/glibc/build/powerpc64le-linux-gnu/math/libm.a -Wl,--start-group /home/azanella/glibc/build/powerpc64le-linux-gnu/libc.a -lgcc -lgcc_eh -Wl,--end-group `/home/azanella/toolchain/install/compilers/powerpc64le-linux-gnu/bin/powerpc64le-glibc-linux-gnu-gcc --print-file-name=crtend.o` /home/azanella/glibc/build/powerpc64le-linux-gnu/csu/crtn.o
/home/azanella/toolchain/install/compilers/powerpc64le-linux-gnu/lib/gcc/powerpc64le-glibc-linux-gnu/10.2.1/../../../../powerpc64le-glibc-linux-gnu/bin/ld: /home/azanella/glibc/build/powerpc64le-linux-gnu/math/libm.a(e_logf128.o): in function `__ieee754_logf128_power8':
/home/azanella/glibc/glibc-git/math/../sysdeps/ieee754/float128/../ldbl-128/e_logl.c:217: undefined reference to `__frexpf128_power8'
/home/azanella/toolchain/install/compilers/powerpc64le-linux-gnu/lib/gcc/powerpc64le-glibc-linux-gnu/10.2.1/../../../../powerpc64le-glibc-linux-gnu/bin/ld: /home/azanella/glibc/build/powerpc64le-linux-gnu/math/libm.a(s_log1pf128.o): in function `__log1pf128_power8':
/home/azanella/glibc/glibc-git/math/../sysdeps/ieee754/float128/../ldbl-128/s_log1pl.c:166: undefined reference to `__frexpf128_power8'
collect2: error: ld returned 1 exit status
make[2]: *** [../Rules:264: /home/azanella/glibc/build/powerpc64le-linux-gnu/math/test-signgam-uchar-static] Error 1
More information about the Libc-alpha
mailing list