Changeset 609 for branches/GNU/src/binutils/bfd/bout.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/bout.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* BFD back-end for Intel 960 b.out binaries. 2 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 3 2000 3 2000, 2001, 2002 4 4 Free Software Foundation, Inc. 5 5 Written by Cygnus Support. … … 29 29 30 30 #include "aout/stab_gnu.h" 31 #include "libaout.h" /* BFD a.out internal data structures */ 32 33 static int aligncode PARAMS ((bfd *abfd, asection *input_section, 34 arelent *r, unsigned int shrink)); 35 static void perform_slip PARAMS ((bfd *abfd, unsigned int slip, 36 asection *input_section, bfd_vma value)); 37 static boolean b_out_squirt_out_relocs PARAMS ((bfd *abfd, asection *section)); 38 static const bfd_target *b_out_callback PARAMS ((bfd *)); 31 #include "libaout.h" /* BFD a.out internal data structures. */ 32 33 static int aligncode 34 PARAMS ((bfd *abfd, asection *input_section, arelent *r, 35 unsigned int shrink)); 36 static void perform_slip 37 PARAMS ((bfd *abfd, unsigned int slip, asection *input_section, 38 bfd_vma value)); 39 static bfd_boolean b_out_squirt_out_relocs 40 PARAMS ((bfd *abfd, asection *section)); 41 static const bfd_target *b_out_callback 42 PARAMS ((bfd *)); 39 43 static bfd_reloc_status_type calljx_callback 40 44 PARAMS ((bfd *, struct bfd_link_info *, arelent *, PTR src, PTR dst, … … 42 46 static bfd_reloc_status_type callj_callback 43 47 PARAMS ((bfd *, struct bfd_link_info *, arelent *, PTR data, 44 unsigned int srcidx, unsigned int dstidx, asection *, b oolean));45 static bfd_vma get_value PARAMS ((arelent *, struct bfd_link_info *,46 47 static int abs32code PARAMS ((bfd *, asection *, arelent *,48 unsigned int, struct bfd_link_info *)); 49 static boolean b_out_bfd_relax_section PARAMS ((bfd *, asection *, 50 struct bfd_link_info *, 51 48 unsigned int srcidx, unsigned int dstidx, asection *, bfd_boolean)); 49 static bfd_vma get_value 50 PARAMS ((arelent *, struct bfd_link_info *, asection *)); 51 static int abs32code 52 PARAMS ((bfd *, asection *, arelent *, unsigned int, 53 struct bfd_link_info *)); 54 static bfd_boolean b_out_bfd_relax_section 55 PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *)); 52 56 static bfd_byte *b_out_bfd_get_relocated_section_contents 53 PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *, 54 bfd_byte *, boolean, asymbol **)); 57 PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *, bfd_byte *, 58 bfd_boolean, asymbol **)); 59 static int b_out_sizeof_headers 60 PARAMS ((bfd *, bfd_boolean)); 61 static bfd_boolean b_out_set_arch_mach 62 PARAMS ((bfd *, enum bfd_architecture, unsigned long)); 63 static bfd_boolean b_out_set_section_contents 64 PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type)); 65 static long b_out_get_reloc_upper_bound 66 PARAMS ((bfd *, sec_ptr)); 67 static long b_out_canonicalize_reloc 68 PARAMS ((bfd *, sec_ptr, arelent **, asymbol **)); 69 static bfd_boolean b_out_slurp_reloc_table 70 PARAMS ((bfd *, sec_ptr, asymbol **)); 71 static reloc_howto_type *b_out_bfd_reloc_type_lookup 72 PARAMS ((bfd *, bfd_reloc_code_real_type)); 73 static bfd_boolean b_out_write_object_contents 74 PARAMS ((bfd *)); 75 static int b_out_symbol_cmp 76 PARAMS ((const void *, const void *)); 77 static bfd_boolean b_out_mkobject 78 PARAMS ((bfd *)); 79 static const bfd_target *b_out_object_p 80 PARAMS ((bfd *)); 81 82 void bout_swap_exec_header_in 83 PARAMS ((bfd *, struct external_exec *, struct internal_exec *)); 84 void bout_swap_exec_header_out 85 PARAMS ((bfd *, struct internal_exec *, struct external_exec *)); 55 86 56 87 /* Swaps the information in an executable header taken from a raw byte … … 66 97 67 98 /* Now fill in fields in the execp, from the bytes in the raw data. */ 68 execp->a_info = bfd_h_get_32 (abfd, bytes->e_info);99 execp->a_info = H_GET_32 (abfd, bytes->e_info); 69 100 execp->a_text = GET_WORD (abfd, bytes->e_text); 70 101 execp->a_data = GET_WORD (abfd, bytes->e_data); … … 85 116 supplied buffer ready for writing to disk. */ 86 117 87 PROTO(void, bout_swap_exec_header_out,88 (bfd *abfd,89 struct internal_exec *execp,90 struct external_exec *raw_bytes));91 118 void 92 119 bout_swap_exec_header_out (abfd, execp, raw_bytes) … … 98 125 99 126 /* Now fill in fields in the raw data, from the fields in the exec struct. */ 100 bfd_h_put_32 (abfd, execp->a_info , bytes->e_info);127 H_PUT_32 (abfd, execp->a_info , bytes->e_info); 101 128 PUT_WORD (abfd, execp->a_text , bytes->e_text); 102 129 PUT_WORD (abfd, execp->a_data , bytes->e_data); … … 120 147 struct internal_exec anexec; 121 148 struct external_exec exec_bytes; 122 123 if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd) 124 != EXEC_BYTES_SIZE) { 125 if (bfd_get_error () != bfd_error_system_call) 149 bfd_size_type amt = EXEC_BYTES_SIZE; 150 151 if (bfd_bread ((PTR) &exec_bytes, amt, abfd) != amt) 152 { 153 if (bfd_get_error () != bfd_error_system_call) 154 bfd_set_error (bfd_error_wrong_format); 155 return 0; 156 } 157 158 anexec.a_info = H_GET_32 (abfd, exec_bytes.e_info); 159 160 if (N_BADMAG (anexec)) 161 { 126 162 bfd_set_error (bfd_error_wrong_format); 127 return 0; 128 } 129 130 anexec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info); 131 132 if (N_BADMAG (anexec)) { 133 bfd_set_error (bfd_error_wrong_format); 134 return 0; 135 } 163 return 0; 164 } 136 165 137 166 bout_swap_exec_header_in (abfd, &exec_bytes, &anexec); … … 149 178 unsigned long bss_start; 150 179 151 /* Architecture and machine type */180 /* Architecture and machine type. */ 152 181 bfd_set_arch_mach(abfd, 153 182 bfd_arch_i960, /* B.out only used on i960 */ … … 159 188 obj_sym_filepos (abfd) = N_SYMOFF (*execp); 160 189 161 /* The alignments of the sections */190 /* The alignments of the sections. */ 162 191 obj_textsec (abfd)->alignment_power = execp->a_talign; 163 192 obj_datasec (abfd)->alignment_power = execp->a_dalign; … … 171 200 obj_datasec (abfd)->lma = obj_datasec (abfd)->vma; 172 201 173 /* And reload the sizes, since the aout module zaps them */202 /* And reload the sizes, since the aout module zaps them. */ 174 203 obj_textsec (abfd)->_raw_size = execp->a_text; 175 204 … … 179 208 obj_bsssec (abfd)->lma = obj_bsssec (abfd)->vma; 180 209 181 /* The file positions of the sections */210 /* The file positions of the sections. */ 182 211 obj_textsec (abfd)->filepos = N_TXTOFF(*execp); 183 212 obj_datasec (abfd)->filepos = N_DATOFF(*execp); 184 213 185 /* The file positions of the relocation info */214 /* The file positions of the relocation info. */ 186 215 obj_textsec (abfd)->rel_filepos = N_TROFF(*execp); 187 216 obj_datasec (abfd)->rel_filepos = N_DROFF(*execp); … … 196 225 } 197 226 198 struct bout_data_struct { 227 struct bout_data_struct 228 { 199 229 struct aoutdata a; 200 230 struct internal_exec e; 201 };202 203 static b oolean231 }; 232 233 static bfd_boolean 204 234 b_out_mkobject (abfd) 205 235 bfd *abfd; 206 236 { 207 237 struct bout_data_struct *rawptr; 208 209 rawptr = (struct bout_data_struct *) bfd_zalloc (abfd, sizeof (struct bout_data_struct)); 238 bfd_size_type amt = sizeof (struct bout_data_struct); 239 240 rawptr = (struct bout_data_struct *) bfd_zalloc (abfd, amt); 210 241 if (rawptr == NULL) 211 return false;242 return FALSE; 212 243 213 244 abfd->tdata.bout_data = rawptr; 214 245 exec_hdr (abfd) = &rawptr->e; 215 246 216 obj_textsec (abfd) = (asection *) NULL;217 obj_datasec (abfd) = (asection *) NULL;218 obj_bsssec (abfd) = (asection *) NULL;219 220 return true;247 obj_textsec (abfd) = (asection *) NULL; 248 obj_datasec (abfd) = (asection *) NULL; 249 obj_bsssec (abfd) = (asection *) NULL; 250 251 return TRUE; 221 252 } 222 253 223 254 static int 224 b_out_symbol_cmp (a, b) 225 struct aout_symbol **a, **b; 226 { 255 b_out_symbol_cmp (a_ptr, b_ptr) 256 const void * a_ptr; 257 const void * b_ptr; 258 { 259 struct aout_symbol ** a = (struct aout_symbol **) a_ptr; 260 struct aout_symbol ** b = (struct aout_symbol **) b_ptr; 227 261 asection *sec; 228 262 bfd_vma av, bv; 229 263 230 /* Primary key is address */264 /* Primary key is address. */ 231 265 sec = bfd_get_section (&(*a)->symbol); 232 266 av = sec->output_section->vma + sec->output_offset + (*a)->symbol.value; … … 249 283 } 250 284 251 static b oolean285 static bfd_boolean 252 286 b_out_write_object_contents (abfd) 253 287 bfd *abfd; 254 288 { 255 289 struct external_exec swapped_hdr; 290 bfd_size_type amt; 256 291 257 292 if (! aout_32_make_sections (abfd)) 258 return false;293 return FALSE; 259 294 260 295 exec_hdr (abfd)->a_info = BMAGIC; … … 279 314 bout_swap_exec_header_out (abfd, exec_hdr (abfd), &swapped_hdr); 280 315 316 amt = EXEC_BYTES_SIZE; 281 317 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0 282 || (bfd_write ((PTR) &swapped_hdr, 1, EXEC_BYTES_SIZE, abfd) 283 != EXEC_BYTES_SIZE)) 284 return false; 318 || bfd_bwrite ((PTR) &swapped_hdr, amt, abfd) != amt) 319 return FALSE; 285 320 286 321 /* Now write out reloc info, followed by syms and strings */ … … 308 343 309 344 if (q > outsyms) 310 qsort (outsyms, q - outsyms, sizeof (asymbol*), b_out_symbol_cmp); 345 qsort (outsyms, (size_t) (q - outsyms), sizeof (asymbol*), 346 b_out_symbol_cmp); 311 347 312 348 /* Back to your regularly scheduled program. */ 313 314 349 if (bfd_seek (abfd, (file_ptr) (N_SYMOFF(*exec_hdr(abfd))), SEEK_SET) 315 350 != 0) 316 return false;351 return FALSE; 317 352 318 353 if (! aout_32_write_syms (abfd)) 319 return false; 320 321 if (bfd_seek (abfd, (file_ptr) (N_TROFF(*exec_hdr(abfd))), SEEK_SET) != 0) 322 return false; 323 324 if (!b_out_squirt_out_relocs (abfd, obj_textsec (abfd))) return false; 354 return FALSE; 355 356 if (bfd_seek (abfd, (file_ptr) (N_TROFF(*exec_hdr(abfd))), SEEK_SET) 357 != 0) 358 return FALSE; 359 360 if (!b_out_squirt_out_relocs (abfd, obj_textsec (abfd))) 361 return FALSE; 325 362 if (bfd_seek (abfd, (file_ptr) (N_DROFF(*exec_hdr(abfd))), SEEK_SET) 326 363 != 0) 327 return false; 328 329 if (!b_out_squirt_out_relocs (abfd, obj_datasec (abfd))) return false; 330 } 331 return true; 332 } 333 334 335 /** Some reloc hackery */ 364 return FALSE; 365 366 if (!b_out_squirt_out_relocs (abfd, obj_datasec (abfd))) 367 return FALSE; 368 } 369 return TRUE; 370 } 371 372 373 /* Some reloc hackery. */ 336 374 337 375 #define CALLS 0x66003800 /* Template for 'calls' instruction */ 338 #define BAL 0x0b000000 /* Template for 'bal' instruction */376 #define BAL 0x0b000000 /* Template for 'bal' instruction */ 339 377 #define BAL_MASK 0x00ffffff 340 378 #define BALX 0x85f00000 /* Template for 'balx' instruction */ … … 345 383 #define output_addr(sec) ((sec)->output_offset+(sec)->output_section->vma) 346 384 347 /* Magic to turn callx into calljx */ 385 /* Magic to turn callx into calljx. */ 386 348 387 static bfd_reloc_status_type 349 388 calljx_callback (abfd, link_info, reloc_entry, src, dst, input_section) … … 366 405 aout_symbol_type *balsym = symbol+1; 367 406 int inst = bfd_get_32 (abfd, (bfd_byte *) src-4); 368 /* The next symbol should be an N_BALNAME */407 /* The next symbol should be an N_BALNAME. */ 369 408 BFD_ASSERT (IS_BALNAME (balsym->other)); 370 409 inst &= BALX_MASK; 371 410 inst |= BALX; 372 bfd_put_32 (abfd, inst, (bfd_byte *) dst-4);411 bfd_put_32 (abfd, (bfd_vma) inst, (bfd_byte *) dst-4); 373 412 symbol = balsym; 374 413 value = (symbol->symbol.value … … 378 417 word += value + reloc_entry->addend; 379 418 380 bfd_put_32 (abfd, word, dst);419 bfd_put_32 (abfd, (bfd_vma) word, dst); 381 420 return bfd_reloc_ok; 382 421 } 383 422 384 /* Magic to turn call into callj */ 423 /* Magic to turn call into callj. */ 424 385 425 static bfd_reloc_status_type 386 426 callj_callback (abfd, link_info, reloc_entry, data, srcidx, dstidx, … … 393 433 unsigned int dstidx; 394 434 asection *input_section; 395 b oolean shrinking;435 bfd_boolean shrinking; 396 436 { 397 437 int word = bfd_get_32 (abfd, (bfd_byte *) data + srcidx); … … 442 482 & BAL_MASK); 443 483 } 444 bfd_put_32 (abfd, word, (bfd_byte *) data + dstidx);484 bfd_put_32 (abfd, (bfd_vma) word, (bfd_byte *) data + dstidx); 445 485 return bfd_reloc_ok; 446 486 } … … 460 500 #define ALIGNDONE 11 461 501 static reloc_howto_type howto_reloc_callj = 462 HOWTO(CALLJ, 0, 2, 24, true, 0, complain_overflow_signed, 0,"callj", true, 0x00ffffff, 0x00ffffff,false);502 HOWTO(CALLJ, 0, 2, 24, TRUE, 0, complain_overflow_signed, 0,"callj", TRUE, 0x00ffffff, 0x00ffffff,FALSE); 463 503 static reloc_howto_type howto_reloc_abs32 = 464 HOWTO(ABS32, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"abs32", true, 0xffffffff,0xffffffff,false);504 HOWTO(ABS32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,0,"abs32", TRUE, 0xffffffff,0xffffffff,FALSE); 465 505 static reloc_howto_type howto_reloc_pcrel24 = 466 HOWTO(PCREL24, 0, 2, 24, true, 0, complain_overflow_signed,0,"pcrel24", true, 0x00ffffff,0x00ffffff,false);506 HOWTO(PCREL24, 0, 2, 24, TRUE, 0, complain_overflow_signed,0,"pcrel24", TRUE, 0x00ffffff,0x00ffffff,FALSE); 467 507 468 508 static reloc_howto_type howto_reloc_pcrel13 = 469 HOWTO(PCREL13, 0, 2, 13, true, 0, complain_overflow_signed,0,"pcrel13", true, 0x00001fff,0x00001fff,false);509 HOWTO(PCREL13, 0, 2, 13, TRUE, 0, complain_overflow_signed,0,"pcrel13", TRUE, 0x00001fff,0x00001fff,FALSE); 470 510 471 511 static reloc_howto_type howto_reloc_abs32codeshrunk = 472 HOWTO(ABS32CODE_SHRUNK, 0, 2, 24, true, 0, complain_overflow_signed, 0,"callx->callj", true, 0x00ffffff, 0x00ffffff,false);512 HOWTO(ABS32CODE_SHRUNK, 0, 2, 24, TRUE, 0, complain_overflow_signed, 0,"callx->callj", TRUE, 0x00ffffff, 0x00ffffff,FALSE); 473 513 474 514 static reloc_howto_type howto_reloc_abs32code = 475 HOWTO(ABS32CODE, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"callx", true, 0xffffffff,0xffffffff,false);515 HOWTO(ABS32CODE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,0,"callx", TRUE, 0xffffffff,0xffffffff,FALSE); 476 516 477 517 static reloc_howto_type howto_align_table[] = { 478 HOWTO (ALIGNER, 0, 0x1, 0, false, 0, complain_overflow_dont, 0, "align16", false, 0, 0, false),479 HOWTO (ALIGNER, 0, 0x3, 0, false, 0, complain_overflow_dont, 0, "align32", false, 0, 0, false),480 HOWTO (ALIGNER, 0, 0x7, 0, false, 0, complain_overflow_dont, 0, "align64", false, 0, 0, false),481 HOWTO (ALIGNER, 0, 0xf, 0, false, 0, complain_overflow_dont, 0, "align128", false, 0, 0, false),518 HOWTO (ALIGNER, 0, 0x1, 0, FALSE, 0, complain_overflow_dont, 0, "align16", FALSE, 0, 0, FALSE), 519 HOWTO (ALIGNER, 0, 0x3, 0, FALSE, 0, complain_overflow_dont, 0, "align32", FALSE, 0, 0, FALSE), 520 HOWTO (ALIGNER, 0, 0x7, 0, FALSE, 0, complain_overflow_dont, 0, "align64", FALSE, 0, 0, FALSE), 521 HOWTO (ALIGNER, 0, 0xf, 0, FALSE, 0, complain_overflow_dont, 0, "align128", FALSE, 0, 0, FALSE), 482 522 }; 483 523 484 524 static reloc_howto_type howto_done_align_table[] = { 485 HOWTO (ALIGNDONE, 0x1, 0x1, 0, false, 0, complain_overflow_dont, 0, "donealign16", false, 0, 0, false),486 HOWTO (ALIGNDONE, 0x3, 0x3, 0, false, 0, complain_overflow_dont, 0, "donealign32", false, 0, 0, false),487 HOWTO (ALIGNDONE, 0x7, 0x7, 0, false, 0, complain_overflow_dont, 0, "donealign64", false, 0, 0, false),488 HOWTO (ALIGNDONE, 0xf, 0xf, 0, false, 0, complain_overflow_dont, 0, "donealign128", false, 0, 0, false),525 HOWTO (ALIGNDONE, 0x1, 0x1, 0, FALSE, 0, complain_overflow_dont, 0, "donealign16", FALSE, 0, 0, FALSE), 526 HOWTO (ALIGNDONE, 0x3, 0x3, 0, FALSE, 0, complain_overflow_dont, 0, "donealign32", FALSE, 0, 0, FALSE), 527 HOWTO (ALIGNDONE, 0x7, 0x7, 0, FALSE, 0, complain_overflow_dont, 0, "donealign64", FALSE, 0, 0, FALSE), 528 HOWTO (ALIGNDONE, 0xf, 0xf, 0, FALSE, 0, complain_overflow_dont, 0, "donealign128", FALSE, 0, 0, FALSE), 489 529 }; 490 530 … … 508 548 } 509 549 510 /* Allocate enough room for all the reloc entries, plus pointers to them all */511 512 static b oolean550 /* Allocate enough room for all the reloc entries, plus pointers to them all. */ 551 552 static bfd_boolean 513 553 b_out_slurp_reloc_table (abfd, asect, symbols) 514 554 bfd *abfd; … … 517 557 { 518 558 register struct relocation_info *rptr; 519 unsigned int counter 520 arelent *cache_ptr 559 unsigned int counter; 560 arelent *cache_ptr; 521 561 int extern_mask, pcrel_mask, callj_mask, length_shift; 522 562 int incode_mask; … … 524 564 bfd_vma prev_addr = 0; 525 565 unsigned int count; 526 size_t reloc_size;566 bfd_size_type reloc_size, amt; 527 567 struct relocation_info *relocs; 528 568 arelent *reloc_cache; 529 569 530 570 if (asect->relocation) 531 return true; 571 return TRUE; 572 532 573 if (!aout_32_slurp_symbol_table (abfd)) 533 return false; 534 535 if (asect == obj_datasec (abfd)) { 536 reloc_size = exec_hdr(abfd)->a_drsize; 537 goto doit; 538 } 539 540 if (asect == obj_textsec (abfd)) { 541 reloc_size = exec_hdr(abfd)->a_trsize; 542 goto doit; 543 } 544 545 if (asect == obj_bsssec (abfd)) { 546 reloc_size = 0; 547 goto doit; 548 } 574 return FALSE; 575 576 if (asect == obj_datasec (abfd)) 577 { 578 reloc_size = exec_hdr(abfd)->a_drsize; 579 goto doit; 580 } 581 582 if (asect == obj_textsec (abfd)) 583 { 584 reloc_size = exec_hdr(abfd)->a_trsize; 585 goto doit; 586 } 587 588 if (asect == obj_bsssec (abfd)) 589 { 590 reloc_size = 0; 591 goto doit; 592 } 549 593 550 594 bfd_set_error (bfd_error_invalid_operation); 551 return false;595 return FALSE; 552 596 553 597 doit: 554 if (bfd_seek (abfd, (file_ptr) (asect->rel_filepos),SEEK_SET) != 0)555 return false;598 if (bfd_seek (abfd, asect->rel_filepos, SEEK_SET) != 0) 599 return FALSE; 556 600 count = reloc_size / sizeof (struct relocation_info); 557 601 558 602 relocs = (struct relocation_info *) bfd_malloc (reloc_size); 559 603 if (!relocs && reloc_size != 0) 560 return false; 561 reloc_cache = (arelent *) bfd_malloc ((count+1) * sizeof (arelent)); 562 if (!reloc_cache) { 563 if (relocs != NULL) 564 free ((char*)relocs); 565 return false; 566 } 567 568 if (bfd_read ((PTR) relocs, 1, reloc_size, abfd) != reloc_size) { 569 free (reloc_cache); 570 if (relocs != NULL) 571 free (relocs); 572 return false; 573 } 574 575 if (bfd_header_big_endian (abfd)) { 576 /* big-endian bit field allocation order */ 577 pcrel_mask = 0x80; 578 extern_mask = 0x10; 579 incode_mask = 0x08; 580 callj_mask = 0x02; 581 size_mask = 0x20; 582 length_shift = 5; 583 } else { 584 /* little-endian bit field allocation order */ 585 pcrel_mask = 0x01; 586 extern_mask = 0x08; 587 incode_mask = 0x10; 588 callj_mask = 0x40; 589 size_mask = 0x02; 590 length_shift = 1; 591 } 604 return FALSE; 605 606 amt = ((bfd_size_type) count + 1) * sizeof (arelent); 607 reloc_cache = (arelent *) bfd_malloc (amt); 608 if (!reloc_cache) 609 { 610 if (relocs != NULL) 611 free (relocs); 612 return FALSE; 613 } 614 615 if (bfd_bread ((PTR) relocs, reloc_size, abfd) != reloc_size) 616 { 617 free (reloc_cache); 618 if (relocs != NULL) 619 free (relocs); 620 return FALSE; 621 } 622 623 if (bfd_header_big_endian (abfd)) 624 { 625 /* Big-endian bit field allocation order. */ 626 pcrel_mask = 0x80; 627 extern_mask = 0x10; 628 incode_mask = 0x08; 629 callj_mask = 0x02; 630 size_mask = 0x20; 631 length_shift = 5; 632 } 633 else 634 { 635 /* Little-endian bit field allocation order. */ 636 pcrel_mask = 0x01; 637 extern_mask = 0x08; 638 incode_mask = 0x10; 639 callj_mask = 0x40; 640 size_mask = 0x02; 641 length_shift = 1; 642 } 592 643 593 644 for (rptr = relocs, cache_ptr = reloc_cache, counter = 0; … … 597 648 unsigned char *raw = (unsigned char *)rptr; 598 649 unsigned int symnum; 599 cache_ptr->address = bfd_h_get_32 (abfd, raw + 0); 650 651 cache_ptr->address = H_GET_32 (abfd, raw + 0); 600 652 cache_ptr->howto = 0; 653 601 654 if (bfd_header_big_endian (abfd)) 602 {603 655 symnum = (raw[4] << 16) | (raw[5] << 8) | raw[6]; 604 }605 656 else 606 {607 657 symnum = (raw[6] << 16) | (raw[5] << 8) | raw[4]; 608 }609 658 610 659 if (raw[7] & extern_mask) 611 { 612 /* if this is set then the r_index is a index into the symbol table; 613 * if the bit is not set then r_index contains a section map. 614 * we either fill in the sym entry with a pointer to the symbol, 615 * or point to the correct section 616 */ 660 { 661 /* If this is set then the r_index is an index into the symbol table; 662 if the bit is not set then r_index contains a section map. 663 We either fill in the sym entry with a pointer to the symbol, 664 or point to the correct section. */ 617 665 cache_ptr->sym_ptr_ptr = symbols + symnum; 618 666 cache_ptr->addend = 0; 619 } else 620 { 621 /* in a.out symbols are relative to the beginning of the 622 * file rather than sections ? 623 * (look in translate_from_native_sym_flags) 624 * the reloc entry addend has added to it the offset into the 625 * file of the data, so subtract the base to make the reloc 626 * section relative */ 627 int s; 667 } 668 else 628 669 { 629 /* sign-extend symnum from 24 bits to whatever host uses */ 670 /* In a.out symbols are relative to the beginning of the 671 file rather than sections ? 672 (look in translate_from_native_sym_flags) 673 The reloc entry addend has added to it the offset into the 674 file of the data, so subtract the base to make the reloc 675 section relative. */ 676 int s; 677 678 /* Sign-extend symnum from 24 bits to whatever host uses. */ 630 679 s = symnum; 631 680 if (s & (1 << 23)) 632 681 s |= (~0) << 24; 682 683 cache_ptr->sym_ptr_ptr = (asymbol **)NULL; 684 switch (s) 685 { 686 case N_TEXT: 687 case N_TEXT | N_EXT: 688 cache_ptr->sym_ptr_ptr = obj_textsec (abfd)->symbol_ptr_ptr; 689 cache_ptr->addend = - obj_textsec (abfd)->vma; 690 break; 691 case N_DATA: 692 case N_DATA | N_EXT: 693 cache_ptr->sym_ptr_ptr = obj_datasec (abfd)->symbol_ptr_ptr; 694 cache_ptr->addend = - obj_datasec (abfd)->vma; 695 break; 696 case N_BSS: 697 case N_BSS | N_EXT: 698 cache_ptr->sym_ptr_ptr = obj_bsssec (abfd)->symbol_ptr_ptr; 699 cache_ptr->addend = - obj_bsssec (abfd)->vma; 700 break; 701 case N_ABS: 702 case N_ABS | N_EXT: 703 cache_ptr->sym_ptr_ptr = obj_bsssec (abfd)->symbol_ptr_ptr; 704 cache_ptr->addend = 0; 705 break; 706 case -2: /* .align */ 707 if (raw[7] & pcrel_mask) 708 { 709 cache_ptr->howto = &howto_align_table[(raw[7] >> length_shift) & 3]; 710 cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; 711 } 712 else 713 { 714 /* .org? */ 715 abort (); 716 } 717 cache_ptr->addend = 0; 718 break; 719 default: 720 BFD_ASSERT(0); 721 break; 722 } 633 723 } 634 cache_ptr->sym_ptr_ptr = (asymbol **)NULL; 635 switch (s) 636 { 637 case N_TEXT: 638 case N_TEXT | N_EXT: 639 cache_ptr->sym_ptr_ptr = obj_textsec(abfd)->symbol_ptr_ptr; 640 cache_ptr->addend = - obj_textsec(abfd)->vma; 641 break; 642 case N_DATA: 643 case N_DATA | N_EXT: 644 cache_ptr->sym_ptr_ptr = obj_datasec(abfd)->symbol_ptr_ptr; 645 cache_ptr->addend = - obj_datasec(abfd)->vma; 646 break; 647 case N_BSS: 648 case N_BSS | N_EXT: 649 cache_ptr->sym_ptr_ptr = obj_bsssec(abfd)->symbol_ptr_ptr; 650 cache_ptr->addend = - obj_bsssec(abfd)->vma; 651 break; 652 case N_ABS: 653 case N_ABS | N_EXT: 654 cache_ptr->sym_ptr_ptr = obj_bsssec(abfd)->symbol_ptr_ptr; 655 cache_ptr->addend = 0; 656 break; 657 case -2: /* .align */ 658 if (raw[7] & pcrel_mask) 659 { 660 cache_ptr->howto = &howto_align_table[(raw[7] >> length_shift) & 3]; 661 cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; 662 } 663 else 664 { 665 /* .org? */ 666 abort (); 667 } 668 cache_ptr->addend = 0; 669 break; 670 default: 671 BFD_ASSERT(0); 672 break; 673 } 674 675 } 676 677 /* the i960 only has a few relocation types: 724 725 /* The i960 only has a few relocation types: 678 726 abs 32-bit and pcrel 24bit. except for callj's! */ 679 727 if (cache_ptr->howto != 0) 680 728 ; 681 729 else if (raw[7] & callj_mask) 682 {683 684 }730 { 731 cache_ptr->howto = &howto_reloc_callj; 732 } 685 733 else if ( raw[7] & pcrel_mask) 686 {687 688 689 690 691 }734 { 735 if (raw[7] & size_mask) 736 cache_ptr->howto = &howto_reloc_pcrel13; 737 else 738 cache_ptr->howto = &howto_reloc_pcrel24; 739 } 692 740 else 693 {694 if (raw[7] & incode_mask)695 741 { 696 cache_ptr->howto = &howto_reloc_abs32code; 742 if (raw[7] & incode_mask) 743 cache_ptr->howto = &howto_reloc_abs32code; 744 else 745 cache_ptr->howto = &howto_reloc_abs32; 697 746 } 698 else 747 748 if (cache_ptr->address < prev_addr) 699 749 { 700 cache_ptr->howto = &howto_reloc_abs32; 750 /* Ouch! this reloc is out of order, insert into the right place. */ 751 arelent tmp; 752 arelent *cursor = cache_ptr-1; 753 bfd_vma stop = cache_ptr->address; 754 755 tmp = *cache_ptr; 756 while (cursor->address > stop && cursor >= reloc_cache) 757 { 758 cursor[1] = cursor[0]; 759 cursor--; 760 } 761 762 cursor[1] = tmp; 701 763 } 702 } 703 if (cache_ptr->address < prev_addr) 704 { 705 /* Ouch! this reloc is out of order, insert into the right place 706 */ 707 arelent tmp; 708 arelent *cursor = cache_ptr-1; 709 bfd_vma stop = cache_ptr->address; 710 tmp = *cache_ptr; 711 while (cursor->address > stop && cursor >= reloc_cache) 764 else 712 765 { 713 cursor[1] = cursor[0]; 714 cursor--; 766 prev_addr = cache_ptr->address; 715 767 } 716 cursor[1] = tmp;717 }718 else719 {720 prev_addr = cache_ptr->address;721 }722 768 } 723 769 … … 727 773 asect->reloc_count = count; 728 774 729 return true;730 } 731 732 static b oolean775 return TRUE; 776 } 777 778 static bfd_boolean 733 779 b_out_squirt_out_relocs (abfd, section) 734 780 bfd *abfd; … … 742 788 unsigned int count = section->reloc_count; 743 789 struct relocation_info *native, *natptr; 744 size_t natsize = count * sizeof (struct relocation_info); 745 int extern_mask, pcrel_mask, len_2, callj_mask; 746 if (count == 0) return true; 747 generic = section->orelocation; 790 bfd_size_type natsize; 791 int extern_mask, pcrel_mask, len_2, callj_mask; 792 793 if (count == 0) 794 return TRUE; 795 796 generic = section->orelocation; 797 natsize = (bfd_size_type) count * sizeof (struct relocation_info); 748 798 native = ((struct relocation_info *) bfd_malloc (natsize)); 749 799 if (!native && natsize != 0) 750 return false;800 return FALSE; 751 801 752 802 if (bfd_header_big_endian (abfd)) 753 {754 /* Big-endian bit field allocation order*/755 pcrel_mask = 0x80;756 extern_mask = 0x10;757 len_2 = 0x40;758 len_1 = 0x20;759 callj_mask = 0x02;760 incode_mask = 0x08;761 }803 { 804 /* Big-endian bit field allocation order. */ 805 pcrel_mask = 0x80; 806 extern_mask = 0x10; 807 len_2 = 0x40; 808 len_1 = 0x20; 809 callj_mask = 0x02; 810 incode_mask = 0x08; 811 } 762 812 else 763 {764 /* Little-endian bit field allocation order*/765 pcrel_mask = 0x01;766 extern_mask = 0x08;767 len_2 = 0x04;768 len_1 = 0x02;769 callj_mask = 0x40;770 incode_mask = 0x10;771 }813 { 814 /* Little-endian bit field allocation order. */ 815 pcrel_mask = 0x01; 816 extern_mask = 0x08; 817 len_2 = 0x04; 818 len_1 = 0x02; 819 callj_mask = 0x40; 820 incode_mask = 0x10; 821 } 772 822 773 823 for (natptr = native; count > 0; --count, ++natptr, ++generic) 774 { 775 arelent *g = *generic; 776 unsigned char *raw = (unsigned char *)natptr; 777 asymbol *sym = *(g->sym_ptr_ptr); 778 779 asection *output_section = sym->section->output_section; 780 781 bfd_h_put_32(abfd, g->address, raw); 782 /* Find a type in the output format which matches the input howto - 783 * at the moment we assume input format == output format FIXME!! 784 */ 785 r_idx = 0; 786 /* FIXME: Need callj stuff here, and to check the howto entries to 787 be sure they are real for this architecture. */ 788 if (g->howto== &howto_reloc_callj) 789 { 790 raw[7] = callj_mask + pcrel_mask + len_2; 791 } 792 else if (g->howto == &howto_reloc_pcrel24) 793 { 794 raw[7] = pcrel_mask + len_2; 795 } 796 else if (g->howto == &howto_reloc_pcrel13) 797 { 798 raw[7] = pcrel_mask + len_1; 799 } 800 else if (g->howto == &howto_reloc_abs32code) 801 { 802 raw[7] = len_2 + incode_mask; 803 } 804 else if (g->howto >= howto_align_table 805 && g->howto <= (howto_align_table 806 + sizeof (howto_align_table) / sizeof (howto_align_table[0]) 807 - 1)) 808 { 809 /* symnum == -2; extern_mask not set, pcrel_mask set */ 810 r_idx = -2; 811 r_extern = 0; 812 raw[7] = (pcrel_mask 813 | ((g->howto - howto_align_table) << 1)); 814 } 815 else { 816 raw[7] = len_2; 817 } 818 819 if (r_idx != 0) 820 /* already mucked with r_extern, r_idx */; 821 else if (bfd_is_com_section (output_section) 822 || bfd_is_abs_section (output_section) 823 || bfd_is_und_section (output_section)) 824 { 825 826 if (bfd_abs_section_ptr->symbol == sym) 827 { 828 /* Whoops, looked like an abs symbol, but is really an offset 829 from the abs section */ 830 r_idx = 0; 831 r_extern = 0; 832 } 824 { 825 arelent *g = *generic; 826 unsigned char *raw = (unsigned char *)natptr; 827 asymbol *sym = *(g->sym_ptr_ptr); 828 asection *output_section = sym->section->output_section; 829 830 H_PUT_32 (abfd, g->address, raw); 831 /* Find a type in the output format which matches the input howto - 832 at the moment we assume input format == output format FIXME!! */ 833 r_idx = 0; 834 /* FIXME: Need callj stuff here, and to check the howto entries to 835 be sure they are real for this architecture. */ 836 if (g->howto== &howto_reloc_callj) 837 raw[7] = callj_mask + pcrel_mask + len_2; 838 else if (g->howto == &howto_reloc_pcrel24) 839 raw[7] = pcrel_mask + len_2; 840 else if (g->howto == &howto_reloc_pcrel13) 841 raw[7] = pcrel_mask + len_1; 842 else if (g->howto == &howto_reloc_abs32code) 843 raw[7] = len_2 + incode_mask; 844 else if (g->howto >= howto_align_table 845 && g->howto <= (howto_align_table 846 + sizeof (howto_align_table) / sizeof (howto_align_table[0]) 847 - 1)) 848 { 849 /* symnum == -2; extern_mask not set, pcrel_mask set. */ 850 r_idx = -2; 851 r_extern = 0; 852 raw[7] = (pcrel_mask 853 | ((g->howto - howto_align_table) << 1)); 854 } 833 855 else 834 { 835 /* Fill in symbol */ 836 837 r_extern = 1; 838 r_idx = (*g->sym_ptr_ptr)->udata.i; 839 } 840 } 841 else 842 { 843 /* Just an ordinary section */ 844 r_extern = 0; 845 r_idx = output_section->target_index; 846 } 847 848 if (bfd_header_big_endian (abfd)) { 849 raw[4] = (unsigned char) (r_idx >> 16); 850 raw[5] = (unsigned char) (r_idx >> 8); 851 raw[6] = (unsigned char) (r_idx ); 852 } else { 853 raw[6] = (unsigned char) (r_idx >> 16); 854 raw[5] = (unsigned char) (r_idx>> 8); 855 raw[4] = (unsigned char) (r_idx ); 856 } 857 if (r_extern) 858 raw[7] |= extern_mask; 859 } 860 861 if (bfd_write ((PTR) native, 1, natsize, abfd) != natsize) { 862 free((PTR)native); 863 return false; 864 } 856 raw[7] = len_2; 857 858 if (r_idx != 0) 859 /* Already mucked with r_extern, r_idx. */; 860 else if (bfd_is_com_section (output_section) 861 || bfd_is_abs_section (output_section) 862 || bfd_is_und_section (output_section)) 863 { 864 if (bfd_abs_section_ptr->symbol == sym) 865 { 866 /* Whoops, looked like an abs symbol, but is really an offset 867 from the abs section. */ 868 r_idx = 0; 869 r_extern = 0; 870 } 871 else 872 { 873 /* Fill in symbol. */ 874 r_extern = 1; 875 r_idx = (*g->sym_ptr_ptr)->udata.i; 876 } 877 } 878 else 879 { 880 /* Just an ordinary section. */ 881 r_extern = 0; 882 r_idx = output_section->target_index; 883 } 884 885 if (bfd_header_big_endian (abfd)) 886 { 887 raw[4] = (unsigned char) (r_idx >> 16); 888 raw[5] = (unsigned char) (r_idx >> 8); 889 raw[6] = (unsigned char) (r_idx ); 890 } 891 else 892 { 893 raw[6] = (unsigned char) (r_idx >> 16); 894 raw[5] = (unsigned char) (r_idx>> 8); 895 raw[4] = (unsigned char) (r_idx ); 896 } 897 898 if (r_extern) 899 raw[7] |= extern_mask; 900 } 901 902 if (bfd_bwrite ((PTR) native, natsize, abfd) != natsize) 903 { 904 free ((PTR)native); 905 return FALSE; 906 } 907 865 908 free ((PTR)native); 866 909 867 return true; 868 } 869 870 /* This is stupid. This function should be a boolean predicate */ 910 return TRUE; 911 } 912 913 /* This is stupid. This function should be a boolean predicate. */ 914 871 915 static long 872 916 b_out_canonicalize_reloc (abfd, section, relptr, symbols) … … 882 926 { 883 927 arelent_chain *chain = section->constructor_chain; 928 884 929 for (count = 0; count < section->reloc_count; count++) 885 930 { … … 909 954 sec_ptr asect; 910 955 { 911 if (bfd_get_format (abfd) != bfd_object) { 912 bfd_set_error (bfd_error_invalid_operation); 913 return -1; 914 } 956 if (bfd_get_format (abfd) != bfd_object) 957 { 958 bfd_set_error (bfd_error_invalid_operation); 959 return -1; 960 } 915 961 916 962 if (asect->flags & SEC_CONSTRUCTOR) … … 935 981 936 982 937 static boolean 983 984 static bfd_boolean 938 985 b_out_set_section_contents (abfd, section, location, offset, count) 939 986 bfd *abfd; … … 943 990 bfd_size_type count; 944 991 { 945 946 if (abfd->output_has_begun == false) { /* set by bfd.c handler */ 947 if (! aout_32_make_sections (abfd)) 948 return false; 949 950 obj_textsec (abfd)->filepos = sizeof (struct internal_exec); 951 obj_datasec(abfd)->filepos = obj_textsec(abfd)->filepos 952 + obj_textsec (abfd)->_raw_size; 953 954 } 955 /* regardless, once we know what we're doing, we might as well get going */ 992 if (! abfd->output_has_begun) 993 { 994 /* Set by bfd.c handler. */ 995 if (! aout_32_make_sections (abfd)) 996 return FALSE; 997 998 obj_textsec (abfd)->filepos = sizeof (struct internal_exec); 999 obj_datasec(abfd)->filepos = obj_textsec(abfd)->filepos 1000 + obj_textsec (abfd)->_raw_size; 1001 } 1002 1003 /* Regardless, once we know what we're doing, we might as well get going. */ 956 1004 if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0) 957 return false;958 959 if (count != 0) {960 return (bfd_write ((PTR)location, 1, count, abfd) == count) ?true:false;961 } 962 return true;963 } 964 965 static b oolean1005 return FALSE; 1006 1007 if (count == 0) 1008 return TRUE; 1009 1010 return bfd_bwrite ((PTR) location, count, abfd) == count; 1011 } 1012 1013 static bfd_boolean 966 1014 b_out_set_arch_mach (abfd, arch, machine) 967 1015 bfd *abfd; … … 971 1019 bfd_default_set_arch_mach(abfd, arch, machine); 972 1020 973 if (arch == bfd_arch_unknown) /* Unknown machine arch is OK */ 974 return true; 975 if (arch == bfd_arch_i960) /* i960 default is OK */ 976 switch (machine) { 977 case bfd_mach_i960_core: 978 case bfd_mach_i960_kb_sb: 979 case bfd_mach_i960_mc: 980 case bfd_mach_i960_xa: 981 case bfd_mach_i960_ca: 982 case bfd_mach_i960_ka_sa: 983 case bfd_mach_i960_jx: 984 case bfd_mach_i960_hx: 985 case 0: 986 return true; 987 default: 988 return false; 989 } 990 991 return false; 1021 if (arch == bfd_arch_unknown) /* Unknown machine arch is OK. */ 1022 return TRUE; 1023 1024 if (arch == bfd_arch_i960) /* i960 default is OK. */ 1025 switch (machine) 1026 { 1027 case bfd_mach_i960_core: 1028 case bfd_mach_i960_kb_sb: 1029 case bfd_mach_i960_mc: 1030 case bfd_mach_i960_xa: 1031 case bfd_mach_i960_ca: 1032 case bfd_mach_i960_ka_sa: 1033 case bfd_mach_i960_jx: 1034 case bfd_mach_i960_hx: 1035 case 0: 1036 return TRUE; 1037 default: 1038 return FALSE; 1039 } 1040 1041 return FALSE; 992 1042 } 993 1043 … … 995 1045 b_out_sizeof_headers (ignore_abfd, ignore) 996 1046 bfd *ignore_abfd ATTRIBUTE_UNUSED; 997 b oolean ignore ATTRIBUTE_UNUSED;1047 bfd_boolean ignore ATTRIBUTE_UNUSED; 998 1048 { 999 1049 return sizeof (struct internal_exec); 1000 1050 } 1001 1051 1002 /************************************************************************/ 1052 1053 1003 1054 static bfd_vma 1004 1055 get_value (reloc, link_info, input_section) … … 1012 1063 /* A symbol holds a pointer to a section, and an offset from the 1013 1064 base of the section. To relocate, we find where the section will 1014 live in the output and add that in */ 1015 1065 live in the output and add that in. */ 1016 1066 if (bfd_is_und_section (symbol->section)) 1017 1067 { … … 1025 1075 h = bfd_wrapped_link_hash_lookup (input_section->owner, link_info, 1026 1076 bfd_asymbol_name (symbol), 1027 false, false, true);1077 FALSE, FALSE, TRUE); 1028 1078 if (h != (struct bfd_link_hash_entry *) NULL 1029 1079 && (h->type == bfd_link_hash_defined … … 1038 1088 (link_info, bfd_asymbol_name (symbol), 1039 1089 input_section->owner, input_section, reloc->address, 1040 true)))1090 TRUE))) 1041 1091 abort (); 1042 1092 value = 0; … … 1048 1098 } 1049 1099 1050 /* Add the value contained in the relocation */1100 /* Add the value contained in the relocation. */ 1051 1101 value += reloc->addend; 1052 1102 … … 1067 1117 1068 1118 /* Find all symbols past this point, and make them know 1069 what's happened */1119 what's happened. */ 1070 1120 while (*s) 1071 { 1072 asymbol *p = *s; 1073 if (p->section == input_section) 1074 { 1075 /* This was pointing into this section, so mangle it */ 1076 if (p->value > value) 1077 { 1078 p->value -=slip; 1079 if (p->udata.p != NULL) 1080 { 1081 struct generic_link_hash_entry *h; 1082 1083 h = (struct generic_link_hash_entry *) p->udata.p; 1084 BFD_ASSERT (h->root.type == bfd_link_hash_defined); 1085 h->root.u.def.value -= slip; 1086 BFD_ASSERT (h->root.u.def.value == p->value); 1087 } 1088 } 1089 } 1090 s++; 1091 1092 } 1121 { 1122 asymbol *p = *s; 1123 1124 if (p->section == input_section) 1125 { 1126 /* This was pointing into this section, so mangle it. */ 1127 if (p->value > value) 1128 { 1129 p->value -=slip; 1130 1131 if (p->udata.p != NULL) 1132 { 1133 struct generic_link_hash_entry *h; 1134 1135 h = (struct generic_link_hash_entry *) p->udata.p; 1136 BFD_ASSERT (h->root.type == bfd_link_hash_defined); 1137 h->root.u.def.value -= slip; 1138 BFD_ASSERT (h->root.u.def.value == p->value); 1139 } 1140 } 1141 } 1142 s++; 1143 } 1093 1144 } 1094 1145 1095 1146 /* This routine works out if the thing we want to get to can be 1096 1147 reached with a 24bit offset instead of a 32 bit one. 1097 If it can, then it changes the amode */1148 If it can, then it changes the amode. */ 1098 1149 1099 1150 static int … … 1111 1162 /* See if the address we're looking at within 2^23 bytes of where 1112 1163 we are, if so then we can use a small branch rather than the 1113 jump we were going to */ 1114 1164 jump we were going to. */ 1115 1165 gap = value - (dot - shrink); 1116 1166 1117 if (-1 <<23 < (long)gap && (long)gap < 1<<23)1118 {1119 /* Change the reloc type from 32bitcode possible 24, to 24bit1120 possible 32*/1121 1122 r->howto = &howto_reloc_abs32codeshrunk;1123 /* The place to relc moves back by four bytes */1124 r->address -=4; 1125 1126 /* This will be four bytes smaller in the long run */1127 shrink += 4;1128 perform_slip (abfd, 4, input_section, r->address-shrink + 4);1129 } 1167 if (-1 << 23 < (long)gap && (long)gap < 1 << 23) 1168 { 1169 /* Change the reloc type from 32bitcode possible 24, to 24bit 1170 possible 32. */ 1171 r->howto = &howto_reloc_abs32codeshrunk; 1172 /* The place to relc moves back by four bytes. */ 1173 r->address -=4; 1174 1175 /* This will be four bytes smaller in the long run. */ 1176 shrink += 4 ; 1177 perform_slip (abfd, 4, input_section, r->address-shrink + 4); 1178 } 1179 1130 1180 return shrink; 1131 1181 } … … 1142 1192 bfd_vma old_end; 1143 1193 bfd_vma new_end; 1144 int shrink_delta;1194 unsigned int shrink_delta; 1145 1195 int size = r->howto->size; 1146 1196 … … 1149 1199 than the alignment required. */ 1150 1200 1151 /* calculate the first byte following the padding before we optimize*/1201 /* Calculate the first byte following the padding before we optimize. */ 1152 1202 old_end = ((dot + size ) & ~size) + size+1; 1153 /* work out where the new end will be - remember that we're smaller1154 than we used to be */1203 /* Work out where the new end will be - remember that we're smaller 1204 than we used to be. */ 1155 1205 new_end = ((dot - shrink + size) & ~size); 1156 1206 1157 /* This is the new end */1207 /* This is the new end. */ 1158 1208 gap = old_end - ((dot + size) & ~size); 1159 1209 … … 1161 1211 1162 1212 if (shrink_delta) 1163 { 1164 /* Change the reloc so that it knows how far to align to */ 1165 r->howto = howto_done_align_table + (r->howto - howto_align_table); 1166 1167 /* Encode the stuff into the addend - for future use we need to 1168 know how big the reloc used to be */ 1169 r->addend = old_end - dot + r->address; 1170 1171 /* This will be N bytes smaller in the long run, adjust all the symbols */ 1172 perform_slip (abfd, shrink_delta, input_section, r->address - shrink); 1173 shrink += shrink_delta; 1174 } 1213 { 1214 /* Change the reloc so that it knows how far to align to. */ 1215 r->howto = howto_done_align_table + (r->howto - howto_align_table); 1216 1217 /* Encode the stuff into the addend - for future use we need to 1218 know how big the reloc used to be. */ 1219 r->addend = old_end - dot + r->address; 1220 1221 /* This will be N bytes smaller in the long run, adjust all the symbols. */ 1222 perform_slip (abfd, shrink_delta, input_section, r->address - shrink); 1223 shrink += shrink_delta; 1224 } 1225 1175 1226 return shrink; 1176 1227 } 1177 1228 1178 static b oolean1229 static bfd_boolean 1179 1230 b_out_bfd_relax_section (abfd, i, link_info, again) 1180 1231 bfd *abfd; 1181 1232 asection *i; 1182 1233 struct bfd_link_info *link_info; 1183 b oolean *again;1184 { 1185 /* Get enough memory to hold the stuff */1234 bfd_boolean *again; 1235 { 1236 /* Get enough memory to hold the stuff. */ 1186 1237 bfd *input_bfd = i->owner; 1187 1238 asection *input_section = i; 1188 int shrink = 0 ;1239 unsigned int shrink = 0 ; 1189 1240 arelent **reloc_vector = NULL; 1190 long reloc_size = bfd_get_reloc_upper_bound (input_bfd,1191 input_section);1241 long reloc_size = bfd_get_reloc_upper_bound (input_bfd, 1242 input_section); 1192 1243 1193 1244 if (reloc_size < 0) 1194 return false;1245 return FALSE; 1195 1246 1196 1247 /* We only run this relaxation once. It might work to run it 1197 1248 multiple times, but it hasn't been tested. */ 1198 *again = false;1249 *again = FALSE; 1199 1250 1200 1251 if (reloc_size) … … 1202 1253 long reloc_count; 1203 1254 1204 reloc_vector = (arelent **) bfd_malloc ( reloc_size);1255 reloc_vector = (arelent **) bfd_malloc ((bfd_size_type) reloc_size); 1205 1256 if (reloc_vector == NULL && reloc_size != 0) 1206 1257 goto error_return; 1207 1258 1208 /* Get the relocs and think about them */1259 /* Get the relocs and think about them. */ 1209 1260 reloc_count = 1210 1261 bfd_canonicalize_reloc (input_bfd, input_section, reloc_vector, … … 1215 1266 { 1216 1267 arelent **parent; 1268 1217 1269 for (parent = reloc_vector; *parent; parent++) 1218 1270 { 1219 1271 arelent *r = *parent; 1272 1220 1273 switch (r->howto->type) 1221 1274 { 1222 1275 case ALIGNER: 1223 /* An alignment reloc */1276 /* An alignment reloc. */ 1224 1277 shrink = aligncode (abfd, input_section, r, shrink); 1225 1278 break; 1226 1279 case ABS32CODE: 1227 /* A 32bit reloc in an addressing mode */1280 /* A 32bit reloc in an addressing mode. */ 1228 1281 shrink = abs32code (input_bfd, input_section, r, shrink, 1229 1282 link_info); 1230 1283 break; 1231 1284 case ABS32CODE_SHRUNK: 1232 shrink +=4;1285 shrink += 4; 1233 1286 break; 1234 1287 } … … 1240 1293 if (reloc_vector != NULL) 1241 1294 free (reloc_vector); 1242 return true;1295 return TRUE; 1243 1296 error_return: 1244 1297 if (reloc_vector != NULL) 1245 1298 free (reloc_vector); 1246 return false;1299 return FALSE; 1247 1300 } 1248 1301 … … 1254 1307 struct bfd_link_order *link_order; 1255 1308 bfd_byte *data; 1256 b oolean relocateable;1309 bfd_boolean relocateable; 1257 1310 asymbol **symbols; 1258 1311 { 1259 /* Get enough memory to hold the stuff */1312 /* Get enough memory to hold the stuff. */ 1260 1313 bfd *input_bfd = link_order->u.indirect.section->owner; 1261 1314 asection *input_section = link_order->u.indirect.section; … … 1275 1328 symbols); 1276 1329 1277 reloc_vector = (arelent **) bfd_malloc ( reloc_size);1330 reloc_vector = (arelent **) bfd_malloc ((bfd_size_type) reloc_size); 1278 1331 if (reloc_vector == NULL && reloc_size != 0) 1279 1332 goto error_return; … … 1281 1334 input_section->reloc_done = 1; 1282 1335 1283 /* read in the section*/1284 BFD_ASSERT ( true ==bfd_get_section_contents (input_bfd,1285 1286 1287 1288 1336 /* Read in the section. */ 1337 BFD_ASSERT (bfd_get_section_contents (input_bfd, 1338 input_section, 1339 data, 1340 (bfd_vma) 0, 1341 input_section->_raw_size)); 1289 1342 1290 1343 reloc_count = bfd_canonicalize_reloc (input_bfd, … … 1298 1351 arelent **parent = reloc_vector; 1299 1352 arelent *reloc ; 1300 1301 1353 unsigned int dst_address = 0; 1302 1354 unsigned int src_address = 0; … … 1304 1356 unsigned int idx; 1305 1357 1306 /* Find how long a run we can do */1358 /* Find how long a run we can do. */ 1307 1359 while (dst_address < link_order->size) 1308 1360 { … … 1312 1364 /* Note that the relaxing didn't tie up the addresses in the 1313 1365 relocation, so we use the original address to work out the 1314 run of non-relocated data */1366 run of non-relocated data. */ 1315 1367 BFD_ASSERT (reloc->address >= src_address); 1316 1368 run = reloc->address - src_address; … … 1321 1373 run = link_order->size - dst_address; 1322 1374 } 1323 /* Copy the bytes */ 1375 1376 /* Copy the bytes. */ 1324 1377 for (idx = 0; idx < run; idx++) 1325 { 1326 data[dst_address++] = data[src_address++]; 1327 } 1328 1329 /* Now do the relocation */ 1330 1378 data[dst_address++] = data[src_address++]; 1379 1380 /* Now do the relocation. */ 1331 1381 if (reloc) 1332 1382 { … … 1337 1387 src_address + data, dst_address + data, 1338 1388 input_section); 1339 src_address +=4;1340 dst_address +=4;1389 src_address += 4; 1390 dst_address += 4; 1341 1391 break; 1342 1392 case ABS32: … … 1345 1395 + get_value (reloc, link_info, input_section)), 1346 1396 data + dst_address); 1347 src_address +=4;1348 dst_address +=4;1397 src_address += 4; 1398 dst_address += 4; 1349 1399 break; 1350 1400 case CALLJ: 1351 1401 callj_callback (input_bfd, link_info, reloc, data, 1352 1402 src_address, dst_address, input_section, 1353 false);1354 src_address +=4;1355 dst_address +=4;1403 FALSE); 1404 src_address += 4; 1405 dst_address += 4; 1356 1406 break; 1357 1407 case ALIGNDONE: 1358 1408 BFD_ASSERT (reloc->addend >= src_address); 1359 BFD_ASSERT (reloc->addend <= input_section->_raw_size); 1409 BFD_ASSERT ((bfd_vma) reloc->addend 1410 <= input_section->_raw_size); 1360 1411 src_address = reloc->addend; 1361 1412 dst_address = ((dst_address + reloc->howto->size) … … 1367 1418 callj_callback (input_bfd, link_info, reloc, data, 1368 1419 src_address + 4, dst_address, input_section, 1369 true);1370 dst_address +=4;1371 src_address +=8;1420 TRUE); 1421 dst_address += 4; 1422 src_address += 8; 1372 1423 break; 1373 1424 case PCREL24: … … 1385 1436 & BAL_MASK)); 1386 1437 1387 bfd_put_32 (input_bfd, word, data + dst_address);1388 dst_address +=4;1389 src_address +=4;1438 bfd_put_32 (input_bfd, (bfd_vma) word, data + dst_address); 1439 dst_address += 4; 1440 src_address += 4; 1390 1441 1391 1442 } 1392 1443 break; 1393 1394 1444 case PCREL13: 1395 1445 { … … 1406 1456 & PCREL13_MASK)); 1407 1457 1408 bfd_put_32 (input_bfd, word, data + dst_address); 1409 dst_address+=4; 1410 src_address+=4; 1411 1458 bfd_put_32 (input_bfd, (bfd_vma) word, data + dst_address); 1459 dst_address += 4; 1460 src_address += 4; 1412 1461 } 1413 1462 break; … … 1427 1476 return NULL; 1428 1477 } 1429 /***********************************************************************/ 1478 1479 1430 1480 1431 1481 /* Build the transfer vectors for Big and Little-Endian B.OUT files. */ … … 1435 1485 1436 1486 #define b_out_bfd_link_hash_table_create _bfd_generic_link_hash_table_create 1487 #define b_out_bfd_link_hash_table_free _bfd_generic_link_hash_table_free 1437 1488 #define b_out_bfd_link_add_symbols _bfd_generic_link_add_symbols 1489 #define b_out_bfd_link_just_syms _bfd_generic_link_just_syms 1438 1490 #define b_out_bfd_final_link _bfd_generic_final_link 1439 1491 #define b_out_bfd_link_split_section _bfd_generic_link_split_section 1440 1492 #define b_out_bfd_gc_sections bfd_generic_gc_sections 1493 #define b_out_bfd_merge_sections bfd_generic_merge_sections 1494 #define b_out_bfd_discard_group bfd_generic_discard_group 1441 1495 1442 1496 #define aout_32_get_section_contents_in_window \ -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.