Commit Graph

53 Commits

Author SHA1 Message Date
Ian Lance Taylor 14cac507a8 * libelf.h (struct bfd_elf_section_data): Add field dynindx.
* elfcode.h (NAME(bfd_elf,size_dynamic_sections)): Don't finalize
	the .dynsym, .dynstr or .hash sections until after the backend
	size_dynamic_sections routine, so that it can add dynamic symbols
	if it wants to.
	* elf32-i386.c (elf_i386_adjust_dynamic_symbol): Don't define the
	symbol to be in the .plt section when generating a shared library
	if it is a defined symbol.
	* elf32-sparc.c (elf32_sparc_adjust_dynamic_symbol): Likewise.
	(elf32_sparc_size_dynamic_sections): When generating a shared
	library, allocate space for a dynamic symbol for each output
	section, storing the index in the dynindx field of the ELF section
	data.  Adjust the other dynindx fields to account for this.
	(elf32_sparc_adjust_dynindx): New static function.
	(elf32_sparc_relocate_section): When copying a reloc into a shared
	library, use the original addend as appropriate.  Convert an
	R_SPARC_32 reloc into an R_SPARC_RELATIVE reloc.  Use the dynamic
	symbol index of the output section, not the normal symbol index.
	(elf32_sparc_finish_dynamic_sections): Don't die if a section does
	not exist when setting the value of the dynamic tags.  Write out
	a dynamic symbol for each output section.
1994-10-27 21:25:31 +00:00
Ian Lance Taylor 12662be4fe Fix the ELF linker to not require an interpreter if no dynamic
objects were seen, even when linking PIC code.
	* libelf.h (ELF_LINK_HASH_NEEDS_PLT): Define.
	(struct elf_link_hash_table): Add field dynamic_sections_created.
	* elfcode.h (elf_link_record_dynamic_symbol): Create dynstr if it
	doesn't already exist.
	(elf_link_add_object_symbols): Create dynamic sections based on
	dynamic_sections_created field, not dynobj field.  Don't bother to
	set dynobj.
	(elf_link_create_dynamic_sections): If dynamic sections were
	already created, don't do anything.  If dynobj is already set, use
	it; otherwise, set it to the bfd argument.  Don't initialize
	dynsymcount.  Only create dynstr if it does not exist.  Set
	dynamic_sections_created to true.
	(NAME(bfd_elf,size_dynamic_sections)): Skip most of this function
	if no dynamic objects were seen.
	(elf_adjust_dynamic_symbol): If a symbol has the
	ELF_LINK_HASH_NEEDS_PLT flag set, let the backend adjust it.
	(elf_bfd_final_link): Change most decisions based on dynobj to
	check dynamic_sections_created instead.
	(elf_link_output_extsym): Only handle dynamic symbols if a dynamic
	object was seen.
	* elf.c (_bfd_elf_link_hash_table_init): Initialize new field
	dynamic_sections_created.  Set dynsymcount to 1, not 0.
	* elf32-i386.c (elf_i386_create_dynamic_sections): Call
	elf_i386_create_got_section rather than creating the .got and
	.got.plt sections.
	(elf_i386_create_got_section): New static function.
	(elf_i386_check_relocs): Just call elf_i386_create_got_section if
	a GOT table is needed, not bfd_elf32_link_create_dynamic_sections.
	Only create the .rel.got section, and only make space for a reloc,
	for a global symbol or when generating a shared object.  For a
	R_386_PLT32 reloc, just set the	ELF_LINK_HASH_NEEDS_PLT flag.
	(elf_i386_adjust_dynamic_symbol): Rework initial assertion to
	permit ELF_LINK_HASH_NEEDS_PLT non dynamic symbols.  Create a
	procedure linkage table entry for such symbols.  But, if no
	dynamic objects were seen, never create a PLT entry.
	(elf_i386_size_dynamic_sections): If no dynamic objects were seen,
	skip most of this function, and force the size of the .rel.got
	section to zero.
	(elf_i386_relocate_section): For a R_386_GOT32 reloc against a global
	symbol when no dynamic object was seen, initialize the contents of
	the .got section.  For a R_386_GOT32 against a local symbol, only
	create a R_386_RELATIVE reloc when generating a shared object.
	Treat a R_386_PLT32 reloc against a symbol for which we did not
	create a PLT entry as a R_386_PC32 reloc.
	(elf_i386_finish_dynamic_sections): Only fiddle with the dynamic
	entries and the PLT if we saw a dynamic object.
	* elf32-sparc.c (elf_sparc_howto_table): Fix R_SPARC_PC22 by
	setting rightshift to 10.  Fix R_SPARC_WPLT20 by setting
	rightshift to 2, size to 2, bitsize to 30, and dst_mask to
	0x3fffffff.
	(elf32_sparc_create_dynamic_sections): Don't set the size of the
	.plt section.  Call elf32_sparc_create_got_section rather than
	creating the .got section.
	(elf32_sparc_check_relocs): Call elf32_sparc_create_got_section if
	a GOT table is needed, not bfd_elf32_link_create_dynamic_sections.
	Only create the .rela.got section, and only make space for a
	reloc, for a global symbol or when generating a shared object.
	Set the alignment of the .rela.got section to 2.  For a
	R_SPARC_WPLT30 reloc, just set the ELF_LINK_HASH_NEEDS_PLT flag.
	(elf32_sparc_adjust_dynamic_symbol): Rework initial assertion to
	permit ELF_LINK_HASH_NEDS_PLT non dynamic symbols.  Create a
	procedure linkage table for such symbols.  But, if no dynamic
	objects were seen, never create a PLT entry.  Initialize the size
	of the .plt section.
	(elf32_sparc_size_dynamic_sections): If no dynamic objects were
	seen, skip most of this function, and force the size of the
	.rela.got section to zero.  Strip empty reloc sections, and strip
	an empty .plt section.
	(elf32_sparc_relocate_section): For a GOT reloc against a global
	symbol when no dynamic object was seen, initialize the contents of
	the .got section.  For a GOT reloc against a local symbol, only
	create a R_SPARC_RELATIVE reloc when generating a shared object.
	Treat a R_SPARC_WPLT30 reloc against a symbol for which we did not
	create a PLT entry as a R_SPARC_WDISP30 reloc.
	(elf32_sparc_finish_dynamic_sections): Only fiddle with the
	dynamic entries and the PLT if we saw a dynamic object.
1994-10-21 22:00:18 +00:00
Ian Lance Taylor cd5220cd63 * elfcode.h (elf_map_symbols): Sort the symbols into a new array,
rather than messing with Elf_Sym_Extra.  Store the symbol index in
	the udata.i field.
	(swap_out_syms): Use outbound_syms as a pointer rather than as an
	array.  Don't worry about elf_sym_num.
	(elf_symbol_from_bfd_symbol): Use udata.i rather than just udata.
	* libelf.h (struct elf_sym_extra): Don't define.
	(Elf_Sym_Extra): Don't define.
	(struct elf_obj_tdata): Remove sym_extra field.
	(elf_sym_extra): Don't define.
	* elf32-hppa.c (elf32_hppa_backend_final_write_processing): Use
	udata.i rather than elf_sym_extra array.
	(elf32_hppa_backend_symbol_table_processing): Don't set
	symextn_hdr->size; just use sh_size.
1994-10-17 23:51:25 +00:00
Ian Lance Taylor eb4267a3f9 Use a hash table when writing out ELF symbol names.
* elfcode.h (elf_stringtab_init): New static function.
	(bfd_new_strtab, bfd_add_to_strtab, bfd_add_2_to_strtab): Remove.
	Change all callers to use elf_stringtab_init or
	_bfd_stringtab_add, and get stringtab lengths using
	_bfd_stringtab_size.
	(elf_fake_sections): Change ignored argument to pointer to
	boolean, and set the boolean to true if an error occurs.  If an
	error has already occurred, don't do anything.
	(assign_section_numbers): Just set sh_size, not contents.
	(elf_compute_section_file_positions): Pass the address of a
	boolean to elf_fake_sections.  Pass the address of a
	bfd_strtab_hash to swap_out_syms.  Write out the .strtab section.
	(prep_headers): Change shstrtab to bfd_strtab_hash.
	(swap_out_syms): Take a pointer to a bfd_strtab_hash as an
	argument.  Set it to the symbol names.
	(NAME(bfd_elf,write_object_contents)): Write out the section
	header names using _bfd_stringtab_emit.
	(elf_debug_section): Remove first argument; get the section name
	via the bfd_section pointer.  Change caller.
	(elf_bfd_final_link): Write out the symbol names using
	_bfd_stringtab_emit.  Likewise for the .dynstr section contents.
	Free the symbol names at the end of the function.
	(elf_link_input_bfd): Remove the last argument, output_names,
	from relocate_section.  Save the old symbol contents before
	calling elf_link_output_sym, and restore them afterward.
	* libelf.h (struct elf_link_hash_table): Change dynstr field to
	struct bfd_strtab_hash.
	(struct elf_backend_data): Remove last argument, output_names,
	from elf_backend_relocate_section field.
	(struct strtab): Don't define.
	(struct elf_obj_tdata): Change strtab_ptr field to struct
	bfd_strtab_hash.
	* elf32-hppa.c (elf32_hppa_relocate_section): Remove last
	argument, output_names.
	* elf32-i386.c (elf_i386_relocate_section): Likewise.
	* elf32-mips.c (mips_elf_relocate_section): Likewise.
	* elf32-sparc.c (elf32_sparc_relocate_section): Likewise.
