RFC: [PATCH] New attempt at fixing MIPS --gc-sections et al.
Tue Aug 16 22:55:00 GMT 2005
This is a follow up to the patches I posted in these threads:
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
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
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
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 <email@example.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_gc_sweep_symbol): Set do_not_emit if symbol is in a
(elf_gc_sweep): Add new parameter *output_bfd. Call
(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_calculate_relocation): Set do_not_emit for '__gnu_local_gp'
(_bfd_mips_elf_finish_dynamic_symbol): Do nothing if do_not_emit
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
More information about the Binutils