Why -static-libgcc? (Or: Do we need a build-time libc.so linker script?)
Florian Weimer
fweimer@redhat.com
Wed Nov 24 22:16:15 GMT 2021
We have:
define build-shlib-helper
$(LINK.o) -shared -static-libgcc -Wl,-O1 $(sysdep-LDFLAGS) \
$(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(rtld-LDFLAGS) \
$(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
$(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
-Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
$(LDFLAGS.so) $(LDFLAGS-lib.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
-L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
endef
And:
define build-module-helper
$(LINK.o) -shared -static-libgcc $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
$(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
-B$(csu-objpfx) $(load-map-file) \
$(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
-L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
endef
Why do we use -static-libgcc? Doesn't this invalidate some of our
tests, because users do not generally build with -static-libgcc?
Background:
I'm dealing with an issue caused by a symbol reference from libgcc_eh.a
to ld.so. We do not link test modules against a libc.so linker script,
instead we use:
link-libc-args = -Wl,--start-group \
$(libc-for-link) \
$(common-objpfx)libc_nonshared.a \
-Wl,--as-needed $(elf-objpfx)ld.so -Wl,--no-as-needed \
-Wl,--end-group
I believe this is the reason why libgcc_eh.a can't reference ld.so: The
initial ld.so gets droped due to --as-needed, and the -lc after
libgcc_eh.a does not supply a second copy because it ends up linking
against the in-tree libc.so, which just the ELF object.
Dropping -static-libgcc seems to make this work.
An alternative would be to use a libc.so linker script during the glibc
as build (not just after installtion). This should bring back the ld.so
reference with -lc after libgcc_eh.a.
Thanks,
Florian
More information about the Libc-alpha
mailing list