View mode: basic / threaded / horizontal-split · Log in · Help
December 17, 2004
Why shared-libgcc ?
Q: Why does GDC add "-shared-libgcc"
to the default command-line options ?


I can understand why e.g. C++ does it,
since it's needed for the exceptions.
But does D really utilize "libgcc_s" ?

All I know is that the D binaries end
up with a "libgcc_s.so.1" dependancy
that I need to take care of at run-time...


I thought it would better to change the
default to -static-libgcc, and then one
can add -shared-libgcc - if it is needed ?

(calling g++ to link instead of gcc, will
add -shared-libgcc automatically I think ?)
But now the normal D programs use "-lgcc".


I'm putting libgcc_s.so next to libstdc++.so...

The static libgcc only added like 16-20K,
to a sample "hello.d" hello world program.

It still links dynamically to the other libs:
> libm.so.6 => /lib/tls/libm.so.6 (0x00b54000)
> libpthread.so.0 => /lib/tls/libpthread.so.0 (0x00279000)
> libc.so.6 => /lib/tls/libc.so.6 (0x00692000)
> /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x0058a000)

--anders

PS. Attaching the patch to change default.
December 18, 2004
Re: Why shared-libgcc ?
GDC uses the same exception mechanism as G++.  If GDC is used to make 
shared libraries that use exceptions, the shared libgcc is needed (on 
some platforms.)  I know D shared libraries aren't completely supported 
now, but...

It is possible to build GCC so that it doesn't use a shared libgcc by 
using the --enable-shared or --disable-shared options with configure. 
Apple must be doing something like this for MacOS X because there is no 
libgcc_s.

David

Anders F Björklund wrote:
> Q: Why does GDC add "-shared-libgcc"
> to the default command-line options ?
> 
> 
> I can understand why e.g. C++ does it,
> since it's needed for the exceptions.
> But does D really utilize "libgcc_s" ?
> 
> All I know is that the D binaries end
> up with a "libgcc_s.so.1" dependancy
> that I need to take care of at run-time...
> 
> 
> I thought it would better to change the
> default to -static-libgcc, and then one
> can add -shared-libgcc - if it is needed ?
> 
> (calling g++ to link instead of gcc, will
> add -shared-libgcc automatically I think ?)
> But now the normal D programs use "-lgcc".
> 
> 
> I'm putting libgcc_s.so next to libstdc++.so...
> 
> The static libgcc only added like 16-20K,
> to a sample "hello.d" hello world program.
> 
> It still links dynamically to the other libs:
> 
>> libm.so.6 => /lib/tls/libm.so.6 (0x00b54000)
>> libpthread.so.0 => /lib/tls/libpthread.so.0 (0x00279000)
>> libc.so.6 => /lib/tls/libc.so.6 (0x00692000)
>> /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x0058a000)
> 
> 
> --anders
> 
> PS. Attaching the patch to change default.
> 
> 
> ------------------------------------------------------------------------
> 
> diff -ur d.orig/d-spec.c d/d-spec.c
> --- d.orig/d-spec.c	2004-10-02 19:19:31.000000000 +0200
> +++ d/d-spec.c	2004-12-17 11:54:05.000000000 +0100
> @@ -121,7 +121,7 @@
>      int need_math = (MATH_LIBRARY[0] != '\0');
>  
>      /* True if we should add -shared-libgcc to the command-line.  */
> -    int shared_libgcc = 1;
> +    int shared_libgcc = 0;
>  
>      /* The total number of arguments with the new stuff.  */
>      int argc;
December 18, 2004
Re: Why shared-libgcc ?
David Friedman wrote:

>> Q: Why does GDC add "-shared-libgcc"
>> to the default command-line options ?
>>
>> I can understand why e.g. C++ does it,
>> since it's needed for the exceptions.
>> But does D really utilize "libgcc_s" ?
>
> GDC uses the same exception mechanism as G++.  If GDC is used to make 
> shared libraries that use exceptions, the shared libgcc is needed (on 
> some platforms.)  I know D shared libraries aren't completely supported 
> now, but...
> 
> It is possible to build GCC so that it doesn't use a shared libgcc by 
> using the --enable-shared or --disable-shared options with configure. 
> Apple must be doing something like this for MacOS X because there is no 
> libgcc_s.

