| 1 | /* BFD backend for hp-ux 9000/300 |
| 2 | Copyright (C) 1990-1991 Free Software Foundation, Inc. |
| 3 | Written by Glenn Engel. |
| 4 | |
| 5 | This file is part of BFD, the Binary File Descriptor library. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 20 | |
| 21 | /* |
| 22 | |
| 23 | hpux native ------------> | | |
| 24 | | hp300hpux bfd | ----------> hpux w/gnu ext |
| 25 | hpux w/gnu extension ----> | | |
| 26 | |
| 27 | |
| 28 | Support for the 9000/[34]00 has several limitations. |
| 29 | 1. Shared libraries are not supported. |
| 30 | 2. The output format from this bfd is not usable by native tools. |
| 31 | 3. Core files are not supported (yet). |
| 32 | |
| 33 | The primary motivation for writing this bfd was to allow use of |
| 34 | gdb and gcc for host based debugging and not to mimic the hp-ux tools |
| 35 | in every detail. This leads to a significant simplification of the |
| 36 | code and a leap in performance. The decision to not output hp native |
| 37 | compatible objects was further strengthened by the fact that the richness |
| 38 | of the gcc compiled objects could not be represented without loss of |
| 39 | information. For example, while the hp format supports the concept of |
| 40 | secondary symbols, it does not support indirect symbols. Another |
| 41 | reason is to maintain backwards compatibility with older implementations |
| 42 | of gcc on hpux which used 'hpxt' to translate .a and .o files into a |
| 43 | format which could be readily understood by the gnu linker and gdb. |
| 44 | This allows reading hp secondary symbols and converting them into |
| 45 | indirect symbols but the reverse it not always possible. |
| 46 | |
| 47 | Another example of differences is that the hp format stores symbol offsets |
| 48 | in the object code while the gnu utilities use a field in the |
| 49 | relocation record for this. To support the hp native format, the object |
| 50 | code would need to be patched with the offsets when producing .o files. |
| 51 | |
| 52 | The basic technique taken in this implementation is to #include the code |
| 53 | from aoutx.h and aout-target.h with appropriate #defines to override |
| 54 | code where a unique implementation is needed: |
| 55 | |
| 56 | { |
| 57 | #define a bunch of stuff |
| 58 | #include <aoutx.h> |
| 59 | |
| 60 | implement a bunch of functions |
| 61 | |
| 62 | #include "aout-target.h" |
| 63 | } |
| 64 | |
| 65 | The hp symbol table is a bit different than other a.out targets. Instead |
| 66 | of having an array of nlist items and an array of strings, hp's format |
| 67 | has them mixed together in one structure. In addition, the strings are |
| 68 | not null terminated. It looks something like this: |
| 69 | |
| 70 | nlist element 1 |
| 71 | string1 |
| 72 | nlist element 2 |
| 73 | string2 |
| 74 | ... |
| 75 | |
| 76 | The whole symbol table is read as one chunk and then we march thru it |
| 77 | and convert it to canonical form. As we march thru the table, we copy |
| 78 | the nlist data into the internal form and we compact the strings and null |
| 79 | terminate them, using storage from the already allocated symbol table: |
| 80 | |
| 81 | string1 |
| 82 | null |
| 83 | string2 |
| 84 | null |
| 85 | */ |
| 86 | |
| 87 | /* @@ Is this really so different from normal a.out that it needs to include |
| 88 | aoutx.h? We should go through this file sometime and see what can be made |
| 89 | more dependent on aout32.o and what might need to be broken off and accessed |
| 90 | through the backend_data field. Or, maybe we really do need such a |
| 91 | completely separate implementation. I don't have time to investigate this |
| 92 | much further right now. [raeburn:19930428.2124EST] */ |
| 93 | /* @@ Also, note that there wind up being two versions of some routines, with |
| 94 | different names, only one of which actually gets used. For example: |
| 95 | slurp_symbol_table |
| 96 | swap_std_reloc_in |
| 97 | slurp_reloc_table |
| 98 | get_symtab |
| 99 | get_symtab_upper_bound |
| 100 | canonicalize_reloc |
| 101 | mkobject |
| 102 | This should also be fixed. */ |
| 103 | |
| 104 | #define ARCH 32 |
| 105 | #define TARGETNAME "a.out-hp300hpux" |
| 106 | #define MY(OP) CAT(hp300hpux_,OP) |
| 107 | |
| 108 | #define external_exec hp300hpux_exec_bytes |
| 109 | #define external_nlist hp300hpux_nlist_bytes |
| 110 | |
| 111 | #include "aout/hp300hpux.h" |
| 112 | |
| 113 | /* define these so we can compile unused routines in aoutx.h */ |
| 114 | #define e_strx e_shlib |
| 115 | #define e_other e_length |
| 116 | #define e_desc e_almod |
| 117 | |
| 118 | #define AR_PAD_CHAR '/' |
| 119 | #define TARGET_IS_BIG_ENDIAN_P |
| 120 | #define DEFAULT_ARCH bfd_arch_m68k |
| 121 | |
| 122 | #define MY_get_section_contents aout_32_get_section_contents |
| 123 | #define MY_close_and_cleanup aout_32_close_and_cleanup |
| 124 | #define MY_slurp_armap bfd_slurp_bsd_armap_f2 |
| 125 | |
| 126 | /***********************************************/ |
| 127 | /* provide overrides for routines in this file */ |
| 128 | /***********************************************/ |
| 129 | #define MY_get_symtab MY(get_symtab) |
| 130 | #define MY_get_symtab_upper_bound MY(get_symtab_upper_bound) |
| 131 | #define MY_canonicalize_reloc MY(canonicalize_reloc) |
| 132 | #define MY_write_object_contents MY(write_object_contents) |
| 133 | |
| 134 | #define hp300hpux_write_syms aout_32_write_syms |
| 135 | |
| 136 | #define MY_callback MY(callback) |
| 137 | |
| 138 | #define NAME_swap_exec_header_in NAME(hp300hpux_32_,swap_exec_header_in) |
| 139 | |
| 140 | #define HP_SYMTYPE_UNDEFINED 0x00 |
| 141 | #define HP_SYMTYPE_ABSOLUTE 0x01 |
| 142 | #define HP_SYMTYPE_TEXT 0x02 |
| 143 | #define HP_SYMTYPE_DATA 0x03 |
| 144 | #define HP_SYMTYPE_BSS 0x04 |
| 145 | #define HP_SYMTYPE_COMMON 0x05 |
| 146 | |
| 147 | #define HP_SYMTYPE_TYPE 0x0F |
| 148 | #define HP_SYMTYPE_FILENAME 0x1F |
| 149 | |
| 150 | #define HP_SYMTYPE_ALIGN 0x10 |
| 151 | #define HP_SYMTYPE_EXTERNAL 0x20 |
| 152 | #define HP_SECONDARY_SYMBOL 0x40 |
| 153 | |
| 154 | /* RELOCATION DEFINITIONS */ |
| 155 | #define HP_RSEGMENT_TEXT 0x00 |
| 156 | #define HP_RSEGMENT_DATA 0x01 |
| 157 | #define HP_RSEGMENT_BSS 0x02 |
| 158 | #define HP_RSEGMENT_EXTERNAL 0x03 |
| 159 | #define HP_RSEGMENT_PCREL 0x04 |
| 160 | #define HP_RSEGMENT_RDLT 0x05 |
| 161 | #define HP_RSEGMENT_RPLT 0x06 |
| 162 | #define HP_RSEGMENT_NOOP 0x3F |
| 163 | |
| 164 | #define HP_RLENGTH_BYTE 0x00 |
| 165 | #define HP_RLENGTH_WORD 0x01 |
| 166 | #define HP_RLENGTH_LONG 0x02 |
| 167 | #define HP_RLENGTH_ALIGN 0x03 |
| 168 | |
| 169 | #define NAME(x,y) CAT3(hp300hpux,_32_,y) |
| 170 | #include "aoutx.h" |
| 171 | |
| 172 | /* Since the hpux symbol table has nlist elements interspersed with |
| 173 | strings and we need to insert som strings for secondary symbols, we |
| 174 | give ourselves a little extra padding up front to account for |
| 175 | this. Note that for each non-secondary symbol we process, we gain |
| 176 | 9 bytes of space for the discarded nlist element (one byte used for |
| 177 | null). SYM_EXTRA_BYTES is the extra space. */ |
| 178 | #define SYM_EXTRA_BYTES 1024 |
| 179 | |
| 180 | /* Set parameters about this a.out file that are machine-dependent. |
| 181 | This routine is called from some_aout_object_p just before it returns. */ |
| 182 | static bfd_target * |
| 183 | DEFUN(MY(callback),(abfd), |
| 184 | bfd *abfd) |
| 185 | { |
| 186 | struct internal_exec *execp = exec_hdr (abfd); |
| 187 | |
| 188 | /* Calculate the file positions of the parts of a newly read aout header */ |
| 189 | obj_textsec (abfd)->_raw_size = N_TXTSIZE(*execp); |
| 190 | |
| 191 | /* The virtual memory addresses of the sections */ |
| 192 | obj_textsec (abfd)->vma = N_TXTADDR(*execp); |
| 193 | obj_datasec (abfd)->vma = N_DATADDR(*execp); |
| 194 | obj_bsssec (abfd)->vma = N_BSSADDR(*execp); |
| 195 | |
| 196 | /* The file offsets of the sections */ |
| 197 | obj_textsec (abfd)->filepos = N_TXTOFF (*execp); |
| 198 | obj_datasec (abfd)->filepos = N_DATOFF (*execp); |
| 199 | |
| 200 | /* The file offsets of the relocation info */ |
| 201 | obj_textsec (abfd)->rel_filepos = N_TRELOFF(*execp); |
| 202 | obj_datasec (abfd)->rel_filepos = N_DRELOFF(*execp); |
| 203 | |
| 204 | /* The file offsets of the string table and symbol table. */ |
| 205 | obj_sym_filepos (abfd) = N_SYMOFF (*execp); |
| 206 | obj_str_filepos (abfd) = N_STROFF (*execp); |
| 207 | |
| 208 | /* Determine the architecture and machine type of the object file. */ |
| 209 | #ifdef SET_ARCH_MACH |
| 210 | SET_ARCH_MACH(abfd, *execp); |
| 211 | #else |
| 212 | bfd_default_set_arch_mach(abfd, DEFAULT_ARCH, 0); |
| 213 | #endif |
| 214 | |
| 215 | |
| 216 | if (obj_aout_subformat(abfd) == gnu_encap_format) |
| 217 | { |
| 218 | /* The file offsets of the relocation info */ |
| 219 | obj_textsec (abfd)->rel_filepos = N_GNU_TRELOFF(*execp); |
| 220 | obj_datasec (abfd)->rel_filepos = N_GNU_DRELOFF(*execp); |
| 221 | |
| 222 | /* The file offsets of the string table and symbol table. */ |
| 223 | obj_sym_filepos (abfd) = N_GNU_SYMOFF(*execp); |
| 224 | obj_str_filepos (abfd) = (obj_sym_filepos (abfd) + execp->a_syms); |
| 225 | |
| 226 | abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS; |
| 227 | bfd_get_symcount (abfd) = execp->a_syms / 12; |
| 228 | obj_symbol_entry_size (abfd) = 12; |
| 229 | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; |
| 230 | } |
| 231 | |
| 232 | return abfd->xvec; |
| 233 | } |
| 234 | |
| 235 | static boolean |
| 236 | DEFUN(MY(write_object_contents),(abfd), |
| 237 | bfd *abfd) |
| 238 | { |
| 239 | struct external_exec exec_bytes; |
| 240 | struct internal_exec *execp = exec_hdr (abfd); |
| 241 | bfd_size_type text_size; /* dummy vars */ |
| 242 | file_ptr text_end; |
| 243 | |
| 244 | memset (&exec_bytes, 0, sizeof (exec_bytes)); |
| 245 | #if CHOOSE_RELOC_SIZE |
| 246 | CHOOSE_RELOC_SIZE(abfd); |
| 247 | #else |
| 248 | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; |
| 249 | #endif |
| 250 | |
| 251 | if (adata(abfd).magic == undecided_magic) |
| 252 | NAME(aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end); |
| 253 | execp->a_syms = 0; |
| 254 | |
| 255 | execp->a_entry = bfd_get_start_address (abfd); |
| 256 | |
| 257 | execp->a_trsize = ((obj_textsec (abfd)->reloc_count) * |
| 258 | obj_reloc_entry_size (abfd)); |
| 259 | execp->a_drsize = ((obj_datasec (abfd)->reloc_count) * |
| 260 | obj_reloc_entry_size (abfd)); |
| 261 | |
| 262 | N_SET_MACHTYPE(*execp, 0xc); |
| 263 | N_SET_FLAGS (*execp, 0x2); |
| 264 | |
| 265 | NAME(aout,swap_exec_header_out) (abfd, execp, &exec_bytes); |
| 266 | |
| 267 | /* update fields not covered by default swap_exec_header_out */ |
| 268 | |
| 269 | /* this is really the sym table size but we store it in drelocs */ |
| 270 | bfd_h_put_32 (abfd, bfd_get_symcount (abfd) * 12, exec_bytes.e_drelocs); |
| 271 | |
| 272 | bfd_seek (abfd, 0L, false); |
| 273 | bfd_write ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd); |
| 274 | |
| 275 | /* Now write out reloc info, followed by syms and strings */ |
| 276 | |
| 277 | if (bfd_get_symcount (abfd) != 0) |
| 278 | { |
| 279 | bfd_seek (abfd, (long)(N_TRELOFF(*execp)), false); |
| 280 | |
| 281 | if (!NAME(aout,squirt_out_relocs) (abfd, obj_textsec (abfd))) return false; |
| 282 | bfd_seek (abfd, (long)(N_DRELOFF(*execp)), false); |
| 283 | |
| 284 | if (!NAME(aout,squirt_out_relocs)(abfd, obj_datasec (abfd))) return false; |
| 285 | } |
| 286 | |
| 287 | MY(write_syms)(abfd); |
| 288 | return true; |
| 289 | } |
| 290 | |
| 291 | /* convert the hp symbol type to be the same as aout64.h usage so we */ |
| 292 | /* can piggyback routines in aoutx.h. */ |
| 293 | |
| 294 | static void |
| 295 | DEFUN(convert_sym_type,(sym_pointer, cache_ptr, abfd), |
| 296 | struct external_nlist *sym_pointer AND |
| 297 | aout_symbol_type *cache_ptr AND |
| 298 | bfd *abfd) |
| 299 | { |
| 300 | int name_type; |
| 301 | int new_type; |
| 302 | |
| 303 | name_type = (cache_ptr->type); |
| 304 | new_type = 0; |
| 305 | |
| 306 | if ((name_type & HP_SYMTYPE_ALIGN) != 0) |
| 307 | { |
| 308 | /* iou_error ("aligned symbol encountered: %s", name);*/ |
| 309 | name_type = 0; |
| 310 | } |
| 311 | |
| 312 | if (name_type == HP_SYMTYPE_FILENAME) |
| 313 | new_type = N_FN; |
| 314 | else |
| 315 | { |
| 316 | switch (name_type & HP_SYMTYPE_TYPE) |
| 317 | { |
| 318 | case HP_SYMTYPE_UNDEFINED: |
| 319 | new_type = N_UNDF; |
| 320 | break; |
| 321 | |
| 322 | case HP_SYMTYPE_ABSOLUTE: |
| 323 | new_type = N_ABS; |
| 324 | break; |
| 325 | |
| 326 | case HP_SYMTYPE_TEXT: |
| 327 | new_type = N_TEXT; |
| 328 | break; |
| 329 | |
| 330 | case HP_SYMTYPE_DATA: |
| 331 | new_type = N_DATA; |
| 332 | break; |
| 333 | |
| 334 | case HP_SYMTYPE_BSS: |
| 335 | new_type = N_BSS; |
| 336 | break; |
| 337 | |
| 338 | case HP_SYMTYPE_COMMON: |
| 339 | new_type = N_COMM; |
| 340 | break; |
| 341 | |
| 342 | default: |
| 343 | printf ("unknown symbol type encountered: %x", name_type); |
| 344 | } |
| 345 | if (name_type & HP_SYMTYPE_EXTERNAL) |
| 346 | new_type |= N_EXT; |
| 347 | |
| 348 | if (name_type & HP_SECONDARY_SYMBOL) |
| 349 | new_type = (new_type & ~N_TYPE) | N_INDR; |
| 350 | } |
| 351 | cache_ptr->type = new_type; |
| 352 | |
| 353 | } |
| 354 | |
| 355 | |
| 356 | /* |
| 357 | DESCRIPTION |
| 358 | Swaps the information in an executable header taken from a raw |
| 359 | byte stream memory image, into the internal exec_header |
| 360 | structure. |
| 361 | */ |
| 362 | |
| 363 | void |
| 364 | DEFUN(NAME(aout,swap_exec_header_in),(abfd, raw_bytes, execp), |
| 365 | bfd *abfd AND |
| 366 | struct external_exec *raw_bytes AND |
| 367 | struct internal_exec *execp) |
| 368 | { |
| 369 | struct external_exec *bytes = (struct external_exec *)raw_bytes; |
| 370 | |
| 371 | /* The internal_exec structure has some fields that are unused in this |
| 372 | configuration (IE for i960), so ensure that all such uninitialized |
| 373 | fields are zero'd out. There are places where two of these structs |
| 374 | are memcmp'd, and thus the contents do matter. */ |
| 375 | memset (execp, 0, sizeof (struct internal_exec)); |
| 376 | /* Now fill in fields in the execp, from the bytes in the raw data. */ |
| 377 | execp->a_info = bfd_h_get_32 (abfd, bytes->e_info); |
| 378 | execp->a_text = GET_WORD (abfd, bytes->e_text); |
| 379 | execp->a_data = GET_WORD (abfd, bytes->e_data); |
| 380 | execp->a_bss = GET_WORD (abfd, bytes->e_bss); |
| 381 | execp->a_syms = GET_WORD (abfd, bytes->e_syms); |
| 382 | execp->a_entry = GET_WORD (abfd, bytes->e_entry); |
| 383 | execp->a_trsize = GET_WORD (abfd, bytes->e_trsize); |
| 384 | execp->a_drsize = GET_WORD (abfd, bytes->e_drsize); |
| 385 | |
| 386 | /***************************************************************/ |
| 387 | /* check the header to see if it was generated by a bfd output */ |
| 388 | /* this is detected rather bizarely by requiring a bunch of */ |
| 389 | /* header fields to be zero and an old unused field (now used) */ |
| 390 | /* to be set. */ |
| 391 | /***************************************************************/ |
| 392 | do |
| 393 | { |
| 394 | long syms; |
| 395 | struct aout_data_struct *rawptr; |
| 396 | if (bfd_h_get_32 (abfd, bytes->e_passize) != 0) break; |
| 397 | if (bfd_h_get_32 (abfd, bytes->e_syms) != 0) break; |
| 398 | if (bfd_h_get_32 (abfd, bytes->e_supsize) != 0) break; |
| 399 | |
| 400 | syms = bfd_h_get_32 (abfd, bytes->e_drelocs); |
| 401 | if (syms == 0) break; |
| 402 | |
| 403 | /* OK, we've passed the test as best as we can determine */ |
| 404 | execp->a_syms = syms; |
| 405 | |
| 406 | /* allocate storage for where we will store this result */ |
| 407 | rawptr = (struct aout_data_struct *) bfd_zalloc (abfd, sizeof (*rawptr)); |
| 408 | |
| 409 | if (rawptr == NULL) { |
| 410 | bfd_error = no_memory; |
| 411 | return; |
| 412 | } |
| 413 | abfd->tdata.aout_data = rawptr; |
| 414 | obj_aout_subformat(abfd) = gnu_encap_format; |
| 415 | } while (0); |
| 416 | } |
| 417 | |
| 418 | |
| 419 | /* The hp symbol table is a bit different than other a.out targets. Instead |
| 420 | of having an array of nlist items and an array of strings, hp's format |
| 421 | has them mixed together in one structure. In addition, the strings are |
| 422 | not null terminated. It looks something like this: |
| 423 | |
| 424 | nlist element 1 |
| 425 | string1 |
| 426 | nlist element 2 |
| 427 | string2 |
| 428 | ... |
| 429 | |
| 430 | The whole symbol table is read as one chunk and then we march thru it |
| 431 | and convert it to canonical form. As we march thru the table, we copy |
| 432 | the nlist data into the internal form and we compact the strings and null |
| 433 | terminate them, using storage from the already allocated symbol table: |
| 434 | |
| 435 | string1 |
| 436 | null |
| 437 | string2 |
| 438 | null |
| 439 | ... |
| 440 | */ |
| 441 | |
| 442 | boolean |
| 443 | DEFUN(MY(slurp_symbol_table),(abfd), |
| 444 | bfd *abfd) |
| 445 | { |
| 446 | bfd_size_type symbol_bytes; |
| 447 | struct external_nlist *syms; |
| 448 | struct external_nlist *sym_pointer; |
| 449 | struct external_nlist *sym_end; |
| 450 | char *strings; |
| 451 | aout_symbol_type *cached; |
| 452 | unsigned num_syms = 0; |
| 453 | unsigned num_secondary = 0; |
| 454 | int xxx = 0; /* for translate_from_native_sym_flags */ |
| 455 | |
| 456 | /* If there's no work to be done, don't do any */ |
| 457 | if (obj_aout_symbols (abfd) != (aout_symbol_type *)NULL) return true; |
| 458 | symbol_bytes = exec_hdr(abfd)->a_syms; |
| 459 | if (symbol_bytes == 0) { |
| 460 | bfd_error = no_symbols; |
| 461 | return false; |
| 462 | } |
| 463 | |
| 464 | strings = (char *) bfd_alloc(abfd, |
| 465 | symbol_bytes + SYM_EXTRA_BYTES); |
| 466 | syms = (struct external_nlist *) (strings + SYM_EXTRA_BYTES); |
| 467 | bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET); |
| 468 | if (bfd_read ((PTR)syms, symbol_bytes, 1, abfd) != symbol_bytes) |
| 469 | { |
| 470 | bfd_release (abfd, syms); |
| 471 | return false; |
| 472 | } |
| 473 | |
| 474 | |
| 475 | sym_end = (struct external_nlist *) (((char *)syms) + symbol_bytes); |
| 476 | |
| 477 | /* first, march thru the table and figure out how many symbols there are */ |
| 478 | for (sym_pointer = syms; sym_pointer < sym_end; sym_pointer++, num_syms++) |
| 479 | { |
| 480 | if (bfd_get_8(abfd, sym_pointer->e_type) & HP_SECONDARY_SYMBOL) |
| 481 | num_secondary++; |
| 482 | /* skip over the embedded symbol. */ |
| 483 | sym_pointer = (struct external_nlist *) (((char *)sym_pointer) + |
| 484 | sym_pointer->e_length[0]); |
| 485 | } |
| 486 | |
| 487 | /* now that we know the symbol count, update the bfd header */ |
| 488 | bfd_get_symcount (abfd) = num_syms+num_secondary; |
| 489 | |
| 490 | cached = (aout_symbol_type *) |
| 491 | bfd_zalloc(abfd, (bfd_size_type)(bfd_get_symcount (abfd) * |
| 492 | sizeof(aout_symbol_type))); |
| 493 | |
| 494 | /* as we march thru the hp symbol table, convert it into a list of |
| 495 | null terminated strings to hold the symbol names. Make sure any |
| 496 | assignment to the strings pointer is done after we're thru using |
| 497 | the nlist so we don't overwrite anything important. */ |
| 498 | num_secondary = 0; |
| 499 | |
| 500 | /* OK, now walk the new symtable, cacheing symbol properties */ |
| 501 | { |
| 502 | aout_symbol_type *cache_ptr = cached; |
| 503 | aout_symbol_type cache_save; |
| 504 | /* Run through table and copy values */ |
| 505 | for (sym_pointer = syms, cache_ptr = cached; |
| 506 | sym_pointer < sym_end; sym_pointer++, cache_ptr++) |
| 507 | { |
| 508 | unsigned int length; |
| 509 | cache_ptr->symbol.the_bfd = abfd; |
| 510 | cache_ptr->symbol.value = GET_SWORD(abfd, sym_pointer->e_value); |
| 511 | cache_ptr->desc = bfd_get_16(abfd, sym_pointer->e_almod); |
| 512 | cache_ptr->type = bfd_get_8(abfd, sym_pointer->e_type); |
| 513 | cache_ptr->symbol.udata = 0; |
| 514 | length = bfd_get_8(abfd, sym_pointer->e_length); |
| 515 | cache_ptr->other = length; /* other not used, save length here */ |
| 516 | |
| 517 | cache_save = *cache_ptr; |
| 518 | convert_sym_type(sym_pointer, cache_ptr, abfd); |
| 519 | translate_from_native_sym_flags (sym_pointer, cache_ptr, abfd, |
| 520 | &xxx); |
| 521 | |
| 522 | /********************************************************/ |
| 523 | /* for hpux, the 'lenght' value indicates the length of */ |
| 524 | /* the symbol name which follows the nlist entry. */ |
| 525 | /********************************************************/ |
| 526 | if (length) |
| 527 | { |
| 528 | /**************************************************************/ |
| 529 | /* the hp string is not null terminated so we create a new one*/ |
| 530 | /* by copying the string to overlap the just vacated nlist */ |
| 531 | /* structure before it in memory. */ |
| 532 | /**************************************************************/ |
| 533 | cache_ptr->symbol.name = strings; |
| 534 | memcpy(strings, sym_pointer+1, length); |
| 535 | strings[length] = '\0'; |
| 536 | strings += length + 1; |
| 537 | } |
| 538 | else |
| 539 | cache_ptr->symbol.name = (char *)NULL; |
| 540 | |
| 541 | /**********************************************************/ |
| 542 | /* this is a bit of a kludge, but a secondary hp symbol */ |
| 543 | /* gets translated into a gnu indirect symbol. When this */ |
| 544 | /* happens, we need to create a "dummy" record to which */ |
| 545 | /* we can point the indirect symbol to. */ |
| 546 | /**********************************************************/ |
| 547 | if ((cache_ptr->type | N_EXT) == (N_INDR | N_EXT)) |
| 548 | { |
| 549 | aout_symbol_type *cache_ptr2 = cached + num_syms+num_secondary; |
| 550 | |
| 551 | num_secondary++; |
| 552 | |
| 553 | /* aoutx.h assumes the "next" value is the indirect sym */ |
| 554 | /* since we don't want to disturb the order by inserting */ |
| 555 | /* a new symbol, we tack on the created secondary syms */ |
| 556 | /* at the end. */ |
| 557 | cache_ptr->symbol.value = (bfd_vma)(cache_ptr2); |
| 558 | *cache_ptr2 = cache_save; |
| 559 | cache_ptr2->symbol.name = strings; |
| 560 | memcpy(strings, cache_ptr->symbol.name, length); |
| 561 | strcpy(strings+length,":secondry"); /* 9 max chars + null */ |
| 562 | strings += length+10; |
| 563 | cache_ptr2->type &= ~HP_SECONDARY_SYMBOL; /* clear secondary */ |
| 564 | convert_sym_type(sym_pointer, cache_ptr2, abfd); |
| 565 | translate_from_native_sym_flags (sym_pointer, cache_ptr2, abfd, |
| 566 | &xxx); |
| 567 | } |
| 568 | |
| 569 | /* skip over the embedded symbol. */ |
| 570 | sym_pointer = (struct external_nlist *) (((char *)sym_pointer) + |
| 571 | length); |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | obj_aout_symbols (abfd) = cached; |
| 576 | |
| 577 | return true; |
| 578 | } |
| 579 | |
| 580 | |
| 581 | |
| 582 | void |
| 583 | DEFUN(MY(swap_std_reloc_in), (abfd, bytes, cache_ptr, symbols), |
| 584 | bfd *abfd AND |
| 585 | struct hp300hpux_reloc *bytes AND |
| 586 | arelent *cache_ptr AND |
| 587 | asymbol **symbols) |
| 588 | { |
| 589 | int r_index; |
| 590 | int r_extern = 0; |
| 591 | unsigned int r_length; |
| 592 | int r_pcrel = 0; |
| 593 | int r_baserel = 0, r_jmptable = 0, r_relative = 0; |
| 594 | struct aoutdata *su = &(abfd->tdata.aout_data->a); |
| 595 | |
| 596 | cache_ptr->address = bfd_h_get_32 (abfd, bytes->r_address); |
| 597 | r_index = bfd_h_get_16(abfd, bytes->r_index); |
| 598 | |
| 599 | switch (bytes->r_type[0]) |
| 600 | { |
| 601 | case HP_RSEGMENT_TEXT: |
| 602 | r_index = N_TEXT; |
| 603 | break; |
| 604 | case HP_RSEGMENT_DATA: |
| 605 | r_index = N_DATA; |
| 606 | break; |
| 607 | case HP_RSEGMENT_BSS: |
| 608 | r_index = N_BSS; |
| 609 | break; |
| 610 | case HP_RSEGMENT_EXTERNAL: |
| 611 | r_extern = 1; |
| 612 | break; |
| 613 | case HP_RSEGMENT_PCREL: |
| 614 | r_extern = 1; |
| 615 | r_pcrel = 1; |
| 616 | break; |
| 617 | case HP_RSEGMENT_RDLT: |
| 618 | break; |
| 619 | case HP_RSEGMENT_RPLT: |
| 620 | break; |
| 621 | case HP_RSEGMENT_NOOP: |
| 622 | break; |
| 623 | default: |
| 624 | printf |
| 625 | ("illegal relocation segment type: %x\n", (bytes->r_type[0])); |
| 626 | } |
| 627 | |
| 628 | switch (bytes->r_length[0]) |
| 629 | { |
| 630 | case HP_RLENGTH_BYTE: |
| 631 | r_length = 0; |
| 632 | break; |
| 633 | case HP_RLENGTH_WORD: |
| 634 | r_length = 1; |
| 635 | break; |
| 636 | case HP_RLENGTH_LONG: |
| 637 | r_length = 2; |
| 638 | break; |
| 639 | default: |
| 640 | printf("illegal relocation length: %x\n",bytes->r_length[0] ); |
| 641 | } |
| 642 | |
| 643 | cache_ptr->howto = howto_table_std + r_length + 4 * r_pcrel; |
| 644 | /* FIXME-soon: Roll baserel, jmptable, relative bits into howto setting */ |
| 645 | |
| 646 | /* This macro uses the r_index value computed above */ |
| 647 | if (r_pcrel && r_extern) |
| 648 | { |
| 649 | /* The GNU linker assumes any offset from beginning of section */ |
| 650 | /* is already incorporated into the image while the HP linker */ |
| 651 | /* adds this in later. Add it in now... */ |
| 652 | MOVE_ADDRESS( - cache_ptr->address); |
| 653 | } |
| 654 | else |
| 655 | { |
| 656 | MOVE_ADDRESS(0); |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | boolean |
| 661 | DEFUN(MY(slurp_reloc_table),(abfd, asect, symbols), |
| 662 | bfd *abfd AND |
| 663 | sec_ptr asect AND |
| 664 | asymbol **symbols) |
| 665 | { |
| 666 | unsigned int count; |
| 667 | bfd_size_type reloc_size; |
| 668 | PTR relocs; |
| 669 | arelent *reloc_cache; |
| 670 | size_t each_size; |
| 671 | struct hp300hpux_reloc *rptr; |
| 672 | unsigned int counter; |
| 673 | arelent *cache_ptr; |
| 674 | |
| 675 | if (asect->relocation) return true; |
| 676 | |
| 677 | if (asect->flags & SEC_CONSTRUCTOR) return true; |
| 678 | |
| 679 | if (asect == obj_datasec (abfd)) { |
| 680 | reloc_size = exec_hdr(abfd)->a_drsize; |
| 681 | goto doit; |
| 682 | } |
| 683 | |
| 684 | if (asect == obj_textsec (abfd)) { |
| 685 | reloc_size = exec_hdr(abfd)->a_trsize; |
| 686 | goto doit; |
| 687 | } |
| 688 | |
| 689 | bfd_error = invalid_operation; |
| 690 | return false; |
| 691 | |
| 692 | doit: |
| 693 | bfd_seek (abfd, asect->rel_filepos, SEEK_SET); |
| 694 | each_size = obj_reloc_entry_size (abfd); |
| 695 | |
| 696 | count = reloc_size / each_size; |
| 697 | |
| 698 | |
| 699 | reloc_cache = (arelent *) bfd_zalloc (abfd, (size_t)(count * sizeof |
| 700 | (arelent))); |
| 701 | if (!reloc_cache) { |
| 702 | nomem: |
| 703 | bfd_error = no_memory; |
| 704 | return false; |
| 705 | } |
| 706 | |
| 707 | relocs = (PTR) bfd_alloc (abfd, reloc_size); |
| 708 | if (!relocs) { |
| 709 | bfd_release (abfd, reloc_cache); |
| 710 | goto nomem; |
| 711 | } |
| 712 | |
| 713 | if (bfd_read (relocs, 1, reloc_size, abfd) != reloc_size) { |
| 714 | bfd_release (abfd, relocs); |
| 715 | bfd_release (abfd, reloc_cache); |
| 716 | bfd_error = system_call_error; |
| 717 | return false; |
| 718 | } |
| 719 | |
| 720 | rptr = (struct hp300hpux_reloc*) relocs; |
| 721 | counter = 0; |
| 722 | cache_ptr = reloc_cache; |
| 723 | |
| 724 | for (; counter < count; counter++, rptr++, cache_ptr++) { |
| 725 | MY(swap_std_reloc_in)(abfd, rptr, cache_ptr, symbols); |
| 726 | } |
| 727 | |
| 728 | |
| 729 | bfd_release (abfd,relocs); |
| 730 | asect->relocation = reloc_cache; |
| 731 | asect->reloc_count = count; |
| 732 | return true; |
| 733 | } |
| 734 | |
| 735 | |
| 736 | /************************************************************************/ |
| 737 | /* The following functions are identical to functions in aoutx.h except */ |
| 738 | /* they refer to MY(func) rather than NAME(aout,func) and they also */ |
| 739 | /* call aout_32 versions if the input file was generated by gcc */ |
| 740 | /************************************************************************/ |
| 741 | |
| 742 | unsigned int aout_32_get_symtab PARAMS((bfd *abfd, asymbol **location)); |
| 743 | unsigned int aout_32_get_symtab_upper_bound PARAMS ((bfd *abfd)); |
| 744 | |
| 745 | unsigned int aout_32_canonicalize_reloc PARAMS((bfd *abfd, sec_ptr section, |
| 746 | arelent **relptr, |
| 747 | asymbol **symbols)); |
| 748 | |
| 749 | unsigned int |
| 750 | DEFUN(MY(get_symtab),(abfd, location), |
| 751 | bfd *abfd AND |
| 752 | asymbol **location) |
| 753 | { |
| 754 | unsigned int counter = 0; |
| 755 | aout_symbol_type *symbase; |
| 756 | |
| 757 | if (obj_aout_subformat(abfd) == gnu_encap_format) |
| 758 | return aout_32_get_symtab(abfd,location); |
| 759 | |
| 760 | if (!MY(slurp_symbol_table)(abfd)) return 0; |
| 761 | |
| 762 | for (symbase = obj_aout_symbols(abfd); counter++ < bfd_get_symcount (abfd);) |
| 763 | *(location++) = (asymbol *)( symbase++); |
| 764 | *location++ =0; |
| 765 | return bfd_get_symcount (abfd); |
| 766 | } |
| 767 | |
| 768 | unsigned int |
| 769 | DEFUN(MY(get_symtab_upper_bound),(abfd), |
| 770 | bfd *abfd) |
| 771 | { |
| 772 | if (obj_aout_subformat(abfd) == gnu_encap_format) |
| 773 | return aout_32_get_symtab_upper_bound(abfd); |
| 774 | if (!MY(slurp_symbol_table)(abfd)) return 0; |
| 775 | |
| 776 | return (bfd_get_symcount (abfd)+1) * (sizeof (aout_symbol_type *)); |
| 777 | } |
| 778 | |
| 779 | |
| 780 | |
| 781 | |
| 782 | unsigned int |
| 783 | DEFUN(MY(canonicalize_reloc),(abfd, section, relptr, symbols), |
| 784 | bfd *abfd AND |
| 785 | sec_ptr section AND |
| 786 | arelent **relptr AND |
| 787 | asymbol **symbols) |
| 788 | { |
| 789 | arelent *tblptr = section->relocation; |
| 790 | unsigned int count; |
| 791 | if (obj_aout_subformat(abfd) == gnu_encap_format) |
| 792 | return aout_32_canonicalize_reloc(abfd,section,relptr,symbols); |
| 793 | |
| 794 | if (!(tblptr || MY(slurp_reloc_table)(abfd, section, symbols))) |
| 795 | return 0; |
| 796 | |
| 797 | if (section->flags & SEC_CONSTRUCTOR) { |
| 798 | arelent_chain *chain = section->constructor_chain; |
| 799 | for (count = 0; count < section->reloc_count; count ++) { |
| 800 | *relptr ++ = &chain->relent; |
| 801 | chain = chain->next; |
| 802 | } |
| 803 | } |
| 804 | else { |
| 805 | tblptr = section->relocation; |
| 806 | if (!tblptr) return 0; |
| 807 | |
| 808 | for (count = 0; count++ < section->reloc_count;) |
| 809 | { |
| 810 | *relptr++ = tblptr++; |
| 811 | } |
| 812 | } |
| 813 | *relptr = 0; |
| 814 | |
| 815 | return section->reloc_count; |
| 816 | } |
| 817 | |
| 818 | |
| 819 | #include "aout-target.h" |