-static-libgcc vs. -Wl,-Bstatic -lgcc

Volker Simonis volker.simonis at gmail.com
Fri Jun 12 17:50:54 UTC 2015


Hi,

while porting the new HS build to linux/ppc64 I saw that we are now setting
some link options unconditionally trough the $(LIBCXX) variable from the
top-level spec.gmk (whihc is good :). With the default configuration, this
variable will contain the value "-Wl,-Bstatic -lstdc++ -lgcc" but this can
be changed by setting --with-stdc++lib=dynamic. Nevertheless, we still set
"-static-libgcc" unconditionally in Common.gmk

Now there's one think I don't understand (and which isn't related to
ppc64). I thought "-static-libgcc" and "-Wl,-Bstatic -lgcc" should be
equivalent options, but apparently they aren’t. For the new build we use
"-Wl,-Bstatic -lstdc++ -lgcc" and additionally set "-static-libgcc". I
thought it should be possible to remove the "-static-libgcc" setting from
the new HS build system (because the question static/dynamic linking of
libstdc++ should be decided at configure time with the --with-stdc++lib
option. But this will produce a different results.

Summing it up:

old build:
-static-libgcc -Wl,-Bstatic -lstdc++       -Wl,-Bdynamic -lm -ldl -lpthread

is the same as new build:
-static-libgcc -Wl,-Bstatic -lstdc++ -lgcc -Wl,-Bdynamic -lm -ldl -lpthread

but not the same as the new build without "-static-libgcc":
               -Wl,-Bstatic -lstdc++ -lgcc -Wl,-Bdynamic -lm -ldl -lpthread
which dynamically links ibgcc_s.so.1 (at least on x86_64)

It turns out (if you run gcc with '-v') that with "-static-libgcc" the
command line expands to:
-lgcc -lgcc_eh -lc -lgcc -lgcc_eh
which will all be statically linked.

while without "-static-libgcc" it expands to:
-lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s
--no-as-needed
and dynamically links libgcc_s.so.1 (at least on x86_64 but not on ppc64).

The problem is that "libgcc_s.so.1" is only available as shared library so
we can't statically link it even if we want.

So should we move "-static-libgcc" to libraries.m4 to the place where we
detect whether to use  --with-stdc++lib=static/dynamic because we
apparently can't live without it if we still want to link libgcc statically?

Regards,
Volker


More information about the build-infra-dev mailing list