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