• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

C/C++ Why do we need libgcc_s ?


New Member

Thanks: 4
Messages: 8

I am new to the forum so first of all hello to everyone and thanks for reading.
I checked threads but could not find any answering the question hence this post.

My concerns is related to the fact that running ldd against every (here trivial "Hello, world" C++ executable) would yield:
libc++.so.1 => /usr/lib/libc++.so.1 (0x800824000)
libcxxrt.so.1 => /lib/libcxxrt.so.1 (0x800aeb000)
libm.so.5 => /lib/libm.so.5 (0x800d09000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x800f34000)
libc.so.7 => /lib/libc.so.7 (0x801142000)
Obviously the executable is dependent on libgcc_s.

However if one check at LLVM Toolkit page there can be found that (bold by me):
If using libc++ and/or libc++abi, you may need to configure them to use compiler-rt rather than libgcc_s by passing -DLIBCXX_USE_COMPILER_RT=YESand/or -DLIBCXXABI_USE_COMPILER_RT=YES to cmake. Otherwise, you may end up with both runtime libraries linked into your program (this is typically harmless, but wasteful).
Of course here only std C++ is LLVM and C++ ABI is not a LLVM's libc++abi but rather PathScale's libcxxrt, however for the low level ABI the PathScale's libcxxrt does not strictly require libgcc_s:
Exception handling requires the assistance of a stack-unwinding library implementing the low-level parts of the ABI. Either libgcc_s or libunwind should work for this purpose.
I assume here PathScale referred to their libunwind not to the LLVM's one, however beside the fact that PathScale libunwind port for FreeBSD was done on v8 (still gcc?) I could not see any dependency on gcc parts, like libgcc_s for libunwind nor libcxxrt nor libc++.

So long story short - is the libgcc_s really needed, or it is there because system compiler was compiled without using alternative implementation and thus all binaries must inherit that?