OSDN Git Service

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