2000-09-09 Kazu Hirata <kazu@hxi.com>
[deliverable/binutils-gdb.git] / bfd / riscix.c
1 /* BFD back-end for RISC iX (Acorn, arm) binaries.
2 Copyright (C) 1994, 95, 96, 97, 98, 99, 2000
3 Free Software Foundation, Inc.
4 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21
22
23 /* RISC iX overloads the MAGIC field to indicate more than just the usual
24 [ZNO]MAGIC values. Also included are squeezing information and
25 shared library usage. */
26
27 /* The following come from the man page. */
28 #define SHLIBLEN 60
29
30 #define MF_IMPURE 00200
31 #define MF_SQUEEZED 01000
32 #define MF_USES_SL 02000
33 #define MF_IS_SL 04000
34
35 /* Common combinations. */
36 #define IMAGIC (MF_IMPURE|ZMAGIC) /* Demand load (impure text) */
37 #define SPOMAGIC (MF_USES_SL|OMAGIC) /* OMAGIC with large header */
38 /* -- may contain a ref to a */
39 /* shared lib required by the */
40 /* object. */
41 #define SLOMAGIC (MF_IS_SL|OMAGIC) /* A reference to a shared library */
42 /* The text portion of the object */
43 /* contains "overflow text" from */
44 /* the shared library to be linked */
45 /* in with an object */
46 #define QMAGIC (MF_SQUEEZED|ZMAGIC) /* Sqeezed demand paged. */
47 /* NOTE: This interpretation of */
48 /* QMAGIC seems to be at variance */
49 /* With that used on other */
50 /* architectures. */
51 #define SPZMAGIC (MF_USES_SL|ZMAGIC) /* program which uses sl */
52 #define SPQMAGIC (MF_USES_SL|QMAGIC) /* sqeezed ditto */
53 #define SLZMAGIC (MF_IS_SL|ZMAGIC) /* shared lib part of prog */
54 #define SLPZMAGIC (MF_USES_SL|SLZMAGIC) /* sl which uses another */
55
56 #define N_SHARED_LIB(x) ((x).a_info & MF_USES_SL)
57
58 /* Only a pure OMAGIC file has the minimal header */
59 #define N_TXTOFF(x) \
60 ((x).a_info == OMAGIC ? 32 \
61 : (N_MAGIC(x) == ZMAGIC) ? TARGET_PAGE_SIZE \
62 : 999)
63
64 #define N_TXTADDR(x) \
65 (N_MAGIC(x) != ZMAGIC ? 0 /* object file or NMAGIC */ \
66 /* Programs with shared libs are loaded at the first page after all the \
67 text segments of the shared library programs. Without looking this \
68 up we can't know exactly what the address will be. A reasonable guess \
69 is that a_entry will be in the first page of the executable. */ \
70 : N_SHARED_LIB(x) ? ((x).a_entry & ~(TARGET_PAGE_SIZE - 1)) \
71 : TEXT_START_ADDR)
72
73 #define N_SYMOFF(x) \
74 (N_TXTOFF (x) + (x).a_text + (x).a_data + (x).a_trsize + (x).a_drsize)
75
76 #define N_STROFF(x) (N_SYMOFF (x) + (x).a_syms)
77
78 #define TEXT_START_ADDR 32768
79 #define TARGET_PAGE_SIZE 32768
80 #define SEGMENT_SIZE TARGET_PAGE_SIZE
81 #define DEFAULT_ARCH bfd_arch_arm
82
83 #define MY(OP) CAT(riscix_,OP)
84 #define TARGETNAME "a.out-riscix"
85 #define N_BADMAG(x) ((((x).a_info & ~007200) != ZMAGIC) && \
86 (((x).a_info & ~006000) != OMAGIC) && \
87 ((x).a_info != NMAGIC))
88 #define N_MAGIC(x) ((x).a_info & ~07200)
89
90 #include "bfd.h"
91 #include "sysdep.h"
92 #include "libbfd.h"
93
94 #define WRITE_HEADERS(abfd, execp) \
95 { \
96 bfd_size_type text_size; /* dummy vars */ \
97 file_ptr text_end; \
98 if (adata(abfd).magic == undecided_magic) \
99 NAME(aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end); \
100 \
101 execp->a_syms = bfd_get_symcount (abfd) * EXTERNAL_NLIST_SIZE; \
102 execp->a_entry = bfd_get_start_address (abfd); \
103 \
104 execp->a_trsize = ((obj_textsec (abfd)->reloc_count) * \
105 obj_reloc_entry_size (abfd)); \
106 execp->a_drsize = ((obj_datasec (abfd)->reloc_count) * \
107 obj_reloc_entry_size (abfd)); \
108 NAME(aout,swap_exec_header_out) (abfd, execp, &exec_bytes); \
109 \
110 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0) return false; \
111 if (bfd_write ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd) \
112 != EXEC_BYTES_SIZE) \
113 return false; \
114 /* Now write out reloc info, followed by syms and strings */ \
115 \
116 if (bfd_get_outsymbols (abfd) != (asymbol **) NULL \
117 && bfd_get_symcount (abfd) != 0) \
118 { \
119 if (bfd_seek (abfd, (file_ptr)(N_SYMOFF(*execp)), SEEK_SET) != 0) \
120 return false; \
121 \
122 if (! NAME(aout,write_syms)(abfd)) return false; \
123 \
124 if (bfd_seek (abfd, (file_ptr)(N_TRELOFF(*execp)), SEEK_SET) != 0) \
125 return false; \
126 \
127 if (! riscix_squirt_out_relocs (abfd, obj_textsec (abfd))) \
128 return false; \
129 if (bfd_seek (abfd, (file_ptr)(N_DRELOFF(*execp)), SEEK_SET) != 0) \
130 return false; \
131 \
132 if (!NAME(aout,squirt_out_relocs)(abfd, obj_datasec (abfd))) \
133 return false; \
134 } \
135 }
136
137 #include "libaout.h"
138 #include "aout/aout64.h"
139
140 static bfd_reloc_status_type
141 riscix_fix_pcrel_26_done PARAMS ((bfd *, arelent *, asymbol *, PTR,
142 asection *, bfd *, char **));
143
144 static bfd_reloc_status_type
145 riscix_fix_pcrel_26 PARAMS ((bfd *, arelent *, asymbol *, PTR,
146 asection *, bfd *, char **));
147
148 static reloc_howto_type riscix_std_reloc_howto[] = {
149 /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone */
150 HOWTO( 0, 0, 0, 8, false, 0, complain_overflow_bitfield,0,"8", true, 0x000000ff,0x000000ff, false),
151 HOWTO( 1, 0, 1, 16, false, 0, complain_overflow_bitfield,0,"16", true, 0x0000ffff,0x0000ffff, false),
152 HOWTO( 2, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"32", true, 0xffffffff,0xffffffff, false),
153 HOWTO( 3, 2, 3, 26, true, 0, complain_overflow_signed, riscix_fix_pcrel_26 , "ARM26", true, 0x00ffffff,0x00ffffff, false),
154 HOWTO( 4, 0, 0, 8, true, 0, complain_overflow_signed, 0,"DISP8", true, 0x000000ff,0x000000ff, true),
155 HOWTO( 5, 0, 1, 16, true, 0, complain_overflow_signed, 0,"DISP16", true, 0x0000ffff,0x0000ffff, true),
156 HOWTO( 6, 0, 2, 32, true, 0, complain_overflow_signed, 0,"DISP32", true, 0xffffffff,0xffffffff, true),
157 HOWTO( 7, 2, 3, 26, false, 0, complain_overflow_signed, riscix_fix_pcrel_26_done, "ARM26D",true,0x00ffffff,0x00ffffff, false),
158 EMPTY_HOWTO (-1),
159 HOWTO( 9, 0, -1, 16, false, 0, complain_overflow_bitfield,0,"NEG16", true, 0x0000ffff,0x0000ffff, false),
160 HOWTO( 10, 0, -2, 32, false, 0, complain_overflow_bitfield,0,"NEG32", true, 0xffffffff,0xffffffff, false)
161 };
162
163 #define RISCIX_TABLE_SIZE \
164 (sizeof (riscix_std_reloc_howto) / sizeof (reloc_howto_type))
165
166
167 static bfd_reloc_status_type
168 riscix_fix_pcrel_26_done (abfd, reloc_entry, symbol, data, input_section,
169 output_bfd, error_message)
170 bfd *abfd ATTRIBUTE_UNUSED;
171 arelent *reloc_entry ATTRIBUTE_UNUSED;
172 asymbol *symbol ATTRIBUTE_UNUSED;
173 PTR data ATTRIBUTE_UNUSED;
174 asection *input_section ATTRIBUTE_UNUSED;
175 bfd *output_bfd ATTRIBUTE_UNUSED;
176 char **error_message ATTRIBUTE_UNUSED;
177 {
178 /* This is dead simple at present. */
179 return bfd_reloc_ok;
180 }
181
182 static bfd_reloc_status_type
183 riscix_fix_pcrel_26 (abfd, reloc_entry, symbol, data, input_section,
184 output_bfd, error_message)
185 bfd *abfd;
186 arelent *reloc_entry;
187 asymbol *symbol;
188 PTR data;
189 asection *input_section;
190 bfd *output_bfd;
191 char **error_message ATTRIBUTE_UNUSED;
192 {
193 bfd_vma relocation;
194 bfd_size_type addr = reloc_entry->address;
195 long target = bfd_get_32 (abfd, (bfd_byte *) data + addr);
196 bfd_reloc_status_type flag = bfd_reloc_ok;
197
198 /* If this is an undefined symbol, return error */
199 if (symbol->section == &bfd_und_section
200 && (symbol->flags & BSF_WEAK) == 0)
201 return output_bfd ? bfd_reloc_continue : bfd_reloc_undefined;
202
203 /* If the sections are different, and we are doing a partial relocation,
204 just ignore it for now. */
205 if (symbol->section->name != input_section->name
206 && output_bfd != (bfd *)NULL)
207 return bfd_reloc_continue;
208
209 relocation = (target & 0x00ffffff) << 2;
210 relocation = (relocation ^ 0x02000000) - 0x02000000; /* Sign extend */
211 relocation += symbol->value;
212 relocation += symbol->section->output_section->vma;
213 relocation += symbol->section->output_offset;
214 relocation += reloc_entry->addend;
215 relocation -= input_section->output_section->vma;
216 relocation -= input_section->output_offset;
217 relocation -= addr;
218 if (relocation & 3)
219 return bfd_reloc_overflow;
220
221 /* Check for overflow */
222 if (relocation & 0x02000000)
223 {
224 if ((relocation & ~ (bfd_vma) 0x03ffffff) != ~ (bfd_vma) 0x03ffffff)
225 flag = bfd_reloc_overflow;
226 }
227 else if (relocation & ~0x03ffffff)
228 flag = bfd_reloc_overflow;
229
230 target &= ~0x00ffffff;
231 target |= (relocation >> 2) & 0x00ffffff;
232 bfd_put_32 (abfd, target, (bfd_byte *) data + addr);
233
234 /* Now the ARM magic... Change the reloc type so that it is marked as done.
235 Strictly this is only necessary if we are doing a partial relocation. */
236 reloc_entry->howto = &riscix_std_reloc_howto[7];
237
238 return flag;
239 }
240
241 reloc_howto_type *
242 riscix_reloc_type_lookup (abfd, code)
243 bfd *abfd;
244 bfd_reloc_code_real_type code;
245 {
246 #define ASTD(i,j) case i: return &riscix_std_reloc_howto[j]
247 if (code == BFD_RELOC_CTOR)
248 switch (bfd_get_arch_info (abfd)->bits_per_address)
249 {
250 case 32:
251 code = BFD_RELOC_32;
252 break;
253 default: return (reloc_howto_type *) NULL;
254 }
255
256 switch (code)
257 {
258 ASTD (BFD_RELOC_16, 1);
259 ASTD (BFD_RELOC_32, 2);
260 ASTD (BFD_RELOC_ARM_PCREL_BRANCH, 3);
261 ASTD (BFD_RELOC_8_PCREL, 4);
262 ASTD (BFD_RELOC_16_PCREL, 5);
263 ASTD (BFD_RELOC_32_PCREL, 6);
264 default: return (reloc_howto_type *) NULL;
265 }
266 }
267
268 #define MY_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
269 #define MY_bfd_link_add_symbols _bfd_generic_link_add_symbols
270 #define MY_final_link_callback should_not_be_used
271 #define MY_bfd_final_link _bfd_generic_final_link
272
273 #define MY_bfd_reloc_type_lookup riscix_reloc_type_lookup
274 #define MY_canonicalize_reloc riscix_canonicalize_reloc
275 #define MY_object_p riscix_object_p
276
277 static const bfd_target *riscix_callback PARAMS ((bfd *));
278
279 void
280 riscix_swap_std_reloc_out (abfd, g, natptr)
281 bfd *abfd;
282 arelent *g;
283 struct reloc_std_external *natptr;
284 {
285 int r_index;
286 asymbol *sym = *(g->sym_ptr_ptr);
287 int r_extern;
288 int r_length;
289 int r_pcrel;
290 int r_neg = 0; /* Negative relocs use the BASEREL bit. */
291 asection *output_section = sym->section->output_section;
292
293 PUT_WORD(abfd, g->address, natptr->r_address);
294
295 r_length = g->howto->size ; /* Size as a power of two */
296 if (r_length < 0)
297 {
298 r_length = -r_length;
299 r_neg = 1;
300 }
301
302 r_pcrel = (int) g->howto->pc_relative; /* Relative to PC? */
303
304 /* For RISC iX, in pc-relative relocs the r_pcrel bit means that the
305 relocation has been done already (Only for the 26-bit one I think)???!!!
306 */
307
308 if (r_length == 3)
309 r_pcrel = r_pcrel ? 0 : 1;
310
311
312 #if 0
313 /* For a standard reloc, the addend is in the object file. */
314 r_addend = g->addend + (*(g->sym_ptr_ptr))->section->output_section->vma;
315 #endif
316
317 /* name was clobbered by aout_write_syms to be symbol index */
318
319 /* If this relocation is relative to a symbol then set the
320 r_index to the symbols index, and the r_extern bit.
321
322 Absolute symbols can come in in two ways, either as an offset
323 from the abs section, or as a symbol which has an abs value.
324 check for that here
325 */
326
327 if (bfd_is_com_section (output_section)
328 || output_section == &bfd_abs_section
329 || output_section == &bfd_und_section)
330 {
331 if (bfd_abs_section.symbol == sym)
332 {
333 /* Whoops, looked like an abs symbol, but is really an offset
334 from the abs section */
335 r_index = 0;
336 r_extern = 0;
337 }
338 else
339 {
340 /* Fill in symbol */
341 r_extern = 1;
342 r_index = (*g->sym_ptr_ptr)->udata.i;
343 }
344 }
345 else
346 {
347 /* Just an ordinary section */
348 r_extern = 0;
349 r_index = output_section->target_index;
350 }
351
352 /* now the fun stuff */
353 if (bfd_header_big_endian (abfd))
354 {
355 natptr->r_index[0] = r_index >> 16;
356 natptr->r_index[1] = r_index >> 8;
357 natptr->r_index[2] = r_index;
358 natptr->r_type[0] =
359 ( (r_extern ? RELOC_STD_BITS_EXTERN_BIG: 0)
360 | (r_pcrel ? RELOC_STD_BITS_PCREL_BIG: 0)
361 | (r_neg ? RELOC_STD_BITS_BASEREL_BIG: 0)
362 | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG));
363 }
364 else
365 {
366 natptr->r_index[2] = r_index >> 16;
367 natptr->r_index[1] = r_index >> 8;
368 natptr->r_index[0] = r_index;
369 natptr->r_type[0] =
370 ( (r_extern ? RELOC_STD_BITS_EXTERN_LITTLE: 0)
371 | (r_pcrel ? RELOC_STD_BITS_PCREL_LITTLE: 0)
372 | (r_neg ? RELOC_STD_BITS_BASEREL_LITTLE: 0)
373 | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE));
374 }
375 }
376
377 boolean
378 riscix_squirt_out_relocs (abfd, section)
379 bfd *abfd;
380 asection *section;
381 {
382 arelent **generic;
383 unsigned char *native, *natptr;
384 size_t each_size;
385
386 unsigned int count = section->reloc_count;
387 size_t natsize;
388
389 if (count == 0) return true;
390
391 each_size = obj_reloc_entry_size (abfd);
392 natsize = each_size * count;
393 native = (unsigned char *) bfd_zalloc (abfd, natsize);
394 if (!native)
395 return false;
396
397 generic = section->orelocation;
398
399 for (natptr = native;
400 count != 0;
401 --count, natptr += each_size, ++generic)
402 riscix_swap_std_reloc_out (abfd, *generic,
403 (struct reloc_std_external *) natptr);
404
405 if ( bfd_write ((PTR) native, 1, natsize, abfd) != natsize)
406 {
407 bfd_release(abfd, native);
408 return false;
409 }
410
411 bfd_release (abfd, native);
412 return true;
413 }
414
415
416 /*
417 * This is just like the standard aoutx.h version but we need to do our
418 * own mapping of external reloc type values to howto entries.
419 */
420 long
421 MY(canonicalize_reloc)(abfd, section, relptr, symbols)
422 bfd *abfd;
423 sec_ptr section;
424 arelent **relptr;
425 asymbol **symbols;
426 {
427 arelent *tblptr = section->relocation;
428 unsigned int count, c;
429 extern reloc_howto_type NAME(aout,std_howto_table)[];
430
431 /* If we have already read in the relocation table, return the values. */
432 if (section->flags & SEC_CONSTRUCTOR) {
433 arelent_chain *chain = section->constructor_chain;
434
435 for (count = 0; count < section->reloc_count; count++) {
436 *relptr++ = &chain->relent;
437 chain = chain->next;
438 }
439 *relptr = 0;
440 return section->reloc_count;
441 }
442 if (tblptr && section->reloc_count) {
443 for (count = 0; count++ < section->reloc_count;)
444 *relptr++ = tblptr++;
445 *relptr = 0;
446 return section->reloc_count;
447 }
448
449 if (!NAME(aout,slurp_reloc_table)(abfd, section, symbols))
450 return -1;
451 tblptr = section->relocation;
452
453 /* fix up howto entries */
454 for (count = 0; count++ < section->reloc_count;)
455 {
456 c = tblptr->howto - NAME(aout,std_howto_table);
457 BFD_ASSERT (c < RISCIX_TABLE_SIZE);
458 tblptr->howto = &riscix_std_reloc_howto[c];
459
460 *relptr++ = tblptr++;
461 }
462 *relptr = 0;
463 return section->reloc_count;
464 }
465
466 /* This is the same as NAME(aout,some_aout_object_p), but has different
467 expansions of the macro definitions. */
468
469 const bfd_target *
470 riscix_some_aout_object_p (abfd, execp, callback_to_real_object_p)
471 bfd *abfd;
472 struct internal_exec *execp;
473 const bfd_target *(*callback_to_real_object_p) PARAMS ((bfd *));
474 {
475 struct aout_data_struct *rawptr, *oldrawptr;
476 const bfd_target *result;
477
478 rawptr = ((struct aout_data_struct *)
479 bfd_zalloc (abfd, sizeof (struct aout_data_struct )));
480
481 if (rawptr == NULL)
482 return 0;
483
484 oldrawptr = abfd->tdata.aout_data;
485 abfd->tdata.aout_data = rawptr;
486
487 /* Copy the contents of the old tdata struct.
488 In particular, we want the subformat, since for hpux it was set in
489 hp300hpux.c:swap_exec_header_in and will be used in
490 hp300hpux.c:callback. */
491 if (oldrawptr != NULL)
492 *abfd->tdata.aout_data = *oldrawptr;
493
494 abfd->tdata.aout_data->a.hdr = &rawptr->e;
495 *(abfd->tdata.aout_data->a.hdr) = *execp; /* Copy in the internal_exec
496 struct */
497 execp = abfd->tdata.aout_data->a.hdr;
498
499 /* Set the file flags */
500 abfd->flags = BFD_NO_FLAGS;
501 if (execp->a_drsize || execp->a_trsize)
502 abfd->flags |= HAS_RELOC;
503 /* Setting of EXEC_P has been deferred to the bottom of this function */
504 if (execp->a_syms)
505 abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS;
506 if (N_DYNAMIC(*execp))
507 abfd->flags |= DYNAMIC;
508
509
510 if ((execp->a_info & MF_SQUEEZED) != 0) /* Squeezed files aren't supported
511 (yet)! */
512 {
513 bfd_set_error (bfd_error_wrong_format);
514 return NULL;
515 }
516 else if ((execp->a_info & MF_IS_SL) != 0) /* Nor are shared libraries */
517 {
518 bfd_set_error (bfd_error_wrong_format);
519 return NULL;
520 }
521 else if (N_MAGIC (*execp) == ZMAGIC)
522 {
523 abfd->flags |= D_PAGED | WP_TEXT;
524 adata (abfd).magic = z_magic;
525 }
526 else if (N_MAGIC (*execp) == NMAGIC)
527 {
528 abfd->flags |= WP_TEXT;
529 adata (abfd).magic = n_magic;
530 }
531 else if (N_MAGIC (*execp) == OMAGIC)
532 adata (abfd).magic = o_magic;
533 else
534 {
535 /* Should have been checked with N_BADMAG before this routine
536 was called. */
537 abort ();
538 }
539
540 bfd_get_start_address (abfd) = execp->a_entry;
541
542 obj_aout_symbols (abfd) = (aout_symbol_type *)NULL;
543 bfd_get_symcount (abfd) = execp->a_syms / sizeof (struct external_nlist);
544
545 /* The default relocation entry size is that of traditional V7 Unix. */
546 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
547
548 /* The default symbol entry size is that of traditional Unix. */
549 obj_symbol_entry_size (abfd) = EXTERNAL_NLIST_SIZE;
550
551 obj_aout_external_syms (abfd) = NULL;
552 obj_aout_external_strings (abfd) = NULL;
553 obj_aout_sym_hashes (abfd) = NULL;
554
555 if (! NAME(aout,make_sections) (abfd))
556 return NULL;
557
558 obj_datasec (abfd)->_raw_size = execp->a_data;
559 obj_bsssec (abfd)->_raw_size = execp->a_bss;
560
561 obj_textsec (abfd)->flags =
562 (execp->a_trsize != 0
563 ? (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_RELOC)
564 : (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS));
565 obj_datasec (abfd)->flags =
566 (execp->a_drsize != 0
567 ? (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS | SEC_RELOC)
568 : (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS));
569 obj_bsssec (abfd)->flags = SEC_ALLOC;
570
571 result = (*callback_to_real_object_p)(abfd);
572
573 #if defined(MACH) || defined(STAT_FOR_EXEC)
574 /* The original heuristic doesn't work in some important cases. The
575 * a.out file has no information about the text start address. For
576 * files (like kernels) linked to non-standard addresses (ld -Ttext
577 * nnn) the entry point may not be between the default text start
578 * (obj_textsec(abfd)->vma) and (obj_textsec(abfd)->vma) + text size
579 * This is not just a mach issue. Many kernels are loaded at non
580 * standard addresses.
581 */
582 {
583 struct stat stat_buf;
584 if (abfd->iostream != NULL
585 && (abfd->flags & BFD_IN_MEMORY) == 0
586 && (fstat(fileno((FILE *) (abfd->iostream)), &stat_buf) == 0)
587 && ((stat_buf.st_mode & 0111) != 0))
588 abfd->flags |= EXEC_P;
589 }
590 #else /* ! MACH */
591 /* Now that the segment addresses have been worked out, take a better
592 guess at whether the file is executable. If the entry point
593 is within the text segment, assume it is. (This makes files
594 executable even if their entry point address is 0, as long as
595 their text starts at zero.)
596
597 At some point we should probably break down and stat the file and
598 declare it executable if (one of) its 'x' bits are on... */
599 if ((execp->a_entry >= obj_textsec(abfd)->vma) &&
600 (execp->a_entry < obj_textsec(abfd)->vma + obj_textsec(abfd)->_raw_size))
601 abfd->flags |= EXEC_P;
602 #endif /* MACH */
603 if (result)
604 {
605 }
606 else
607 {
608 free (rawptr);
609 abfd->tdata.aout_data = oldrawptr;
610 }
611 return result;
612 }
613
614
615 static const bfd_target *
616 MY(object_p) (abfd)
617 bfd *abfd;
618 {
619 struct external_exec exec_bytes; /* Raw exec header from file */
620 struct internal_exec exec; /* Cleaned-up exec header */
621 const bfd_target *target;
622
623 if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
624 != EXEC_BYTES_SIZE) {
625 if (bfd_get_error () != bfd_error_system_call)
626 bfd_set_error (bfd_error_wrong_format);
627 return 0;
628 }
629
630 exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
631
632 if (N_BADMAG (exec)) return 0;
633 #ifdef MACHTYPE_OK
634 if (!(MACHTYPE_OK (N_MACHTYPE (exec)))) return 0;
635 #endif
636
637 NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &exec);
638
639 target = riscix_some_aout_object_p (abfd, &exec, MY(callback));
640
641 return target;
642 }
643
644
645 #include "aout-target.h"
This page took 0.057604 seconds and 4 git commands to generate.