OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gdb-7.2/] [bfd/] [hp300hpux.c] - Blame information for rev 853

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.