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