RFC: [PATCH] New attempt at fixing MIPS --gc-sections et al.

David Daney ddaney@avtrex.com
Tue Aug 16 22:55:00 GMT 2005


This is a follow up to the patches I posted in these threads:

http://sourceware.org/ml/binutils/2005-07/msg00521.html
http://sourceware.org/ml/binutils/2005-08/msg00040.html
http://sourceware.org/ml/binutils/2005-07/msg00511.html

The main problem I was having (and that this patch fixes) was that some 
symbols defined in GCed sections, were being emitted into the dynamic 
symbol table as undefined symbols.  This caused errors in the runtime 
linker as the symbols were not defined anywhere.

A secondary problem (worked around in the patch found in the third 
hyper-link above) was that the magic '_gp_disp' and '__gnu_local_gp' 
symbols were being emitted into the dynamic symbol table even though 
they are resolved by the linker.

The theory behind the patch is this:

A new field (do_not_emit) is added to the elf_link_hash_entry structure. 
  When it is set, the corresponding symbol will not be emitted into the 
linker output.

The do_not_emit field is then set in elf_gc_sweep_symbol if the symbol's 
section was GCed.  Similarly it is set for the magic '_gp_disp' and 
'__gnu_local_gp' symbols.

I have run make -k check with no regressions on a mipsel-linux cross 
build running on x86 FC3.  I have two large multi-got executables that 
can now be successfully built/run with gcc -ffunction-sections 
-fdata-sections and ld --gc-sections.  The space savings in one of them 
is about 20%, so I am quite happy with the results.

I am only seeking comments at this time because this is a quite 
intrusive patch, and I have only tried it on mipsel-linux targets.

There are several potential problems:

1) struct elf_link_hash_entry may be 4 bytes larger (I am not sure about 
this though).

2) Non-MIPS targets may not work anymore with --gc-sections.  For MIPS 
the GOT generation code needed some patching.  I suspect that other 
targets might need similar things as well, but I don't really have any 
good way to test them.

Let me know what you think.


2005-08-16  David Daney  <ddaney@avtrex.com>

	* elf-bfd.h (struct elf_link_hash_entry.do_not_emit): New field.
	* elflink.c (elf_link_renumber_hash_table_dynsyms): Do nothing if
	do_not_emit is true.
	(elf_link_renumber_local_hash_table_dynsyms): Ditto.
	(elf_collect_hash_codes): Ditto.
	(elf_link_output_extsym): Ditto.
	(elf_gc_sweep_symbol): Set do_not_emit if symbol is in a
	SEC_EXCLUDE section.
	(elf_gc_sweep): Add new parameter *output_bfd.  Call
	_bfd_elf_link_renumber_dynsyms.
	(bfd_elf_gc_sections):  Pass new output_bfd parameter to elf_gc_sweep.
	* elfxx-mips.c (mips_elf_sort_hash_table_f): Do nothing if
	do_not_emit is true.
	(mips_elf_record_global_got_symbol): Ditto.
	(mips_elf_make_got_per_bfd): Ditto.
	(mips_elf_set_global_got_offset): Ditto.
	(mips_elf_calculate_relocation): Set do_not_emit for '__gnu_local_gp'
	and '_gp_disp'.
	(_bfd_mips_elf_finish_dynamic_symbol): Do nothing if do_not_emit
	is true.


David Daney.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: gc-sections.d
URL: <https://sourceware.org/pipermail/binutils/attachments/20050816/ba251b6e/attachment.ksh>


More information about the Binutils mailing list