1994-10-17 22:03:14 +00:00
Ian Lance Taylor 24f13b0331 * elfcode.h (elf_swap_shdr_in): Use rawdata, not bfd_section.
Clear contents field.
	(bfd_section_from_shdr): In SHT_STRTAB case, check bfd_section,
	not rawdata.  Don't set rawdata if e_shstrndx.  Use bfd_section
	rather than rawdata in commented out code.  In SHT_REL[A] case,
	don't bother to check elf_section_data of section returned by
	section_from_elf_index.
	(elf_fake_sections): Set bfd_section, not rawdata.  Don't set
	size.
	(elf_map_symbols): Don't set elf_num_section_syms.  Don't create
	section symbols that already exist.
	(assign_file_position_for_section): Use bfd_section, not rawdata.
	(section_from_elf_index): Just check bfd_section field.
	(elf_section_from_bfd_section): Likewise.
	(elf_debug_section): Don't print rawdata, contents, or size.
	(elf_link_add_object_symbols): Don't error out if
	section_from_elf_index returns NULL.
	(elf_bfd_final_link): Check return value from
	section_from_elf_index against NULL, not bfd_is_abs_section.
	(elf_link_input_bfd): Don't check section_from_elf_index return
	value.
	* libelf.h (struct elf_obj_tdata): Remove num_section_syms field.
	(elf_num_section_syms): Don't define.
	* elf.c (elf_get_str_section): Store section contents in contents
	field rather than rawdata field.
	(elf_string_from_elf_section): Likewise.
	(_bfd_elf_make_section_from_shdr): Store BFD section pointer in
	bfd_section field rather than rawdata field.
	* elf32-hppa.c (elf32_hppa_read_symext_info): Use bfd_section
	rather than rawdata.
	(elf32_hppa_size_stubs): Likewise.
	* elf32-mips.c (mips_elf_final_write_processing): Use bfd_section
	rathern than rawdata.
	(mips_elf_section_from_shdr): Likewise.
	(mips_elf_section_processing): Likewise.
	(mips_elf_section_from_bfd_section): Remove rawdata check.
1994-10-17 18:27:40 +00:00
Ken Raeburn 64e21e0fd7 * elf.c (bfd_elf_print_symbol): Moved here from elf_print_symbol in elfcode.h.
(case bfd_print_symbol_all): Print symbol's size field, except for common
symbols; print their alignment.
* elfcode.h (elf_print_symbol): Deleted.
* libelf.h (bfd_elf_print_symbol): Declare.
(bfd_elf{32,64}_print_symbol): Replace declarations with macros.
1994-09-29 20:36:24 +00:00
Ian Lance Taylor 1208625d33 * libelf.h (struct elf_backend_data): Change second argument of
elf_backend_final_write_processing hook to boolean.
	(struct elf_obj_tdata): Add linker field.
	* elfcode.h (NAME(bfd_elf,write_object_contents)): Pass value of
	tdata linker field to final_write_processing, rather than NULL.
	(elf_bfd_final_link): Don't call final_write_processing hook.  Set
	tdata linker field to true.
	* elf32-mips.c (mips_elf_final_write_processing): Change type of
	second argument to boolean.
	* elf32-hppa.c (elf32_hppa_backend_final_write_processing):
	Likewise.
1994-09-07 23:41:58 +00:00
Ian Lance Taylor 374d2ef905 Add support for creating shared libraries under i386 ELF and SPARC
ELF.  Based on patches by Eric Youngdale <ericy@cais.cais.com>.
	* libelf.h (struct elf_link_hash_entry): Remove copy_offset field.
	Add got_offset and plt_offset fields.
	(ELF_LINK_HASH_REF_DYNAMIC_MULTIPLE): Don't define.
	(ELF_LINK_HASH_DEF_DYNAMIC_MULTIPLE): Don't define.
	(ELF_LINK_HASH_NEEDS_COPY): Define.
	(struct elf_backend_data): Add check_relocs field.
	(struct bfd_elf_section_data): Change relocs from PTR to
	Elf_Internal_Rela *.
	(struct elf_obj_tdata): Add local_got_offsets field.
	(elf_local_got_offsets): Define accessor macro.
	(bfd_elf32_link_create_dynamic_sections): Declare.
	(bfd_elf32_link_record_dynamic_symbol): Declare.
	(bfd_elf64_link_create_dynamic_sections): Declare.
	(bfd_elf64_link_record_dynamic_symbol): Declare.
	* elfcode.h (elf_slurp_reloc_table): Don't use the section data
	relocs field.
	(elf_link_record_dynamic_symbol): Make globally visible.  Use
	macro to rename to NAME(bfd_elf,link_record_dynamic_symbol).
	(elf_link_add_object_symbols): If creating a shared library, put
	make all local symbols dynamic.  Don't bother with the
	DYNAMIC_MULTIPLE flags.  Call the check_relocs backend function if
	it is defined.
	(elf_link_create_dynamic_sections): Make globally visible.  Use
	macro to rename to NAME(bfd_elf,link_create_dynamic_sections).  If
	creating a shared library, make sure that _DYNAMIC is added as a
	dynamic symbol.
	(elf_link_read_relocs): New function.
	(NAME(bfd_elf,record_link_assignment)): If creating a shared
	library, always create symbols, and always make them dynamic.
	(elf_bfd_final_link): Permit creation of shared libraries.
	(elf_link_input_bfd): Use elf_link_read_relocs to get the relocs.
	* elf.c (_bfd_elf_link_hash_newfunc): Don't initialize
	copy_offset.  Initialize got_offset and plt_offset.
	* elf32-target.h (elf_backend_check_relocs): Define as 0 if not
	defined.
	(elf32_bed): Initialize check_relocs field.
	* elf64-target.h (elf_backend_check_relocs): Define as 0 if not
	defined.
	(elf64_bed): Initialize check_relocs field.
	* elf32-i386.c (elf_howto_table): Change R_386_PLT32 and
	R_386_GOTPC to be pc_relative and pcrel_offset.
	(elf_i386_pic_plt0_entry): Define.
	(elf_i386_pic_plt_entry): Define.
	(elf_i386_create_dynamic_sections): Create a .got.plt section, and
	define _GLOBAL_OFFSET_TABLE_ at the start of it.  If creating a
	shared library, make sure that _GLOBAL_OFFSET_TABLE_ is added as a
	dynamic symbol.  Don't create .rel.bss if creating a shared
	library.
	(elf_i386_check_relocs): New function.
	(elf_i386_adjust_dynamic_symbol): Don't make a PLT entry if the
	symbol already has one.  When making a PLT entry, set plt_offset.
	Don't create a copy reloc when creating a shared library.  Don't
	set copy_offset, just set ELF_LINK_HASH_NEEDS_COPY.
	(elf_i386_allocate_dynamic_section): Remove.
	(elf_i386_size_dynamic_sections): Look through all the sections
	rather than assuming we know their names.  Remove any empty reloc
	or plt sections.  Only add a DT_DEBUG entry if not creating a
	shared library.  Only add a DT_PLTGOT entry if there is a PLT.
	Add a DT_TEXTREL entry if required.
	(elf_i386_relocate_section): Permit undefined symbols when
	creating a shared library.  Handle the special relocation types
	specially.
	(elf_i386_finish_dynamic_symbol): Create a PLT entry if plt_offset
	is set.  If creating a shared library, produce a PIC PLT entry.
	Only mark a PLT symbol as undefined if it was not defined by a
	regular object file.  Create a GOT entry if got_offset is set.
	Create a copy reloc if ELF_LINK_HASH_NEEDS_COPY is set.
	(elf_i386_finish_dynamic_sections): Change the handling of
	DT_RELSZ to simply subtract out the size of .rel.plt.  If creating
	a shared library, produce PIC PLT code.
	(elf_backend_check_relocs): Define.
	* elf32-sparc.c (elf_sparc_howto_table): Change R_SPARC_GOT10,
	R_SPARC_GOT22, and R_SPARC_PC10 to not warn about reloc overflow.
	(elf32_sparc_create_dynamic_sections): If creating a shared
	library, make sure that _GLOBAL_OFFSET_TABLE_ is added as a
        dynamic symbol, and set the type to STT_OBJECT.  Likewise for
        _PROCEDURE_LINKAGE_TABLE_.  Don't create .rel.bss if creating a
        shared library.
	(elf32_sparc_check_relocs): New function.
	(elf32_sparc_adjust_dynamic_symbol): Don't make a PLT entry if the
	symbol already has one.  When making a PLT entry, set plt_offset.
	Don't create a copy reloc when creating a shared library.  Don't
	set copy_offset, just set ELF_LINK_HASH_NEEDS_COPY.
	(elf32_sparc_allocate_dynamic_section): Remove.
	(elf32_sparc_size_dynamic_sections): Look through all the sections
	rather than assuming we know their names.  Only add a DT_DEBUG
	entry if not creating a shared library.  Add a DT_TEXTREL entry if
	required.
	(elf32_sparc_relocate_section): Permit undefined symbols when
	creating a shared library.  Handle the special relocation types
	specially.
	(elf32_sparc_finish_dynamic_symbol): Create a PLT entry if plt_offset
	is set.  Only mark a PLT symbol as undefined if it was not defined
	by a regular object file.  Create a GOT entry if got_offset is
	set.  Create a copy reloc if ELF_LINK_HASH_NEEDS_COPY is set.
	(elf32_sparc_finish_dynamic_sections): Store dynobj in a local
	variable.
	(elf_backend_check_relocs): Define.
