diff options
author | Ian Lance Taylor <ian@airs.com> | 1994-09-06 19:28:55 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@airs.com> | 1994-09-06 19:28:55 +0000 |
commit | 69645d10fb4647f6855c76ae54a1acf60f28fc94 (patch) | |
tree | 61e36c9f73fda03557d67fda9f185ea6a7828b5f /bfd/coff-a29k.c | |
parent | de733a0edf37f2e2f4a7733da66b55a07ef1f804 (diff) | |
download | gdb-69645d10fb4647f6855c76ae54a1acf60f28fc94.zip gdb-69645d10fb4647f6855c76ae54a1acf60f28fc94.tar.gz gdb-69645d10fb4647f6855c76ae54a1acf60f28fc94.tar.bz2 |
Add new style linker support to COFF backend. a29k only for now.
* cofflink.c: New file.
* libcoff-in.h: Include bfdlink.h.
(obj_coff_external_syms, obj_coff_strings): Define accessor macro.
(obj_coff_sym_hashes): Define accessor macro.
(struct coff_tdata): Add fields external_syms, strings, and
sym_hashes.
(struct coff_link_hash_entry): Define.
(struct coff_link_hash_table): Define.
(coff_link_hash_lookup, coff_link_hash_traverse): Define.
(coff_hash_table): Define.
(_bfd_coff_link_hash_table_create): Declare.
(_bfd_coff_link_add_symbols, _bfd_coff_final_link): Declare.
* coffcode.h (bfd_coff_backend_data): Add fields _bfd_relsz,
_bfd_coff_swap_reloc_in, _bfd_coff_sym_is_global,
_bfd_coff_compute_section_file_positions,
_bfd_coff_relocate_section.
(bfd_coff_relsz, bfd_coff_swap_reloc_in): Define.
(bfd_coff_sym_is_global): Define.
(bfd_coff_compute_section_file_positions): Define.
(bfd_coff_relocate_section): Define.
(coff_mkobject_hook): Initialize obj_raw_syment_count and
obj_conv_table_size.
(coff_compute_section_file_positions): Set target_index of all
sections. Set output_has_begun field.
(coff_write_object_contents): Don't set target_index; now done by
coff_compute_section_file_positions. Remove obsolete handling of
scn_base and data_base. Don't bother to check that target_index
is positive, since it always is. Remove use of pad, which is
always zero. Check obj_raw_syment_count, not bfd_get_symcount,
for the number of symbols, but only write them out if
bfd_get_symcount is non-zero.
(coff_slurp_symbol_table): Use obj_raw_syment_count, not
bfd_get_symcount for the number of symbols. Don't set
obj_conv_table_size.
(coff_sym_is_global): New static function or macro.
(coff_slurp_reloc_table): Call coff_swap_reloc_in, not
bfd_swap_reloc_in.
(coff_bfd_link_hash_table_create): If coff_relocate_section is
defined, define as _bfd_coff_link_hash_table_create.
(coff_bfd_link_add_symbols): Similar change.
(coff_bfd_final_link): Similar change.
(coff_relocate_section): Define as NULL if not defined.
(bfd_coff_std_swap_table): Initialize new fields.
* coffgen.c (coff_real_object_p): Don't set obj_raw_syment_count
and obj_conv_table_size here.
(coff_count_linenumbers): Reindent. If bfd_get_symcount is zero,
add up the line numbers from the sections.
(coff_write_symbols): Don't set bfd_get_symcount.
(coff_pointerize_aux): Don't pointerize a nonpositive x_endndx
field.
(coff_get_normalized_symtab): Use obj_raw_syment_count, not
bfd_get_symcount.
(coff_print_symbol): If auxp->fix_end, print x_endndx value.
* coffswap.h (coff_swap_reloc_in): Rename from bfd_swap_reloc_in.
Reindent. Change argument type to PTR.
* coff-a29k.c (coff_a29k_relocate_section): New static function.
(coff_relocate_section): Define.
* configure.in (a29kcoff_big_vec): Compile cofflink.o.
* coff-alpha.c (alpha_ecoff_backend_data): Initialize new fields.
* coff-mips.c (mips_ecoff_backend_data): Likewise.
* libcoff.h: Rebuilt.
* Makefile.in: Rebuilt dependencies.
(BFD32_BACKENDS): Add cofflink.o.
(CFILES): Add cofflink.c.
Diffstat (limited to 'bfd/coff-a29k.c')
-rw-r--r-- | bfd/coff-a29k.c | 221 |
1 files changed, 221 insertions, 0 deletions
diff --git a/bfd/coff-a29k.c b/bfd/coff-a29k.c index 473c372..35e6ea3 100644 --- a/bfd/coff-a29k.c +++ b/bfd/coff-a29k.c @@ -31,6 +31,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ static long get_symbol_value PARAMS ((asymbol *)); static bfd_reloc_status_type a29k_reloc PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); +static boolean coff_a29k_relocate_section + PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, + struct internal_reloc *, struct internal_syment *, asection **)); #define INSERT_HWORD(WORD,HWORD) \ (((WORD) & 0xff00ff00) | (((HWORD) & 0xff00) << 8) | ((HWORD)& 0xff)) @@ -303,6 +306,224 @@ reloc_processing (relent,reloc, symbols, abfd, section) } } +/* The reloc processing routine for the optimized COFF linker. */ + +static boolean +coff_a29k_relocate_section (output_bfd, info, input_bfd, input_section, + contents, relocs, syms, sections) + bfd *output_bfd; + struct bfd_link_info *info; + bfd *input_bfd; + asection *input_section; + bfd_byte *contents; + struct internal_reloc *relocs; + struct internal_syment *syms; + asection **sections; +{ + struct internal_reloc *rel; + struct internal_reloc *relend; + boolean hihalf; + bfd_vma hihalf_val; + + /* If we are performing a relocateable link, we don't need to do a + thing. The caller will take care of adjusting the reloc + addresses and symbol indices. */ + if (info->relocateable) + return true; + + hihalf = false; + hihalf_val = 0; + + rel = relocs; + relend = rel + input_section->reloc_count; + for (; rel < relend; rel++) + { + long symndx; + bfd_byte *loc; + struct coff_link_hash_entry *h; + struct internal_syment *sym; + asection *sec; + bfd_vma val; + boolean overflow; + unsigned long insn; + long signed_value; + unsigned long unsigned_value; + bfd_reloc_status_type rstat; + + symndx = rel->r_symndx; + loc = contents + rel->r_vaddr - input_section->vma; + + h = obj_coff_sym_hashes (input_bfd)[symndx]; + + sym = NULL; + sec = NULL; + val = 0; + + /* An R_IHCONST reloc does not have a symbol. Instead, the + symbol index is an addend. R_IHCONST is always used in + conjunction with R_IHHALF. */ + if (rel->r_type != R_IHCONST) + { + if (h == NULL) + { + sym = syms + symndx; + sec = sections[symndx]; + val = (sec->output_section->vma + + sec->output_offset + + sym->n_value + - sec->vma); + } + else + { + if (h->root.type == bfd_link_hash_defined) + { + sec = h->root.u.def.section; + val = (h->root.u.def.value + + sec->output_section->vma + + sec->output_offset); + } + else + { + if (! ((*info->callbacks->undefined_symbol) + (info, h->root.root.string, input_bfd, input_section, + rel->r_vaddr - input_section->vma))) + return false; + } + } + + if (hihalf) + { + if (! ((*info->callbacks->reloc_dangerous) + (info, "missing IHCONST reloc", input_bfd, + input_section, rel->r_vaddr - input_section->vma))) + return false; + hihalf = false; + } + } + + overflow = false; + + switch (rel->r_type) + { + default: + bfd_set_error (bfd_error_bad_value); + return false; + + case R_IREL: + insn = bfd_get_32 (input_bfd, loc); + + /* Extract the addend. */ + signed_value = EXTRACT_HWORD (insn); + signed_value = SIGN_EXTEND_HWORD (signed_value); + signed_value <<= 2; + + /* Determine the destination of the jump. */ + signed_value += val + rel->r_vaddr - input_section->vma; + + if ((signed_value & ~0x3ffff) == 0) + { + /* We can use an absolute jump. */ + insn |= (1 << 24); + } + else + { + /* Make the destination PC relative. */ + signed_value -= (input_section->output_section->vma + + input_section->output_offset + + (rel->r_vaddr - input_section->vma)); + if (signed_value > 0x1ffff || signed_value < - 0x20000) + { + overflow = true; + signed_value = 0; + } + } + + /* Put the adjusted value back into the instruction. */ + signed_value >>= 2; + insn = INSERT_HWORD (insn, signed_value); + + bfd_put_32 (input_bfd, (bfd_vma) insn, loc); + + break; + + case R_ILOHALF: + insn = bfd_get_32 (input_bfd, loc); + unsigned_value = EXTRACT_HWORD (insn); + unsigned_value += val; + insn = INSERT_HWORD (insn, unsigned_value); + bfd_put_32 (input_bfd, insn, loc); + break; + + case R_IHIHALF: + /* Save the value for the R_IHCONST reloc. */ + hihalf = true; + hihalf_val = val; + break; + + case R_IHCONST: + if (! hihalf) + { + if (! ((*info->callbacks->reloc_dangerous) + (info, "missing IHIHALF reloc", input_bfd, + input_section, rel->r_vaddr - input_section->vma))) + return false; + hihalf_val = 0; + } + + insn = bfd_get_32 (input_bfd, loc); + unsigned_value = rel->r_symndx + hihalf_val; + unsigned_value >>= 16; + insn = INSERT_HWORD (insn, unsigned_value); + bfd_put_32 (input_bfd, (bfd_vma) insn, loc); + + hihalf = false; + + break; + + case R_BYTE: + case R_HWORD: + case R_WORD: + rstat = _bfd_relocate_contents (howto_table + rel->r_type, + input_bfd, val, loc); + if (rstat == bfd_reloc_overflow) + overflow = true; + else if (rstat != bfd_reloc_ok) + abort (); + break; + } + + if (overflow) + { + const char *name; + char buf[SYMNMLEN + 1]; + + if (h != NULL) + name = h->root.root.string; + else if (sym == NULL) + name = "*unknown*"; + else if (sym->_n._n_n._n_zeroes == 0 + && sym->_n._n_n._n_offset != 0) + name = obj_coff_strings (input_bfd) + sym->_n._n_n._n_offset; + else + { + strncpy (buf, sym->_n._n_name, SYMNMLEN); + buf[SYMNMLEN] = '\0'; + name = buf; + } + + if (! ((*info->callbacks->reloc_overflow) + (info, name, howto_table[rel->r_type].name, (bfd_vma) 0, + input_bfd, input_section, + rel->r_vaddr - input_section->vma))) + return false; + } + } + + return true; +} + +#define coff_relocate_section coff_a29k_relocate_section + #include "coffcode.h" const bfd_target a29kcoff_big_vec = |