Bug 4992 - ld: --print-gc-sections + --verbose = mess
Summary: ld: --print-gc-sections + --verbose = mess
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.18
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-05 16:21 UTC by Denis Vlasenko
Modified: 2007-09-15 03:03 UTC (History)
1 user (show)

See Also:
Host: any
Target: any
Build: any
Last reconfirmed: 2007-09-15 02:51:24


Attachments
Flush stdout before emitting an error message (351 bytes, patch)
2007-09-07 14:30 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Denis Vlasenko 2007-09-05 16:21:31 UTC
ld version 2.18 introduced --print-gc-sections, and it seems
to have problem coexisting with --verbose.

This is what I see in the build log when I redirect both stdout and stderr to a
file:

(arch/x86_64/lib/lib.a)rwlock.o
(arch/x86_64/lib/lib.a)thunk.o
(arch/x86_64/lib/lib.a)usercopy.o
attempt to openx86_64-pc-linux-gnu-ld: Removing unused section
'.bss.Version_132631' in file 'init/built-in.o'
x86_64-pc-linux-gnu-ld: Removing unused section '.text.bad_intr' in file
'arch/x86_64/kernel/built-in.o'
x86_64-pc-linux-gnu-ld: Removing unused section '.text.do_device_not_available'
in file 'arch/x86_64/kernel/built-in.o'
x86_64-pc-linux-gnu-ld: Removing unused section '.text.check_tsc_unstable' in
file 'arch/x86_64/kernel/built-in.o'
...
...
...
x86_64-pc-linux-gnu-ld: Removing unused section '.bss.tr_table' in file
'net/built-in.o'
x86_64-pc-linux-gnu-ld: Removing unused section '.eh_frame' in file
'arch/x86_64/lib/lib.a(csum-copy.o)'
 lib/built-in.o succeeded
lib/built-in.o
attempt to open arch/x86_64/lib/built-in.o succeeded


"attempt to open lib/built-in.o succeeded" was printed to stdout,
and due to stdout being fully-buffered when redirected to a file,
it got split in mid-line by output to stderr here:

bfd/elflink.c:

          if (info->print_gc_sections && o->size != 0)
            _bfd_error_handler (_("Removing unused section '%s' in file '%B'"),
sub, o->name);

The fix is to either make _bfd_error_handler() always do
fflush(stdout) internally before printing to stderr,
or to do setlinebuf(stdout) at the very beginning of ld's main().
Comment 1 Nick Clifton 2007-09-07 14:30:53 UTC
Created attachment 1986 [details]
Flush stdout before emitting an error message
Comment 2 Nick Clifton 2007-09-07 14:31:52 UTC
Hi Denis,

  Flushing stdout before emitting the error/information message seems to be the
right thing to do.  Please could you try out the uploaded patch and let me know
if it works for you.

Cheers
  Nick
Comment 3 Denis Vlasenko 2007-09-08 13:57:20 UTC
Tested, works for me. Thanks!
Comment 4 Alan Modra 2007-09-15 02:51:24 UTC
...