This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
static link with gold + gc-sections does not flush stdout buffer to file.
- From: Sriraman Tallam <tmsriram at google dot com>
- To: binutils at sourceware dot org
- Date: Mon, 4 Jan 2010 17:02:03 -0800
- Subject: static link with gold + gc-sections does not flush stdout buffer to file.
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.
RCS file: /cvs/src/src/gold/object.cc,v
retrieving revision 1.113
diff -u -u -p -r1.113 object.cc
--- object.cc 5 Jan 2010 00:32:22 -0000 1.113
+++ object.cc 5 Jan 2010 01:00:19 -0000
@@ -1,6 +1,6 @@
// object.cc -- support for an object file for linking in gold
-// Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
// Written by Ian Lance Taylor <iant@google.com>.
// This file is part of gold.
@@ -316,7 +316,8 @@ Relobj::is_section_name_included(const c
|| (is_prefix_of(".data", name)
&& strstr(name, "personality"))
|| (is_prefix_of(".gnu.linkonce.d", name)
- && strstr(name, "personality")))
+ && strstr(name, "personality"))
+ || is_prefix_of("__libc", name))
{
return true;
}
Is this alright ?
Thanks,
-Sriraman.