static link with gold + gc-sections does not flush stdout buffer to file.

H.J. Lu hjl.tools@gmail.com
Tue Jan 5 15:49:00 GMT 2010


On Mon, Jan 4, 2010 at 5:02 PM, Sriraman Tallam <tmsriram@google.com> wrote:
> Hi,
>
> Here is how to reproduce the bug :
>
> $ cat hello.cc
> #include <stdio.h>
> int main()
> {
>  printf("Hello World\n");
> }
>
> $ gcc hello.cc -static -Wl,--gc-sections
> $ ./a.out > tt.out
> $ wc tt.out
> 0 0 0 tt.out
>
>
> Also, this bug is present in GNU ld. Will file a bug for this.
>
> Looking at the sections discarded shows the following :
>
> ld: removing unused section from '__libc_atexit' in file
> '/usr/grte/v1/lib/../lib64/libc.a(genops.o)'
> ld: removing unused section from '__libc_freeres_fn' in file
> '/usr/grte/v1/lib/../lib64/libc.a(register-atfork.o)'
> ld: removing unused section from '__libc_subfreeres' in file
> '/usr/grte/v1/lib/../lib64/libc.a(register-atfork.o)'
> ld: removing unused section from '__libc_freeres_fn' in file
> '/usr/grte/v1/lib/../lib64/libc.a(dcigettext.o)'
>
> Out of these, removing __libc_atexit is responsible for this behaviour
> as it registers __IO_cleanup which flushes the buffer. Also, to me, it
> looks like the other symbols with __libc prefix are also important.
>
> Here is a patch to make gc-sections not delete sections prefixed with
> __libc and this fixes the problem.
>
>
> 2010-01-04  Sriraman Tallam  <tmsriram@google.com>
>
>        * object.cc (Relobj::is_section_name_included): Keep sections whose
>        names begin with "__libc" from being discarded by gc-sections.
>

The fix is wrong. Please see my comments at

http://sourceware.org/bugzilla/show_bug.cgi?id=11133

-- 
H.J.



More information about the Binutils mailing list