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