1994-07-26 17:18:37 +00:00
Ian Lance Taylor 7c6da9cade * aoutx.h (aout_link_check_ar_symbols): When changing a symbol to
common, set the alignment.
	(aout_link_add_symbols): Restrict the alignment of a common symbol
	to the alignment power given by the architecture.
	* elf.c (_bfd_elf_link_hash_newfunc): Don't initialize align.  Do
	initialize copy_offset.
	* elf32-i386.c (elf_i386_adjust_dynamic_symbol): Use copy_offset
	field rather than align field.  Get alignment using bfd_log2
	rather than switch.
	* elf32-sparc.c (elf32_sparc_adjust_dynamic_symbol): Likewise.
	* elf32-i386.c (elf_i386_finish_dynamic_symbol): Use copy_offset,
	not align.
	* elf32-sparc.c (elf32_sparc_finish_dynamic_symbol): Likewise.
1994-07-22 18:53:23 +00:00
Ian Lance Taylor bf73e4f3fe * libelf.h (ELF_LINK_HASH_DEFINED_WEAK): Define.
* elfcode.h (elf_link_add_object_symbols): If symbol is defined as
	weak, set ELF_LINK_HASH_DEFINED_WEAK.
	(elf_link_output_extsym): If symbol is defined as weak, mark it
	STB_WEAK.
1994-07-17 02:15:24 +00:00
Ian Lance Taylor ea61717495 * libelf.h (struct bfd_elf_section_data): Add relocs field.
(shdr_name): Remove; unused.
	* elfcode.h (elf_slurp_reloc_table): Rewrote to handle both REL
	and RELA relocs.  Free up the unswapped relocs.  Permit the relocs
	to be cached in the section_data.  Correct the reloc address.
	(elf_slurp_reloca_table): Remove.
	(elf_canonicalize_reloc): Rewrote.
	(elf_link_input_bfd): Permit the relocs to be cached in the
	section data.
1994-07-17 01:15:42 +00:00
Ian Lance Taylor 840846dac5 * libelf.h (bfd_elf32_swap_symbol_in): Declare.
(bfd_elf32_swap_symbol_out): Declare.
	(bfd_elf64_swap_symbol_in, bfd_elf64_swap_symbol_out): Declare.
	* elf32-hppa.c (elf32_hppa_args_hash_table_init): Correct cast.
1994-07-12 16:13:05 +00:00
Jeff Law ff5a090fb4 * Support code for enabling the new style linker for PA ELF.
* elfcode.h (swap_symbol_in, swap_symbol_out): Externalize.
	(elf_compute_section_file_positions): Pass link_info to
	the begin_write_processing hook.
	(bfd_elf_write_object_contents): Pass NULL for new link_info
	argument to final_write_processing hook.
	(elf_link_output_sym): Accept new "input_section" argument for
	the symbols's input section.  All callers changed.  Call the
	link_output_symbol_hook if it's defined.
	(elf_bfd_final_link): Call the final_write_processing hook if
	it's defined.
	* libelf.h (elf_backend_link_output_symbol_hook): Declare.
	(elf_backend_begin_write_processing): Add new "info" argument.
	(elf_backend_final_write_processing): Likewise.
	* elf32-target.h (elf_backend_link_output_symbol_hook): Provide
	a default definition.
	(elf32_bed): Add elf_backend_link_output_symbol_hook.
	* elf64-target.h: Likewise.

	* Major rework of the PA ELF code.  Uses the new style BFD
	linker, major cleanups.
	* hppa_stubs.h: Rewrite from scratch.  Much smaller and simpler.
	* elf32-hppa.h: Delete all symbol extension related code.
	(hppa_look_for_stubs_in_section): Delete decl.
	(elf32_hppa_size_stubs, elf32_hppa_build_stubs): New decls.
	* elf32-hppa.c: Symbol extension stuff moved form elf32-hppa.h
	into elf32-hppa.c.  Do not include aout64.h.
	(typdef hppa_stub_type): Delete.
	(elf32_hppa_stub_name_list_struct): Delete.
	(elf32_hppa_stub_description_struct): Delete.
	(arg_reloc_type): Use simpler enumerations.  All references changed.
	(arg_location, arg_reloc_relocation): Likewise.
	(elf32_hppa_symextn_map_struct): Delete.
	(get_symbol_value): Delete.
	(elf32_hppa_get_sym_extn): Delete.
	(find_stubs, new_stubs, type_of_mismatch): Delete.
	(find_stub_by_name, add_stub_by_name): Delete.
	(hppa_elf_stub_finish, hppa_elf_stub_reloc): Delete.
	(hppa_elf_arg_reloc_needed): Renamed.  Simplify.
	(hppa_elf_build_linker_stub, hppa_elf_create_stub_sec): Delete.
	(hppa_elf_long_branch_needed_p): Delete.
	(hppa_look_for_stubs_in_section): Delete.
	(hppa_elf_get_section_contents): Delete.
	(elf32_hppa_backend_symbol_processing): Delete.
	(elf32_hppa_backend_section_processing): Delete.
	(elf32_hppa_backend_section_from_shdr): Delete.
	(elf32_hppa_backend_fake_sections): Delete.
	(elf32_hppa_backend_section_from_bfd_section): Delete.
	(NEW_INSTRUCTION): Delete.
	(CURRENT_STUB_OFFSET): Delete.
	(elf32_hppa_relocate_section): New function.
	(elf32_hppa_bfd_final_link_relocate): New function.
	(elf32_hppa_size_symext): New function.
	(elf32_hppa_link_output_symbol_hook): New function.
	(elf32_hppa_read_symext_info): New function.
	(elf32_hppa_add_symbol_hook): New function.
	(elf32_hppa_name_of_stub): New function.
	(elf32_hppa_size_of_stub): New function.
	(elf32_hppa_build_one_sub): New function.
	(elf32_hppa_build_stubs): New function.
	(elf32_hppa_size_stubs): New function.
	(linker, stub and argument hash tables): Add appropriate
	structures, definitions and functions to implement all three
	hash tables.
	(hppa_elf_relocate_insn): Don't need argument location information
	in this function.
	(add_entry_to_symext_chain): Accept a symbol's argument location
	information rather than the symbol itself.  All callers changed.
	(hppa_elf_gen_reloc_type): Simplify.
	(hppa_elf_set_section_contents): Stub section is no longer special.
	(hppa_elf_reloc): Greatly simplify.
	(elf32_hppa_begin_write_processing): Accept link_info argument.
	Handle being called from the BFD backend linker.
	(elf32_hppa_final_write_processing): Likewise.
	(elf_hppa_tc_make_sections): No longer call stub_finish.
1994-07-01 19:00:17 +00:00
Jeff Law 6dde66d569 * libelf.h (relocate_section): New argument "output_names" added
to prototype.
	* elfcode.h (elf_link_input_bfd): New argument "output_names"
	added to prototype of relocate_section.  Pass the output symbol
	names to relocate_section.
	* elf32-i386.c (elf_i386_relocate_section): Use "output_names" to
	determine the name of a local symbol.
	* elf32-mips.c (mips_elf_relocate_section): Likewise.
	* elf32-sparc.c (elf32_sparc_relocate_section): Likewise.
1994-06-27 00:17:41 +00:00
Ian Lance Taylor 2f3508ad05 * Many files: change all bfd_target vectors to be const. Change
all uses of bfd_target * to be const bfd_target *.  Change
	bfd_target_vector and bfd_default_vector arrays to be const
	bfd_target * const *.
1994-06-20 21:55:45 +00:00
Ian Lance Taylor c1f84521bf * libelf.h (struct elf_obj_tdata): New field dt_needed_name.
(elf_dt_needed_name): New accessor macro.
	* elfcode.h (elf_link_add_object_symbols): If elf_dt_needed_name
	is set, use that instead of the filename for the DT_NEEDED dynamic
	entry.
	* elf.c (bfd_elf_set_dt_needed_name): New function.
	* bfd-in.h (bfd_elf_set_dt_needed_name): Declare.
	* bfd-in2.h: Rebuilt.
