elf32-i386.c .got

Alan Modra amodra@bigpond.net.au
Mon Jun 4 22:38:00 GMT 2001


This probably should be split up into three patches, in the same way
I organized the ChangeLog entries, but it was all done at one time and
I'm too lazy to break up the commits.

bfd/ChangeLog
	* elf32-i386.c (struct elf_i386_link_hash_table): Add sgot,
	sgotplt, srelgot, splt, srelplt, sdynbss, srelbss fields.
	(elf_i386_link_hash_table_create): Init them.
	(create_got_section): New function.
	(elf_i386_create_dynamic_sections): New function.
	(elf_backend_create_dynamic_sections): Set to above.
	(elf_i386_check_relocs): Use shortcuts from hash table rather than
	calling bfd_get_section_by_name.
	(elf_i386_gc_sweep_hook): Likewise.
	(elf_i386_adjust_dynamic_symbol): Likewise.
	(elf_i386_size_dynamic_sections): Likewise.
	(elf_i386_relocate_section): Likewise.
	(elf_i386_finish_dynamic_sections): Likewise.

The above is really only an optimization.  Calling bfd_get_section_by_name
inside functions like elf_i386_adjust_dynamic_section, which are called
via bfd_hash_traverse for all symbols can be a little expensive, especially
if we have a lot of sections (eg. gcc -ffunction-sections).  The following
a) delays allocation of .got and .rel.got space until
   size_dynamic_sections.  Garbage collection, symbol versioning and
   visibility, and shared library semantics combine to make it impossible
   to do so earlier without R_386_NONE relocs appearing in .rel.got.
b) Fixes initialisation of .got for symbols that have been forced local.
c) Implements .plt reference counting for all reloc types.  Previously,
   R_386_32 and R_386_PC32 relocs were not reference counted, so garbage
   collection wasn't ideal.

	* elf32-i386.c (elf_i386_check_relocs): Don't allocate .got and
	.relgot space here.
	(elf_i386_gc_sweep_hook): ..and no need to deallocate here..
	(elf32_hppa_adjust_dynamic_symbol): ..and don't allocate .plt and
	.rel.plt here..
	(allocate_plt_and_got): ..instead do it all here.  New function.
	(elf_i386_size_dynamic_sections): Allocate local .got space and
	call allocate_plt_and_got.  No need to zap .relgot if not dynamic.
	(bfd_elf32_bfd_final_link): Delete.  (ie. use regular final link
	rather than gc variety).
	(WILL_CALL_FINISH_DYNAMIC_SYMBOL): Define.
	(elf_i386_relocate_section): Use it here and correct handling of
	R_386_GOT32.  Provide section and offset for "unresolvable
	relocation" error message.
	(elf_i386_finish_dynamic_symbol): Correct handling of R_386_GOT32.

	* elf32-i386.c (elf_i386_discard_copies): Rename to
	discard_copies, and use elf_link_hash_entry arg rather than
	elf_i386_link_hash_entry.
	(elf_i386_link_hash_traverse): Delete.
	(elf_i386_size_dynamic_sections): Adjust call to discard_copies.
	Tidy sizing of dynamic sections.
	(elf_i386_check_relocs <R_386_32, R_386_PC32>): Reference count
	possible .plt entries.
	(elf_i386_gc_sweep_hook): Likewise.
	(elf_i386_adjust_dynamic_symbol): Discard .plt entries for
	everything with plt.refcount <= 0.

-- 
Alan Modra



More information about the Binutils mailing list