* configure.in: Call AM_PROG_LEX rather than AC_PROG_LEX and
[deliverable/binutils-gdb.git] / bfd / hp300hpux.c
CommitLineData
bafe0602 1/* BFD backend for hp-ux 9000/300
1ff0461b 2 Copyright (C) 1990, 1991, 1994, 1995 Free Software Foundation, Inc.
bafe0602
KR
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
7a7fbffb 19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
bafe0602
KR
20
21/*
34dd8ba3 22
bafe0602
KR
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.
bafe0602
KR
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
34dd8ba3 47 in the object code while the gnu utilities use a field in the
bafe0602
KR
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
34dd8ba3 60
bafe0602
KR
61 #include "aout-target.h"
62 }
34dd8ba3 63
bafe0602
KR
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:
34dd8ba3 68
bafe0602
KR
69 nlist element 1
70 string1
71 nlist element 2
72 string2
73 ...
34dd8ba3 74
bafe0602
KR
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:
34dd8ba3 79
bafe0602
KR
80 string1
81 null
82 string2
83 null
bafe0602
KR
84 */
85
34dd8ba3
JG
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
bafe0602
KR
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 '/'
34dd8ba3 117#define TARGET_IS_BIG_ENDIAN_P
bafe0602
KR
118#define DEFAULT_ARCH bfd_arch_m68k
119
120#define MY_get_section_contents aout_32_get_section_contents
bafe0602
KR
121#define MY_slurp_armap bfd_slurp_bsd_armap_f2
122
123/***********************************************/
124/* provide overrides for routines in this file */
125/***********************************************/
9783e04a
DM
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
7a7fbffb
ILT
134#define MY_read_minisymbols _bfd_generic_read_minisymbols
135#define MY_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
136
9783e04a
DM
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
263a3f17 139#define MY_final_link_callback unused
9783e04a 140#define MY_bfd_final_link _bfd_generic_final_link
bafe0602 141
5c8444f8
ILT
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
bafe0602
KR
148#define hp300hpux_write_syms aout_32_write_syms
149
150#define MY_callback MY(callback)
151
263a3f17
ILT
152#define MY_exec_hdr_flags 0x2
153
34dd8ba3 154#define NAME_swap_exec_header_in NAME(hp300hpux_32_,swap_exec_header_in)
bafe0602
KR
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
34dd8ba3 185#define NAME(x,y) CAT3(hp300hpux,_32_,y)
9783e04a 186#define ARCH_SIZE 32
263a3f17
ILT
187
188/* aoutx.h requires definitions for BMAGIC and QMAGIC. */
7a7fbffb 189#define BMAGIC HPUX_DOT_O_MAGIC
263a3f17
ILT
190#define QMAGIC 0314
191
bafe0602
KR
192#include "aoutx.h"
193
34dd8ba3
JG
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. */
bafe0602
KR
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. */
7a7fbffb 204static const bfd_target *
25057836
JL
205MY (callback) (abfd)
206 bfd *abfd;
bafe0602
KR
207{
208 struct internal_exec *execp = exec_hdr (abfd);
209
210 /* Calculate the file positions of the parts of a newly read aout header */
25057836 211 obj_textsec (abfd)->_raw_size = N_TXTSIZE (*execp);
bafe0602
KR
212
213 /* The virtual memory addresses of the sections */
25057836
JL
214 obj_textsec (abfd)->vma = N_TXTADDR (*execp);
215 obj_datasec (abfd)->vma = N_DATADDR (*execp);
216 obj_bsssec (abfd)->vma = N_BSSADDR (*execp);
bafe0602 217
1ff0461b
ILT
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
bafe0602
KR
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 */
25057836
JL
227 obj_textsec (abfd)->rel_filepos = N_TRELOFF (*execp);
228 obj_datasec (abfd)->rel_filepos = N_DRELOFF (*execp);
bafe0602
KR
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);
34dd8ba3 233
bafe0602
KR
234 /* Determine the architecture and machine type of the object file. */
235#ifdef SET_ARCH_MACH
25057836 236 SET_ARCH_MACH (abfd, *execp);
bafe0602 237#else
25057836 238 bfd_default_set_arch_mach (abfd, DEFAULT_ARCH, 0);
bafe0602
KR
239#endif
240
241
25057836
JL
242 if (obj_aout_subformat (abfd) == gnu_encap_format)
243 {
bafe0602 244 /* The file offsets of the relocation info */
25057836
JL
245 obj_textsec (abfd)->rel_filepos = N_GNU_TRELOFF (*execp);
246 obj_datasec (abfd)->rel_filepos = N_GNU_DRELOFF (*execp);
34dd8ba3 247
bafe0602 248 /* The file offsets of the string table and symbol table. */
25057836 249 obj_sym_filepos (abfd) = N_GNU_SYMOFF (*execp);
bafe0602 250 obj_str_filepos (abfd) = (obj_sym_filepos (abfd) + execp->a_syms);
34dd8ba3 251
bafe0602
KR
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;
25057836 256 }
34dd8ba3 257
bafe0602
KR
258 return abfd->xvec;
259}
260
25057836 261extern boolean aout_32_write_syms PARAMS ((bfd * abfd));
9783e04a 262
bafe0602 263static boolean
25057836
JL
264MY (write_object_contents) (abfd)
265 bfd *abfd;
bafe0602 266{
25057836
JL
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;
34dd8ba3 271
25057836 272 memset (&exec_bytes, 0, sizeof (exec_bytes));
bafe0602 273#if CHOOSE_RELOC_SIZE
25057836 274 CHOOSE_RELOC_SIZE (abfd);
bafe0602 275#else
25057836 276 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
bafe0602 277#endif
34dd8ba3 278
25057836 279 if (adata (abfd).magic == undecided_magic)
263a3f17 280 NAME (aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end);
25057836 281 execp->a_syms = 0;
34dd8ba3 282
25057836 283 execp->a_entry = bfd_get_start_address (abfd);
34dd8ba3 284
25057836
JL
285 execp->a_trsize = ((obj_textsec (abfd)->reloc_count) *
286 obj_reloc_entry_size (abfd));
287 execp->a_drsize = ((obj_datasec (abfd)->reloc_count) *
288 obj_reloc_entry_size (abfd));
34dd8ba3 289
25057836 290 N_SET_MACHTYPE (*execp, 0xc);
263a3f17 291 N_SET_FLAGS (*execp, aout_backend_info (abfd)->exec_hdr_flags);
34dd8ba3 292
263a3f17 293 NAME (aout,swap_exec_header_out) (abfd, execp, &exec_bytes);
34dd8ba3 294
25057836 295 /* update fields not covered by default swap_exec_header_out */
bafe0602 296
25057836
JL
297 /* this is really the sym table size but we store it in drelocs */
298 bfd_h_put_32 (abfd, bfd_get_symcount (abfd) * 12, exec_bytes.e_drelocs);
34dd8ba3 299
4002f18a
ILT
300 if (bfd_seek (abfd, 0L, false) != 0
301 || (bfd_write ((PTR) & exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
302 != EXEC_BYTES_SIZE))
303 return false;
34dd8ba3 304
25057836 305 /* Write out the symbols, and then the relocs. We must write out
9783e04a
DM
306 the symbols first so that we know the symbol indices. */
307
25057836
JL
308 if (bfd_get_symcount (abfd) != 0)
309 {
310 /* Skip the relocs to where we want to put the symbols. */
311 if (bfd_seek (abfd, (file_ptr) N_DRELOFF (*execp) + execp->a_drsize,
312 SEEK_SET) != 0)
313 return false;
314 }
9783e04a 315
25057836
JL
316 if (!MY (write_syms) (abfd))
317 return false;
34dd8ba3 318
25057836
JL
319 if (bfd_get_symcount (abfd) != 0)
320 {
4002f18a
ILT
321 if (bfd_seek (abfd, (long) (N_TRELOFF (*execp)), false) != 0)
322 return false;
263a3f17 323 if (!NAME (aout,squirt_out_relocs) (abfd, obj_textsec (abfd)))
25057836 324 return false;
4002f18a
ILT
325 if (bfd_seek (abfd, (long) (N_DRELOFF (*execp)), false) != 0)
326 return false;
263a3f17 327 if (!NAME (aout,squirt_out_relocs) (abfd, obj_datasec (abfd)))
25057836 328 return false;
bafe0602
KR
329 }
330
25057836
JL
331 return true;
332}
bafe0602
KR
333
334/* convert the hp symbol type to be the same as aout64.h usage so we */
335/* can piggyback routines in aoutx.h. */
336
337static void
25057836
JL
338convert_sym_type (sym_pointer, cache_ptr, abfd)
339 struct external_nlist *sym_pointer;
340 aout_symbol_type *cache_ptr;
341 bfd *abfd;
bafe0602 342{
25057836
JL
343 int name_type;
344 int new_type;
bafe0602 345
25057836
JL
346 name_type = (cache_ptr->type);
347 new_type = 0;
34dd8ba3 348
25057836 349 if ((name_type & HP_SYMTYPE_ALIGN) != 0)
bafe0602 350 {
25057836
JL
351 /* iou_error ("aligned symbol encountered: %s", name);*/
352 name_type = 0;
bafe0602
KR
353 }
354
25057836
JL
355 if (name_type == HP_SYMTYPE_FILENAME)
356 new_type = N_FN;
357 else
358 {
359 switch (name_type & HP_SYMTYPE_TYPE)
360 {
361 case HP_SYMTYPE_UNDEFINED:
362 new_type = N_UNDF;
363 break;
364
365 case HP_SYMTYPE_ABSOLUTE:
366 new_type = N_ABS;
367 break;
368
369 case HP_SYMTYPE_TEXT:
370 new_type = N_TEXT;
371 break;
372
373 case HP_SYMTYPE_DATA:
374 new_type = N_DATA;
375 break;
376
377 case HP_SYMTYPE_BSS:
378 new_type = N_BSS;
379 break;
380
381 case HP_SYMTYPE_COMMON:
382 new_type = N_COMM;
383 break;
384
385 default:
7a7fbffb
ILT
386 abort ();
387 break;
25057836
JL
388 }
389 if (name_type & HP_SYMTYPE_EXTERNAL)
390 new_type |= N_EXT;
391
392 if (name_type & HP_SECONDARY_SYMBOL)
1ff0461b
ILT
393 {
394 switch (new_type)
395 {
396 default:
397 abort ();
398 case N_UNDF | N_EXT:
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 }
25057836
JL
415 }
416 cache_ptr->type = new_type;
34dd8ba3 417
bafe0602
KR
418}
419
420
421/*
422DESCRIPTION
423 Swaps the information in an executable header taken from a raw
424 byte stream memory image, into the internal exec_header
425 structure.
426*/
427
428void
263a3f17 429NAME (aout,swap_exec_header_in) (abfd, raw_bytes, execp)
25057836
JL
430 bfd *abfd;
431 struct external_exec *raw_bytes;
432 struct internal_exec *execp;
bafe0602 433{
25057836 434 struct external_exec *bytes = (struct external_exec *) raw_bytes;
bafe0602
KR
435
436 /* The internal_exec structure has some fields that are unused in this
437 configuration (IE for i960), so ensure that all such uninitialized
438 fields are zero'd out. There are places where two of these structs
439 are memcmp'd, and thus the contents do matter. */
440 memset (execp, 0, sizeof (struct internal_exec));
441 /* Now fill in fields in the execp, from the bytes in the raw data. */
25057836
JL
442 execp->a_info = bfd_h_get_32 (abfd, bytes->e_info);
443 execp->a_text = GET_WORD (abfd, bytes->e_text);
444 execp->a_data = GET_WORD (abfd, bytes->e_data);
445 execp->a_bss = GET_WORD (abfd, bytes->e_bss);
446 execp->a_syms = GET_WORD (abfd, bytes->e_syms);
447 execp->a_entry = GET_WORD (abfd, bytes->e_entry);
bafe0602
KR
448 execp->a_trsize = GET_WORD (abfd, bytes->e_trsize);
449 execp->a_drsize = GET_WORD (abfd, bytes->e_drsize);
450
451 /***************************************************************/
452 /* check the header to see if it was generated by a bfd output */
453 /* this is detected rather bizarely by requiring a bunch of */
454 /* header fields to be zero and an old unused field (now used) */
455 /* to be set. */
456 /***************************************************************/
457 do
25057836 458 {
bafe0602 459 long syms;
25057836
JL
460 struct aout_data_struct *rawptr;
461 if (bfd_h_get_32 (abfd, bytes->e_passize) != 0)
462 break;
463 if (bfd_h_get_32 (abfd, bytes->e_syms) != 0)
464 break;
465 if (bfd_h_get_32 (abfd, bytes->e_supsize) != 0)
466 break;
34dd8ba3 467
bafe0602 468 syms = bfd_h_get_32 (abfd, bytes->e_drelocs);
25057836
JL
469 if (syms == 0)
470 break;
bafe0602
KR
471
472 /* OK, we've passed the test as best as we can determine */
473 execp->a_syms = syms;
474
475 /* allocate storage for where we will store this result */
25057836 476 rawptr = (struct aout_data_struct *) bfd_zalloc (abfd, sizeof (*rawptr));
bafe0602 477
25057836
JL
478 if (rawptr == NULL)
479 {
480 bfd_set_error (bfd_error_no_memory);
481 return;
482 }
bafe0602 483 abfd->tdata.aout_data = rawptr;
25057836
JL
484 obj_aout_subformat (abfd) = gnu_encap_format;
485 }
486 while (0);
bafe0602
KR
487}
488
489
490/* The hp symbol table is a bit different than other a.out targets. Instead
491 of having an array of nlist items and an array of strings, hp's format
492 has them mixed together in one structure. In addition, the strings are
493 not null terminated. It looks something like this:
494
495 nlist element 1
496 string1
497 nlist element 2
498 string2
499 ...
500
501 The whole symbol table is read as one chunk and then we march thru it
502 and convert it to canonical form. As we march thru the table, we copy
503 the nlist data into the internal form and we compact the strings and null
504 terminate them, using storage from the already allocated symbol table:
505
506 string1
507 null
508 string2
509 null
510 ...
511*/
512
513boolean
25057836
JL
514MY (slurp_symbol_table) (abfd)
515 bfd *abfd;
bafe0602
KR
516{
517 bfd_size_type symbol_bytes;
518 struct external_nlist *syms;
519 struct external_nlist *sym_pointer;
520 struct external_nlist *sym_end;
521 char *strings;
522 aout_symbol_type *cached;
523 unsigned num_syms = 0;
34dd8ba3 524
bafe0602 525 /* If there's no work to be done, don't do any */
25057836
JL
526 if (obj_aout_symbols (abfd) != (aout_symbol_type *) NULL)
527 return true;
528 symbol_bytes = exec_hdr (abfd)->a_syms;
bafe0602 529
25057836
JL
530 strings = (char *) bfd_alloc (abfd,
531 symbol_bytes + SYM_EXTRA_BYTES);
9783e04a
DM
532 if (!strings)
533 {
25057836 534 bfd_set_error (bfd_error_no_memory);
9783e04a
DM
535 return false;
536 }
bafe0602 537 syms = (struct external_nlist *) (strings + SYM_EXTRA_BYTES);
4002f18a
ILT
538 if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
539 || bfd_read ((PTR) syms, symbol_bytes, 1, abfd) != symbol_bytes)
25057836 540 {
bafe0602
KR
541 bfd_release (abfd, syms);
542 return false;
25057836 543 }
34dd8ba3 544
bafe0602 545
25057836 546 sym_end = (struct external_nlist *) (((char *) syms) + symbol_bytes);
34dd8ba3 547
bafe0602 548 /* first, march thru the table and figure out how many symbols there are */
34dd8ba3 549 for (sym_pointer = syms; sym_pointer < sym_end; sym_pointer++, num_syms++)
25057836 550 {
bafe0602 551 /* skip over the embedded symbol. */
25057836
JL
552 sym_pointer = (struct external_nlist *) (((char *) sym_pointer) +
553 sym_pointer->e_length[0]);
554 }
bafe0602
KR
555
556 /* now that we know the symbol count, update the bfd header */
1ff0461b 557 bfd_get_symcount (abfd) = num_syms;
34dd8ba3 558
7a7fbffb
ILT
559 cached = ((aout_symbol_type *)
560 bfd_zalloc (abfd,
561 bfd_get_symcount (abfd) * sizeof (aout_symbol_type)));
562 if (cached == NULL && bfd_get_symcount (abfd) != 0)
9783e04a 563 {
25057836 564 bfd_set_error (bfd_error_no_memory);
9783e04a
DM
565 return false;
566 }
34dd8ba3 567
bafe0602
KR
568 /* as we march thru the hp symbol table, convert it into a list of
569 null terminated strings to hold the symbol names. Make sure any
570 assignment to the strings pointer is done after we're thru using
571 the nlist so we don't overwrite anything important. */
34dd8ba3 572
bafe0602 573 /* OK, now walk the new symtable, cacheing symbol properties */
25057836
JL
574 {
575 aout_symbol_type *cache_ptr = cached;
576 aout_symbol_type cache_save;
577 /* Run through table and copy values */
578 for (sym_pointer = syms, cache_ptr = cached;
579 sym_pointer < sym_end; sym_pointer++, cache_ptr++)
580 {
581 unsigned int length;
582 cache_ptr->symbol.the_bfd = abfd;
583 cache_ptr->symbol.value = GET_SWORD (abfd, sym_pointer->e_value);
584 cache_ptr->desc = bfd_get_16 (abfd, sym_pointer->e_almod);
585 cache_ptr->type = bfd_get_8 (abfd, sym_pointer->e_type);
7a7fbffb 586 cache_ptr->symbol.udata.p = NULL;
25057836
JL
587 length = bfd_get_8 (abfd, sym_pointer->e_length);
588 cache_ptr->other = length; /* other not used, save length here */
589
590 cache_save = *cache_ptr;
591 convert_sym_type (sym_pointer, cache_ptr, abfd);
263a3f17 592 if (!translate_from_native_sym_flags (abfd, cache_ptr))
25057836
JL
593 return false;
594
595 /********************************************************/
596 /* for hpux, the 'lenght' value indicates the length of */
597 /* the symbol name which follows the nlist entry. */
598 /********************************************************/
599 if (length)
bafe0602 600 {
25057836
JL
601 /**************************************************************/
602 /* the hp string is not null terminated so we create a new one*/
603 /* by copying the string to overlap the just vacated nlist */
604 /* structure before it in memory. */
605 /**************************************************************/
606 cache_ptr->symbol.name = strings;
607 memcpy (strings, sym_pointer + 1, length);
608 strings[length] = '\0';
609 strings += length + 1;
610 }
611 else
612 cache_ptr->symbol.name = (char *) NULL;
613
25057836
JL
614 /* skip over the embedded symbol. */
615 sym_pointer = (struct external_nlist *) (((char *) sym_pointer) +
616 length);
617 }
618 }
619
620 obj_aout_symbols (abfd) = cached;
34dd8ba3 621
bafe0602
KR
622 return true;
623}
624
625
626
627void
7a7fbffb 628MY (swap_std_reloc_in) (abfd, bytes, cache_ptr, symbols, symcount)
25057836
JL
629 bfd *abfd;
630 struct hp300hpux_reloc *bytes;
631 arelent *cache_ptr;
632 asymbol **symbols;
7a7fbffb 633 bfd_size_type symcount;
bafe0602
KR
634{
635 int r_index;
636 int r_extern = 0;
637 unsigned int r_length;
638 int r_pcrel = 0;
25057836 639 struct aoutdata *su = &(abfd->tdata.aout_data->a);
bafe0602 640
34dd8ba3 641 cache_ptr->address = bfd_h_get_32 (abfd, bytes->r_address);
25057836 642 r_index = bfd_h_get_16 (abfd, bytes->r_index);
34dd8ba3 643
bafe0602 644 switch (bytes->r_type[0])
25057836
JL
645 {
646 case HP_RSEGMENT_TEXT:
bafe0602
KR
647 r_index = N_TEXT;
648 break;
25057836 649 case HP_RSEGMENT_DATA:
bafe0602
KR
650 r_index = N_DATA;
651 break;
25057836 652 case HP_RSEGMENT_BSS:
bafe0602
KR
653 r_index = N_BSS;
654 break;
25057836 655 case HP_RSEGMENT_EXTERNAL:
bafe0602
KR
656 r_extern = 1;
657 break;
25057836 658 case HP_RSEGMENT_PCREL:
bafe0602
KR
659 r_extern = 1;
660 r_pcrel = 1;
661 break;
25057836 662 case HP_RSEGMENT_RDLT:
bafe0602 663 break;
25057836 664 case HP_RSEGMENT_RPLT:
bafe0602 665 break;
25057836 666 case HP_RSEGMENT_NOOP:
bafe0602 667 break;
25057836 668 default:
7a7fbffb
ILT
669 abort ();
670 break;
25057836 671 }
34dd8ba3 672
bafe0602
KR
673 switch (bytes->r_length[0])
674 {
675 case HP_RLENGTH_BYTE:
676 r_length = 0;
677 break;
678 case HP_RLENGTH_WORD:
679 r_length = 1;
680 break;
681 case HP_RLENGTH_LONG:
682 r_length = 2;
683 break;
684 default:
7a7fbffb
ILT
685 abort ();
686 break;
bafe0602
KR
687 }
688
25057836 689 cache_ptr->howto = howto_table_std + r_length + 4 * r_pcrel;
bafe0602
KR
690 /* FIXME-soon: Roll baserel, jmptable, relative bits into howto setting */
691
692 /* This macro uses the r_index value computed above */
693 if (r_pcrel && r_extern)
25057836
JL
694 {
695 /* The GNU linker assumes any offset from beginning of section */
696 /* is already incorporated into the image while the HP linker */
697 /* adds this in later. Add it in now... */
698 MOVE_ADDRESS (-cache_ptr->address);
699 }
bafe0602 700 else
25057836
JL
701 {
702 MOVE_ADDRESS (0);
703 }
bafe0602
KR
704}
705
706boolean
25057836
JL
707MY (slurp_reloc_table) (abfd, asect, symbols)
708 bfd *abfd;
709 sec_ptr asect;
710 asymbol **symbols;
bafe0602
KR
711{
712 unsigned int count;
713 bfd_size_type reloc_size;
714 PTR relocs;
715 arelent *reloc_cache;
716 size_t each_size;
717 struct hp300hpux_reloc *rptr;
718 unsigned int counter;
719 arelent *cache_ptr;
34dd8ba3 720
25057836
JL
721 if (asect->relocation)
722 return true;
bafe0602 723
25057836
JL
724 if (asect->flags & SEC_CONSTRUCTOR)
725 return true;
bafe0602 726
25057836
JL
727 if (asect == obj_datasec (abfd))
728 {
729 reloc_size = exec_hdr (abfd)->a_drsize;
730 goto doit;
731 }
bafe0602 732
25057836
JL
733 if (asect == obj_textsec (abfd))
734 {
735 reloc_size = exec_hdr (abfd)->a_trsize;
736 goto doit;
737 }
bafe0602 738
25057836 739 bfd_set_error (bfd_error_invalid_operation);
bafe0602
KR
740 return false;
741
25057836 742doit:
4002f18a
ILT
743 if (bfd_seek (abfd, asect->rel_filepos, SEEK_SET) != 0)
744 return false;
bafe0602
KR
745 each_size = obj_reloc_entry_size (abfd);
746
747 count = reloc_size / each_size;
748
749
25057836
JL
750 reloc_cache = (arelent *) bfd_zalloc (abfd, (size_t) (count * sizeof
751 (arelent)));
b3cee0a9 752 if (!reloc_cache && count != 0)
25057836
JL
753 {
754 nomem:
755 bfd_set_error (bfd_error_no_memory);
756 return false;
757 }
bafe0602
KR
758
759 relocs = (PTR) bfd_alloc (abfd, reloc_size);
b3cee0a9 760 if (!relocs && reloc_size != 0)
25057836
JL
761 {
762 bfd_release (abfd, reloc_cache);
763 goto nomem;
764 }
bafe0602 765
25057836
JL
766 if (bfd_read (relocs, 1, reloc_size, abfd) != reloc_size)
767 {
768 bfd_release (abfd, relocs);
769 bfd_release (abfd, reloc_cache);
770 return false;
771 }
bafe0602 772
25057836
JL
773 rptr = (struct hp300hpux_reloc *) relocs;
774 counter = 0;
775 cache_ptr = reloc_cache;
bafe0602 776
25057836
JL
777 for (; counter < count; counter++, rptr++, cache_ptr++)
778 {
7a7fbffb
ILT
779 MY (swap_std_reloc_in) (abfd, rptr, cache_ptr, symbols,
780 bfd_get_symcount (abfd));
bafe0602
KR
781 }
782
783
25057836 784 bfd_release (abfd, relocs);
bafe0602
KR
785 asect->relocation = reloc_cache;
786 asect->reloc_count = count;
787 return true;
788}
789
790
791/************************************************************************/
792/* The following functions are identical to functions in aoutx.h except */
793/* they refer to MY(func) rather than NAME(aout,func) and they also */
794/* call aout_32 versions if the input file was generated by gcc */
795/************************************************************************/
796
326e32d7
ILT
797long aout_32_get_symtab PARAMS ((bfd * abfd, asymbol ** location));
798long aout_32_get_symtab_upper_bound PARAMS ((bfd * abfd));
bafe0602 799
326e32d7
ILT
800long aout_32_canonicalize_reloc PARAMS ((bfd * abfd, sec_ptr section,
801 arelent ** relptr,
802 asymbol ** symbols));
bafe0602 803
326e32d7 804long
25057836
JL
805MY (get_symtab) (abfd, location)
806 bfd *abfd;
807 asymbol **location;
bafe0602 808{
25057836
JL
809 unsigned int counter = 0;
810 aout_symbol_type *symbase;
bafe0602 811
25057836
JL
812 if (obj_aout_subformat (abfd) == gnu_encap_format)
813 return aout_32_get_symtab (abfd, location);
34dd8ba3 814
25057836 815 if (!MY (slurp_symbol_table) (abfd))
326e32d7 816 return -1;
bafe0602 817
25057836
JL
818 for (symbase = obj_aout_symbols (abfd); counter++ < bfd_get_symcount (abfd);)
819 *(location++) = (asymbol *) (symbase++);
820 *location++ = 0;
821 return bfd_get_symcount (abfd);
bafe0602
KR
822}
823
326e32d7 824long
25057836
JL
825MY (get_symtab_upper_bound) (abfd)
826 bfd *abfd;
bafe0602 827{
25057836
JL
828 if (obj_aout_subformat (abfd) == gnu_encap_format)
829 return aout_32_get_symtab_upper_bound (abfd);
830 if (!MY (slurp_symbol_table) (abfd))
326e32d7 831 return -1;
bafe0602 832
25057836 833 return (bfd_get_symcount (abfd) + 1) * (sizeof (aout_symbol_type *));
bafe0602
KR
834}
835
836
837
838
326e32d7 839long
25057836
JL
840MY (canonicalize_reloc) (abfd, section, relptr, symbols)
841 bfd *abfd;
842 sec_ptr section;
843 arelent **relptr;
844 asymbol **symbols;
bafe0602
KR
845{
846 arelent *tblptr = section->relocation;
847 unsigned int count;
25057836
JL
848 if (obj_aout_subformat (abfd) == gnu_encap_format)
849 return aout_32_canonicalize_reloc (abfd, section, relptr, symbols);
bafe0602 850
25057836 851 if (!(tblptr || MY (slurp_reloc_table) (abfd, section, symbols)))
326e32d7 852 return -1;
bafe0602 853
25057836
JL
854 if (section->flags & SEC_CONSTRUCTOR)
855 {
856 arelent_chain *chain = section->constructor_chain;
857 for (count = 0; count < section->reloc_count; count++)
858 {
859 *relptr++ = &chain->relent;
860 chain = chain->next;
861 }
862 }
863 else
864 {
865 tblptr = section->relocation;
25057836
JL
866
867 for (count = 0; count++ < section->reloc_count;)
868 {
869 *relptr++ = tblptr++;
870 }
bafe0602 871 }
bafe0602
KR
872 *relptr = 0;
873
874 return section->reloc_count;
875}
876
877
878#include "aout-target.h"
This page took 0.225816 seconds and 4 git commands to generate.