1994-06-16 00:01:32 +00:00
Ian Lance Taylor 5315c42827 Make MIPS ELF use new ELF backend linker. No shared library
support yet.
	* elf32-mips.c (bfd_mips_elf32_swap_gptab_in): New function.
	(bfd_mips_elf32_swap_gptab_out): New function.
	(mips_elf_object_p): If last symbol is LOCAL, set elf_bad_symtab.
	(mips_elf_final_write_processing): Set sh_info field for .gptab.*
	sections.
	(mips_elf_fake_sections): Set sh_entsize for .gptab.* sections.
	(mips_elf_read_ecoff_info): Read and free external symbols last,
	not first, for clarity.
	(struct mips_elf_link_hash_entry): Define new structure.
	(struct mips_elf_link_hash_table): Define new structure.
	(mips_elf_link_hash_lookup): Define new macro.
	(mips_elf_link_hash_traverse): Define new macro.
	(mips_elf_hash_table): Define new macro.
	(mips_elf_link_hash_newfunc): New static function.
	(mips_elf_link_hash_table_create): New static function.
	(mips_elf_add_symbol_hook): New static function.
	(struct extsym_info): Define new structure.
	(mips_elf_get_extr, mips_elf_set_index): Remove.
	(mips_elf_output_extsym): New static function.
	(gptab_compare): New static function.
	(mips_elf_final_link): Rewrite to use ELF backend linker, and to
	merge gptab information in input files.
	(mips_elf_relocate_hi16): New static function.
	(mips_elf_relocate_section): New static function.
	(bfd_elf32_bfd_link_hash_table_create): Define as macro before
	including elf32-target.h.
	(elf_backend_relocate_section): Likewise.
	(elf_backend_add_symbol_hook): Likewise.
	* elf.c (_bfd_elf_link_hash_newfunc): Rename from
	elf_link_hash_newfunc and make globally visible.  Change caller.
	(_bfd_elf_link_hash_table_init): New function, broken out of
	_bfd_elf_link_hash_table_create.
	(_bfd_elf_link_hash_table_create): Use
	_bfd_elf_link_hash_table_init.
	* libelf.h (struct elf_obj_tdata): Add new field bad_symtab.
	(elf_bad_symtab): Define new accessor macro.
	(_bfd_elf_link_hash_newfunc): Declare.
	(_bew_elf_link_hash_table_init): Declare.
	* elfcode.h (elf_object_p): Call backend object_p hook after
	swapping in all the section headers.
	(map_program_segments): Correct typo: Internal for External.
	(elf_link_add_object_symbols): If elf_bad_symtab is set, read all
	the symbols.  Skip STB_LOCAL symbols rather than giving an error.
	(elf_bfd_final_link): If elf_bad_symtab is set, allocate space for
	all symbols, not just locals.
	(elf_link_output_extsym): Only skip a symbol not mentioned by a
	regular file if it is mentioned by a dynamic object.
	(elf_link_input_bfd): If elf_bad_symtab is set, read all the
	symbols.
1994-05-24 20:44:50 +00:00
Ian Lance Taylor 497c543457 * elf.c (_bfd_elf_make_section_from_shdr): New function, based on
code repeated three times in bfd_section_from_shdr in elfcode.h.
	* libelf.h (_bfd_elf_make_section_from_shdr): Declare.
	* elfcode.h (bfd_section_from_shdr): Use new function
	_bfd_elf_make_section_from_shdr to create BFD sections.  If a
	reloc section does not use the main symbol table, or it is part of
	the process image, treat it as a normal section, not relocs.
	* elf32-mips.c (mips_elf_section_from_shdr): Use new function
	_bfd_elf_make_section_from_shdr.
1994-05-20 16:04:59 +00:00
Ian Lance Taylor 013dec1ad9 Add support for ELF shared libraries. Loosely based on work by
Eric Youngdale <ericy@cais.com>.
	* libelf.h (struct elf_backend_data): Add new fields for dynamic
	linking: elf_backend_create_dynamic_sections,
	elf_backend_adjust_dynamic_symbol,
	elf_backend_size_dynamic_sections,
	elf_backend_finish_dynamic_symbol,
	elf_backend_finish_dynamic_sections.
	(struct elf_link_hash_entry): Change type of align field to
	bfd_size_type.  Add fields dynindx, dynstr_index, weakdef,
	elf_link_hash_flags.
	(struct elf_link_hash_table): Add fields dynobj, dynsymcount,
	dynstr, bucketcount.
	(bfd_elf32_swap_reloc_in, bfd_elf32_swap_reloc_out): Declare.
	(bfd_elf32_swap_reloca_in, bfd_elf32_swap_reloca_out): Declare.
	(bfd_elf32_swap_dyn_in, bfd_elf32_swap_dyn_out): Declare.
	(bfd_elf32_add_dynamic_entry): Declare.
	(bfd_elf64_swap_reloc_in, bfd_elf64_swap_reloc_out): Declare.
	(bfd_elf64_swap_reloca_in, bfd_elf64_swap_reloca_out): Declare.
	(bfd_elf64_swap_dyn_in, bfd_elf64_swap_dyn_out): Declare.
	(bfd_elf64_add_dynamic_entry): Declare.
	* elfcode.h (Elf_External_Dyn): Define.
	(elf_swap_reloc_in): Define as macro using NAME.  Make externally
	visible.
	(elf_swap_reloc_out): Likewise.
	(elf_swap_reloca_in, elf_swap_reloca_out): Likewise.
	(elf_swap_dyn_in, elf_swap_dyn_out): Define as macro using NAME
	and as new externally visible function.
	(elf_fake_sections): Set section type of dynamic sections based on
	section names.
	(elf_write_phdrs): Remove.
	(assign_file_position_for_section): Add new align argument.
	Change all callers.
	(get_program_header_size): New static function.
	(struct seg_info): Remove.
	(map_program_segments): Completely rewrite.
	(assign_file_positions_except_relocs): Completely rewrite.
	(assign_file_positions_for_relocs): Don't set a file position for
	sections which already have one.  Don't bother to align the file
	position here.
	(section_from_elf_index): Handle SHT_HASH and SHT_DYNAMIC
	section types.
	(elf_section_from_bfd_section): Likewise.
	(elf_slurp_symbol_table): If section_from_elf_index fails, just
	use bfd_abs_section rather than returning an error.
	(elf_sizeof_headers): Make useful.
	(elf_link_record_dynamic_symbol): New static function.
	(elf_link_add_object_symbols): Handle dynamic objects.
	(elf_link_create_dynamic_sections): New static function.
	(elf_add_dynamic_entry): Define as macro using NAME and as new
	externally visible function.
	(NAME(bfd_elf,record_link_assignment)): New function.
	(elf_buckets): New static variable.
	(NAME(bfd_elf,size_dynamic_sections)): New function.
	(struct elf_final_link_info): Add dynsym_sec and hash_sec fields.
	(elf_bfd_final_link): Handle dynamic linking.  Create a section
	symbol for all ELF sections, not all BFD sections.  Store section
	symbol index in target_index field, not index field.  Traverse
	over global symbols even if stripping.
	(elf_link_output_extsym): Output dynamic symbols.  Mark symbols
	defined by dynamic objects as undefined.
	(elf_link_input_bfd): Ignore dynamic objects.  Use target_index
	field for section relocs, and make sure it is set.
	(elf_reloc_link_order): Use target_index field for section relocs,
	and make sure it is set.
	* elf.c (elf_link_hash_newfunc): Initialize dynindx, dynstr_index,
	weakdef and elf_link_hash_flags fields.
	(_bfd_elf_link_hash_table_create): Initialize dynobj, dynsymcount,
	dynstr and bucketcount fields.
	* elf32-target.h: Initialize new dynamic linking fields.
	* elf64-target.h: Likewise.
	* elf32-i386.c: New functions for dynamic linking support.
	* elf32-sparc.c: Likewise.
	* bfd-in.h (bfd_elf32_record_link_assignment): Declare.
	(bfd_elf64_record_link_assignment): Declare.
	(bfd_elf32_size_dynamic_sections): Declare.
	(bfd_elf64_size_dynamic_sections): Declare.
	* bfd-in2.h: Rebuilt.