The -static-libgcc works just fine to override the default setting
of dynamic, I was just curious as to why it was dynamic by default...
(also means I need to remove that patch, and include libgcc_s.so again)


Mac OS X is a little "weird", since it also uses a static libstdc++.a,
in addition to /usr/lib/libgcc.a for the GCC compiler library itself.
(Like you say, there is no support for a shared libgcc on Mac OS X.)

The system GCC 3.3 compiler has ENABLE_SHARED_LIBGCC undefined, even.
http://developer.apple.com/documentation/DeveloperTools/gcc-3.3/gcc/Link-Options.html

Contrastingly, you can't build any totally static binaries either...
http://developer.apple.com/qa/qa2001/qa1118.html

This means that neither -static nor -shared flags are supported
(as Mac OS X uses the -dynamic flag, to build .dylib libraries)


The question about the shared libgcc was actually for Linux,
wondered if I needed to make libgcc version 3.x a requirement
for all binaries compiled by GDC. Looks like that I do... ?

It's only a problem for old systems, with GCC 2 as system compiler.
(I believe that GDC should be able to use the libgcc_s.so from e.g.
GCC 3.3.2, since they have the same so-version: /lib/libgcc_s.so.1 ?)


Wonder if C++ exceptions from shared libraries really work on
Mac OS X ? And if they do, what dirty tricks they resorted to... :-)

--anders
December 19, 2004
Re: Why shared-libgcc ?
Anders F Björklund wrote:
> David Friedman wrote:
> 
>>> Q: Why does GDC add "-shared-libgcc"
>>> to the default command-line options ?
>>>
>>> I can understand why e.g. C++ does it,
>>> since it's needed for the exceptions.
>>> But does D really utilize "libgcc_s" ?
>>
>>
>> GDC uses the same exception mechanism as G++.  If GDC is used to make 
>> shared libraries that use exceptions, the shared libgcc is needed (on 
>> some platforms.)  I know D shared libraries aren't completely 
>> supported now, but...
>>
>> It is possible to build GCC so that it doesn't use a shared libgcc by 
>> using the --enable-shared or --disable-shared options with configure. 
>> Apple must be doing something like this for MacOS X because there is 
>> no libgcc_s.
> 
> 
> The -static-libgcc works just fine to override the default setting
> of dynamic, I was just curious as to why it was dynamic by default...
> (also means I need to remove that patch, and include libgcc_s.so again)
> 
> 
> Mac OS X is a little "weird", since it also uses a static libstdc++.a,
> in addition to /usr/lib/libgcc.a for the GCC compiler library itself.
> (Like you say, there is no support for a shared libgcc on Mac OS X.)
> 
> The system GCC 3.3 compiler has ENABLE_SHARED_LIBGCC undefined, even.
> http://developer.apple.com/documentation/DeveloperTools/gcc-3.3/gcc/Link-Options.html 
> 
> 
> Contrastingly, you can't build any totally static binaries either...
> http://developer.apple.com/qa/qa2001/qa1118.html
> 
> This means that neither -static nor -shared flags are supported
> (as Mac OS X uses the -dynamic flag, to build .dylib libraries)
> 
> 
> The question about the shared libgcc was actually for Linux,
> wondered if I needed to make libgcc version 3.x a requirement
> for all binaries compiled by GDC. Looks like that I do... ?
> 

Yes. Phobos requires a 3.x libgcc for the stack unwinder.

> It's only a problem for old systems, with GCC 2 as system compiler.
> (I believe that GDC should be able to use the libgcc_s.so from e.g.
> GCC 3.3.2, since they have the same so-version: /lib/libgcc_s.so.1 ?)
> 
> 
> Wonder if C++ exceptions from shared libraries really work on
> Mac OS X ? And if they do, what dirty tricks they resorted to... :-)
> 
> --anders

I think the important bits were moved into libSystem and the dynamic 
loader... It's probably better that since there are less runtime 
dependencies.

David
Top | Discussion index | About this forum | D home