diff options
author | Alan Modra <amodra@gmail.com> | 2000-07-09 07:23:07 +0000 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2000-07-09 07:23:07 +0000 |
commit | edd21acadce8f7371b03653a60b6a01caaea87f4 (patch) | |
tree | a8de787fd14cbab7516c34817c3979e32a1fb118 /bfd | |
parent | 63ac3005ce93e195643a80fca2c051cbd08fc491 (diff) | |
download | fsf-binutils-gdb-edd21acadce8f7371b03653a60b6a01caaea87f4.zip fsf-binutils-gdb-edd21acadce8f7371b03653a60b6a01caaea87f4.tar.gz fsf-binutils-gdb-edd21acadce8f7371b03653a60b6a01caaea87f4.tar.bz2 |
Restore hppa-elf32 to working order.
Diffstat (limited to 'bfd')
-rw-r--r-- | bfd/ChangeLog | 180 | ||||
-rw-r--r-- | bfd/Makefile.am | 4 | ||||
-rw-r--r-- | bfd/Makefile.in | 6 | ||||
-rw-r--r-- | bfd/config.bfd | 11 | ||||
-rw-r--r-- | bfd/doc/ChangeLog | 4 | ||||
-rw-r--r-- | bfd/doc/Makefile.in | 2 | ||||
-rw-r--r-- | bfd/elf-hppa.h | 79 | ||||
-rw-r--r-- | bfd/elf32-hppa.c | 1761 | ||||
-rw-r--r-- | bfd/elf32-hppa.h | 6 | ||||
-rw-r--r-- | bfd/elf64-hppa.c | 26 | ||||
-rw-r--r-- | bfd/elf64-hppa.h | 2 | ||||
-rw-r--r-- | bfd/hppa_stubs.h | 23 | ||||
-rw-r--r-- | bfd/libhppa.h | 615 |
13 files changed, 1407 insertions, 1312 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index ce058dc..805a3d7 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,183 @@ +2000-07-09 Alan Modra <alan@linuxcare.com.au> + + * elf64-hppa.c (elf64_hppa_dyn_hash_table_init): Add + ATTRIBUTE_UNUSED to unused args. + (get_opd): Likewise. + (get_plt): Likewise. + (get_dlt): Likewise. + (get_stub): Likewise. + (elf64_hppa_adjust_dynamic_symbol): Likewise. + (elf64_hppa_link_output_symbol_hook): Likewise. + (elf64_hppa_check_relocs): Delete unused var. + (elf64_hppa_size_dynamic_sections): Likewise. + (elf64_hppa_finalize_opd): Likewise. + (elf64_hppa_finalize_dynreloc): Likewise. + (elf64_hppa_modify_segment_map): Likewise. + (elf64_hppa_finish_dynamic_sections): Likewise. + + * elf-hppa.h (elf_hppa_final_write_processing): Add + ATTRIBUTE_UNUSED to unused args. + (elf_hppa_final_link_relocate): Likewise. + (elf_hppa_record_segment_addrs): Add paretheses. + (elf_hppa_relocate_section): Constify dyn_name. + + From David Huggins-Daines <dhd@linuxcare.com> + * config.bfd: Add hppa*64*-*-linux-gnu 64-bit target, and + rearrange case statement so that it gets preferred to 32-bit ones. + + * elf32-hppa.c (elf32_hppa_bfd_final_link_relocate): Use + asection->id instead of address of asection structure. + (elf32_hppa_size_stubs): Likewise. + + * elf32-hppa.c (elf32_hppa_size_stubs): Use just one stub section + for .init* and .fini*. + + * elf32-hppa.c (elf32_hppa_bfd_final_link_relocate): Mask pointers + and addends used in stub names to 32 bits. + (elf32_hppa_size_stubs): Likewise. + + * elf-hppa.h (elf_hppa_final_link_relocate): Don't sum addend + twice for R_PARISC_GPREL64. Use bfd_put_32 for R_PARISC_PCREL32, + not bfd_put_64. Fix minor comment typo and formatting. + + Changes to create multiple linker stubs, positioned immediately + before the section where they are required. + * elf32-hppa.c: Don't include hppa_stubs.h. + (elf32_hppa_stub_hash_entry): Add a pointer to the stub section. + (elf32_hppa_stub_hash_table): Delete. + (elf32_hppa_link_hash_entry): Delete. + (elf32_hppa_link_hash_table): Use plain bfd_hash_table for + stub_hash_table, and store the struct here rather than a pointer. + Delete output_symbol_count. Add offset array. Change + global_value to a bfd_vma. + (elf32_hppa_stub_hash_lookup): Use table instead of table->root. + (elf32_hppa_stub_hash_traverse): Delete. + (elf32_hppa_name_of_stub): Delete. + (elf32_hppa_link_hash_lookup): Delete. + (elf32_hppa_link_hash_traverse): Delete. + (elf32_hppa_stub_hash_table_init): Delete. + (elf32_hppa_size_of_stub): Pass input section and offset rather + than location and calculate location here. Don't pass name as all + stubs are now the same size. + (elf32_hppa_stub_hash_newfunc): Init new fields. + (elf32_hppa_link_hash_table_create): Likewise, and stub_hash_table + too. + (elf32_hppa_bfd_final_link_relocate): Cast enums to int before + comparing against ints. Rewrite stub handling code. + (elf32_hppa_relocate_section): Make r_type and r_symndx unsigned. + Case enums to int before comparing against ints. Remove + bfd_reloc_dangerous case. + (elf32_hppa_build_one_stub): Rewrite. + (elf32_hppa_size_one_stub): New function. + (elf32_hppa_build_stubs): Rewrite. + (elf32_hppa_size_stubs): Pass in linker call-back functions. + Rewrite stub-handling specific code. + + * elf32-hppa.h (elf32_hppa_size_stubs): Update prototype. + + * elf64-hppa.c (elf64_hppa_dyn_hash_entry): Fix a comment typo. + + * hppa_stubs.h: Delete. + * Makefile.am (SOURCE_HFILES): Remove hppa_stubs.h + (elf32-hppa.lo): Remove hppa_stubs.h from dependencies. + * Makefile.in: Regenerate. + + * elf-hppa.h (_bfd_elf_hppa_gen_reloc_type): Handle e_nlsel and + e_nlrsel. + + * libhppa.h (hppa_field_adjust): Correct e_nsel case. + + * elf32-hppa.c (elf32_hppa_relocate_section): Mention the offset + and section name for bfd_reloc_notsupported error message. + (elf32_hppa_bfd_final_link_relocate): Print reasons for returning + bfd_reloc_notsupported. + (elf32_hppa_relocate_section): Add ATTRIBUTE_UNUSED to output_bfd. + + * elf32-hppa.c (elf32_hppa_bfd_final_link_relocate): Handle + undefined weak symbols for all relocs. + (elf32_hppa_size_of_stub): Adjust calculation by 8 since branch + offsets are relative to one past the delay slot. + (elf32_hppa_size_stubs): Account for reloc addend when calculating + branch destination. Put addend into stub name too. + (elf32_hppa_bfd_final_link_relocate): Account for reloc addend and + adjust by 8 when deciding whether a linker stub is needed. Put + addend into stub name as for above. + + * elf32-hppa.c (hppa_elf_relocate_insn): Change signed/unsigned on + various args and vars. + (elf32_hppa_bfd_final_link_relocate): Here too. + (elf32_hppa_size_stubs): Rename index -> indx. Use e_indx for + inner block var to avoid shadowing. + + * elf32-hppa.h (_bfd_elf32_hppa_gen_reloc_type): Make `field' arg + unsigned. + * elf64-hppa.h (_bfd_elf64_hppa_gen_reloc_type): Ditto. + * elf-hppa.h (_bfd_elf_hppa_gen_reloc_type): Ditto. + (elf_hppa_fake_sections): Rename local var to avoid shadowing. + + * libhppa.h: Change practically all unsigned ints to plain ints. + Remove tests on gcc version. Instead use ATTRIBUTE_UNUSED for + prototypes. + + From Ryan Bradetich <rbradetich@uswest.net> + * libhppa.h (hppa_opcode_type): New enum to replace #define's. + * elf32-hppa.c (elf32_hppa_bfd_final_link_relocate): Modify to + suit above. + From David Huggins-Daines <dhd@linuxcare.com> + * elf-hppa.h (elf_hppa_relocate_insn): Update the opcode constants + to the new OP_* ones. + + * elf32-hppa.c (elf32_hppa_size_stubs): Consolidate freeing on + error exit. Bail out earlier on plabel relocs that we aren't + interested in. Don't tell elf32_hppa_stub_hash_lookup to copy + string, and then don't free our copy. + (elf32_hppa_build_one_stub): Make insn unsigned int. + + * libhppa.h (bfd_hppa_insn2fmt): 22 bit branches are only + available with BL, not BE and BLE. + + * elf32-hppa.c (hppa_elf_relocate_insn): Add some more example + code for elf arg relocs. + (elf32_hppa_bfd_final_link_relocate): Replace boolean is_local + argument with elf_link_hash_entry h. Handle undefined weak + symbols. Move $global$ lookup from here... + (elf32_hppa_relocate_section): ...to here. Return correct error + message for non-handled relocs. + (elf32_hppa_size_of_stub): Correctly test branch range. Previous + wrong test was -0x3ffff to +0x40000. + + * elf-hppa.h (elf_hppa_final_link_relocate): R_PARISC_DIR17R, + R_PARISC_DIR17F, and R_PARISC_DIR21L are for absolute branches; + Handle them as such. + (elf_hppa_relocate_insn): Fix a typo. + + * libhppa.h (GET_FIELD, GET_BIT, MASK, CATENATE, ELEVEN): Delete. + (assemble_3, assemble_6, assemble_12, assemble_16, assemble_16a, + assemble_17, assemble_21): Delete. + Supply defines for all 64 possible opcodes. + (bfd_hppa_insn2fmt): Add bfd argument, and use to select wide mode + formats. Handle COMICLR. + (hppa_rebuild_insn): Delete bfd argument. Handle formats 10, -11, + -10, -16, 16, 22. + + * elf32-hppa.c (hppa_elf_relocate_insn): Complete rewrite. + (elf32_hppa_bfd_final_link_relocate): Major rewrite. + (elf32_hppa_build_one_stub): Modify hppa_elf_relocate_insn calls + to suit. + (elf32_hppa_size_stubs): Don't free stub_name twice. Read in all + the local syms - did this code get deleted accidentally? Ignore + undefined and undefweak syms. + + * elf-hppa.h (elf_hppa_final_link): Move hppa_info to outermost + block. Use it instead of elf64_hppa_hash_table (info). + (elf_hppa_final_link_relocate): Use hppa_info instead of + elf64_hppa_hash_table (info). + + * libhppa.h (re_assemble_3, re_assemble_12, re_assemble_16, + re_assemble_17, re_assemble_21, re_assemble_22): Don't mask insn. + (hppa_rebuild_insn): Mask immediate bits here instead. + * elf-hppa.h (elf_hppa_relocate_insn): Mask here too. + 2000-07-08 Alan Modra <alan@linuxcare.com.au> * section.c (struct sec): Add id field. Tidy comment formatting. diff --git a/bfd/Makefile.am b/bfd/Makefile.am index 6d408a3..aa30593 100644 --- a/bfd/Makefile.am +++ b/bfd/Makefile.am @@ -470,7 +470,7 @@ SOURCE_HFILES = \ aout-target.h aoutf1.h aoutx.h coffcode.h coffswap.h ecoffswap.h \ elf-bfd.h elf-hppa.h elf32-arm.h elf32-hppa.h elf64-hppa.h \ elfcode.h elfcore.h elflink.h freebsd.h genlink.h go32stub.h \ - hppa_stubs.h libaout.h libbfd.h libcoff.h libecoff.h libhppa.h \ + libaout.h libbfd.h libcoff.h libecoff.h libhppa.h \ libieee.h libnlm.h liboasys.h libpei.h netbsd.h nlm-target.h \ nlmcode.h nlmswap.h ns32k.h peicode.h som.h vms.h xcoff-target.h @@ -931,7 +931,7 @@ elf32-gen.lo: elf32-gen.c $(INCDIR)/filenames.h elf-bfd.h \ elf32-hppa.lo: elf32-hppa.c $(INCDIR)/filenames.h elf-bfd.h \ $(INCDIR)/elf/common.h $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h \ $(INCDIR)/bfdlink.h $(INCDIR)/elf/hppa.h $(INCDIR)/elf/reloc-macros.h \ - libhppa.h elf32-hppa.h elf-hppa.h hppa_stubs.h elf32-target.h + libhppa.h elf32-hppa.h elf-hppa.h elf32-target.h elf32-i370.lo: elf32-i370.c $(INCDIR)/filenames.h $(INCDIR)/bfdlink.h \ elf-bfd.h $(INCDIR)/elf/common.h $(INCDIR)/elf/internal.h \ $(INCDIR)/elf/external.h $(INCDIR)/elf/i370.h elf32-target.h diff --git a/bfd/Makefile.in b/bfd/Makefile.in index 4029d8d..9f809e3 100644 --- a/bfd/Makefile.in +++ b/bfd/Makefile.in @@ -593,7 +593,7 @@ SOURCE_HFILES = \ aout-target.h aoutf1.h aoutx.h coffcode.h coffswap.h ecoffswap.h \ elf-bfd.h elf-hppa.h elf32-arm.h elf32-hppa.h elf64-hppa.h \ elfcode.h elfcore.h elflink.h freebsd.h genlink.h go32stub.h \ - hppa_stubs.h libaout.h libbfd.h libcoff.h libecoff.h libhppa.h \ + libaout.h libbfd.h libcoff.h libecoff.h libhppa.h \ libieee.h libnlm.h liboasys.h libpei.h netbsd.h nlm-target.h \ nlmcode.h nlmswap.h ns32k.h peicode.h som.h vms.h xcoff-target.h @@ -671,7 +671,7 @@ configure.in DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) -TAR = gtar +TAR = tar GZIP_ENV = --best SOURCES = $(libbfd_a_SOURCES) $(libbfd_la_SOURCES) OBJECTS = $(libbfd_a_OBJECTS) $(libbfd_la_OBJECTS) @@ -1459,7 +1459,7 @@ elf32-gen.lo: elf32-gen.c $(INCDIR)/filenames.h elf-bfd.h \ elf32-hppa.lo: elf32-hppa.c $(INCDIR)/filenames.h elf-bfd.h \ $(INCDIR)/elf/common.h $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h \ $(INCDIR)/bfdlink.h $(INCDIR)/elf/hppa.h $(INCDIR)/elf/reloc-macros.h \ - libhppa.h elf32-hppa.h elf-hppa.h hppa_stubs.h elf32-target.h + libhppa.h elf32-hppa.h elf-hppa.h elf32-target.h elf32-i370.lo: elf32-i370.c $(INCDIR)/filenames.h $(INCDIR)/bfdlink.h \ elf-bfd.h $(INCDIR)/elf/common.h $(INCDIR)/elf/internal.h \ $(INCDIR)/elf/external.h $(INCDIR)/elf/i370.h elf32-target.h diff --git a/bfd/config.bfd b/bfd/config.bfd index 9406427..9b0d81c 100644 --- a/bfd/config.bfd +++ b/bfd/config.bfd @@ -230,15 +230,20 @@ case "${targ}" in targ_underscore=yes ;; - hppa*-*-*elf* | hppa*-*-linux-gnu* | hppa*-*-lites* | hppa*-*-sysv4* | hppa*-*-rtems*) - targ_defvec=bfd_elf32_hppa_vec - ;; #ifdef BFD64 + hppa*64*-*-linux-gnu*) + targ_defvec=bfd_elf64_hppa_vec + ;; hppa*64*-*-hpux11*) targ_defvec=bfd_elf64_hppa_vec targ_cflags=-DHPUX_LARGE_AR_IDS ;; #endif + + hppa*-*-*elf* | hppa*-*-linux-gnu* | hppa*-*-lites* | hppa*-*-sysv4* | hppa*-*-rtems*) + targ_defvec=bfd_elf32_hppa_vec + ;; + #if defined (HOST_HPPAHPUX) || defined (HOST_HPPABSD) || defined (HOST_HPPAOSF) || defined (HOST_HPPAMPEIX) hppa*-*-bsd*) targ_defvec=som_vec diff --git a/bfd/doc/ChangeLog b/bfd/doc/ChangeLog index 3a739b7..0640017 100644 --- a/bfd/doc/ChangeLog +++ b/bfd/doc/ChangeLog @@ -1,3 +1,7 @@ +2000-07-09 Alan Modra <alan@linuxcare.com.au> + + * Makefile.in: Regenerate. + 2000-07-08 Alan Modra <alan@linuxcare.com.au> * chew.c (outputdots): Don't add a space before `/*'. diff --git a/bfd/doc/Makefile.in b/bfd/doc/Makefile.in index 80be82a..e45ab48 100644 --- a/bfd/doc/Makefile.in +++ b/bfd/doc/Makefile.in @@ -188,7 +188,7 @@ DIST_COMMON = ChangeLog Makefile.am Makefile.in DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) -TAR = gtar +TAR = tar GZIP_ENV = --best all: all-redirect .SUFFIXES: diff --git a/bfd/elf-hppa.h b/bfd/elf-hppa.h index 0a4dc64..e67ada4 100644 --- a/bfd/elf-hppa.h +++ b/bfd/elf-hppa.h @@ -45,7 +45,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #endif elf_hppa_reloc_type ** _bfd_elf_hppa_gen_reloc_type - PARAMS ((bfd *, elf_hppa_reloc_type, int, int, int, asymbol *)); + PARAMS ((bfd *, elf_hppa_reloc_type, int, unsigned int, int, asymbol *)); static void elf_hppa_info_to_howto PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); @@ -604,7 +604,7 @@ _bfd_elf_hppa_gen_reloc_type (abfd, base_type, format, field, ignore, sym) bfd *abfd; elf_hppa_reloc_type base_type; int format; - int field; + unsigned int field; int ignore ATTRIBUTE_UNUSED; asymbol *sym ATTRIBUTE_UNUSED; { @@ -688,6 +688,8 @@ _bfd_elf_hppa_gen_reloc_type (abfd, base_type, format, field, ignore, sym) { case e_lsel: case e_lrsel: + case e_nlsel: + case e_nlrsel: final_type = R_PARISC_DIR21L; break; case e_ltsel: @@ -751,9 +753,11 @@ _bfd_elf_hppa_gen_reloc_type (abfd, base_type, format, field, ignore, sym) { case e_rsel: case e_rrsel: + /* R_PARISC_DLTREL14R for elf64, R_PARISC_DPREL14R for elf32 */ final_type = base_type + OFFSET_14R_FROM_21L; break; case e_fsel: + /* R_PARISC_DLTREL14F for elf64, R_PARISC_DPREL14F for elf32 */ final_type = base_type + OFFSET_14F_FROM_21L; break; default: @@ -764,8 +768,11 @@ _bfd_elf_hppa_gen_reloc_type (abfd, base_type, format, field, ignore, sym) case 21: switch (field) { - case e_lrsel: case e_lsel: + case e_lrsel: + case e_nlsel: + case e_nlrsel: + /* R_PARISC_DLTREL21L for elf64, R_PARISC_DPREL21L for elf32 */ final_type = base_type; break; default: @@ -812,23 +819,25 @@ _bfd_elf_hppa_gen_reloc_type (abfd, base_type, format, field, ignore, sym) } break; - case 22: + case 21: switch (field) { - case e_fsel: - final_type = R_PARISC_PCREL22F; + case e_lsel: + case e_lrsel: + case e_nlsel: + case e_nlrsel: + final_type = R_PARISC_PCREL21L; break; default: return NULL; } break; - case 21: + case 22: switch (field) { - case e_lsel: - case e_lrsel: - final_type = R_PARISC_PCREL21L; + case e_fsel: + final_type = R_PARISC_PCREL22F; break; default: return NULL; @@ -920,7 +929,7 @@ elf_hppa_fake_sections (abfd, hdr, sec) if (strcmp (name, ".PARISC.unwind") == 0) { int indx; - asection *sec; + asection *asec; #if ARCH_SIZE == 64 hdr->sh_type = SHT_LOPROC + 1; #else @@ -935,9 +944,9 @@ elf_hppa_fake_sections (abfd, hdr, sec) So we (gasp) recompute it here. Hopefully nobody ever changes the way sections are numbered in elf.c! */ - for (sec = abfd->sections, indx = 1; sec; sec = sec->next, indx++) + for (asec = abfd->sections, indx = 1; asec; asec = asec->next, indx++) { - if (sec->name && strcmp (sec->name, ".text") == 0) + if (asec->name && strcmp (asec->name, ".text") == 0) { hdr->sh_info = indx; break; @@ -954,7 +963,7 @@ elf_hppa_fake_sections (abfd, hdr, sec) static void elf_hppa_final_write_processing (abfd, linker) bfd *abfd; - boolean linker; + boolean linker ATTRIBUTE_UNUSED; { int mach = bfd_get_mach (abfd); @@ -1095,13 +1104,13 @@ elf_hppa_record_segment_addrs (abfd, section, data) value = section->vma - section->filepos; - if ((section->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY) + if (((section->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY)) == (SEC_ALLOC | SEC_LOAD | SEC_READONLY)) && value < hppa_info->text_segment_base) hppa_info->text_segment_base = value; - else if ((section->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY) - == (SEC_ALLOC | SEC_LOAD)) - && value < hppa_info->data_segment_base) + else if (((section->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY)) + == (SEC_ALLOC | SEC_LOAD)) + && value < hppa_info->data_segment_base) hppa_info->data_segment_base = value; } @@ -1117,14 +1126,12 @@ elf_hppa_final_link (abfd, info) struct bfd_link_info *info; { boolean retval; + struct elf64_hppa_link_hash_table *hppa_info = elf64_hppa_hash_table (info); if (! info->relocateable) { struct elf_link_hash_entry *gp; bfd_vma gp_val; - struct elf64_hppa_link_hash_table *hppa_info; - - hppa_info = elf64_hppa_hash_table (info); /* The linker script defines a value for __gp iff it was referenced by one of the objects being linked. First try to find the symbol @@ -1139,7 +1146,7 @@ elf_hppa_final_link (abfd, info) /* Adjust the value of __gp as we may want to slide it into the .plt section so that the stubs can access PLT entries without using an addil sequence. */ - gp->root.u.def.value += elf64_hppa_hash_table (info)->gp_offset; + gp->root.u.def.value += hppa_info->gp_offset; gp_val = (gp->root.u.def.section->output_section->vma + gp->root.u.def.section->output_offset @@ -1181,10 +1188,10 @@ elf_hppa_final_link (abfd, info) } /* We need to know the base of the text and data segments so that we - can perform SEGREL relocations. We will recore the base addresses + can perform SEGREL relocations. We will record the base addresses when we encounter the first SEGREL relocation. */ - elf64_hppa_hash_table (info)->text_segment_base = (bfd_vma)-1; - elf64_hppa_hash_table (info)->data_segment_base = (bfd_vma)-1; + hppa_info->text_segment_base = (bfd_vma)-1; + hppa_info->data_segment_base = (bfd_vma)-1; /* HP's shared libraries have references to symbols that are not defined anywhere. The generic ELF BFD linker code will complaim @@ -1243,7 +1250,7 @@ elf_hppa_relocate_section (output_bfd, info, input_bfd, input_section, bfd_vma relocation; bfd_reloc_status_type r; const char *sym_name; - char *dyn_name; + const char *dyn_name; char *dynh_buf = NULL; size_t dynh_buflen = 0; struct elf64_hppa_dyn_hash_entry *dyn_h = NULL; @@ -1442,7 +1449,7 @@ elf_hppa_final_link_relocate (rel, input_bfd, output_bfd, bfd_vma value; struct bfd_link_info *info; asection *sym_sec; - struct elf_link_hash_entry *h; + struct elf_link_hash_entry *h ATTRIBUTE_UNUSED; struct elf64_hppa_dyn_hash_entry *dyn_h; { unsigned int insn; @@ -1560,7 +1567,7 @@ elf_hppa_final_link_relocate (rel, input_bfd, output_bfd, case R_PARISC_LTOFF16DF: { /* If this relocation was against a local symbol, then we still - have not set up the DLT entry (it's not convienent to do so + have not set up the DLT entry (it's not convenient to do so in the "finalize_dlt" routine because it is difficult to get to the local symbol's value). @@ -1822,7 +1829,6 @@ elf_hppa_final_link_relocate (rel, input_bfd, output_bfd, /* Subtract out the global pointer value to make value a DLT relative address. */ value -= _bfd_get_gp_value (output_bfd); - value += addend; bfd_put_64 (input_bfd, value + addend, hit_data); return bfd_reloc_ok; @@ -1855,7 +1861,7 @@ elf_hppa_final_link_relocate (rel, input_bfd, output_bfd, value += addend; value -= 8; - bfd_put_64 (input_bfd, value, hit_data); + bfd_put_32 (input_bfd, value, hit_data); return bfd_reloc_ok; } @@ -1913,8 +1919,7 @@ elf_hppa_final_link_relocate (rel, input_bfd, output_bfd, case R_PARISC_SECREL32: bfd_put_32 (input_bfd, - (value + addend - - sym_sec->output_section->vma), + value + addend - sym_sec->output_section->vma, hit_data); return bfd_reloc_ok; @@ -1925,7 +1930,7 @@ elf_hppa_final_link_relocate (rel, input_bfd, output_bfd, the segment base values. */ if (hppa_info->text_segment_base == (bfd_vma) -1) bfd_map_over_sections (output_bfd, elf_hppa_record_segment_addrs, - elf64_hppa_hash_table (info)); + hppa_info); /* VALUE holds the absolute address. We want to include the addend, then turn it into a segment relative address. @@ -1955,7 +1960,7 @@ elf_hppa_final_link_relocate (rel, input_bfd, output_bfd, /* Update the instruction word. */ bfd_put_32 (input_bfd, insn, hit_data); - return (bfd_reloc_ok); + return bfd_reloc_ok; } /* Relocate the given INSN. VALUE should be the actual value we want @@ -1976,7 +1981,7 @@ elf_hppa_relocate_insn (insn, sym_value, r_type) the "B" instruction. */ case R_PARISC_PCREL22F: case R_PARISC_PCREL22C: - return re_assemble_22 (insn & ~ 0x3ff1ffd, sym_value); + return (insn & ~ 0x3ff1ffd) | re_assemble_22 (sym_value); /* This is any 17bit branch. In PA2.0 syntax it also corresponds to the "B" instruction as well as BE. */ @@ -1985,7 +1990,7 @@ elf_hppa_relocate_insn (insn, sym_value, r_type) case R_PARISC_DIR17R: case R_PARISC_PCREL17C: case R_PARISC_PCREL17R: - return re_assemble_17 (insn & ~ 0x1f1ffd, sym_value); + return (insn & ~ 0x1f1ffd) | re_assemble_17 (sym_value); /* ADDIL or LDIL instructions. */ case R_PARISC_DLTREL21L: @@ -1996,7 +2001,7 @@ elf_hppa_relocate_insn (insn, sym_value, r_type) case R_PARISC_DPREL21L: case R_PARISC_PLTOFF21L: case R_PARISC_DIR21L: - return re_assemble_21 (insn & ~ 0x1fffff, sym_value); + return (insn & ~ 0x1fffff) | re_assemble_21 (sym_value); /* LDO and integer loads/stores with 14bit displacements. */ case R_PARISC_DLTREL14R: diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c index 1fdd4ab..f57911a 100644 --- a/bfd/elf32-hppa.c +++ b/bfd/elf32-hppa.c @@ -33,10 +33,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "elf32-hppa.h" #define ARCH_SIZE 32 #include "elf-hppa.h" +#include "elf32-hppa.h" -/* We use three different hash tables to hold information for - linking PA ELF objects. +/* We use two hash tables to hold information for linking PA ELF objects. The first is the elf32_hppa_link_hash_table which is derived from the standard ELF linker hash table. We use this as a place to @@ -50,12 +50,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ struct elf32_hppa_stub_hash_entry { - /* Base hash table entry structure, we can get the name of the stub - (and thus know exactly what actions it performs) from the base - hash table entry. */ + /* Base hash table entry structure. */ struct bfd_hash_entry root; - /* Offset of the beginning of this stub. */ + /* The stub section. */ + asection *stub_sec; + + /* Offset within stub_sec of the beginning of this stub. */ bfd_vma offset; /* Given the symbol's value and its section we can determine its final @@ -64,121 +65,67 @@ struct elf32_hppa_stub_hash_entry asection *target_section; }; -struct elf32_hppa_stub_hash_table -{ - /* The hash table itself. */ - struct bfd_hash_table root; - - /* The stub BFD. */ - bfd *stub_bfd; - - /* Where to place the next stub. */ - bfd_byte *location; - - /* Current offset in the stub section. */ - unsigned int offset; - -}; - -struct elf32_hppa_link_hash_entry -{ - struct elf_link_hash_entry root; -}; - struct elf32_hppa_link_hash_table { /* The main hash table. */ struct elf_link_hash_table root; /* The stub hash table. */ - struct elf32_hppa_stub_hash_table *stub_hash_table; + struct bfd_hash_table stub_hash_table; - /* A count of the number of output symbols. */ - unsigned int output_symbol_count; + /* Current offsets in the stub sections. */ + bfd_vma *offset; - /* Stuff so we can handle DP relative relocations. */ - long global_value; - int global_sym_defined; + /* Global data pointer. */ + bfd_vma global_value; }; -/* ELF32/HPPA relocation support - This file contains ELF32/HPPA relocation support as specified - in the Stratus FTX/Golf Object File Format (SED-1762) dated - February 1994. */ +/* For linker stub hash tables. */ -#include "elf32-hppa.h" -#include "hppa_stubs.h" +#define elf32_hppa_stub_hash_lookup(table, string, create, copy) \ + ((struct elf32_hppa_stub_hash_entry *) \ + bfd_hash_lookup ((table), (string), (create), (copy))) -static unsigned long hppa_elf_relocate_insn - PARAMS ((bfd *, asection *, unsigned long, unsigned long, long, - long, unsigned long, unsigned long, unsigned long)); +/* Get the PA ELF linker hash table from a link_info structure. */ -static boolean elf32_hppa_add_symbol_hook - PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *, - const char **, flagword *, asection **, bfd_vma *)); +#define elf32_hppa_hash_table(p) \ + ((struct elf32_hppa_link_hash_table *) ((p)->hash)) -static bfd_reloc_status_type elf32_hppa_bfd_final_link_relocate - PARAMS ((reloc_howto_type *, bfd *, bfd *, asection *, - bfd_byte *, bfd_vma, bfd_vma, bfd_vma, struct bfd_link_info *, - asection *, const char *, int)); + +static struct bfd_hash_entry *elf32_hppa_stub_hash_newfunc + PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); static struct bfd_link_hash_table *elf32_hppa_link_hash_table_create PARAMS ((bfd *)); -static struct bfd_hash_entry * -elf32_hppa_stub_hash_newfunc - PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); +static char *elf32_hppa_stub_name + PARAMS ((const char *, const asection *, const asection *, + bfd_vma, const struct elf_link_hash_entry *)); -static boolean -elf32_hppa_relocate_section +static int elf32_hppa_relocate_insn + PARAMS ((int, bfd_vma, bfd_signed_vma, unsigned int, int, + enum hppa_reloc_field_selector_type_alt)); + +static bfd_reloc_status_type elf32_hppa_bfd_final_link_relocate + PARAMS ((reloc_howto_type *, bfd *, asection *, + bfd_byte *, bfd_vma, bfd_vma, bfd_signed_vma, + struct bfd_link_info *, asection *, const char *, + struct elf_link_hash_entry *)); + +static boolean elf32_hppa_relocate_section PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); -static boolean -elf32_hppa_stub_hash_table_init - PARAMS ((struct elf32_hppa_stub_hash_table *, bfd *, - struct bfd_hash_entry *(*) PARAMS ((struct bfd_hash_entry *, - struct bfd_hash_table *, - const char *)))); - -static boolean -elf32_hppa_build_one_stub PARAMS ((struct bfd_hash_entry *, PTR)); +static boolean elf32_hppa_add_symbol_hook + PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *, + const char **, flagword *, asection **, bfd_vma *)); static unsigned int elf32_hppa_size_of_stub - PARAMS ((bfd_vma, bfd_vma, const char *)); - -static void elf32_hppa_name_of_stub - PARAMS ((bfd_vma, bfd_vma, char *)); - -/* For linker stub hash tables. */ -#define elf32_hppa_stub_hash_lookup(table, string, create, copy) \ - ((struct elf32_hppa_stub_hash_entry *) \ - bfd_hash_lookup (&(table)->root, (string), (create), (copy))) + PARAMS ((asection *, bfd_vma, bfd_vma)); -#define elf32_hppa_stub_hash_traverse(table, func, info) \ - (bfd_hash_traverse \ - (&(table)->root, \ - (boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) (func), \ - (info))) - -/* For HPPA linker hash table. */ - -#define elf32_hppa_link_hash_lookup(table, string, create, copy, follow)\ - ((struct elf32_hppa_link_hash_entry *) \ - elf_link_hash_lookup (&(table)->root, (string), (create), \ - (copy), (follow))) - -#define elf32_hppa_link_hash_traverse(table, func, info) \ - (elf_link_hash_traverse \ - (&(table)->root, \ - (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \ - (info))) - -/* Get the PA ELF linker hash table from a link_info structure. */ - -#define elf32_hppa_hash_table(p) \ - ((struct elf32_hppa_link_hash_table *) ((p)->hash)) +static boolean elf32_hppa_build_one_stub + PARAMS ((struct bfd_hash_entry *, PTR)); /* Assorted hash table functions. */ @@ -211,6 +158,7 @@ elf32_hppa_stub_hash_newfunc (entry, table, string) if (ret) { /* Initialize the local fields. */ + ret->stub_sec = NULL; ret->offset = 0; ret->target_value = 0; ret->target_section = NULL; @@ -219,22 +167,6 @@ elf32_hppa_stub_hash_newfunc (entry, table, string) return (struct bfd_hash_entry *) ret; } -/* Initialize a stub hash table. */ - -static boolean -elf32_hppa_stub_hash_table_init (table, stub_bfd, newfunc) - struct elf32_hppa_stub_hash_table *table; - bfd *stub_bfd; - struct bfd_hash_entry *(*newfunc) PARAMS ((struct bfd_hash_entry *, - struct bfd_hash_table *, - const char *)); -{ - table->offset = 0; - table->location = 0; - table->stub_bfd = stub_bfd; - return (bfd_hash_table_init (&table->root, newfunc)); -} - /* Create the derived linker hash table. The PA ELF port uses the derived hash table to keep information specific to the PA ELF linker (without using static variables). */ @@ -245,103 +177,375 @@ elf32_hppa_link_hash_table_create (abfd) { struct elf32_hppa_link_hash_table *ret; - ret = ((struct elf32_hppa_link_hash_table *) - bfd_alloc (abfd, sizeof (struct elf32_hppa_link_hash_table))); + ret = ((struct elf32_hppa_link_hash_table *) bfd_alloc (abfd, sizeof (*ret))); if (ret == NULL) return NULL; + if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, _bfd_elf_link_hash_newfunc)) { bfd_release (abfd, ret); return NULL; } - ret->stub_hash_table = NULL; - ret->output_symbol_count = 0; + + /* Init the stub hash table too. */ + if (!bfd_hash_table_init (&ret->stub_hash_table, + elf32_hppa_stub_hash_newfunc)) + return NULL; + + ret->offset = NULL; ret->global_value = 0; - ret->global_sym_defined = 0; return &ret->root.root; } -/* Relocate the given INSN given the various input parameters. +/* Build a name for a long branch stub. */ +static char * +elf32_hppa_stub_name (sym_name, sym_sec, input_section, addend, hash) + const char *sym_name; + const asection *sym_sec; + const asection *input_section; + bfd_vma addend; + const struct elf_link_hash_entry *hash; +{ + char *stub_name; + int len; + + len = strlen (sym_name) + 19; + if (hash == NULL) + len += 9; - FIXME: endianness and sizeof (long) issues abound here. */ + stub_name = bfd_malloc (len); + if (stub_name != NULL) + { + sprintf (stub_name, "%08x_%08x_%s", + input_section->id & 0xffffffff, + (int) addend & 0xffffffff, + sym_name); + + /* Tack on an ID so we can uniquely identify + this local symbol in the stub hash tables. */ + if (hash == NULL) + sprintf (stub_name + len - 10, "_%08x", + sym_sec->id & 0xffffffff); + } + return stub_name; +} -static unsigned long -hppa_elf_relocate_insn (abfd, input_sect, insn, address, sym_value, - r_addend, r_format, r_field, pcrel) - bfd *abfd; - asection *input_sect; - unsigned long insn; - unsigned long address; - long sym_value; - long r_addend; - unsigned long r_format; - unsigned long r_field; - unsigned long pcrel; +/* Relocate the given INSN given the various input parameters. */ + +static int +elf32_hppa_relocate_insn (insn, sym_value, r_addend, r_type, r_format, r_field) + int insn; + bfd_vma sym_value; + bfd_signed_vma r_addend; + unsigned int r_type; + int r_format; + enum hppa_reloc_field_selector_type_alt r_field; { - unsigned char opcode = get_opcode (insn); - long constant_value; + int value; +#ifdef ELF_ARG_RELOC +#ifndef ELF_ARG_RELOC_INSN + /* Ick. Who would want to support this? */ + int imm; + + switch (r_type) + { + /* The offset is partly stored in the instruction for cases + where the top ten bits of the addend are used for arg_reloc. + This is a little tricky, because the immediate value in the + instruction not only needs to be pieced together from + multiple bit fields, but also needs to be shifted left to + restore the original quantity. Which bits of the offset + we can retrieve from the instruction depend on exactly which + instruction we are dealing with. */ + case R_PARISC_PCREL17R: + case R_PARISC_PCREL17F: + case R_PARISC_PCREL17C: + case R_PARISC_DIR17R: + case R_PARISC_DIR17F: + /* For these relocs, we choose to use the low 10 bits from the + instruction and store the high 22 bits in the reloc addend. + It doesn't matter that the bottom 2 bits of the value are + always zero, as branches must be to a location which is a + multiple of 4. */ +#if 0 + /* It isn't necessary to retrieve the whole immediate, but + this documents what we have in the instruction. */ + imm = (((insn & 0x1f0000) >> 5) + | ((insn & 0x0004) << 8) + | ((insn & 0x1ff8) >> 3)) - ((insn & 1) << 17); + imm <<= 2; + imm = imm & 0x3ff; +#else + imm = (insn & 0x7f8) >> 1; +#endif + r_addend = (r_addend << (BFD_ARCH_SIZE-22)) >> (BFD_ARCH_SIZE-32); + r_addend = r_addend | imm; + break; + + case R_PARISC_PCREL21L: + case R_PARISC_DIR21L: + /* In this case, the instruction stores the high 21 bits of the + value, so we pick off the top 10 bits, and use the reloc + addend to store the low 22 bits. */ +#if 0 + /* It isn't necessary to retrieve the whole immediate, but + this documents what we have in the instruction. */ + imm = (( (insn & 0x000ffe) << 8) + | ((insn & 0x00c000) >> 7) + | ((insn & 0x1f0000) >> 14) + | ((insn & 0x003000) >> 12)) - ((insn & 1) << 20); + imm <<= 11; + imm = imm & ~ 0x3fffff; +#else + /* Just pick off the 10 needed bits, ensuring we sign extend. */ + imm = ((insn & 0x000ff8) << 19) - ((insn & 1) << 31); +#endif + r_addend = imm | (r_addend & 0x3fffff); + break; + + default: + break; + } +#endif +#endif + + switch (r_type) + { + case R_PARISC_PCREL21L: + case R_PARISC_PCREL17C: + case R_PARISC_PCREL17F: + case R_PARISC_PCREL17R: + case R_PARISC_PCREL14R: + /* Adjust PC relative offset. */ + r_addend -= 8; + break; + default: + break; + } + value = hppa_field_adjust (sym_value, r_addend, r_field); - switch (opcode) + switch (r_type) { - case LDO: - case LDB: - case LDH: - case LDW: - case LDWM: - case STB: - case STH: - case STW: - case STWM: - case COMICLR: - case SUBI: - case ADDIT: - case ADDI: - case LDIL: - case ADDIL: - constant_value = HPPA_R_CONSTANT (r_addend); - - if (pcrel) - sym_value -= address; - - sym_value = hppa_field_adjust (sym_value, constant_value, r_field); - return hppa_rebuild_insn (abfd, insn, sym_value, r_format); - - case BL: - case BE: - case BLE: - /* XXX r_addend ignored ???. */ - constant_value = assemble_17 ((insn & 0x001f0000) >> 16, - (insn & 0x00001ffc) >> 2, - insn & 1); - - constant_value = (constant_value << (BFD_ARCH_SIZE-17)) - >> (BFD_ARCH_SIZE-17); - if (pcrel) + case R_PARISC_PCREL17C: + case R_PARISC_PCREL17F: + case R_PARISC_PCREL17R: + case R_PARISC_DIR17F: + case R_PARISC_DIR17R: + /* This is a branch. Divide the offset by four. + Note that we need to decide whether it's a branch or + otherwise by inspecting the reloc. Inspecting insn won't + work as insn might be from a .word directive. */ + value >>= 2; + break; + + default: + break; + } + + return hppa_rebuild_insn (insn, value, r_format); +} + +/* Actually perform a relocation as part of a final link. This can get + rather hairy when linker stubs are needed. */ + +static bfd_reloc_status_type +elf32_hppa_bfd_final_link_relocate (howto, input_bfd, input_section, + contents, offset, value, addend, + info, sym_sec, sym_name, h) + reloc_howto_type *howto; + bfd *input_bfd; + asection *input_section; + bfd_byte *contents; + bfd_vma offset; + bfd_vma value; + bfd_signed_vma addend; + struct bfd_link_info *info; + asection *sym_sec; + const char *sym_name; + struct elf_link_hash_entry *h; +{ + int insn; + unsigned int r_type = howto->type; + int r_format = howto->bitsize; + enum hppa_reloc_field_selector_type_alt r_field = e_fsel; + bfd_byte *hit_data = contents + offset; + bfd_vma location; + + if (r_type == R_PARISC_NONE) + return bfd_reloc_ok; + + insn = bfd_get_32 (input_bfd, hit_data); + + /* Find out where we are and where we're going. */ + location = (offset + + input_section->output_offset + + input_section->output_section->vma); + + switch (r_type) + { + case R_PARISC_PCREL21L: + case R_PARISC_PCREL17C: + case R_PARISC_PCREL17F: + case R_PARISC_PCREL17R: + case R_PARISC_PCREL14R: + /* Make it a pc relative offset. */ + value -= location; + break; + default: + break; + } + + switch (r_type) + { + case R_PARISC_DIR32: + case R_PARISC_DIR17F: + case R_PARISC_PCREL17C: + r_field = e_fsel; + break; + + case R_PARISC_DIR21L: + case R_PARISC_PCREL21L: + r_field = e_lrsel; + break; + + case R_PARISC_DIR17R: + case R_PARISC_PCREL17R: + case R_PARISC_DIR14R: + case R_PARISC_PCREL14R: + r_field = e_rrsel; + break; + + /* For all the DP relative relocations, we need to examine the symbol's + section. If it's a code section, then "data pointer relative" makes + no sense. In that case we don't adjust the "value", and for 21 bit + addil instructions, we change the source addend register from %dp to + %r0. */ + case R_PARISC_DPREL21L: + r_field = e_lrsel; + if (sym_sec != NULL) { - sym_value -= (address + input_sect->output_offset - + input_sect->output_section->vma); - sym_value = hppa_field_adjust (sym_value, -8, r_field); + if ((sym_sec->flags & SEC_CODE) != 0) + { + if ((insn & ((0x3f << 26) | (0x1f << 21))) + == (((int) OP_ADDIL << 26) | (27 << 21))) + { + insn &= ~ (0x1f << 21); + } + } + else + value -= elf32_hppa_hash_table (info)->global_value; } - else - sym_value = hppa_field_adjust (sym_value, constant_value, r_field); + break; + + case R_PARISC_DPREL14R: + r_field = e_rrsel; + if (sym_sec != NULL && (sym_sec->flags & SEC_CODE) == 0) + value -= elf32_hppa_hash_table (info)->global_value; + break; - return hppa_rebuild_insn (abfd, insn, sym_value >> 2, r_format); + case R_PARISC_DPREL14F: + r_field = e_fsel; + if (sym_sec != NULL && (sym_sec->flags & SEC_CODE) == 0) + value -= elf32_hppa_hash_table (info)->global_value; + break; - default: - if (opcode == 0) + case R_PARISC_PLABEL32: + r_field = e_fsel; + break; + + case R_PARISC_PLABEL21L: + r_field = e_lrsel; + break; + + case R_PARISC_PLABEL14R: + r_field = e_rrsel; + break; + + /* This case is separate as it may involve a lot more work + to deal with linker stubs. */ + case R_PARISC_PCREL17F: + r_field = e_fsel; + + /* bfd_link_hash_undefweak symbols have sym_sec == NULL. */ + if (sym_sec == NULL) + break; + + /* Any kind of linker stub needed? */ + /* bfd_vma value is unsigned, so this is testing for offsets + outside the range -0x40000 to +0x3ffff */ + if (value + addend - 8 + 0x40000 >= 0x80000) { - constant_value = HPPA_R_CONSTANT (r_addend); + struct bfd_hash_table *stub_hash_table; + struct elf32_hppa_stub_hash_entry *stub_entry; + char *stub_name; + + stub_name = elf32_hppa_stub_name (sym_name, sym_sec, + input_section, addend, h); + if (!stub_name) + { + (*_bfd_error_handler) ("%s: %s", + bfd_get_filename (input_bfd), + bfd_errmsg (bfd_get_error ())); + return bfd_reloc_notsupported; + } + + stub_hash_table = &elf32_hppa_hash_table (info)->stub_hash_table; - if (pcrel) - sym_value -= address; + stub_entry = elf32_hppa_stub_hash_lookup (stub_hash_table, + stub_name, + false, + false); + if (stub_entry == NULL) + { + (*_bfd_error_handler) + (_("%s: cannot find stub entry %s"), + bfd_get_filename (input_bfd), + stub_name); + free (stub_name); + return bfd_reloc_notsupported; + } + + /* Munge up the value and addend for elf32_hppa_relocate_insn. */ + value = (stub_entry->offset + + stub_entry->stub_sec->output_offset + + stub_entry->stub_sec->output_section->vma + - location); + addend = 0; + + if (value + addend - 8 + 0x40000 >= 0x80000) + { + (*_bfd_error_handler) + (_("%s: cannot reach stub %s, recompile with -ffunction-sections"), + bfd_get_filename (input_bfd), + stub_name); + free (stub_name); + return bfd_reloc_notsupported; + } - return hppa_field_adjust (sym_value, constant_value, r_field); + free (stub_name); } - else - abort (); + break; + + /* Something we don't know how to handle. */ + default: + return bfd_reloc_notsupported; } + + /* bfd_link_hash_undefweak symbols have sym_sec == NULL. */ + if (sym_sec == NULL) + { + BFD_ASSERT (h != NULL && h->root.type == bfd_link_hash_undefweak); + value = 0; + } + + insn = elf32_hppa_relocate_insn (insn, value, addend, + r_type, r_format, r_field); + + /* Update the instruction word. */ + bfd_put_32 (input_bfd, insn, hit_data); + return bfd_reloc_ok; } /* Relocate an HPPA ELF section. */ @@ -349,7 +553,7 @@ hppa_elf_relocate_insn (abfd, input_sect, insn, address, sym_value, static boolean elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section, contents, relocs, local_syms, local_sections) - bfd *output_bfd; + bfd *output_bfd ATTRIBUTE_UNUSED; struct bfd_link_info *info; bfd *input_bfd; asection *input_section; @@ -368,9 +572,9 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section, relend = relocs + input_section->reloc_count; for (; rel < relend; rel++) { - int r_type; + unsigned int r_type; reloc_howto_type *howto; - unsigned long r_symndx; + unsigned int r_symndx; struct elf_link_hash_entry *h; Elf_Internal_Sym *sym; asection *sym_sec; @@ -379,7 +583,7 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section, const char *sym_name; r_type = ELF32_R_TYPE (rel->r_info); - if (r_type < 0 || r_type >= (int) R_PARISC_UNIMPLEMENTED) + if (r_type >= (unsigned int) R_PARISC_UNIMPLEMENTED) { bfd_set_error (bfd_error_bad_value); return false; @@ -422,7 +626,7 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section, } else { - long indx; + int indx; indx = r_symndx - symtab_hdr->sh_info; h = elf_sym_hashes (input_bfd)[indx]; @@ -462,332 +666,87 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section, sym_name = bfd_section_name (input_bfd, sym_sec); } - r = elf32_hppa_bfd_final_link_relocate (howto, input_bfd, output_bfd, + r = elf32_hppa_bfd_final_link_relocate (howto, input_bfd, input_section, contents, rel->r_offset, relocation, rel->r_addend, info, sym_sec, - sym_name, h == NULL); + sym_name, h); - if (r != bfd_reloc_ok) + switch (r) { - switch (r) - { - /* This can happen for DP relative relocs if $global$ is - undefined. This is a panic situation so we don't try - to continue. */ - case bfd_reloc_undefined: - case bfd_reloc_notsupported: - if (!((*info->callbacks->undefined_symbol) - (info, "$global$", input_bfd, - input_section, rel->r_offset, true))) - return false; + case bfd_reloc_ok: + break; + + case bfd_reloc_undefined: + case bfd_reloc_notsupported: + (*_bfd_error_handler) + (_("%s: cannot handle relocation %s for %s at 0x%x in %s"), + bfd_get_filename (input_bfd), + howto->name, + sym_name, + rel->r_offset, + input_section->name); + return false; + + default: + case bfd_reloc_outofrange: + case bfd_reloc_overflow: + { + if (!((*info->callbacks->reloc_overflow) + (info, sym_name, howto->name, (bfd_vma) 0, + input_bfd, input_section, rel->r_offset))) return false; - case bfd_reloc_dangerous: - { - /* We use this return value to indicate that we performed - a "dangerous" relocation. This doesn't mean we did - the wrong thing, it just means there may be some cleanup - that needs to be done here. - - In particular we had to swap the last call insn and its - delay slot. If the delay slot insn needed a relocation, - then we'll need to adjust the next relocation entry's - offset to account for the fact that the insn moved. - - This hair wouldn't be necessary if we inserted stubs - between procedures and used a "bl" to get to the stub. */ - if (rel != relend) - { - Elf_Internal_Rela *next_rel = rel + 1; - - if (rel->r_offset + 4 == next_rel->r_offset) - next_rel->r_offset -= 4; - } - break; - } - default: - case bfd_reloc_outofrange: - case bfd_reloc_overflow: - { - if (!((*info->callbacks->reloc_overflow) - (info, sym_name, howto->name, (bfd_vma) 0, - input_bfd, input_section, rel->r_offset))) - return false; - } - break; - } + } + break; } } return true; } -/* Actually perform a relocation as part of a final link. This can get - rather hairy when linker stubs are needed. */ +/* Called after we have seen all the input files/sections, but before + final symbol resolution and section placement has been determined. -static bfd_reloc_status_type -elf32_hppa_bfd_final_link_relocate (howto, input_bfd, output_bfd, - input_section, contents, offset, value, - addend, info, sym_sec, sym_name, is_local) - reloc_howto_type *howto; - bfd *input_bfd; - bfd *output_bfd ATTRIBUTE_UNUSED; - asection *input_section; - bfd_byte *contents; - bfd_vma offset; - bfd_vma value; - bfd_vma addend; + We use this hook to (possibly) provide a value for __gp, then we + fall back to the generic ELF final link routine. */ + +boolean +elf32_hppa_final_link (abfd, info) + bfd *abfd; struct bfd_link_info *info; - asection *sym_sec; - const char *sym_name; - int is_local; { - unsigned long insn; - unsigned long r_type = howto->type; - unsigned long r_format = howto->bitsize; - unsigned long r_field = e_fsel; - bfd_byte *hit_data = contents + offset; - boolean r_pcrel = howto->pc_relative; - - insn = bfd_get_32 (input_bfd, hit_data); - - /* Make sure we have a value for $global$. FIXME isn't this effectively - just like the gp pointer on MIPS? Can we use those routines for this - purpose? */ - if (!elf32_hppa_hash_table (info)->global_sym_defined) + if (!info->relocateable) { struct elf_link_hash_entry *h; asection *sec; + bfd_vma gp_val; - h = elf_link_hash_lookup (elf_hash_table (info), "$global$", false, - false, false); - - /* If there isn't a $global$, then we're in deep trouble. */ - if (h == NULL) - return bfd_reloc_notsupported; - - /* If $global$ isn't a defined symbol, then we're still in deep - trouble. */ - if (h->root.type != bfd_link_hash_defined) - return bfd_reloc_undefined; - - sec = h->root.u.def.section; - elf32_hppa_hash_table (info)->global_value = (h->root.u.def.value - + sec->output_section->vma - + sec->output_offset); - elf32_hppa_hash_table (info)->global_sym_defined = 1; - } - - switch (r_type) - { - case R_PARISC_NONE: - break; - - case R_PARISC_DIR32: - case R_PARISC_DIR17F: - case R_PARISC_PCREL17C: - r_field = e_fsel; - goto do_basic_type_1; - case R_PARISC_DIR21L: - case R_PARISC_PCREL21L: - r_field = e_lrsel; - goto do_basic_type_1; - case R_PARISC_DIR17R: - case R_PARISC_PCREL17R: - case R_PARISC_DIR14R: - case R_PARISC_PCREL14R: - r_field = e_rrsel; - goto do_basic_type_1; + h = elf_link_hash_lookup (elf_hash_table (info), "$global$", + false, false, false); - /* For all the DP relative relocations, we need to examine the symbol's - section. If it's a code section, then "data pointer relative" makes - no sense. In that case we don't adjust the "value", and for 21 bit - addil instructions, we change the source addend register from %dp to - %r0. */ - case R_PARISC_DPREL21L: - r_field = e_lrsel; - if (sym_sec->flags & SEC_CODE) + if (h != NULL + && h->root.type == bfd_link_hash_defined) { - if ((insn & 0xfc000000) >> 26 == 0xa - && (insn & 0x03e00000) >> 21 == 0x1b) - insn &= ~0x03e00000; + gp_val = h->root.u.def.value; + sec = h->root.u.def.section; } else - value -= elf32_hppa_hash_table (info)->global_value; - goto do_basic_type_1; - case R_PARISC_DPREL14R: - r_field = e_rrsel; - if ((sym_sec->flags & SEC_CODE) == 0) - value -= elf32_hppa_hash_table (info)->global_value; - goto do_basic_type_1; - case R_PARISC_DPREL14F: - r_field = e_fsel; - if ((sym_sec->flags & SEC_CODE) == 0) - value -= elf32_hppa_hash_table (info)->global_value; - goto do_basic_type_1; - - /* These cases are separate as they may involve a lot more work - to deal with linker stubs. */ - case R_PARISC_PLABEL32: - case R_PARISC_PLABEL21L: - case R_PARISC_PLABEL14R: - case R_PARISC_PCREL17F: - { - bfd_vma location; - unsigned int len; - char *new_name, *stub_name; - - /* Get the field selector right. We'll need it in a minute. */ - if (r_type == R_PARISC_PCREL17F - || r_type == R_PARISC_PLABEL32) - r_field = e_fsel; - else if (r_type == R_PARISC_PLABEL21L) - r_field = e_lrsel; - else if (r_type == R_PARISC_PLABEL14R) - r_field = e_rrsel; - - /* Find out where we are and where we're going. */ - location = (offset + - input_section->output_offset + - input_section->output_section->vma); - - len = strlen (sym_name) + 1; - if (is_local) - len += 9; - new_name = bfd_malloc (len); - if (!new_name) - return bfd_reloc_notsupported; - strcpy (new_name, sym_name); - - /* Local symbols have unique IDs. */ - if (is_local) - sprintf (new_name + len - 10, "_%08x", (int)sym_sec); - - /* Any kind of linker stub needed? */ - if (((int)(value - location) > 0x3ffff) - || ((int)(value - location) < -0x40000)) - { - struct elf32_hppa_stub_hash_table *stub_hash_table; - struct elf32_hppa_stub_hash_entry *stub_hash; - asection *stub_section; - - /* Build a name for the stub. */ - - len = strlen (new_name); - len += 23; - stub_name = bfd_malloc (len); - if (!stub_name) - return bfd_reloc_notsupported; - elf32_hppa_name_of_stub (location, value, stub_name); - strcat (stub_name, new_name); - free (new_name); - - stub_hash_table = elf32_hppa_hash_table (info)->stub_hash_table; - - stub_hash - = elf32_hppa_stub_hash_lookup (stub_hash_table, stub_name, - false, false); - - /* We're done with that name. */ - free (stub_name); - - /* The stub BFD only has one section. */ - stub_section = stub_hash_table->stub_bfd->sections; - - if (stub_hash != NULL) - { - if (r_type == R_PARISC_PCREL17F) - { - unsigned long delay_insn; - unsigned int opcode, rtn_reg, ldo_target_reg, ldo_src_reg; - - /* We'll need to peek at the next insn. */ - delay_insn = bfd_get_32 (input_bfd, hit_data + 4); - opcode = get_opcode (delay_insn); - - /* We also need to know the return register for this - call. */ - rtn_reg = (insn & 0x03e00000) >> 21; - - ldo_src_reg = (delay_insn & 0x03e00000) >> 21; - ldo_target_reg = (delay_insn & 0x001f0000) >> 16; - - /* Munge up the value and other parameters for - hppa_elf_relocate_insn. */ - - value = (stub_hash->offset - + stub_section->output_offset - + stub_section->output_section->vma); - - r_format = 17; - r_field = e_fsel; - r_pcrel = 0; - addend = 0; - - /* We need to peek at the delay insn and determine if - we'll need to swap the branch and its delay insn. */ - if ((insn & 2) - || (opcode == LDO - && ldo_target_reg == rtn_reg) - || (delay_insn == 0x08000240)) - { - /* No need to swap the branch and its delay slot, but - we do need to make sure to jump past the return - pointer update in the stub. */ - value += 4; - - /* If the delay insn does a return pointer adjustment, - then we have to make sure it stays valid. */ - if (opcode == LDO - && ldo_target_reg == rtn_reg) - { - delay_insn &= 0xfc00ffff; - delay_insn |= ((31 << 21) | (31 << 16)); - bfd_put_32 (input_bfd, delay_insn, hit_data + 4); - } - /* Use a BLE to reach the stub. */ - insn = BLE_SR4_R0; - } - else - { - /* Wonderful, we have to swap the call insn and its - delay slot. */ - bfd_put_32 (input_bfd, delay_insn, hit_data); - /* Use a BLE,n to reach the stub. */ - insn = (BLE_SR4_R0 | 0x2); - bfd_put_32 (input_bfd, insn, hit_data + 4); - insn = hppa_elf_relocate_insn (input_bfd, - input_section, - insn, offset + 4, - value, addend, - r_format, r_field, - r_pcrel); - /* Update the instruction word. */ - bfd_put_32 (input_bfd, insn, hit_data + 4); - return bfd_reloc_dangerous; - } - } - else - return bfd_reloc_notsupported; - } - } - goto do_basic_type_1; - } - -do_basic_type_1: - insn = hppa_elf_relocate_insn (input_bfd, input_section, insn, - offset, value, addend, r_format, - r_field, r_pcrel); - break; + { + /* If $global$ isn't defined, we could make one up ourselves + from the start of .plt, .dlt, or .data For the time + being, just bomb. */ + (*info->callbacks->undefined_symbol) + (info, "$global$", abfd, NULL, 0, true); + return false; + } - /* Something we don't know how to handle. */ - default: - return bfd_reloc_notsupported; + elf32_hppa_hash_table (info)->global_value = (gp_val + + sec->output_section->vma + + sec->output_offset); } - /* Update the instruction word. */ - bfd_put_32 (input_bfd, insn, hit_data); - return (bfd_reloc_ok); + /* Invoke the standard linker. */ + return bfd_elf_bfd_final_link (abfd, info); } /* Undo the generic ELF code's subtraction of section->vma from the @@ -807,119 +766,105 @@ elf32_hppa_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp) return true; } -/* Determine the name of the stub needed to perform a call assuming the - argument relocation bits for caller and callee are in CALLER and CALLEE - for a call from LOCATION to DESTINATION. Copy the name into STUB_NAME. */ - -static void -elf32_hppa_name_of_stub (location, destination, stub_name) - bfd_vma location ATTRIBUTE_UNUSED; - bfd_vma destination ATTRIBUTE_UNUSED; - char *stub_name; -{ - strcpy (stub_name, "_____long_branch_stub_"); -} - -/* Compute the size of the stub needed to call from LOCATION to DESTINATION - (a function named SYM_NAME), with argument relocation bits CALLER and - CALLEE. Return zero if no stub is needed to perform such a call. */ +/* Compute the size of the stub needed to call from INPUT_SEC (OFFSET) + to DESTINATION. Return zero if no stub is needed to perform such a + call. */ static unsigned int -elf32_hppa_size_of_stub (location, destination, sym_name) - bfd_vma location, destination; - const char *sym_name; +elf32_hppa_size_of_stub (input_sec, offset, destination) + asection *input_sec; + bfd_vma offset; + bfd_vma destination; { - /* Determine if a long branch stub is needed. */ - if (!(((int)(location - destination) > 0x3ffff) - || ((int)(location - destination) < -0x40000))) - return 0; - - if (!strncmp ("$$", sym_name, 2) - && strcmp ("$$dyncall", sym_name)) - return 12; - else - return 16; + bfd_vma location; + + /* Determine where the call point is. */ + location = (input_sec->output_offset + + input_sec->output_section->vma + + offset); + + /* Determine if a long branch stub is needed. parisc branch offsets + are relative to the second instruction past the branch, ie. +8 + bytes on from the branch instruction location. The offset is + signed, 17 bits wide, and counts in units of 4 bytes. + bfd_vma is unsigned, so this is testing for offsets outside the + range -0x40000 to +0x3ffff */ + if (destination - location - 8 + 0x40000 >= 0x80000) + return 8; + return 0; } /* Build one linker stub as defined by the stub hash table entry GEN_ENTRY. - IN_ARGS contains the stub BFD and link info pointers. */ + IN_ARG contains the link info pointer. */ + +#define LDIL_R1 0x20200000 /* ldil LR'XXX,%r1 */ +#define BE_SR4_R1 0xe0202002 /* be,n RR'XXX(%sr4,%r1) */ static boolean -elf32_hppa_build_one_stub (gen_entry, in_args) +elf32_hppa_build_one_stub (gen_entry, in_arg) struct bfd_hash_entry *gen_entry; - PTR in_args; + PTR in_arg; { - void **args = (void **)in_args; - bfd *stub_bfd = (bfd *)args[0]; - struct bfd_link_info *info = (struct bfd_link_info *)args[1]; - struct elf32_hppa_stub_hash_entry *entry; - struct elf32_hppa_stub_hash_table *stub_hash_table; + struct elf32_hppa_stub_hash_entry *stub_entry; + struct elf32_hppa_link_hash_table *hppa_link_hash; + asection *stub_sec; + bfd *stub_bfd; bfd_byte *loc; symvalue sym_value; - const char *sym_name; + int insn; + + /* Massage our args to the form they really have. */ + stub_entry = (struct elf32_hppa_stub_hash_entry *) gen_entry; + hppa_link_hash = (struct elf32_hppa_link_hash_table *) in_arg; - /* Initialize pointers to the stub hash table, the particular entry we - are building a stub for, and where (in memory) we should place the stub - instructions. */ - entry = (struct elf32_hppa_stub_hash_entry *)gen_entry; - stub_hash_table = elf32_hppa_hash_table(info)->stub_hash_table; - loc = stub_hash_table->location; + stub_sec = stub_entry->stub_sec; /* Make a note of the offset within the stubs for this entry. */ - entry->offset = stub_hash_table->offset; + stub_entry->offset = hppa_link_hash->offset[stub_sec->index]; + loc = stub_sec->contents + stub_entry->offset; - /* The symbol's name starts at offset 22. */ - sym_name = entry->root.string + 22; + sym_value = (stub_entry->target_value + + stub_entry->target_section->output_offset + + stub_entry->target_section->output_section->vma); - sym_value = (entry->target_value - + entry->target_section->output_offset - + entry->target_section->output_section->vma); + stub_bfd = stub_sec->owner; - if (1) - { - /* Create one of two variant long branch stubs. One for $$dyncall and - normal calls, the other for calls to millicode. */ - unsigned long insn; - int millicode_call = 0; - - if (!strncmp ("$$", sym_name, 2) && strcmp ("$$dyncall", sym_name)) - millicode_call = 1; - - /* First the return pointer adjustment. Depending on exact calling - sequence this instruction may be skipped. */ - bfd_put_32 (stub_bfd, LDO_M4_R31_R31, loc); - - /* The next two instructions are the long branch itself. A long branch - is formed with "ldil" loading the upper bits of the target address - into a register, then branching with "be" which adds in the lower bits. - Long branches to millicode nullify the delay slot of the "be". */ - insn = hppa_rebuild_insn (stub_bfd, LDIL_R1, - hppa_field_adjust (sym_value, 0, e_lrsel), 21); - bfd_put_32 (stub_bfd, insn, loc + 4); - insn = hppa_rebuild_insn (stub_bfd, BE_SR4_R1 | (millicode_call ? 2 : 0), - hppa_field_adjust (sym_value, 0, e_rrsel) >> 2, - 17); - bfd_put_32 (stub_bfd, insn, loc + 8); - - if (!millicode_call) - { - /* The sequence to call this stub places the return pointer into %r31, - the final target expects the return pointer in %r2, so copy the - return pointer into the proper register. */ - bfd_put_32 (stub_bfd, COPY_R31_R2, loc + 12); - - /* Update the location and offsets. */ - stub_hash_table->location += 16; - stub_hash_table->offset += 16; - } - else - { - /* Update the location and offsets. */ - stub_hash_table->location += 12; - stub_hash_table->offset += 12; - } + /* Create the long branch. A long branch is formed with "ldil" + loading the upper bits of the target address into a register, + then branching with "be" which adds in the lower bits. + The "be" has its delay slot nullified. */ + insn = hppa_rebuild_insn (LDIL_R1, + hppa_field_adjust (sym_value, 0, e_lrsel), + 21); + bfd_put_32 (stub_bfd, insn, loc); + + insn = hppa_rebuild_insn (BE_SR4_R1, + hppa_field_adjust (sym_value, 0, e_rrsel) >> 2, + 17); + bfd_put_32 (stub_bfd, insn, loc + 4); + + hppa_link_hash->offset[stub_sec->index] += 8; + + return true; +} + +/* As above, but don't actually build the stub. Just bump offset so + we know stub section sizes. */ + +static boolean +elf32_hppa_size_one_stub (gen_entry, in_arg) + struct bfd_hash_entry *gen_entry; + PTR in_arg; +{ + struct elf32_hppa_stub_hash_entry *stub_entry; + struct elf32_hppa_link_hash_table *hppa_link_hash; + + /* Massage our args to the form they really have. */ + stub_entry = (struct elf32_hppa_stub_hash_entry *) gen_entry; + hppa_link_hash = (struct elf32_hppa_link_hash_table *) in_arg; + + hppa_link_hash->offset[stub_entry->stub_sec->index] += 8; - } return true; } @@ -930,31 +875,32 @@ elf32_hppa_build_one_stub (gen_entry, in_args) table. This is called via hppaelf_finish in the linker. */ boolean -elf32_hppa_build_stubs (stub_bfd, info) +elf32_hppa_build_stubs (stub_bfd, link_info) bfd *stub_bfd; - struct bfd_link_info *info; + struct bfd_link_info *link_info; { - /* The stub BFD only has one section. */ - asection *stub_sec = stub_bfd->sections; - struct elf32_hppa_stub_hash_table *table; - unsigned int size; - void *args[2]; - - /* So we can pass both the BFD for the stubs and the link info - structure to the routine which actually builds stubs. */ - args[0] = stub_bfd; - args[1] = info; - - /* Allocate memory to hold the linker stubs. */ - size = bfd_section_size (stub_bfd, stub_sec); - stub_sec->contents = (unsigned char *) bfd_zalloc (stub_bfd, size); - if (stub_sec->contents == NULL) - return false; - table = elf32_hppa_hash_table(info)->stub_hash_table; - table->location = stub_sec->contents; + asection *stub_sec; + struct bfd_hash_table *table; + struct elf32_hppa_link_hash_table *hppa_link_hash; + + for (stub_sec = stub_bfd->sections; stub_sec; stub_sec = stub_sec->next) + { + unsigned int size; + + /* Allocate memory to hold the linker stubs. */ + size = bfd_section_size (stub_bfd, stub_sec); + stub_sec->contents = (unsigned char *) bfd_zalloc (stub_bfd, size); + if (stub_sec->contents == NULL && size != 0) + return false; + } /* Build the stubs as directed by the stub hash table. */ - elf32_hppa_stub_hash_traverse (table, elf32_hppa_build_one_stub, args); + hppa_link_hash = elf32_hppa_hash_table (link_info); + memset (hppa_link_hash->offset, 0, + stub_bfd->section_count * sizeof (bfd_vma)); + + table = &hppa_link_hash->stub_hash_table; + bfd_hash_traverse (table, elf32_hppa_build_one_stub, hppa_link_hash); return true; } @@ -964,345 +910,416 @@ elf32_hppa_build_stubs (stub_bfd, info) The basic idea here is to examine all the relocations looking for PC-relative calls to a target that is unreachable with a "bl" instruction or calls where the caller and callee disagree on the - location of their arguments or return value. */ + location of their arguments or return value. Currently, we don't + support elf arg relocs. */ boolean -elf32_hppa_size_stubs (stub_bfd, output_bfd, link_info) +elf32_hppa_size_stubs (stub_bfd, link_info, + add_stub_section, layout_sections_again) bfd *stub_bfd; - bfd *output_bfd ATTRIBUTE_UNUSED; struct bfd_link_info *link_info; + asection * (*add_stub_section) PARAMS ((const char *, asection *)); + void (*layout_sections_again) PARAMS ((void)); { bfd *input_bfd; - asection *section, *stub_sec = 0; - Elf_Internal_Shdr *symtab_hdr; + asection *section; Elf_Internal_Sym *local_syms, **all_local_syms; - unsigned int i, index, bfd_count = 0; - struct elf32_hppa_stub_hash_table *stub_hash_table = 0; - - /* Create and initialize the stub hash table. */ - stub_hash_table = ((struct elf32_hppa_stub_hash_table *) - bfd_malloc (sizeof (struct elf32_hppa_stub_hash_table))); - if (!stub_hash_table) - goto error_return; - - if (!elf32_hppa_stub_hash_table_init (stub_hash_table, stub_bfd, - elf32_hppa_stub_hash_newfunc)) - goto error_return; - - /* Attach the hash tables to the main hash table. */ - elf32_hppa_hash_table(link_info)->stub_hash_table = stub_hash_table; - - /* Count the number of input BFDs. */ - for (input_bfd = link_info->input_bfds; + asection **stub_section_created; + unsigned int i, indx, bfd_count, sec_count; + asection *stub_sec; + asection *first_init_sec = NULL; + asection *first_fini_sec = NULL; + struct elf32_hppa_link_hash_table *hppa_link_hash; + struct bfd_hash_table *stub_hash_table; + boolean stub_changed; + + /* Count the number of input BFDs and the total number of input sections. */ + for (input_bfd = link_info->input_bfds, bfd_count = 0, sec_count = 0; input_bfd != NULL; input_bfd = input_bfd->link_next) - bfd_count++; - - /* Magic as we know the stub bfd only has one section. */ - stub_sec = stub_bfd->sections; - - /* If generating a relocateable output file, then we don't - have to examine the relocs. */ - if (link_info->relocateable) { - for (i = 0; i < bfd_count; i++) - if (all_local_syms[i]) - free (all_local_syms[i]); - free (all_local_syms); - return true; + bfd_count += 1; + sec_count += input_bfd->section_count; } - /* Now that we have argument location information for all the global - functions we can start looking for stubs. */ - for (input_bfd = link_info->input_bfds, index = 0; + stub_section_created + = (asection **) bfd_zmalloc (sizeof (asection *) * sec_count); + if (stub_section_created == NULL) + return false; + + /* We want to read in symbol extension records only once. To do this + we need to read in the local symbols in parallel and save them for + later use; so hold pointers to the local symbols in an array. */ + all_local_syms + = (Elf_Internal_Sym **) bfd_zmalloc (sizeof (Elf_Internal_Sym *) + * bfd_count); + if (all_local_syms == NULL) + goto error_ret_free_stub; + + /* Walk over all the input BFDs adding entries to the args hash table + for all the external functions. */ + for (input_bfd = link_info->input_bfds, indx = 0; input_bfd != NULL; - input_bfd = input_bfd->link_next, index++) + input_bfd = input_bfd->link_next, indx++) { + Elf_Internal_Shdr *symtab_hdr; + Elf_Internal_Sym *isym; + Elf32_External_Sym *ext_syms, *esym; + /* We'll need the symbol table in a second. */ symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; if (symtab_hdr->sh_info == 0) continue; - local_syms = all_local_syms[index]; + /* We need an array of the local symbols attached to the input bfd. + Unfortunately, we're going to have to read & swap them in. */ + local_syms = (Elf_Internal_Sym *) + bfd_malloc (symtab_hdr->sh_info * sizeof (Elf_Internal_Sym)); + if (local_syms == NULL) + { + goto error_ret_free_local; + } + all_local_syms[indx] = local_syms; + ext_syms = (Elf32_External_Sym *) + bfd_malloc (symtab_hdr->sh_info * sizeof (Elf32_External_Sym)); + if (ext_syms == NULL) + { + goto error_ret_free_local; + } + + if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0 + || (bfd_read (ext_syms, 1, + (symtab_hdr->sh_info * sizeof (Elf32_External_Sym)), + input_bfd) + != (symtab_hdr->sh_info * sizeof (Elf32_External_Sym)))) + { + free (ext_syms); + goto error_ret_free_local; + } + + /* Swap the local symbols in. */ + isym = local_syms; + esym = ext_syms; + for (i = 0; i < symtab_hdr->sh_info; i++, esym++, isym++) + bfd_elf32_swap_symbol_in (input_bfd, esym, isym); + + /* Now we can free the external symbols. */ + free (ext_syms); + } + + stub_hash_table = &elf32_hppa_hash_table (link_info)->stub_hash_table; + + while (1) + { + stub_changed = 0; - /* Walk over each section attached to the input bfd. */ - for (section = input_bfd->sections; - section != NULL; - section = section->next) + /* Now that we have argument location information for all the + global functions we can start looking for stubs. */ + for (input_bfd = link_info->input_bfds, indx = 0, sec_count = 0; + input_bfd != NULL; + input_bfd = input_bfd->link_next, indx++) { - Elf_Internal_Shdr *input_rel_hdr; - Elf32_External_Rela *external_relocs, *erelaend, *erela; - Elf_Internal_Rela *internal_relocs, *irelaend, *irela; + Elf_Internal_Shdr *symtab_hdr; - /* If there aren't any relocs, then there's nothing to do. */ - if ((section->flags & SEC_RELOC) == 0 - || section->reloc_count == 0) + /* We'll need the symbol table in a second. */ + symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; + if (symtab_hdr->sh_info == 0) continue; - /* Allocate space for the external relocations. */ - external_relocs - = ((Elf32_External_Rela *) - bfd_malloc (section->reloc_count - * sizeof (Elf32_External_Rela))); - if (external_relocs == NULL) - { - for (i = 0; i < bfd_count; i++) - if (all_local_syms[i]) - free (all_local_syms[i]); - free (all_local_syms); - goto error_return; - } + local_syms = all_local_syms[indx]; - /* Likewise for the internal relocations. */ - internal_relocs - = ((Elf_Internal_Rela *) - bfd_malloc (section->reloc_count * sizeof (Elf_Internal_Rela))); - if (internal_relocs == NULL) + /* Walk over each section attached to the input bfd. */ + for (section = input_bfd->sections; + section != NULL; + section = section->next, sec_count++) { - free (external_relocs); - for (i = 0; i < bfd_count; i++) - if (all_local_syms[i]) - free (all_local_syms[i]); - free (all_local_syms); - goto error_return; - } + Elf_Internal_Shdr *input_rel_hdr; + Elf32_External_Rela *external_relocs, *erelaend, *erela; + Elf_Internal_Rela *internal_relocs, *irelaend, *irela; - /* Read in the external relocs. */ - input_rel_hdr = &elf_section_data (section)->rel_hdr; - if (bfd_seek (input_bfd, input_rel_hdr->sh_offset, SEEK_SET) != 0 - || bfd_read (external_relocs, 1, input_rel_hdr->sh_size, - input_bfd) != input_rel_hdr->sh_size) - { - free (external_relocs); - free (internal_relocs); - for (i = 0; i < bfd_count; i++) - if (all_local_syms[i]) - free (all_local_syms[i]); - free (all_local_syms); - goto error_return; - } + /* If there aren't any relocs, then there's nothing to do. */ + if ((section->flags & SEC_RELOC) == 0 + || section->reloc_count == 0) + continue; - /* Swap in the relocs. */ - erela = external_relocs; - erelaend = erela + section->reloc_count; - irela = internal_relocs; - for (; erela < erelaend; erela++, irela++) - bfd_elf32_swap_reloca_in (input_bfd, erela, irela); + /* Allocate space for the external relocations. */ + external_relocs + = ((Elf32_External_Rela *) + bfd_malloc (section->reloc_count + * sizeof (Elf32_External_Rela))); + if (external_relocs == NULL) + { + goto error_ret_free_local; + } - /* We're done with the external relocs, free them. */ - free (external_relocs); + /* Likewise for the internal relocations. */ + internal_relocs = ((Elf_Internal_Rela *) + bfd_malloc (section->reloc_count + * sizeof (Elf_Internal_Rela))); + if (internal_relocs == NULL) + { + free (external_relocs); + goto error_ret_free_local; + } - /* Now examine each relocation. */ - irela = internal_relocs; - irelaend = irela + section->reloc_count; - for (; irela < irelaend; irela++) - { - long r_type, size_of_stub; - unsigned long r_index; - struct elf_link_hash_entry *hash; - struct elf32_hppa_stub_hash_entry *stub_hash; - Elf_Internal_Sym *sym; - asection *sym_sec; - const char *sym_name; - symvalue sym_value; - bfd_vma location, destination; - char *new_name = NULL; - - r_type = ELF32_R_TYPE (irela->r_info); - r_index = ELF32_R_SYM (irela->r_info); - - if (r_type < 0 || r_type >= (int) R_PARISC_UNIMPLEMENTED) + /* Read in the external relocs. */ + input_rel_hdr = &elf_section_data (section)->rel_hdr; + if (bfd_seek (input_bfd, input_rel_hdr->sh_offset, SEEK_SET) != 0 + || bfd_read (external_relocs, 1, + input_rel_hdr->sh_size, + input_bfd) != input_rel_hdr->sh_size) { - bfd_set_error (bfd_error_bad_value); + free (external_relocs); + error_ret_free_internal: free (internal_relocs); - for (i = 0; i < bfd_count; i++) - if (all_local_syms[i]) - free (all_local_syms[i]); - free (all_local_syms); - goto error_return; + goto error_ret_free_local; } - /* Only look for stubs on call instructions or plabel - references. */ - if (r_type != R_PARISC_PCREL17F - && r_type != R_PARISC_PLABEL32 - && r_type != R_PARISC_PLABEL21L - && r_type != R_PARISC_PLABEL14R) - continue; + /* Swap in the relocs. */ + erela = external_relocs; + erelaend = erela + section->reloc_count; + irela = internal_relocs; + for (; erela < erelaend; erela++, irela++) + bfd_elf32_swap_reloca_in (input_bfd, erela, irela); + + /* We're done with the external relocs, free them. */ + free (external_relocs); - /* Now determine the call target, its name, value, section - and argument relocation bits. */ - hash = NULL; - sym = NULL; - sym_sec = NULL; - if (r_index < symtab_hdr->sh_info) + /* Now examine each relocation. */ + irela = internal_relocs; + irelaend = irela + section->reloc_count; + for (; irela < irelaend; irela++) { - /* It's a local symbol. */ - Elf_Internal_Shdr *hdr; - - sym = local_syms + r_index; - hdr = elf_elfsections (input_bfd)[sym->st_shndx]; - sym_sec = hdr->bfd_section; - sym_name = bfd_elf_string_from_elf_section (input_bfd, - symtab_hdr->sh_link, - sym->st_name); - sym_value = (ELF_ST_TYPE (sym->st_info) == STT_SECTION - ? 0 : sym->st_value); - destination = (sym_value - + sym_sec->output_offset - + sym_sec->output_section->vma); - - /* Tack on an ID so we can uniquely identify this local - symbol in the stub or arg info hash tables. */ - new_name = bfd_malloc (strlen (sym_name) + 10); - if (new_name == 0) + unsigned int r_type, r_indx, size_of_stub; + struct elf32_hppa_stub_hash_entry *stub_entry; + asection *sym_sec; + const char *sym_name; + symvalue sym_value; + bfd_vma destination; + struct elf_link_hash_entry *hash; + char *stub_name; + + r_type = ELF32_R_TYPE (irela->r_info); + r_indx = ELF32_R_SYM (irela->r_info); + + if (r_type >= (unsigned int) R_PARISC_UNIMPLEMENTED) { - free (internal_relocs); - for (i = 0; i < bfd_count; i++) - if (all_local_syms[i]) - free (all_local_syms[i]); - free (all_local_syms); - goto error_return; + bfd_set_error (bfd_error_bad_value); + goto error_ret_free_internal; } - sprintf (new_name, "%s_%08x", sym_name, (int)sym_sec); - sym_name = new_name; - } - else - { - /* It's an external symbol. */ - long index; - index = r_index - symtab_hdr->sh_info; - hash = elf_sym_hashes (input_bfd)[index]; - if (hash->root.type == bfd_link_hash_defined - || hash->root.type == bfd_link_hash_defweak) + /* Only look for stubs on call instructions. */ + if (r_type != (unsigned int) R_PARISC_PCREL17F) + continue; + + /* Now determine the call target, its name, value, section + and argument relocation bits. */ + sym_sec = NULL; + hash = NULL; + if (r_indx < symtab_hdr->sh_info) { - sym_sec = hash->root.u.def.section; - sym_name = hash->root.root.string; - sym_value = hash->root.u.def.value; - destination = (sym_value + /* It's a local symbol. */ + Elf_Internal_Sym *sym; + Elf_Internal_Shdr *hdr; + + sym = local_syms + r_indx; + hdr = elf_elfsections (input_bfd)[sym->st_shndx]; + sym_sec = hdr->bfd_section; + sym_name = + bfd_elf_string_from_elf_section (input_bfd, + symtab_hdr->sh_link, + sym->st_name); + sym_value = (ELF_ST_TYPE (sym->st_info) == STT_SECTION + ? 0 : sym->st_value); + destination = (sym_value + irela->r_addend + sym_sec->output_offset + sym_sec->output_section->vma); } else { - bfd_set_error (bfd_error_bad_value); - free (internal_relocs); - for (i = 0; i < bfd_count; i++) - if (all_local_syms[i]) - free (all_local_syms[i]); - free (all_local_syms); - goto error_return; - } - } + /* It's an external symbol. */ + int e_indx; - /* Now determine where the call point is. */ - location = (section->output_offset - + section->output_section->vma - + irela->r_offset); - - /* We only care about the destination for PCREL function - calls (eg. we don't care for PLABELS). */ - if (r_type != R_PARISC_PCREL17F) - location = destination; - - /* Determine what (if any) linker stub is needed and its - size (in bytes). */ - size_of_stub = elf32_hppa_size_of_stub (location, - destination, - sym_name); - if (size_of_stub != 0) - { - char *stub_name; - unsigned int len; + e_indx = r_indx - symtab_hdr->sh_info; + hash = elf_sym_hashes (input_bfd)[e_indx]; - /* Get the name of this stub. */ - len = strlen (sym_name); - len += 23; + while (hash->root.type == bfd_link_hash_indirect + || hash->root.type == bfd_link_hash_warning) + hash = (struct elf_link_hash_entry *) + hash->root.u.i.link; - stub_name = bfd_malloc (len); - if (!stub_name) - { - /* Because sym_name was mallocd above for local - symbols. */ - if (r_index < symtab_hdr->sh_info) - free (new_name); - - free (internal_relocs); - for (i = 0; i < bfd_count; i++) - if (all_local_syms[i]) - free (all_local_syms[i]); - free (all_local_syms); - goto error_return; + if (hash->root.type == bfd_link_hash_undefined + || hash->root.type == bfd_link_hash_undefweak) + continue; + + if (hash->root.type == bfd_link_hash_defined + || hash->root.type == bfd_link_hash_defweak) + { + sym_sec = hash->root.u.def.section; + sym_name = hash->root.root.string; + sym_value = hash->root.u.def.value; + destination = (sym_value + irela->r_addend + + sym_sec->output_offset + + sym_sec->output_section->vma); + } + else + { + bfd_set_error (bfd_error_bad_value); + goto error_ret_free_internal; + } } - elf32_hppa_name_of_stub (location, destination, stub_name); - strcat (stub_name + 22, sym_name); - /* Because sym_name was malloced above for local symbols. */ - if (r_index < symtab_hdr->sh_info) - free (new_name); + /* Determine what (if any) linker stub is needed and its + size (in bytes). */ + size_of_stub = elf32_hppa_size_of_stub (section, + irela->r_offset, + destination); + if (size_of_stub == 0) + continue; + + /* Get the name of this stub. */ + stub_name = elf32_hppa_stub_name (sym_name, + sym_sec, + section, + irela->r_addend, + hash); + if (!stub_name) + goto error_ret_free_internal; - stub_hash - = elf32_hppa_stub_hash_lookup (stub_hash_table, stub_name, - false, false); - if (stub_hash != NULL) + stub_entry = elf32_hppa_stub_hash_lookup (stub_hash_table, + stub_name, + false, + false); + if (stub_entry != NULL) { - /* The proper stub has already been created, nothing - else to do. */ + /* The proper stub has already been created. */ free (stub_name); + continue; } - else + + stub_sec = stub_section_created[sec_count]; + if (stub_sec == NULL) { - bfd_set_section_size (stub_bfd, stub_sec, - (bfd_section_size (stub_bfd, - stub_sec) - + size_of_stub)); - - /* Enter this entry into the linker stub hash table. */ - stub_hash - = elf32_hppa_stub_hash_lookup (stub_hash_table, - stub_name, true, true); - if (stub_hash == NULL) + char *s_name; + int nstub; + int special_sec = 0; + + /* We only want one stub for .init and .fini + because glibc splits the _init and _fini + functions into two parts. We don't want to + put a stub in the middle of a function. */ + if (strncmp (section->name, ".init", 5) == 0) + { + stub_sec = first_init_sec; + special_sec = 1; + } + else if (strncmp (section->name, ".fini", 5) == 0) + { + stub_sec = first_fini_sec; + special_sec = 2; + } + if (stub_sec == NULL) { - free (stub_name); - free (internal_relocs); - for (i = 0; i < bfd_count; i++) - if (all_local_syms[i]) - free (all_local_syms[i]); - free (all_local_syms); - goto error_return; + s_name = bfd_alloc (stub_bfd, 16); + if (s_name == NULL) + { + free (stub_name); + goto error_ret_free_internal; + } + nstub = stub_bfd->section_count; + sprintf (s_name, ".stub_%x", nstub); + stub_sec = (*add_stub_section) (s_name, section); + if (stub_sec == NULL) + { + free (stub_name); + goto error_ret_free_internal; + } + if (special_sec != 0) + { + if (special_sec == 1) + first_init_sec = stub_sec; + else + first_fini_sec = stub_sec; + } } + stub_section_created[sec_count] = stub_sec; + } - /* We'll need these to determine the address that the - stub will branch to. */ - stub_hash->target_value = sym_value; - stub_hash->target_section = sym_sec; + /* Enter this entry into the linker stub + hash table. */ + stub_entry = elf32_hppa_stub_hash_lookup (stub_hash_table, + stub_name, + true, + false); + if (stub_entry == NULL) + { + (*_bfd_error_handler) + (_("%s: cannot find stub entry %s"), + bfd_get_filename (section->owner), + stub_name); + free (stub_name); + goto error_ret_free_internal; } - free (stub_name); + + /* We'll need these to determine the address + that the stub will branch to. */ + stub_entry->stub_sec = stub_sec; + stub_entry->offset = 0; + stub_entry->target_value = sym_value; + stub_entry->target_section = sym_sec; + stub_changed = 1; } + /* We're done with the internal relocs, free them. */ + free (internal_relocs); } - /* We're done with the internal relocs, free them. */ - free (internal_relocs); } + + if (!stub_changed) + break; + + /* OK, we've added some stubs. Find out the new size of the + stub sections. */ + hppa_link_hash = elf32_hppa_hash_table (link_info); + hppa_link_hash->offset = (bfd_vma *) + bfd_realloc (hppa_link_hash->offset, + stub_bfd->section_count * sizeof (bfd_vma)); + if (hppa_link_hash->offset == NULL) + goto error_ret_free_local; + + memset (hppa_link_hash->offset, 0, + stub_bfd->section_count * sizeof (bfd_vma)); + + bfd_hash_traverse (stub_hash_table, + elf32_hppa_size_one_stub, + hppa_link_hash); + + for (stub_sec = stub_bfd->sections; + stub_sec != NULL; + stub_sec = stub_sec->next) + { + bfd_set_section_size (stub_bfd, stub_sec, + hppa_link_hash->offset[stub_sec->index]); + } + /* Ask the linker to do its stuff. */ + (*layout_sections_again) (); } + /* We're done with the local symbols, free them. */ for (i = 0; i < bfd_count; i++) if (all_local_syms[i]) free (all_local_syms[i]); free (all_local_syms); + free (stub_section_created); return true; -error_return: - /* Return gracefully, avoiding dangling references to the hash tables. */ - if (stub_hash_table) - { - elf32_hppa_hash_table(link_info)->stub_hash_table = NULL; - free (stub_hash_table); - } - /* Set the size of the stub section to zero since we're never going - to create them. Avoids losing when we try to get its contents - too. */ - bfd_set_section_size (stub_bfd, stub_sec, 0); + error_ret_free_local: + for (i = 0; i < bfd_count; i++) + if (all_local_syms[i]) + free (all_local_syms[i]); + free (all_local_syms); + + error_ret_free_stub: + free (stub_section_created); return false; } @@ -1315,6 +1332,10 @@ error_return: /* Stuff for the BFD linker. */ #define elf_backend_relocate_section elf32_hppa_relocate_section #define elf_backend_add_symbol_hook elf32_hppa_add_symbol_hook +#define bfd_elf32_bfd_final_link elf32_hppa_final_link +#if 0 +#define elf_backend_check_relocs elf32_hppa_check_relocs +#endif #define bfd_elf32_bfd_link_hash_table_create \ elf32_hppa_link_hash_table_create #define elf_backend_fake_sections elf_hppa_fake_sections diff --git a/bfd/elf32-hppa.h b/bfd/elf32-hppa.h index 17c5e16..127170c 100644 --- a/bfd/elf32-hppa.h +++ b/bfd/elf32-hppa.h @@ -37,13 +37,15 @@ #include "elf/hppa.h" boolean elf32_hppa_size_stubs - PARAMS ((bfd *, bfd *, struct bfd_link_info *)); + PARAMS ((bfd *, struct bfd_link_info *, + asection * (*) PARAMS ((const char *, asection *)), + void (*) PARAMS ((void)))); boolean elf32_hppa_build_stubs PARAMS ((bfd *, struct bfd_link_info *)); extern elf_hppa_reloc_type ** _bfd_elf32_hppa_gen_reloc_type - PARAMS ((bfd *, elf_hppa_reloc_type, int, int, int, asymbol *)); + PARAMS ((bfd *, elf_hppa_reloc_type, int, unsigned int, int, asymbol *)); /* Define groups of basic relocations. FIXME: These should be the only basic relocations created by GAS. The rest diff --git a/bfd/elf64-hppa.c b/bfd/elf64-hppa.c index b5b9f7f..4b07556 100644 --- a/bfd/elf64-hppa.c +++ b/bfd/elf64-hppa.c @@ -55,7 +55,7 @@ struct elf64_hppa_dyn_hash_entry bfd_vma opd_offset; bfd_vma stub_offset; - /* The symbol table entry, if any, that this was derrived from. */ + /* The symbol table entry, if any, that this was derived from. */ struct elf_link_hash_entry *h; /* The index of the (possibly local) symbol in the input bfd and its @@ -262,7 +262,7 @@ static boolean get_stub static boolean elf64_hppa_dyn_hash_table_init (ht, abfd, new) struct elf64_hppa_dyn_hash_table *ht; - bfd *abfd; + bfd *abfd ATTRIBUTE_UNUSED; new_hash_entry_func new; { memset (ht, 0, sizeof(*ht)); @@ -575,7 +575,6 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs) if (info->shared && hppa_info->section_syms_bfd != abfd) { int i, highest_shndx; - asection *section; Elf_Internal_Sym *local_syms, *isym; Elf64_External_Sym *ext_syms, *esym; @@ -1177,7 +1176,7 @@ elf64_hppa_post_process_headers (abfd, link_info) static boolean get_opd (abfd, info, hppa_info) bfd *abfd; - struct bfd_link_info *info; + struct bfd_link_info *info ATTRIBUTE_UNUSED; struct elf64_hppa_link_hash_table *hppa_info; { asection *opd; @@ -1215,7 +1214,7 @@ get_opd (abfd, info, hppa_info) static boolean get_plt (abfd, info, hppa_info) bfd *abfd; - struct bfd_link_info *info; + struct bfd_link_info *info ATTRIBUTE_UNUSED; struct elf64_hppa_link_hash_table *hppa_info; { asection *plt; @@ -1253,7 +1252,7 @@ get_plt (abfd, info, hppa_info) static boolean get_dlt (abfd, info, hppa_info) bfd *abfd; - struct bfd_link_info *info; + struct bfd_link_info *info ATTRIBUTE_UNUSED; struct elf64_hppa_link_hash_table *hppa_info; { asection *dlt; @@ -1291,7 +1290,7 @@ get_dlt (abfd, info, hppa_info) static boolean get_stub (abfd, info, hppa_info) bfd *abfd; - struct bfd_link_info *info; + struct bfd_link_info *info ATTRIBUTE_UNUSED; struct elf64_hppa_link_hash_table *hppa_info; { asection *stub; @@ -1510,7 +1509,7 @@ allocate_dynrel_entries (dyn_h, data) static boolean elf64_hppa_adjust_dynamic_symbol (info, h) - struct bfd_link_info *info; + struct bfd_link_info *info ATTRIBUTE_UNUSED; struct elf_link_hash_entry *h; { /* ??? Undefined symbols with PLT entries should be re-defined @@ -1551,7 +1550,6 @@ elf64_hppa_size_dynamic_sections (output_bfd, info) boolean plt; boolean relocs; boolean reltext; - boolean stubs; struct elf64_hppa_allocate_data data; struct elf64_hppa_link_hash_table *hppa_info; @@ -1807,11 +1805,11 @@ elf64_hppa_size_dynamic_sections (output_bfd, info) static boolean elf64_hppa_link_output_symbol_hook (abfd, info, name, sym, input_sec) - bfd *abfd; + bfd *abfd ATTRIBUTE_UNUSED; struct bfd_link_info *info; const char *name; Elf_Internal_Sym *sym; - asection *input_sec; + asection *input_sec ATTRIBUTE_UNUSED; { struct elf64_hppa_link_hash_table *hppa_info; struct elf64_hppa_dyn_hash_entry *dyn_h; @@ -2038,7 +2036,6 @@ elf64_hppa_finalize_opd (dyn_h, data) if (info->shared && dyn_h && dyn_h->want_opd) { Elf64_Internal_Rela rel; - bfd_vma value; int dynindx; /* We may need to do a relocation against a local symbol, in @@ -2287,8 +2284,6 @@ elf64_hppa_finalize_dynreloc (dyn_h, data) if (info->shared && rent->type == R_PARISC_FPTR64) { bfd_vma value, value2; - asymbol *sym; - int elf_index; /* First compute the address of the opd entry for this symbol. */ value = (dyn_h->opd_offset @@ -2366,7 +2361,6 @@ elf64_hppa_finish_dynamic_sections (output_bfd, info) if (elf_hash_table (info)->dynamic_sections_created) { Elf64_External_Dyn *dyncon, *dynconend; - struct elf_link_hash_entry *h; BFD_ASSERT (sdyn != NULL); @@ -2488,7 +2482,7 @@ static boolean elf64_hppa_modify_segment_map (abfd) bfd *abfd; { - struct elf_segment_map *m, **pm; + struct elf_segment_map *m; asection *s; s = bfd_get_section_by_name (abfd, ".interp"); diff --git a/bfd/elf64-hppa.h b/bfd/elf64-hppa.h index 5098e0c..9c15e6a 100644 --- a/bfd/elf64-hppa.h +++ b/bfd/elf64-hppa.h @@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "elf/hppa.h" extern elf_hppa_reloc_type ** _bfd_elf64_hppa_gen_reloc_type - PARAMS ((bfd *, elf_hppa_reloc_type, int, int, int, asymbol *)); + PARAMS ((bfd *, elf_hppa_reloc_type, int, unsigned int, int, asymbol *)); /* Define groups of basic relocations. FIXME: These should be the only basic relocations created by GAS. The rest diff --git a/bfd/hppa_stubs.h b/bfd/hppa_stubs.h deleted file mode 100644 index ee893e8..0000000 --- a/bfd/hppa_stubs.h +++ /dev/null @@ -1,23 +0,0 @@ -/* HPPA linker stub instructions */ - -/* These are the instructions which the linker may insert into the - code stream when building final executables to handle out-of-range - calls and argument relocations. */ - -#define LDO_M4_R31_R31 0x37ff3ff9 /* ldo -4(%r31),%r31 */ -#define LDIL_R1 0x20200000 /* ldil XXX,%r1 */ -#define BE_SR4_R1 0xe0202000 /* be XXX(%sr4,%r1) */ -#define COPY_R31_R2 0x081f0242 /* copy %r31,%r2 */ -#define BLE_SR4_R0 0xe4002000 /* ble XXX(%sr4,%r0) */ -#define BLE_SR4_R1 0xe4202000 /* ble XXX(%sr4,%r1) */ -#define BV_N_0_R31 0xebe0c002 /* bv,n 0(%r31) */ -#define STW_R31_M8R30 0x6bdf3ff1 /* stw %r31,-8(%r30) */ -#define LDW_M8R30_R31 0x4bdf3ff1 /* ldw -8(%r30),%r31 */ -#define STW_ARG_M16R30 0x6bc03fe1 /* stw %argX,-16(%r30) */ -#define LDW_M16R30_ARG 0x4bc03fe1 /* ldw -12(%r30),%argX */ -#define STW_ARG_M12R30 0x6bc03fe9 /* stw %argX,-16(%r30) */ -#define LDW_M12R30_ARG 0x4bc03fe9 /* ldw -12(%r30),%argX */ -#define FSTW_FARG_M16R30 0x27c11200 /* fstws %fargX,-16(%r30) */ -#define FLDW_M16R30_FARG 0x27c11000 /* fldws -16(%r30),%fargX */ -#define FSTD_FARG_M16R30 0x2fc11200 /* fstds %fargX,-16(%r30) */ -#define FLDD_M16R30_FARG 0x2fc11000 /* fldds -16(%r30),%fargX */ diff --git a/bfd/libhppa.h b/bfd/libhppa.h index 7a8af9a..8ef8f53 100644 --- a/bfd/libhppa.h +++ b/bfd/libhppa.h @@ -21,8 +21,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef _HPPA_H -#define _HPPA_H +#ifndef _LIBHPPA_H +#define _LIBHPPA_H #define BYTES_IN_WORD 4 #define PA_PAGESIZE 0x1000 @@ -159,224 +159,71 @@ enum hppa_reloc_expr_type_alt ((((bfd_signed_vma)(a)) << (BFD_ARCH_SIZE-22)) >> (BFD_ARCH_SIZE-22)) #define HPPA_R_ADDEND(r, c) \ (((r) << 22) + ((c) & 0x3fffff)) -#define HPPA_WIDE (0) /* PSW W-bit, need to check! FIXME */ -/* These macros get bit fields using HP's numbering (MSB = 0), - * but note that "MASK" assumes that the LSB bits are what's - * wanted. - */ -#ifndef GET_FIELD -#define GET_FIELD(X, FROM, TO) \ - ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1)) -#endif -#define GET_BIT(X, WHICH) \ - GET_FIELD (X, WHICH, WHICH) - -#define MASK(SIZE) \ - (~((-1) << SIZE)) - -#define CATENATE(X, XSIZE, Y, YSIZE) \ - (((X & MASK (XSIZE)) << YSIZE) | (Y & MASK (YSIZE))) - -#define ELEVEN(X) \ - CATENATE (GET_BIT (X, 10), 1, GET_FIELD (X, 0, 9), 10) /* Some functions to manipulate PA instructions. */ -/* NOTE: these use the HP convention that f{0} is the _left_ most - * bit (MSB) of f; they sometimes have to impose an assumption - * about the size of a field; and as far as I can tell, most - * aren't used. - */ - -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) /* Declare the functions with the unused attribute to avoid warnings. */ -static INLINE unsigned int sign_extend (unsigned int, unsigned int) - __attribute__ ((__unused__)); -static INLINE unsigned int low_sign_extend (unsigned int, unsigned int) - __attribute__ ((__unused__)); -static INLINE unsigned int assemble_3 (unsigned int) - __attribute__ ((__unused__)); -static INLINE unsigned int assemble_6 (unsigned int, unsigned int) - __attribute__ ((__unused__)); -static INLINE unsigned int assemble_12 (unsigned int, unsigned int) - __attribute__ ((__unused__)); -static INLINE unsigned int assemble_16 (unsigned int, unsigned int) - __attribute__ ((__unused__)); -static INLINE unsigned int assemble_16a (unsigned int, unsigned int, - unsigned int) - __attribute__ ((__unused__)); -static INLINE unsigned int assemble_17 (unsigned int, unsigned int, - unsigned int) - __attribute__ ((__unused__)); -static INLINE unsigned int assemble_21 (unsigned int) - __attribute ((__unused__)); - -static INLINE unsigned int sign_unext (unsigned int, unsigned int) - __attribute__ ((__unused__)); -static INLINE unsigned int low_sign_unext (unsigned int, unsigned int) - __attribute__ ((__unused__)); -static INLINE unsigned int re_assemble_3 (unsigned int, unsigned int) - __attribute__ ((__unused__)); -static INLINE unsigned int re_assemble_12 (unsigned int, unsigned int) - __attribute__ ((__unused__)); -static INLINE unsigned int re_assemble_16 (unsigned int, unsigned int, int) - __attribute__ ((__unused__)); -static INLINE unsigned int re_assemble_17 (unsigned int, unsigned int) - __attribute__ ((__unused__)); -static INLINE unsigned int re_assemble_22 (unsigned int, unsigned int) - __attribute__ ((__unused__)); -static INLINE unsigned int re_assemble_21 (unsigned int, unsigned int) - __attribute__ ((__unused__)); -static INLINE bfd_signed_vma hppa_field_adjust (bfd_signed_vma, bfd_signed_vma, - enum hppa_reloc_field_selector_type_alt) - __attribute__ ((__unused__)); -static INLINE int bfd_hppa_insn2fmt (unsigned int) - __attribute__ ((__unused__)); -static INLINE unsigned int hppa_rebuild_insn (bfd *, unsigned int, - unsigned int, unsigned int) - __attribute__ ((__unused__)); -#endif /* gcc 2.7 or higher */ - - -/* The *sign_extend and assemble_* functions are used to assemble - various bitfields taken from an instruction and return the - resulting immediate value. They correspond to functions by the - same name in HP's PA-RISC 2.0 Architecture Reference Manual. */ - -static INLINE unsigned int +static INLINE int sign_extend PARAMS ((int, int)) ATTRIBUTE_UNUSED; +static INLINE int low_sign_extend PARAMS ((int, int)) ATTRIBUTE_UNUSED; +static INLINE int sign_unext PARAMS ((int, int)) ATTRIBUTE_UNUSED; +static INLINE int low_sign_unext PARAMS ((int, int)) ATTRIBUTE_UNUSED; +static INLINE int re_assemble_3 PARAMS ((int)) ATTRIBUTE_UNUSED; +static INLINE int re_assemble_12 PARAMS ((int)) ATTRIBUTE_UNUSED; +static INLINE int re_assemble_14 PARAMS ((int)) ATTRIBUTE_UNUSED; +static INLINE int re_assemble_16 PARAMS ((int)) ATTRIBUTE_UNUSED; +static INLINE int re_assemble_17 PARAMS ((int)) ATTRIBUTE_UNUSED; +static INLINE int re_assemble_21 PARAMS ((int)) ATTRIBUTE_UNUSED; +static INLINE int re_assemble_22 PARAMS ((int)) ATTRIBUTE_UNUSED; +static INLINE bfd_signed_vma hppa_field_adjust + PARAMS ((bfd_vma, bfd_signed_vma, + enum hppa_reloc_field_selector_type_alt)) ATTRIBUTE_UNUSED; +static INLINE int bfd_hppa_insn2fmt PARAMS ((bfd *, int)) ATTRIBUTE_UNUSED; +static INLINE int hppa_rebuild_insn PARAMS ((int, int, int)) ATTRIBUTE_UNUSED; + + +/* The *sign_extend functions are used to assemble various bitfields + taken from an instruction and return the resulting immediate + value. */ + +static INLINE int sign_extend (x, len) - unsigned int x, len; + int x, len; { - unsigned int signbit = (1 << (len - 1)); - unsigned int mask = (signbit << 1) - 1; + int signbit = (1 << (len - 1)); + int mask = (signbit << 1) - 1; return ((x & mask) ^ signbit) - signbit; } -static INLINE unsigned int +static INLINE int low_sign_extend (x, len) - unsigned int x, len; + int x, len; { return (x >> 1) - ((x & 1) << (len - 1)); } -static INLINE unsigned int -assemble_3 (x) - unsigned int x; -{ - return CATENATE (GET_BIT (x, 2), 1, GET_FIELD (x, 0, 1), 2); -} - -static INLINE unsigned int -assemble_6 (x, y) - unsigned int x, y; -{ - return (((x & 1) << 5) + (32 - (y & 0x1f))); -} - -static INLINE unsigned int -assemble_12 (x, y) - unsigned int x, y; -{ - return CATENATE (CATENATE (y, 1, GET_BIT (x, 10), 1), 2, - GET_FIELD (x, 0, 9), 9); -} - -static INLINE unsigned int -assemble_16 (x, y) - unsigned int x, y; -{ - /* Depends on PSW W-bit !*/ - unsigned int temp; - - if (HPPA_WIDE) - temp = CATENATE (CATENATE (GET_BIT (y, 13), 1, - (GET_BIT (y, 13) ^ GET_BIT (x, 0)), 1), 2, - CATENATE ((GET_BIT (y, 13) ^ GET_BIT (x, 1)), 1, - GET_FIELD (y, 0, 12), 13), 14); - else - temp = CATENATE (CATENATE (GET_BIT (y, 13), 1, GET_BIT (y, 13), 1), 2, - CATENATE (GET_BIT (y, 13), 1, GET_FIELD (y, 0, 12), 13), 14); - - return sign_extend (temp, 16); -} - -static INLINE unsigned int -assemble_16a (x, y, z) - unsigned int x, y, z; -{ - /* Depends on PSW W-bit !*/ - unsigned int temp; - - if (HPPA_WIDE) - temp = CATENATE (CATENATE (z, 1, (z ^ GET_BIT (x, 0)), 1), 2, - CATENATE ((z ^ GET_BIT (x, 1)), 1, y, 11), 12); - else - temp = CATENATE (CATENATE (z, 1, z, 1), 2, CATENATE (z, 1, y, 11), 12); - - return sign_extend ((temp << 2), 16); -} - -static INLINE unsigned int -assemble_17 (x, y, z) - unsigned int x, y, z; -{ - unsigned int temp; - - temp = CATENATE (CATENATE (z, 1, x, 5), 6, - CATENATE (GET_BIT (y, 10), 1, GET_FIELD (y, 0, 9), 10), 11); - - return temp; -} - -static INLINE unsigned int -assemble_21 (x) - unsigned int x; -{ - unsigned int temp; - - temp = (( (x & 0x000001) << 20) - | ((x & 0x000ffe) << 8) - | ((x & 0x003000) >> 12) - | ((x & 0x00c000) >> 7) - | ((x & 0x1f0000) >> 14)); - return temp; -} - -static INLINE unsigned int -assemble_22 (a,b,c,d) - unsigned int a,b,c,d; -{ - unsigned int temp; - - temp = CATENATE (CATENATE (d, 1, a, 5), 6, - CATENATE (b, 5, ELEVEN (c), 11), 16); - - return sign_extend (temp, 22); -} - -/* The re_assemble_* functions splice together an opcode and an - immediate value. pa-risc uses all sorts of weird bitfields in the - instruction to hold the value. */ +/* The re_assemble_* functions prepare an immediate value for + insertion into an opcode. pa-risc uses all sorts of weird bitfields + in the instruction to hold the value. */ -static INLINE unsigned int +static INLINE int sign_unext (x, len) - unsigned int x, len; + int x, len; { - unsigned int len_ones; + int len_ones; - len_ones = ((unsigned int) 1 << len) - 1; + len_ones = (1 << len) - 1; return x & len_ones; } -static INLINE unsigned int +static INLINE int low_sign_unext (x, len) - unsigned int x, len; + int x, len; { - unsigned int temp; - unsigned int sign; + int temp; + int sign; sign = (x >> (len-1)) & 1; @@ -385,83 +232,69 @@ low_sign_unext (x, len) return (temp << 1) | sign; } -static INLINE unsigned int -re_assemble_3 (insn, as3) - unsigned int insn; - unsigned int as3; +static INLINE int +re_assemble_3 (as3) + int as3; { - return (insn - | ((as3 & 4) << (13-2)) + return (( (as3 & 4) << (13-2)) | ((as3 & 3) << (13+1))); } -static INLINE unsigned int -re_assemble_12 (insn, as12) - unsigned int insn; - unsigned int as12; +static INLINE int +re_assemble_12 (as12) + int as12; { - return (insn - | ((as12 & 0x800) >> 11) + return (( (as12 & 0x800) >> 11) | ((as12 & 0x400) >> (10 - 2)) | ((as12 & 0x3ff) << (1 + 2))); } -static INLINE unsigned int -re_assemble_16 (insn, as16, wide) - unsigned int insn; - unsigned int as16; - int wide; +static INLINE int +re_assemble_14 (as14) + int as14; { - unsigned int s, t; + return (( (as14 & 0x1fff) << 1) + | ((as14 & 0x2000) >> 13)); +} - if (wide) - { - /* Unusual 16-bit encoding. */ - t = (as16 << 1) & 0xffff; - s = (as16 & 0x8000); - return insn | (t ^ s ^ (s >> 1)) | (s >> 15); - } - else - { - /* Standard 14-bit encoding. */ - t = (as16 << 1) & 0x3fff; - s = (as16 & 0x2000); - return insn | t | (s >> 13); - } +static INLINE int +re_assemble_16 (as16) + int as16; +{ + int s, t; + + /* Unusual 16-bit encoding, for wide mode only. */ + t = (as16 << 1) & 0xffff; + s = (as16 & 0x8000); + return (t ^ s ^ (s >> 1)) | (s >> 15); } -static INLINE unsigned int -re_assemble_17 (insn, as17) - unsigned int insn; - unsigned int as17; +static INLINE int +re_assemble_17 (as17) + int as17; { - return (insn - | ((as17 & 0x10000) >> 16) + return (( (as17 & 0x10000) >> 16) | ((as17 & 0x0f800) << (16 - 11)) | ((as17 & 0x00400) >> (10 - 2)) | ((as17 & 0x003ff) << (1 + 2))); } -static INLINE unsigned int -re_assemble_21 (insn, as21) - unsigned int insn; - unsigned int as21; +static INLINE int +re_assemble_21 (as21) + int as21; { - return (insn - | ((as21 & 0x100000) >> 20) + return (( (as21 & 0x100000) >> 20) | ((as21 & 0x0ffe00) >> 8) | ((as21 & 0x000180) << 7) | ((as21 & 0x00007c) << 14) | ((as21 & 0x000003) << 12)); } -static INLINE unsigned int -re_assemble_22 (insn, as22) - unsigned int insn; - unsigned int as22; +static INLINE int +re_assemble_22 (as22) + int as22; { - return (insn - | ((as22 & 0x200000) >> 21) + return (( (as22 & 0x200000) >> 21) | ((as22 & 0x1f0000) << (21 - 16)) | ((as22 & 0x00f800) << (16 - 11)) | ((as22 & 0x000400) >> (10 - 2)) @@ -481,7 +314,7 @@ re_assemble_22 (insn, as22) static INLINE bfd_signed_vma hppa_field_adjust (sym_val, addend, r_field) - bfd_signed_vma sym_val; + bfd_vma sym_val; bfd_signed_vma addend; enum hppa_reloc_field_selector_type_alt r_field; { @@ -491,10 +324,18 @@ hppa_field_adjust (sym_val, addend, r_field) switch (r_field) { case e_fsel: - case e_nsel: /* F: No change. */ break; + case e_nsel: + /* N: null selector. I don't really understand what this is all + about, but HP's documentation says "this indicates that zero + bits are to be used for the displacement on the instruction. + This fixup is used to identify three-instruction sequences to + access data (for importing shared library data)." */ + value = 0; + break; + case e_lsel: case e_nlsel: /* L: Select top 21 bits. */ @@ -558,123 +399,158 @@ hppa_field_adjust (sym_val, addend, r_field) /* PA-RISC OPCODES */ #define get_opcode(insn) (((insn) >> 26) & 0x3f) -/* FIXME: this list is incomplete. It should also be an enumerated - type rather than #defines. */ - -#define LDO 0x0d -#define LDB 0x10 -#define LDH 0x11 -#define LDW 0x12 -#define LDWM 0x13 -#define STB 0x18 -#define STH 0x19 -#define STW 0x1a -#define STWM 0x1b -#define COMICLR 0x24 -#define SUBI 0x25 -#define SUBIO 0x25 -#define ADDIT 0x2c -#define ADDITO 0x2c -#define ADDI 0x2d -#define ADDIO 0x2d -#define LDIL 0x08 -#define ADDIL 0x0a - -#define MOVB 0x32 -#define MOVIB 0x33 -#define COMBT 0x20 -#define COMBF 0x22 -#define COMIBT 0x21 -#define COMIBF 0x23 -#define ADDBT 0x28 -#define ADDBF 0x2a -#define ADDIBT 0x29 -#define ADDIBF 0x2b -#define BVB 0x30 -#define BB 0x31 - -#define BL 0x3a -#define BLE 0x39 -#define BE 0x38 - -#define CMPBDT 0x27 -#define CMPBDF 0x2f -#define CMPIBD 0x3b -#define LDD 0x14 -#define STD 0x1c -#define LDWL 0x17 -#define STWL 0x1f -#define FLDW 0x16 -#define FSTW 0x1e - -/* Given a machine instruction, return its format. - - FIXME: opcodes which do not map to a known format - should return an error of some sort. */ +enum hppa_opcode_type +{ + /* None of the opcodes in the first group generate relocs, so we + aren't too concerned about them. */ + OP_SYSOP = 0x00, + OP_MEMMNG = 0x01, + OP_ALU = 0x02, + OP_NDXMEM = 0x03, + OP_SPOP = 0x04, + OP_DIAG = 0x05, + OP_FMPYADD = 0x06, + OP_UNDEF07 = 0x07, + OP_COPRW = 0x09, + OP_COPRDW = 0x0b, + OP_COPR = 0x0c, + OP_FLOAT = 0x0e, + OP_PRDSPEC = 0x0f, + OP_UNDEF15 = 0x15, + OP_UNDEF1d = 0x1d, + OP_FMPYSUB = 0x26, + OP_FPFUSED = 0x2e, + OP_SHEXDP0 = 0x34, + OP_SHEXDP1 = 0x35, + OP_SHEXDP2 = 0x36, + OP_UNDEF37 = 0x37, + OP_SHEXDP3 = 0x3c, + OP_SHEXDP4 = 0x3d, + OP_MULTMED = 0x3e, + OP_UNDEF3f = 0x3f, + + OP_LDIL = 0x08, + OP_ADDIL = 0x0a, + + OP_LDO = 0x0d, + OP_LDB = 0x10, + OP_LDH = 0x11, + OP_LDW = 0x12, + OP_LDWM = 0x13, + OP_STB = 0x18, + OP_STH = 0x19, + OP_STW = 0x1a, + OP_STWM = 0x1b, + + OP_LDD = 0x14, + OP_STD = 0x1c, + + OP_FLDW = 0x16, + OP_LDWL = 0x17, + OP_FSTW = 0x1e, + OP_STWL = 0x1f, + + OP_COMBT = 0x20, + OP_COMIBT = 0x21, + OP_COMBF = 0x22, + OP_COMIBF = 0x23, + OP_CMPBDT = 0x27, + OP_ADDBT = 0x28, + OP_ADDIBT = 0x29, + OP_ADDBF = 0x2a, + OP_ADDIBF = 0x2b, + OP_CMPBDF = 0x2f, + OP_BVB = 0x30, + OP_BB = 0x31, + OP_MOVB = 0x32, + OP_MOVIB = 0x33, + OP_CMPIBD = 0x3b, + + OP_COMICLR = 0x24, + OP_SUBI = 0x25, + OP_ADDIT = 0x2c, + OP_ADDI = 0x2d, + + OP_BE = 0x38, + OP_BLE = 0x39, + OP_BL = 0x3a +}; + + +/* Given a machine instruction, return its format. */ static INLINE int -bfd_hppa_insn2fmt (insn) - unsigned int insn; +bfd_hppa_insn2fmt (abfd, insn) + bfd *abfd; + int insn; { - unsigned char op = get_opcode (insn); + enum hppa_opcode_type op = get_opcode (insn); switch (op) { - case ADDI: - case ADDIT: - case SUBI: + case OP_COMICLR: + case OP_SUBI: + case OP_ADDIT: + case OP_ADDI: return 11; - case MOVB: - case MOVIB: - case COMBT: - case COMBF: - case COMIBT: - case COMIBF: - case ADDBT: - case ADDBF: - case ADDIBT: - case ADDIBF: - case BVB: - case BB: - case CMPBDT: - case CMPBDF: - case CMPIBD: + case OP_COMBT: + case OP_COMIBT: + case OP_COMBF: + case OP_COMIBF: + case OP_CMPBDT: + case OP_ADDBT: + case OP_ADDIBT: + case OP_ADDBF: + case OP_ADDIBF: + case OP_CMPBDF: + case OP_BVB: + case OP_BB: + case OP_MOVB: + case OP_MOVIB: + case OP_CMPIBD: return 12; - case LDO: - case LDB: - case LDH: - case LDW: - case LDWM: - case STB: - case STH: - case STW: - case STWM: + case OP_LDO: + case OP_LDB: + case OP_LDH: + case OP_LDW: + case OP_LDWM: + case OP_STB: + case OP_STH: + case OP_STW: + case OP_STWM: + if (abfd->arch_info->mach >= 25) + return 16; /* Wide mode, format 16. */ return 14; - case LDWL: - case STWL: - case FLDW: - case FSTW: + case OP_FLDW: + case OP_LDWL: + case OP_FSTW: + case OP_STWL: /* This is a hack. Unfortunately, format 11 is already taken and we're using integers rather than an enum, so it's hard to describe the 11a format. */ + if (abfd->arch_info->mach >= 25) + return -16; /* Wide mode, format 16a. */ return -11; - case LDD: - case STD: + case OP_LDD: + case OP_STD: + if (abfd->arch_info->mach >= 25) + return -10; /* Wide mode, format 10a. */ return 10; - case BL: - case BE: - case BLE: - if ((insn & 0x00008000) != 0) + case OP_BL: + if ((insn & 0x8000) != 0) return 22; + /* fall thru */ + case OP_BE: + case OP_BLE: return 17; - case LDIL: - case ADDIL: + case OP_LDIL: + case OP_ADDIL: return 21; default: @@ -687,21 +563,52 @@ bfd_hppa_insn2fmt (insn) /* Insert VALUE into INSN using R_FORMAT to determine exactly what bits to change. */ -static INLINE unsigned int -hppa_rebuild_insn (abfd, insn, value, r_format) - bfd *abfd ATTRIBUTE_UNUSED; - unsigned int insn; - unsigned int value; - unsigned int r_format; +static INLINE int +hppa_rebuild_insn (insn, value, r_format) + int insn; + int value; + int r_format; { switch (r_format) { - case 11: return (insn & ~ 0x7ff) | low_sign_unext (value, 11); - case 12: return re_assemble_12 (insn & ~ 0x1ffd, value); - case 14: return (insn & ~ 0x3fff) | low_sign_unext (value, 14); - case 17: return re_assemble_17 (insn & ~ 0x1f1ffd, value); - case 21: return re_assemble_21 (insn & ~ 0x1fffff, value); - case 32: return value; + case 11: + return (insn & ~ 0x7ff) | low_sign_unext (value, 11); + + case 12: + return (insn & ~ 0x1ffd) | re_assemble_12 (value); + + + case 10: + return (insn & ~ 0x3ff1) | re_assemble_14 (value & -8); + + case -11: + return (insn & ~ 0x3ff9) | re_assemble_14 (value & -4); + + case 14: + return (insn & ~ 0x3fff) | re_assemble_14 (value); + + + case -10: + return (insn & ~ 0xfff1) | re_assemble_16 (value & -8); + + case -16: + return (insn & ~ 0xfff9) | re_assemble_16 (value & -4); + + case 16: + return (insn & ~ 0xffff) | re_assemble_16 (value); + + + case 17: + return (insn & ~ 0x1f1ffd) | re_assemble_17 (value); + + case 21: + return (insn & ~ 0x1fffff) | re_assemble_21 (value); + + case 22: + return (insn & ~ 0x3ff1ffd) | re_assemble_22 (value); + + case 32: + return value; default: abort (); @@ -709,4 +616,4 @@ hppa_rebuild_insn (abfd, insn, value, r_format) return insn; } -#endif /* _HPPA_H */ +#endif /* _LIBHPPA_H */ |