Why -static-libgcc? (Or: Do we need a build-time libc.so linker script?)

Joseph Myers joseph@codesourcery.com
Wed Nov 24 23:19:29 GMT 2021


On Wed, 24 Nov 2021, Florian Weimer via Libc-alpha wrote:

> Why do we use -static-libgcc?  Doesn't this invalidate some of our
> tests, because users do not generally build with -static-libgcc?

There is a principle that (a) building glibc should not require a GCC 
built with shared libgcc (to avoid circular dependencies, because building 
shared libgcc requires having first built shared libc) and (b) if you 
build glibc with a static-only C-only inhibit_libc GCC, the resulting 
stripped binaries should be identical to those you get from a longer 
alternating sequence of GCC and glibc builds (in particular, the binaries 
should be identical to those you get from building with shared libgcc 
available) (note that this requires appropriate use of 
--with-glibc-version when configuring that first GCC in some cases - and 
that, while I verified the "identical stripped binaries" property when 
implementing --with-glibc-version and related glibc build fixes, I haven't 
checked it recently and it's possible it could have regressed since 2013).

So building installed shared libraries needs to avoid any dependence on 
shared libgcc (unless such dependence is handled in a way not requiring 
shared libgcc to be available at build time - note that we know the 
libgcc_s SONAME via shlib-versions, so if desired we could insert a 
DT_NEEDED for it without using the real library, by building a dummy 
shared library to link against or otherwise).

Testing is not expected to work fully with a static-only C-only 
inhibit_libc GCC, so using the real shared libgcc in linking tests should 
be OK (and desirable when the tests correspond to normal user code that 
would end up linking with shared libgcc, on the general principle of 
testing something as close as possible to how people would use installed 
glibc).

-- 
Joseph S. Myers
joseph@codesourcery.com


More information about the Libc-alpha mailing list