From mboxrd@z Thu Jan 1 00:00:00 1970 From: "H . J . Lu" To: Nick Clifton Cc: binutils@sources.redhat.com, Ian Lance Taylor Subject: Re: elf_link_hash_entry vs generic_link_hash_entry Date: Thu, 23 Aug 2001 11:36:00 -0000 Message-id: <20010823113656.A17692@lucon.org> References: <20010823092140.A15101@lucon.org> X-SW-Source: 2001-08/msg00545.html On Thu, Aug 23, 2001 at 09:21:40AM -0700, H . J . Lu wrote: > On Wed, Aug 22, 2001 at 08:41:11AM +0100, Nick Clifton wrote: > > > > 3. Go back to the old situation where elf ports that do not provide > > their own relocation backends use the generic linker hash table > > entry structure, but add code to the other elf routines to > > detect this and fail before they try to access fields in the > > hash structure that are not there. > > > > I'd like this one. How about we turn elf_hash_table into something > specific to each backend? For those targets which don't use > _bfd_elf_link_hash_table_create, it will return NULL or a fatal > bfd error. > > Here is a patch. Ian, as you mentioned, linking directly to S-records no longer works. I got /export/build/gnu/binutils/build-full-i686-linux/ld/ld-new -o tmpdir/sr2.sr -T text 0x1000 --oformat srec tmpdir/sr1.o tmpdir/sr2.o child killed: segmentation violation FAIL: S-records /export/build/gnu/binutils/build-full-i686-linux/ld/ld-new -o tmpdir/sr2.sr -T text 0x1000 --oformat srec tmpdir/sr3.o child killed: segmentation violation FAIL: S-records with constructors How should we fix it? Thanks. H.J. ---- 2001-08-23 H.J. Lu * bfdlink.h (bfd_link_hash_table_type): New. The linker hash table type, bfd_link_generic_hash_table and bfd_link_elf_hash_table. (bfd_link_hash_table): Add a new field, type, for the linker hash table type. 2001-08-23 H.J. Lu * elf-bfd.h (elf_hash_table): Return NULL if the linker hash table is not an ELF linker hash table. * elf.c (_bfd_elf_link_hash_table_init): Set the linker hash table type to bfd_link_elf_hash_table. * elfxx-target.h (bfd_elfNN_bfd_link_hash_table_create): Revert the last change. * linker.c (_bfd_link_hash_table_init): Set the linker hash table type to bfd_link_generic_hash_table. Index: bfd/elf-bfd.h =================================================================== RCS file: /work/cvs/gnu/binutils/bfd/elf-bfd.h,v retrieving revision 1.17 diff -u -p -r1.17 elf-bfd.h --- bfd/elf-bfd.h 2001/08/23 17:02:19 1.17 +++ bfd/elf-bfd.h 2001/08/23 18:25:39 @@ -280,7 +280,9 @@ struct elf_link_hash_table /* Get the ELF linker hash table from a link_info structure. */ -#define elf_hash_table(p) ((struct elf_link_hash_table *) ((p)->hash)) +#define elf_hash_table(p) \ + ((struct elf_link_hash_table *) \ + (((p)->hash->type == bfd_link_elf_hash_table) ? (p)->hash : NULL)) /* Constant information held for an ELF backend. */ Index: bfd/elf.c =================================================================== RCS file: /work/cvs/gnu/binutils/bfd/elf.c,v retrieving revision 1.62 diff -u -p -r1.62 elf.c --- bfd/elf.c 2001/08/23 17:02:20 1.62 +++ bfd/elf.c 2001/08/23 18:25:40 @@ -1047,6 +1047,7 @@ _bfd_elf_link_hash_table_init (table, ab struct bfd_hash_table *, const char *)); { + boolean ret; table->dynamic_sections_created = false; table->dynobj = NULL; /* The first dynamic symbol is a dummy. */ @@ -1060,7 +1061,9 @@ _bfd_elf_link_hash_table_init (table, ab table->stab_info = NULL; table->merge_info = NULL; table->dynlocal = NULL; - return _bfd_link_hash_table_init (&table->root, abfd, newfunc); + ret = _bfd_link_hash_table_init (&table->root, abfd, newfunc); + table->root.type = bfd_link_elf_hash_table; + return ret; } /* Create an ELF linker hash table. */ Index: bfd/elfxx-target.h =================================================================== RCS file: /work/cvs/gnu/binutils/bfd/elfxx-target.h,v retrieving revision 1.1.1.21 diff -u -p -r1.1.1.21 elfxx-target.h --- bfd/elfxx-target.h 2001/08/23 16:39:09 1.1.1.21 +++ bfd/elfxx-target.h 2001/08/23 18:25:40 @@ -162,11 +162,16 @@ Foundation, Inc., 59 Temple Place - Suit _bfd_elf_canonicalize_dynamic_reloc #endif +#ifdef elf_backend_relocate_section #ifndef bfd_elfNN_bfd_link_hash_table_create #define bfd_elfNN_bfd_link_hash_table_create _bfd_elf_link_hash_table_create #endif -#ifndef elf_backend_relocate_section +#else /* ! defined (elf_backend_relocate_section) */ /* If no backend relocate_section routine, use the generic linker. */ +#ifndef bfd_elfNN_bfd_link_hash_table_create +#define bfd_elfNN_bfd_link_hash_table_create \ + _bfd_generic_link_hash_table_create +#endif #ifndef bfd_elfNN_bfd_link_add_symbols #define bfd_elfNN_bfd_link_add_symbols _bfd_generic_link_add_symbols #endif Index: bfd/linker.c =================================================================== RCS file: /work/cvs/gnu/binutils/bfd/linker.c,v retrieving revision 1.10 diff -u -p -r1.10 linker.c --- bfd/linker.c 2001/08/17 17:56:20 1.10 +++ bfd/linker.c 2001/08/23 18:25:40 @@ -483,6 +483,7 @@ _bfd_link_hash_table_init (table, abfd, table->creator = abfd->xvec; table->undefs = NULL; table->undefs_tail = NULL; + table->type = bfd_link_generic_hash_table; return bfd_hash_table_init (&table->table, newfunc); } Index: include/bfdlink.h =================================================================== RCS file: /work/cvs/gnu/binutils/include/bfdlink.h,v retrieving revision 1.15 diff -u -p -r1.15 bfdlink.h --- include/bfdlink.h 2001/08/23 17:02:23 1.15 +++ include/bfdlink.h 2001/08/23 18:25:42 @@ -42,6 +42,12 @@ enum bfd_link_discard discard_all /* Discard all locals. */ }; +enum bfd_link_hash_table_type +{ + bfd_link_generic_hash_table, + bfd_link_elf_hash_table +}; + /* These are the possible types of an entry in the BFD link hash table. */ @@ -146,6 +152,8 @@ struct bfd_link_hash_table struct bfd_link_hash_entry *undefs; /* Entries are added to the tail of the undefs list. */ struct bfd_link_hash_entry *undefs_tail; + /* The type of the ink hash table. */ + enum bfd_link_hash_table_type type; }; /* Look up an entry in a link hash table. If FOLLOW is true, this