This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/3400] New: gcc -Wl,--gc-sections -static build doesn't flush stdout
- From: "vda dot linux at googlemail dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 19 Oct 2006 18:10:01 -0000
- Subject: [Bug libc/3400] New: gcc -Wl,--gc-sections -static build doesn't flush stdout
- Reply-to: sourceware-bugzilla at sourceware dot org
t.c:
#include <stdio.h>
int main() {
printf("Hello world\n");
}
# gcc -O2 t.c -o shared
# gcc -O2 t.c -static -o static
# gcc -O2 t.c -Wl,--gc-sections -static -o gc-sect
# ./shared | cat
Hello world
# ./static | cat
Hello world
# ./gc-sect | cat
The last command outputs nothing.
Adding fflush(stdout) after printf makes it work.
(Pipe is needed to make stdout buffered).
IOW: static link with section garbage collection desn't work correctly,
which is a pity because it is such a handy optimization.
This is why:
Makerules:
PROVIDE(__start___libc_atexit = .);\
__libc_atexit : { *(__libc_atexit) }\
PROVIDE(__stop___libc_atexit = .);\
libio/genops.c:
#ifdef text_set_element
text_set_element(__libc_atexit, _IO_cleanup);
#endif
include/libc-symbols.h:
#ifdef HAVE_ELF
/* Make SYMBOL, which is in the text segment, an element of SET. */
# define text_set_element(set, symbol) _elf_set_element(set, symbol)
/* These are all done the same way in ELF.
There is a new section created for each set. */
# ifdef SHARED
/* When building a shared library, make the set section writable,
because it will need to be relocated at run time anyway. */
# define _elf_set_element(set, symbol) \
static const void *__elf_set_##set##_element_##symbol##__ \
__attribute__ ((used, section (#set))) = &(symbol)
# else
And of course:
void
exit (int status)
{
...
RUN_HOOK (__libc_atexit, ());
_exit (status);
}
You have to explain to ld that it should never drop __libc_atexit sections...
--
Summary: gcc -Wl,--gc-sections -static build doesn't flush stdout
Product: glibc
Version: 2.4
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: drepper at redhat dot com
ReportedBy: vda dot linux at googlemail dot com
CC: glibc-bugs at sources dot redhat dot com
GCC build triplet: i386-pc-linux-gnu
GCC host triplet: i386-pc-linux-gnu
GCC target triplet: i386-pc-linux-gnu
http://sourceware.org/bugzilla/show_bug.cgi?id=3400
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.