This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Hi,

     I have re-done this patch for gold. Please take a look and let me
know what you think. Basically, I detect references to __start_XXX and
__stop_XXX symbols from sections that will be kept and then do not
discard any section with name XXX.

2010-01-06  Sriraman Tallam  <tmsriram@google.com>

	* gc.cc (Garbage_collection::do_transitive_closure): Add referenced
	orphan sections to the worklist.
	(Garbage_collection::track_orphan_section): New function.
	* gc.h (Garbage_collection::Tracked_orphan_section_map): New typedef.
	(Garbage_collection::Tracked_orphan_section_range): New typedef.
	(Garbage_collection::Orphan_section_map): New typedef.
	(Garbage_collection::track_orphan_section): New function.
	(Garbage_collection::tracked_orphan_sections): New function.
	(Garbage_collection::orphan_sections): New function.
	(Garbage_collection::tracked_orphan_sections_): New member.
	(Garbage_collection::orphan_sections_): New member.
	(gc_process_relocs): Track orphan section references.
	* symtab.cc (Symbol_table::gc_update_orphan_sections): New function.
	* symtab.h (Symbol_table::gc_update_orphan_sections): New function.
	* testsuite/Makefile.am: Add gc_orphan_section_test.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/gc_orphan_section_test.cc: New file.
	* testsuite/gc_orphan_section_test.sh: New file.

Thanks,
-Sri.

On Tue, Jan 5, 2010 at 7:49 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> 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.
>

Attachment: gold_orphan_section_patch.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]