From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27184 invoked by alias); 19 Oct 2006 18:10:15 -0000 Received: (qmail 27080 invoked by uid 48); 19 Oct 2006 18:10:01 -0000 Date: Thu, 19 Oct 2006 18:10:00 -0000 From: "vda dot linux at googlemail dot com" To: glibc-bugs@sources.redhat.com Message-ID: <20061019181000.3400.vda.linux@googlemail.com> Reply-To: sourceware-bugzilla@sourceware.org Subject: [Bug libc/3400] New: gcc -Wl,--gc-sections -static build doesn't flush stdout X-Bugzilla-Reason: CC Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sourceware.org X-SW-Source: 2006-10/txt/msg00109.txt.bz2 List-Id: t.c: #include 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.