Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove libgcc_s dependency from gcc

Tags:

linux

gcc

I have installed gcc-7.1.0 from source based on: https://gcc.gnu.org/install/index.html to use a newer gcc.

The compiled binaries have an extra dependency with libgcc:

$ ldd a.out
        linux-vdso.so.1 =>  (0x00007fffd85fd000)
        librt.so.1 => /lib64/librt.so.1 (0x000000365b400000)
        libdl.so.2 => /lib64/libdl.so.2 (0x000000365a800000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x000000301ae00000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x000000365b000000)
        libc.so.6 => /lib64/libc.so.6 (0x000000365a000000)
        /lib64/ld-linux-x86-64.so.2 (0x0000003659c00000)

I didn't choose any particular configuration options (other than --prefix) and installed with defaults. Looking at the config.log, it appears that configuration decided it couldn't do so by default. Relevant parts:

configure:5038: checking whether g++ accepts -static-libstdc++ -static-libgcc
configure:5055: g++ -o conftest -g -O2   -static-libstdc++ -static-libgcc conftest.cpp  >&5
g++: unrecognized option '-static-libstdc++'
conftest.cpp:11:2: error: #error -static-libstdc++ not implemented
configure:5055: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| /* end confdefs.h.  */
|
| #if (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
| #error -static-libstdc++ not implemented
| #endif
| int main() {}
configure:5059: result: no

(The g++ available - used above - is a bit old: g++ 4.1.2 if that's relevant).

I am compiling only C code. So, if there's no static linking support -static-libstdc++, that's not an issue. But I don't understand why libgcc is tied with -static-libstdc++.

libgcc_s.so.1 isn't always available on all machines. While I can install it, I don't want this extra requirement on my customers. Is there any way I can remove this dependency?

While using -static-libgcc switch does get remove libgcc_s.so.1, I am looking for a way to let gcc itself do this. If that means re-configuring and reinstalling gcc, it is fine by me.

P.S.: I also have to follow the workarounds from here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61955 as the machine is a bit old.

like image 401
P.P Avatar asked Mar 04 '26 02:03

P.P


1 Answers

But I don't understand why libgcc is tied with -static-libstdc++.

It isn't. That configure test controls whether the intermediate compiler during bootstrap is linked statically or dynamically, it has nothing to do with the executables produced by the final GCC.

libgcc_s.so.1 isn't always available on all machines. While I can install it, I don't want this extra requirement on my customers. Is there any way I can remove this dependency?

IMHO it should be installed anyway, lots of packages depend on it.

The executables depend on libgcc because they use something from that library. Link with -static-libgcc to use libgcc.a instead of libgcc_s.so. If you want that to happen automatically either install a wrapper script around your new GCC that always adds it to the command-line arguments, or use a custom specs file that always adds that option, e.g. by configuring GCC with something like:

--with-specs=%{!shared-libgcc:-static-libgcc}

This should mean that -static-libgcc is always used implicitly unless -shared-libgcc is explicitly provided on the command line. I haven't tested it though.

like image 72
Jonathan Wakely Avatar answered Mar 06 '26 17:03

Jonathan Wakely