1994-05-19 18:23:40 +00:00
Ian Lance Taylor 6ec3bb6a75 * elfcode.h: Include bfdlink.h. Added several new functions to do
linking.
	(ELF_R_TYPE): Define.
	(bfd_add_to_strtab): Return unsigned long.  Change check for
	realloc failure.
	(elf_fake_sections): Check return value of bfd_add_to_strtab.
	(elf_compute_section_file_positions): Add link_info argument.
	Call elf_backend_begin_write_processing hook and prep_headers
	here.  Only call swap_out_syms if link_info is NULL.  Set up
	.shstrtab section here.  Pass dosyms argument to
	assign_file_positions_except_relocs.  Set output_has_begun flag.
	(assign_file_positions_for_symtab_and_strtabs): Add dosyms
	argument, and use it to control setting .symtab and .strtab file
	positions.
	(assign_file_positions_except_relocs): Add dosyms argument, and
	pass it on.
	(prep_headers): Check return value of bfd_add_to_strtab.
	(swap_out_syms): Likewise.  Also, don't set up .shstrtab here.
	(NAME(bfd_elf,write_object_contents)): Some calls moved into
	elf_compute_section_file_positions.
	(elf_set_section_contents): Likewise.
	(elf_slurp_symbol_table): SHN_LORESERV corrected to SHN_LORESERVE.
	* libelf.h: Include bfdlink.h.
	(struct elf_backend_data): Add fields collect,
	elf_add_symbol_hook, elf_backend_relocate_section.
	(struct bfd_elf_section_data): Add field rel_hashes.
	(struct elf_obj_tdata): Remove fields internal_syms and symbols.
	Add field sym_hashes.
	(obj_symbols, obj_internal_syms): Remove definitions.
	(elf_sym_hashes): Define.
	(struct elf_link_hash_entry): Define.
	(struct elf_link_hash_table): Define.
	(elf_link_hash_lookup): Define.
	(elf_link_hash_traverse): Define.
	(elf_hash_table): Define.
	(_bfd_elf_link_hash_table_create): Declare.
	(bfd_elf32_bfd_link_add_symbols): Declare.
	(bfd_elf32_bfd_final_link): Declare.
	(bfd_elf64_bfd_link_add_symbols): Declare.
	(bfd_elf64_bfd_final_link): Declare.
	* elf.c: Include bfdlink.h.
	(elf_link_hash_newfunc): New function.
	(_bfd_elf_link_hash_table_create): New function.
	* elf32-target.h (elf_backend_relocate_section): If not defined,
	define as 0 and use generic linker.  Otherwise, use ELF backend
	linker.
	(elf_backend_collect): If not defined, define as false.
	(elf_backend_add_symbol_hook): If not defined, define as 0.
	(elf32_bed): Initialize new fields.
	* elf64-target.h: Same changes as elf32-target.h.
	* elf32-i386.c: Include bfdlink.h.
	(elf_i386_relocate_section): New function.
	(elf_backend_relocate_section): Define.
	* elf32-sparc.c: Include bfdlink.h.
	(elf_info_to_howto): Change type of dst from Elf32_Internal_Rela
	to Elf_Internal_Rela (they're the same type anyhow).
	(elf_sparc_relocate_section): New function.
	(elf_backend_relocate_section): Define.
	* elf32-mips.c (elf_backend_collect): Define.
1994-05-09 16:58:36 +00:00
Peter Schauer cb71adf12b * libelf.h (elf_obj_tdata): Add members for dynamic symbol table
handling.
	* elfcode.h (bfd_section_from_shdr):  Handle dynamic symbol table.
	* elfcode.h (elf_slurp_symbol_table):  Take additional parameter
	to select static or dynamic symbol table and return number of
	symbols slurped or -1 on error.
	* elfcode.h (elf_get_symtab):  Set bfd symcount from
	elf_slurp_symbol_table result.
	* elfcode.h (elf_get_dynamic_symtab_upper_bound,
	elf_canonicalize_dynamic_symtab):  New functions to handle dynamic
	symbol table.
	* elf32-target.h, elf64-target.h (BFD_JUMP_TABLE_DYNAMIC):
	Change to handle dynamic symbol table, provide default definitions
	for dynamic relocs.
	* aoutx.h (howto_table_std, NAME(aout,swap_std_reloc_out),
	NAME(aout,swap_std_reloc_in), aout_link_input_section_std,
	aout_link_reloc_link_order):  Handle r_jmptable and r_relative
	relocations.
1994-04-21 17:01:12 +00:00
Jeff Law 99a6c7613c * elfcode.h (elf_set_section_contents): Support calling the backend
function elf_backend_begin_write_processing when just beginning to
	write an object file.

	* libelf.h (elf_backend_begin_write_processing): Declare.

	* elf{32,64}-target.h (elf_backend_begin_write_processing): Provide
	a default definition.
	(elf{32,64}_bed): Add elf_backend_begin_write_processing.

	* elf32-hppa.h (elf_hppa_tc_symbol): Delete extern declaration.
	(elf_hppa_tc_make_sections): Likewise.

	* elf32-hppa.c (symext_chain_built): Delete.
	(symext_chain_size): Renamed from symextn_contents_real_size.
	(elf32_hppa_backend_{begin,final}_write_processing): New functions.
	(add_entry_to_symext_chain): New function.
	(hppa_elf_set_section_contents): Ignore writes to the symbol extension
	section until it's been rebuilt internally.
	(hppa_elf_get_section_contents): Symbol extension section is no
	longer special.
	(elf_backend_{begin,final}_write_processing): Define.
	(elf_hppa_tc_make_sections): Simplify now that much code has
	migrated into elf32_hppa_backend_{being,final}_write_processing.
1994-04-07 18:12:25 +00:00
Ian Lance Taylor 326e32d7ce Wed Mar 30 16:25:41 1994 Ian Lance Taylor (ian@tweedledumb.cygnus.com)
Changes to let BFD return an error indication from
	get_symtab_upper_bound, bfd_canonicalize_symtab,
	bfd_get_reloc_upper_bound, and bfd_canonicalize_reloc.  They now
	return long instead of unsigned int, and use -1 to indicate an
	error.  Along the way, rename get_symtab_upper_bound to
	bfd_get_symtab_upper_bound.
	* bfd.c (bfd_get_reloc_upper_bound): Return long, and -1 on
	errors.
	(bfd_canonicalize_reloc): Likewise.
	* syms.c (bfd_get_symtab_upper_bound): Renamed from
	get_symtab_upper_bound.
	* targets.c (bfd_target): Renamed _get_symtab_upper_bound to
	_bfd_get_symtab_upper_bound, and changed it and
	_bfd_canonicalize_symtab and _get_reloc_upper_bound and
	_bfd_canonicalize_reloc to all return long.
	* aoutx.h (NAME(aout,get_symtab)): Return long, and -1 on errors.
	(NAME(aout,canonicalize_reloc)): Likewise.
	(NAME(aout,get_reloc_upper_bound)): Likewise.
	(NAME(aout,get_symtab_upper_bound)): Likewise.
	* bout.c (b_out_canonicalize_reloc): Likewise.
	(b_out_get_reloc_upper_bound): Likewise.
	* coffcode.h (coff_canonicalize_reloc): Likewise.
	* coffgen.c (coff_get_symtab_upper_bound): Likewise.
	(coff_get_symtab): Likewise.
	(coff_get_reloc_upper_bound): Likewise.
	* ecoff.c (ecoff_get_symtab_upper_bound): Likewise.
	(ecoff_get_symtab): Likewise.
	(ecoff_canonicalize_reloc): Likewise.
	* elfcode.h (elf_get_symtab_upper_bound): Likewise.
	(elf_get_reloc_upper_bound): Likewise.
	(elf_canonicalize_reloc): Likewise.
	(elf_get_symtab): Likewise.
	* hp300hpux.c (MY(get_symtab)): Likewise.
	(MY(get_symtab_upper_bound)): Likewise.
	(MY(canonicalize_reloc)): Likewise.
	* i386lynx.c (NAME(lynx,canonicalize_reloc)): Likewise.
	* ieee.c (ieee_slurp_external_symbols): Change return type to
	boolean.  Check for errors from get_symbol.
	(ieee_slurp_symbol_table): Change return type to boolean.  Check
	for errors from ieee_slurp_external_symbols.
	(ieee_get_symtab_upper_bound): Return long, and -1 on errors.
	(ieee_get_symtab): Likewise.
	(ieee_get_reloc_upper_bound): Likewise.
	(ieee_canonicalize_reloc): Likewise.
	* mipsbsd.c (MY(canonicalize_reloc)): Likewise.
	* nlmcode.h (nlm_get_symtab_upper_bound): Likewise.
	(nlm_get_symtab): Likewise.
	(nlm_get_reloc_upper_bound): Likewise.
	(nlm_canonicalize_reloc): Likewise.
	* oasys.c (oasys_get_symtab_upper_bound): Likewise.
	(oasys_get_symtab): Likewise.
	(oasys_get_reloc_upper_bound): Likewise.
	(oasys_canonicalize_reloc): Likewise.
	* som.c (som_get_symtab_upper_bound): Likewise.
	(som_get_symtab): Likewise.
	(som_get_reloc_upper_bound): Likewise.
	(som_canonicalize_reloc): Likewise.
	* srec.c (srec_get_symtab_upper_bound): Likewise.
	(srec_get_symtab): Likewise.
	(srec_get_reloc_upper_bound): Define as bfd_0l.
	(srec_canonicalize_reloc): Likewise.
	* tekhex.c (tekhex_get_symtab): Return long, and -1 on errors.
	(tekhex_get_symtab_upper_bound): Likewise.
	(tekhex_get_reloc_upper_bound): Define as bfd_0l.
	(tekhex_canonicalize_reloc): Likewise.
	* libaout.h (NAME(aout,get_symtab_upper_bound)): Change
	declaration to return long.
	(NAME(aout,get_symtab)): Likewise.
	(NAME(aout,canonicalize_reloc)): Likewise.
	(NAME(aout,get_reloc_upper_bound)): Likewise.
	* libcoff-in.h (coff_get_symtab_upper_bound): Likewise.
	(coff_get_symtab): Likewise.
	(coff_get_reloc_upper_bound): Likewise.
	* libecoff.h (ecoff_get_symtab_upper_bound): Likewise.
	(ecoff_get_symtab): Likewise.
	(ecoff_canonicalize_reloc): Likewise.
	* libelf.h (bfd_elf32_get_symtab_upper_bound): Likewise.
	(bfd_elf32_get_symtab): Likewise.
	(bfd_elf32_get_reloc_upper_bound): Likewise.
	(bfd_elf32_canonicalize_reloc): Likewise.
	(bfd_elf64_get_symtab_upper_bound): Likewise.
	(bfd_elf64_get_symtab): Likewise.
	(bfd_elf64_get_reloc_upper_bound): Likewise.
	(bfd_elf64_canonicalize_reloc): Likewise.
	* libnlm.h (nlmNAME(get_symtab_upper_bound)): Likewise.
	(nlmNAME(get_symtab)): Likewise.
	(nlmNAME(get_reloc_upper_bound)): Likewise.
	(nlmNAME(canonicalize_reloc)): Likewise.
	* archive.c (compute_and_write_armap): Use error_return and
	no_memory_return labels rather than freeing information in various
	places.  Change storage, symcount and src_count to long.  Check
	errors from bfd_get_symtab_upper_bound and
	bfd_canonicalize_symtab.
	* bout.c (b_out_relax_section): Change reloc_size to long.  Check
	for errors from bfd_get_reloc_upper_bound and
	bfd_canonicalize_reloc.
	(b_out_get_relocated_section_contents): Likewise.
	* coff-alpha.c (alpha_ecoff_get_relocated_section_contents):
	Likewise.
	* elf32-mips.c: Likewise.
	* elf32-hppa.c (hppa_elf_stub_finish): Likewise.
	(hppa_look_for_stubs_in_section): Check for errors from
	bfd_get_symtab_upper_bound, bfd_canonicalize_symtab, and
	bfd_canonicalize_reloc.
	* ecofflink.c (bfd_ecoff_debug_accumulate_other): Check for errors
	from bfd_get_symtab_upper_bound and bfd_canonicalize_symtab.
	* linker.c (generic_link_read_symbols): Likewise.
	(_bfd_generic_final_link): Check for errors from
	bfd_get_reloc_upper_bound and bfd_canonicalize_reloc.
	* reloc.c (bfd_generic_get_relocated_section_contents): Likewise.
	* reloc16.c (bfd_coff_reloc16_relax_section): Likewise.
	(bfd_coff_reloc16_get_relocated_section_contents): Likewise.
	* libbfd.c (bfd_0l): New function.
	* libbfd-in.h (bfd_0l): Declare.
	* aix386-core.c: Change get_symtab_upper_bound, get_symtab,
	get_reloc_upper_bound, and canonicalize_reloc to use bfd_0l rather
	than bfd_0u.
	* cisco-core.c, hppabsd-core.c, hpux-core.c: Likewise.
	* irix-core.c, osf-core.c, ptrace-core.c, trad-core.c: Likewise.
	* bfd-in2.h: Rebuilt.
	* libbfd.h: Rebuilt.
	* libcoff.h: Rebuilt.

	* nlm32-sparc.c (nlm_sparc_read_reloc): Remove unused variables
	temp and name.
1994-03-30 22:15:07 +00:00
David MacKenzie d1ad85a6e6 * bfd.c (bfd_get_error, bfd_set_error): New functions.
(bfd_error): Make static.
	(bfd_error_type): Renamed from bfd_ec.  Prepend "bfd_error_" to
	all values.
	* bfd-in2.h: Regenerated.
	* aix386-core.c, aout-adobe.c, aout-encap.c, aout-target.h,
	aoutf1.h, aoutx.h, archive.c, archures.c,
	bfd.c, bout.c, cache.c, coff-alpha.c, coff-mips.c,
	coff-rs6000.c, coffcode.h, coffgen.c, core.c, ctor.c,
	ecoff.c, ecofflink.c, elf.c, elf32-hppa.c, elf32-mips.c,
	elfcode.h, format.c, hash.c, hp300hpux.c, hppabsd-core.c,
	i386lynx.c, ieee.c, libbfd.c, libelf.h, linker.c,
	lynx-core.c, nlm.c, nlm32-alpha.c, nlm32-i386.c,
	nlm32-sparc.c, nlmcode.h, oasys.c, opncls.c, osf-core.c,
	ptrace-core.c, reloc16.c, rs6000-core.c, section.c, som.c,
	srec.c, sunos.c, syms.c, targets.c, tekhex.c,
	trad-core.c: Change callers.
1994-02-17 18:08:41 +00:00
Ian Lance Taylor cf286547ef * ecofflink.c: Extensive changes to compress and merge debugging
information, and to write some of out directly rather than saving
	it in memory.  Several new functions and structures, and new
	arguments to existing functions.
	* ecoff.c (ecoff_compute_reloc_file_positions): Compute
	sym_filepos as well.
	(ecoff_get_extr): Use ifdmap instead of ifdbase.
	(ecoff_write_object_contents): Don't compute sym_filepos here.
	Only output symbols if outsymbols is not NULL.
	(ecoff_bfd_final_link): Adjust for changes in ecoff_debug_info and
	bfd_ecoff_debug functions.  Write out debugging information here.
	(ecoff_final_link_debug_accumulate): Adjust for changes in
	bfd_ecoff_debug functions.
	(ecoff_link_write_external): Use ifdmap rather than ifdbase.
	* elf32-mips.c (mips_elf_read_ecoff_info): Read external symbols
	first, to put them in the first memory buffer.  Clear fdr field.
	(mips_elf_get_extr): Use pointer to unswapped external symbol.
	(mips_elf_final_link): Adjust for changes in bfd_ecoff functions.
	Preserve .text, .data and .bss even if they are empty.  Save
	pointer to unswapped external symbol rather than copying it.
	Don't free up the external symbols.
	* libelf.h (elf_symbol_type): Change mips_extr to PTR.
	* bfd-in.h (bfd_ecoff_debug_init, bfd_ecoff_debug_free): Declare.
	(bfd_ecoff_debug_accumulate): Update declaration.
	(bfd_ecoff_debug_accumulate_other): Rename declaration from
	bfd_ecoff_debug_link_other and update.
	(bfd_ecoff_write_accumulated_debug): Declare.
	* bfd-in2.h: Rebuilt.
	* Makefile.in: Rebuilt dependencies.
1994-01-11 16:23:41 +00:00
Ian Lance Taylor 4c3721d514 Extensive changes to move the bulk of the linker into BFD so that
more efficient backend code can be written for specific object
	files.  Only existing efficient backend is a.out.
	* seclet.c, seclet.h: Removed.
	* hash.c, linker.c, genlink.h: New files.
	* bfd-in.h: Removed bfd_error_vector.  Declared hash table
	structures and functions.
	(JUMP_TABLE): Removed bfd_seclet_link, added
	bfd_link_hash_table_create, bfd_link_add_symbols and
	bfd_final_link.
	* All backends: Changed accordingly.
	* bfd-in2.h: Rebuilt.
	* bfd.c (struct _bfd): Added link_next and archive_pass fields.
	Removed ld_symbols field.
	(bfd_nonrepresentable_section, bfd_undefined_symbol,
	bfd_reloc_value_truncated, bfd_reloc_is_dangerous,
	bfd_error_vector): Removed.
	(bfd_default_error_trap, bfd_error_trap,
	bfd_error_nonrepresentabltrap): Removed.
	(bfd_get_relocated_section_contents): Pass link_info.  Pass
	link_order instead of seclet.  Pass symbols.
	(bfd_relax_section): Pass link_info.
	(bfd_seclet_link): Removed.
	(bfd_link_hash_table_create, bfd_link_add_symbols,
	bfd_final_link): New macros.
	* libbfd-in.h: If __GNUC__ is defined and alloca is not, define
	alloca as __builtin_alloca.  Declare internal linking functions.
	* libbfd.h: Rebuilt.
	* libbfd.c (bfd_seek): Comment out fseek assertion.  It's worked
	for months.
	* reloc.c (reloc_howto_type): Added error_message argument to
	special_function field.  Changed all callers and all definitions.
	(bfd_get_reloc_size): Make argument a const pointer.
	(bfd_perform_relocation): Add error_message argument to hold
	string set if return value if bfd_reloc_dangerous.  Changed all
	callers.
	(_bfd_final_link_relocate, _bfd_relocate_contents): New functions.
	* section.c (asection): Renamed seclets_head and seclets_tail to
	link_order_head and link_order_tail.
	* targets.c (bfd_target): Replaced seclet argument with link_info
	and link_order and symbols arguments in
	bfd_get_relocated_section_contents.  Added symbols argument to
	bfd_relax_section.  Removed bfd_seclet_link.  Added
	bfd_link_hash_table_create, bfd_link_add_symbols and
	bfd_final_link.
	* libaout.h (struct aoutdata): Added external_syms,
	external_sym_count, external_strings, sym_hashes fields.
	(obj_aout_external_syms, obj_aout_external_sym_count,
	obj_aout_external_strings, obj_aout_sym_hashes): New accessor
	macros.
	(WRITE_HEADERS): Only output symbols if outsymbols is not NULL.
	* aoutx.h: Wrote new back end linker routines.
	(translate_to_native_sym_flags): Return boolean value.  Don't use
	bfd_error_vector.
	(NAME(aout,write_syms)): Return boolean value.  Check return value
	of translate_to_native_sym_flags and bfd_write.
	* aout-target.h (final_link_callback): New function.
	(MY_bfd_final_link): New function.
	* aout-adobe.c (aout_adobe_write_object_contents): Check return
	value of aout_32_write_syms.
	* hp300hpux.c (MY(write_object_contents)): Likewise.
	* i386lynx.c (WRITE_HEADERS): Likewise.
	* libaout.h (WRITE_HEADERS): Likewise.
	* bout.c: Changed functions to use link_info->callbacks rather
	than bfd_error_vector, and link_orders rather than seclets.
	* coff-alpha.c: Likewise.
	* coff-h8300.c: Likewise.
	* coff-h8500.c: Likewise.
	* coff-sh.c: Likewise.
	* coff-z8k.c: Likewise.
	* elf32-hppa.c: Likewise.
	* reloc16.c: Likewise.
	* coff-alpha.c (alpha_ecoff_get_relocated_section_contents): Look
	up _gp in the hash table rather than in outsymbols.
	* coff-a29k.c (a29k_reloc): Pass errors back in new error_message
	argument rather than printing them.
	* coffcode.h (bfd_coff_reloc16_extra_cases): Take link_info and
	link_order arguments rather than seclet.  Changed all uses and
	definitions.
	(bfd_coff_reloc16_estimate): Pass link_info arguments.  Changed
	all uses and definitions.
	* libcoff.h: Rebuilt.
	* ecoff.c (ecoff_get_extr): If symbol is defined by linker, but
	not by ECOFF, make it scAbs.
	(ecoff_bfd_final_link): Renamed from ecoff_bfd_seclet_link and
	rewritten.
	* elf32-mips.c (mips_elf_final_link): Renamed from
	mips_elf_seclet_link and rewritten.
	* elf32-hppa.c (elf32_hppa_stub_description): Added link_info
	field.
	(new_stub, add_stub_by_name, hppa_elf_build_arg_reloc_stub,
	hppa_elf_build_long_branch_stub, hppa_look_for_stubs_in_section):
	Added link_info arguments.  Changed all callers.
	* elfcode.h (elf_slurp_symbol_table): Don't quit if outsymbols is
	not NULL.
	* oasys.c (oasys_write_sections): Return boolean value rather than
	using bfd_error_vector.
	(oasys_write_object_contents): Check return value of
	oasys_write_sections.
	* hosts/std-host.h: Don't declare qsort or strtol.
	* Makefile.in: Rebuild dependencies.
	(BFD_LIBS): Removed seclet.o.  Added hash.o and linker.o.
	(CFILES): Removed seclet.c.  Added hash.c and linker.c.
	(HFILES): Removed seclet.h.  Added genlink.h.
1993-12-30 19:56:50 +00:00
Ian Lance Taylor 8d12f138ea * ecofflink.c: New file to hold ECOFF debug information linking
routines.
	* ecoff.c (ecoff_clear_output_flags, ecoff_rel, ecoff_dump_seclet,
	ecoff_add_string, ecoff_get_debug): Removed.  Functionality now in
	ecofflink.c.
	(ecoff_get_extr, ecoff_set_index): New functions.
	(ecoff_slurp_symbolic_info): Don't save raw_size.
	(ecoff_bfd_seclet_link): Rewrote to use ecofflink.c functions.
	(ecoff_compute_section_file_positions): Don't set EXEC_P just
	because there is a start address.
	(ecoff_write_object_contents): Handle external symbols here.  Use
	ecofflink.c functions to write out debugging information.
	* elf32-mips.c (mips_elf_read_ecoff_info, mips_elf_get_extr,
	mips_elf_set_index): New functions.
	(mips_elf_seclet_link): Discard empty sections, the .options
	section and .gptab sections.  Handle linking .mdebug section.
	* libecoff.h (ecoff_data_type): Removed raw_size and ifdbase.
	* libelf.h (elf_symbol_type): Added mips_extr to tc_data union.
	* bfd-in.h: Added prototypes for routines in ecofflink.c (some are
	called by gas, so they are public).
	* bfd-in2.h: Rebuilt.
	* Makefile.in (BFD_LIBS): Added ecofflink.o.
	(CFILES): Added ecofflink.c.
	(ecofflink.o): New target.  Rebuilt dependencies.
1993-11-24 07:21:28 +00:00
Ian Lance Taylor 643e9fc768 * libelf.h (struct elf_backend_data): Added fields
elf_backend_sym_is_global and elf_backend_final_write_processing.
	* elf32-target.h (elf32_bed): Added corresponding initializers.
	* elf64-target.h (elf64_bed): Likewise.
1993-11-18 17:10:42 +00:00
Ian Lance Taylor a5ccdad1fc * elfcode.h (elf_object_p): Rather than looking through an array
of architectures, get the ELF EM_xxx code from the backend
	information.  Let the generic ELF target match any EM_xxx code not
	matched by another ELF target.  Call elf_backend_object_p to let
	the backend do more checks and set global information.
	* libelf.h (struct elf_backend_data): Added elf_machine_code and
	elf_backend_object_p fields.
	(struct bfd_elf_arch_map): Removed.
	(bfd_elf_arch_map, bfd_elf_arch_map_size): Don't declare.
	* elf32-target.h, elf64-target.h: Initialize elf_machine_code
	field with ELF_MACHINE_CODE.  Initialize elf_backend_object_p
	field with elf_backend_object_p (if it is defined).
	* elf32-gen.c, elf32-hppa.c, elf32-i386.c, elf32-i860.c,
	elf32-m68k.c, elf32-m88k.c, elf32-mips.c, elf32-sparc.c,
	elf64-gen.c (ELF_MACHINE_CODE): Defined.
	* elf32-mips.c: Include ecoffswap.h to get ECOFF swapping
	routines.
	(mips_elf_object_p): Set the right machine number.
	(mips_elf_ecoff_debug_swap): Defined.
	(elf_backend_object_p): Defined to be mips_elf_object_p.
	(elf_backend_ecoff_debug_swap): Defined to be
	mips_elf_ecoff_debug_swap.
	* elf.c (bfd_elf_arch_map, bfd_elf_arch_map_size): Removed.

	* elf32-mips.c (elf_mips_howto_table): Don't complain on overflow
	for R_MIPS_26.  Correct overflow detection requires matching the
	upper four bits of the destination against the PC.  From Ted Lemon
	<mellon@pepper.ncd.com>.

	* elf32-hppa.c (elf_hppa_reloc_type_lookup): Return type
	should point to const data.
1993-11-09 21:08:58 +00:00
Ian Lance Taylor 95469b0290 * libelf.h: Added some comments.
(struct elf_backend_data): Added elf_backend_ecoff_debug_swap
	field.  Removed unused write_relocs field.
	* elf32-target.h: Adjusted elf_backend_data initialization
	accordingly.
	* elf64-target.h: Corrected elf_backend_data initialization to
	fill in all fields and to set elf_64_p to 1.
1993-11-09 16:33:28 +00:00
Ian Lance Taylor d5a30a0879 * elf32-mips.c: Extensive additions to do relocations and to
handle MIPS specific sections.
	* libelf.h (elf_backend_data): Pass fourth argument to
	elf_backend_section_from_bfd_section to permit it to control the
	section index to use.
	(elf_obj_tdata): Add gp and gp_size fields.
	(elf_gp, elf_gp_size): New accessor macros.
	* elfcode.h: Removed a number of unused local variables.
	(elf_fake_sections): Clear section header before calling
	elf_backend_fake_sections, not after.
	(prep_headers): Return true at end.
	(elf_section_from_bfd_section): Pass retval argument to
	elf_backend_section_from_bfd_section.
	* elf32-hppa.c (elf32_hppa_backend_section_from_bfd_section):
	Accept and ignore new retval argument.
	* bfd.c: Include libelf.h.
	(bfd_set_gp_size): Handle ELF targets.
	* Makefile.in (bfd.o): Depends upon libelf.h.
	(elf32-mips.o): Depends upon $(INCDIR)/elf/mips.h.
1993-10-12 21:16:14 +00:00
Ian Lance Taylor 207f85b54b * elf32-i386.c (elf_howto_table): Add bfd_elf_generic_reloc
special function for all reloc entries.
	* elf32-target.h (TARGET_LITTLE_SYM): Add SEC_CODE to
	section_flags.
	* libelf.h (elf_symbol_type): Remove desc, type and other fields.
	* Makefile.in (elf32-*.o): These depend upon elf32-target.h.
1993-09-14 22:29:26 +00:00
Ken Raeburn ee8cb54804 Deleted some fields of elf*_symbol_type and elf_obj_tdata that were getting
set but not used.  Merged elf*_symbol_type into a single elf_symbol_type.
1993-09-03 20:12:05 +00:00
Ken Raeburn 78e1e6d95a removed some "#if 0" code 1993-08-27 23:59:37 +00:00
Ken Raeburn e2a422b84c Merged in changes from Jeff Law and Pete Hoogenboom at Utah for PA ELF
support.  Compiles, not particularly well tested.  See ChangeLog for details.
1993-08-25 01:15:07 +00:00
Ken Raeburn d24928c05b * elfcode.h (elf_build_phdrs): Unused function deleted.
(bfd_shdr_from_section): Ditto.
(write_relocs): Don't change section contents for addend.
(elf_locate_sh): Return type is now always elf_internal_shdr, since the other
types were really aliases for this type anyways.  Don't compile this function,
since it is static and doesn't appear to be used in this file.
(sym_is_global): Return non-zero for weak symbols.  Abort if sec ptr is null.
(swap_out_syms): Reorder tests so function symbols can be weak.
(elf_slurp_symbol_table): Don't use BSF_EXPORT.
(elf_slurp_reloca_table): Make RELOC_PROCESSING section smaller by
extracting out some common code.  Abort if BFD section symbol has null name.
(elf_slurp_reloc_table): Translate ELF section symbols into BFD section
symbols.  Don't read section contents to fill in addend field.

* Merged from OSF:

Tue Jun 15 14:38:32 1993  Michael Meissner  (meissner@osf.org)

* libelf.h (struct Elf_Sym_Extra): New structure to contain ELF
specific information for a symbol.  Put in elf_sym_num, which
gives the external symbol number in the elf object file, since
local symbols must come before global symbols.
(elf_sym_extra): New macro.
(elf_symtab_map): Delete, in favor of using Elf_Sym_Extra.
* elfcode.h (elf_map_symbols): Use Elf_Sym_Extra to map internal
symbol number to external number.  Store the address of the
Elf_Sym_Extra field for the symbol in the udata field.
(elf_write_object_contents): Use Elf_Sym_Extra to map out symbols.

Sun Jun 20 16:30:11 1993  Michael Meissner  (meissner@osf.org)

* elfcode.h (elf_obj_tdata): Add field to count the size of the
array of pointers to section symbols.
(elf_map_symbols): Bump the max index of the section symbols so
that we don't overwrite memory.  Store the max index into the
elf_obj_tdata field.

Sat Jun 19 10:12:27 1993  Michael Meissner  (meissner@osf.org)

* elfcode.h (elf_obj_tdata): Add pointer to an array of pointers
to the section symbols we created.  Remove unused field internal_syms.
(elf_map_symbols): Fill in array of pointers to section symbols.  Only create
section symbols for sections that have SEC_ALLOC set, and have non-zero size.
(elf_symbol_from_bfd_symbol): If udata is NULL, and this is a section symbol,
look up the section in the list of section symbols, and set the udata pointer
appropriately.  Otherwise, if udata is still NULL, fail an assertion, and use
0, instead of dropping core.
1993-08-20 22:21:49 +00:00
Ken Raeburn 153cb9ade3 * libelf.h (NAME): Provide a default definition, that's neither
for 32 bits nor for 64.

Tue Jun 15 14:38:32 1993  Michael Meissner  (meissner@osf.org)

* libelf.h (elf_hash): Change declaration to bfd_elf_hash, since
that is what is in elf.c.
1993-08-06 19:29:57 +00:00
Ken Raeburn d79ab07c4a * libelf.h (struct elf_backend_data): New field, maxpagesize.
(struct elf_obj_tdata): New field, phdr.
1993-07-26 18:44:03 +00:00
Fred Fish c3e964b955 * configure.in (*-*-netware, i[34]86-*-netware): New configs.
* Makefile.in (BFD32_BACKENDS):  Add nlm.o, nlm32.o, nlm32-gen.o.
	* Makefile.in (BFD64_BACKENDS):  Add nlm64.o, nlm64-gen.o.
	* Makefile.in (CFILES):  Add nlm{32,64}.c, nlm{32,64}-gen.c.
	* Makefile.in (nlm.o, nlm{32,64}.o, nlm{32,64}-gen.o:  New targets.
	* bfd-in2.h (INLINE):  Defines moved here.
	* {aoutx.h, elf.c, elfcode.h}:  Move INLINE defines to bfd-in2.h.
	* libelf.h (CAT4):  Move define to bfd-in2.h.
	* bfd-in2.h (CAT4):  Merge CAT4 macro with other CAT macros.
	* bfd-in2.h (union tdata):  Add nlm_obj_data.
	* bfd-in2.h (enum target_flavour):  Add bfd_target_nlm_flavour.
	* targets.c (bfd_nlm{32,64}_{big,little}_vec):  Add prototypes.
	* targets.c (target_vector):  Add bfd_nlm{32,64}_{big,little}_vec.
	* (libnlm.h, nlm.c, nlmcode.h, nlm{32,64}-gen.c,
	nlm{32,64}-target.h, nlm{32,64}.c, config/i386-nlm.mt):  New files
	for NLM support.
1993-07-20 04:45:13 +00:00
Ken Raeburn 32090b8e4f * elf.c, elfcode.h, libelf.h: Serious reorganization.
Deleted `thunk' structure, merged into tdata, duplicate data eliminated.
Rearranged functions, grouping by function.
Broke up many functions in elfcode.h, re-ordered many parts of file writing
to handle unpredictable state of section relocation table as provided by
various applications.
Still needs cleanup: Merge functions back together, split out data structure
with only data that is used only when writing out object file.

* elf.c (bfd_elf_generic_reloc): New function, taken from coff-mips.c.
* elf32-sparc.c (elf_sparc_howto_table): Use it, to work around
bfd_perform_relocation lossage.
1993-07-19 19:12:59 +00:00
Ken Raeburn cb6d724fb9 (struct elf_obj_tdata): Add field `thunk'. 1993-07-12 14:46:20 +00:00
Ken Raeburn 7e37f9ff25 more prototypes, in libelf.h 1993-07-06 21:14:36 +00:00
Ken Raeburn 7d9bb6dab4 (CAT4): Added Saber-C (ANSI mode) version.
(bfd_elf64_*): New decls.
1993-06-30 10:04:58 +00:00
Ken Raeburn 998ce1e0c7 Thu Jun 24 17:25:51 1993 Ken Raeburn (raeburn@poseidon.cygnus.com)
* elfcode.h (elf_new_section_hook): Do nothing for now.
	(elf_write_object_contents): Output common symbols the way ELF
	wants them.

Wed Jun 23 16:20:07 1993  Ken Raeburn  (raeburn@poseidon.cygnus.com)

	* libelf.h (struct elf_obj_tdata and associated macros): Moved
	here from elfcode.h.  A couple of size-specific structure pointers
	were changed to PTR; uses fixed appropriately.
	(elf32_symbol_type, elf64_symbol_type): Separated definitions.
	(bfd_elf_mkobject): Renamed from bfd_elf32_mkobject.
	(bfd_elf32_mkobject, bfd_elf64_mkobject, elf_mkobject): New
	temporary macros to ease name change.
	* elf.c (elf_read, elf_mkobject, elf_get_str_section,
	elf_string_from_elf_section, bfd_elf_find_section): Moved here
	from elfcode.h.
	* doc/Makefile.in (libbfd.h): Process elf.c too.
	* Makefile.in (elf.o): Note new dependencies.

	* elfcode.h: Lots of stuff moved elsewhere.  Deleted some unused
	code, tweaked some debug hooks.
	(elf_slurp_reloca_table): Translate ELF section symbols into BFD
	section symbols.
1993-06-24 21:30:26 +00:00
Ken Raeburn 268f94aca3 Use new size-independent versions of elf internal data structures. 1993-06-22 03:06:29 +00:00
Ken Raeburn 638616cafb Second try at getting elfNAME macros right.
Under ANSI C, "32_" is not a valid pp-token...
1993-06-15 23:29:48 +00:00
Ken Raeburn e6858d1b68 (elfNAME, ElfNAME): Use CAT directly rather than going through NAME.
(bfd_elf32_new_section_hook): Declare.
1993-06-15 21:44:03 +00:00
Ken Raeburn 7050286db6 elfcode.h 1993-06-02 21:24:35 +00:00
Ken Raeburn 9942e68438 Updated for new macro, type, and structure names.
Cleaned up some namespace pollution; renamed elf vectors.
1993-05-25 20:11:26 +00:00
David MacKenzie 93b4f01814 Move printing from bfd to nm and add POSIX and SysV formats. 1993-05-21 21:06:25 +00:00