1 /* evax-etir.c -- BFD back-end for ALPHA EVAX (openVMS/AXP) files.
2 Copyright 1996 Free Software Foundation, Inc.
3 ETIR record handling functions
5 go and read the openVMS linker manual (esp. appendix B)
6 if you don't know what's going on here :-)
9 of proGIS Softwareentwicklung, Aachen, Germany
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 /* The following type abbreviations are used:
28 cs counted string (ascii string with length byte)
30 sh short (2 byte, 16 bit)
31 lw longword (4 byte, 32 bit)
32 qw quadword (8 byte, 64 bit)
46 static void location_save
47 PARAMS ((bfd *abfd, unsigned long index, unsigned long loc, int section));
48 static unsigned long location_restore
49 PARAMS ((bfd *abfd, unsigned long index, int *section));
52 static void image_set_ptr PARAMS ((bfd *abfd, int psect, uquad offset));
53 static void image_inc_ptr PARAMS ((bfd *abfd, uquad offset));
54 static void image_dump PARAMS ((bfd *abfd, unsigned char *ptr, int size, int offset));
55 static void image_write_b PARAMS ((bfd *abfd, unsigned int value));
56 static void image_write_w PARAMS ((bfd *abfd, unsigned int value));
57 static void image_write_l PARAMS ((bfd *abfd, unsigned long value));
58 static void image_write_q PARAMS ((bfd *abfd, uquad value));
60 /*-----------------------------------------------------------------------------*/
64 /* Save location counter at index */
67 location_save (abfd, index, loc, section)
73 PRIV(location_stack)[index].value = loc;
74 PRIV(location_stack)[index].psect = section;
79 /* Restore location counter from index */
82 location_restore (abfd, index, section)
88 *section = PRIV(location_stack)[index].psect;
89 return PRIV(location_stack)[index].value;
94 /* routines to fill sections contents during etir read */
96 /* Initialize image buffer pointer to be filled */
99 image_set_ptr (abfd, psect, offset)
105 evax_debug (4, "image_set_ptr(%d=%s, %d)\n",
106 psect, PRIV(sections)[psect]->name, offset);
109 PRIV(image_ptr) = PRIV(sections)[psect]->contents + offset;
114 /* Increment image buffer pointer by offset */
117 image_inc_ptr (abfd, offset)
122 evax_debug (4, "image_inc_ptr(%d)\n", offset);
125 PRIV(image_ptr) += offset;
131 /* Dump multiple bytes to section image */
134 image_dump (abfd, ptr, size, offset)
141 evax_debug (6, "image_dump from (%p, %d) to (%p)\n", ptr, size, PRIV(image_ptr));
142 _bfd_hexdump (7, ptr, size, offset);
146 *PRIV(image_ptr)++ = *ptr++;
151 /* Write byte to section image */
154 image_write_b (abfd, value)
159 evax_debug (6, "image_write_b(%02x)\n", (int)value);
162 *PRIV(image_ptr)++ = (value & 0xff);
167 /* Write 2-byte word to image */
170 image_write_w (abfd, value)
175 evax_debug (6, "image_write_w(%04x)\n", (int)value);
178 bfd_putl16 (value, PRIV(image_ptr));
179 PRIV(image_ptr) += 2;
185 /* Write 4-byte long to image */
188 image_write_l (abfd, value)
193 evax_debug (6, "image_write_l(%08lx)\n", value);
196 bfd_putl32 (value, PRIV(image_ptr));
197 PRIV(image_ptr) += 4;
203 /* Write 4-byte long to image */
206 image_write_q (abfd, value)
211 evax_debug (6, "image_write_q(%016lx)\n", value);
214 bfd_putl64 (value, PRIV(image_ptr));
215 PRIV(image_ptr) += 8;
221 #define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L)
227 handle sta_xxx commands in etir section
228 ptr points to data area in record
230 see table B-8 of the openVMS linker manual */
233 etir_sta (abfd, cmd, ptr)
246 stack 32 bit value of symbol (high bits set to 0) */
248 case ETIR_S_C_STA_GBL:
251 evax_symbol_entry *entry;
253 name = _bfd_evax_save_counted_string ((char *)ptr);
254 entry = (evax_symbol_entry *)
255 bfd_hash_lookup (PRIV(evax_symbol_table), name, false, false);
256 if (entry == (evax_symbol_entry *)NULL)
259 evax_debug (3, "ETIR_S_C_STA_GBL: no symbol \"%s\"\n", name);
265 _bfd_evax_push (abfd, (uquad)(entry->symbol->value), -1);
273 stack 32 bit value, sign extend to 64 bit */
275 case ETIR_S_C_STA_LW:
276 _bfd_evax_push (abfd, (uquad)bfd_getl32 (ptr), -1);
282 stack 64 bit value of symbol */
284 case ETIR_S_C_STA_QW:
285 _bfd_evax_push (abfd, (uquad)bfd_getl64(ptr), -1);
288 /* stack psect base plus quadword offset
289 arg: lw section index
290 qw signed quadword offset (low 32 bits)
292 stack qw argument and section index
293 (see ETIR_S_C_STO_OFF, ETIR_S_C_CTL_SETRB) */
295 case ETIR_S_C_STA_PQ:
300 psect = bfd_getl32 (ptr);
301 if (psect >= PRIV(egsd_sec_count))
303 (*_bfd_error_handler) ("Bad section index in ETIR_S_C_STA_PQ");
304 bfd_set_error (bfd_error_bad_value);
307 dummy = bfd_getl64 (ptr+4);
308 _bfd_evax_push (abfd, dummy, psect);
312 /* all not supported */
314 case ETIR_S_C_STA_LI:
315 case ETIR_S_C_STA_MOD:
316 case ETIR_S_C_STA_CKARG:
318 (*_bfd_error_handler) ("Unsupported STA cmd %d", cmd);
323 (*_bfd_error_handler) ("Reserved STA cmd %d", cmd);
336 handle sto_xxx commands in etir section
337 ptr points to data area in record
339 see table B-9 of the openVMS linker manual */
342 etir_sto (abfd, cmd, ptr)
353 /* store byte: pop stack, write byte
357 dummy = _bfd_evax_pop (abfd, &psect);
359 if (is_share) /* FIXME */
360 (*_bfd_error_handler) ("ETIR_S_C_STO_B: byte fixups not supported");
362 image_write_b (abfd, dummy & 0xff); /* FIXME: check top bits */
365 /* store word: pop stack, write word
369 dummy = _bfd_evax_pop (abfd, &psect);
371 if (is_share) /* FIXME */
372 (*_bfd_error_handler) ("ETIR_S_C_STO_B: word fixups not supported");
374 image_write_w (abfd, dummy & 0xffff); /* FIXME: check top bits */
377 /* store longword: pop stack, write longword
380 case ETIR_S_C_STO_LW:
381 dummy = _bfd_evax_pop (abfd, &psect);
382 dummy += (PRIV(sections)[psect])->vma;
383 image_write_l (abfd, dummy & 0xffffffff);/* FIXME: check top bits */
386 evax_debug (3, "ETIR_S_C_STO_LW: Relocation !\n");
388 evax_debug (3, "ETIR_S_C_STO_LW: Fix-up share !\n");
392 /* store quadword: pop stack, write quadword
395 case ETIR_S_C_STO_QW:
396 dummy = _bfd_evax_pop (abfd, &psect);
397 dummy += (PRIV(sections)[psect])->vma;
398 image_write_q(abfd, dummy); /* FIXME: check top bits */
401 evax_debug (3, "ETIR_S_C_STO_LW: Relocation !\n");
403 evax_debug (3, "ETIR_S_C_STO_LW: Fix-up share !\n");
407 /* store immediate repeated: pop stack for repeat count
411 case ETIR_S_C_STO_IMMR:
415 size = bfd_getl32 (ptr);
416 dummy = (unsigned long)_bfd_evax_pop (abfd, NULL);
418 image_dump (abfd, ptr+4, size, 0);
422 /* store global: write symbol value
423 arg: cs global symbol name */
425 case ETIR_S_C_STO_GBL:
427 evax_symbol_entry *entry;
430 name = _bfd_evax_save_counted_string ((char *)ptr);
431 entry = (evax_symbol_entry *)bfd_hash_lookup (PRIV(evax_symbol_table), name, false, false);
432 if (entry == (evax_symbol_entry *)NULL)
434 (*_bfd_error_handler) ("ETIR_S_C_STO_GBL: no symbol \"%s\"",
439 image_write_q (abfd, (uquad)(entry->symbol->value)); /* FIXME, reloc */
443 /* store code address: write address of entry point
444 arg: cs global symbol name (procedure) */
446 case ETIR_S_C_STO_CA:
448 evax_symbol_entry *entry;
451 name = _bfd_evax_save_counted_string ((char *)ptr);
452 entry = (evax_symbol_entry *) bfd_hash_lookup (PRIV(evax_symbol_table), name, false, false);
453 if (entry == (evax_symbol_entry *)NULL)
455 (*_bfd_error_handler) ("ETIR_S_C_STO_CA: no symbol \"%s\"",
460 image_write_q (abfd, (uquad)(entry->symbol->value)); /* FIXME, reloc */
466 case ETIR_S_C_STO_RB:
467 case ETIR_S_C_STO_AB:
468 (*_bfd_error_handler) ("ETIR_S_C_STO_RB/AB: Not supported");
471 /* store offset to psect: pop stack, add low 32 bits to base of psect
474 case ETIR_S_C_STO_OFF:
479 q = _bfd_evax_pop (abfd, &psect);
480 q += (PRIV(sections)[psect])->vma;
481 image_write_q (abfd, q);
486 arg: lw count of bytes
489 case ETIR_S_C_STO_IMM:
493 size = bfd_getl32 (ptr);
494 image_dump (abfd, ptr+4, size, 0);
498 /* this code is 'reserved to digital' according to the openVMS linker manual,
499 however it is generated by the DEC C compiler and defined in the include file.
500 FIXME, since the following is just a guess
501 store global longword: store 32bit value of symbol
502 arg: cs symbol name */
504 case ETIR_S_C_STO_GBL_LW:
506 evax_symbol_entry *entry;
509 name = _bfd_evax_save_counted_string ((char *)ptr);
510 entry = (evax_symbol_entry *)bfd_hash_lookup (PRIV(evax_symbol_table), name, false, false);
511 if (entry == (evax_symbol_entry *)NULL)
514 evax_debug (3, "ETIR_S_C_STO_GBL_LW: no symbol \"%s\"\n", name);
519 image_write_l (abfd, (unsigned long)(entry->symbol->value)); /* FIXME, reloc */
525 case ETIR_S_C_STO_LP_PSB:
526 (*_bfd_error_handler) ("ETIR_S_C_STO_LP_PSB: Not supported");
531 case ETIR_S_C_STO_HINT_GBL:
532 (*_bfd_error_handler) ("ETIR_S_C_STO_HINT_GBL: not implemented");
537 case ETIR_S_C_STO_HINT_PS:
538 (*_bfd_error_handler) ("ETIR_S_C_STO_HINT_PS: not implemented");
542 (*_bfd_error_handler) ("Reserved STO cmd %d", cmd);
549 /* stack operator commands
550 all 32 bit signed arithmetic
551 all word just like a stack calculator
552 arguments are popped from stack, results are pushed on stack
554 see table B-10 of the openVMS linker manual */
557 etir_opr (abfd, cmd, ptr)
570 case ETIR_S_C_OPR_NOP:
575 case ETIR_S_C_OPR_ADD:
576 op1 = (long)_bfd_evax_pop (abfd, NULL);
577 op2 = (long)_bfd_evax_pop (abfd, NULL);
578 _bfd_evax_push (abfd, (uquad)(op1 + op2), -1);
583 case ETIR_S_C_OPR_SUB:
584 op1 = (long)_bfd_evax_pop (abfd, NULL);
585 op2 = (long)_bfd_evax_pop (abfd, NULL);
586 _bfd_evax_push (abfd, (uquad)(op2 - op1), -1);
591 case ETIR_S_C_OPR_MUL:
592 op1 = (long)_bfd_evax_pop (abfd, NULL);
593 op2 = (long)_bfd_evax_pop (abfd, NULL);
594 _bfd_evax_push (abfd, (uquad)(op1 * op2), -1);
599 case ETIR_S_C_OPR_DIV:
600 op1 = (long)_bfd_evax_pop (abfd, NULL);
601 op2 = (long)_bfd_evax_pop (abfd, NULL);
603 _bfd_evax_push (abfd, (uquad)0L, -1);
605 _bfd_evax_push (abfd, (uquad)(op2 / op1), -1);
610 case ETIR_S_C_OPR_AND:
611 op1 = (long)_bfd_evax_pop (abfd, NULL);
612 op2 = (long)_bfd_evax_pop (abfd, NULL);
613 _bfd_evax_push (abfd, (uquad)(op1 & op2), -1);
616 /* logical inclusive or */
618 case ETIR_S_C_OPR_IOR:
619 op1 = (long)_bfd_evax_pop (abfd, NULL);
620 op2 = (long)_bfd_evax_pop (abfd, NULL);
621 _bfd_evax_push (abfd, (uquad)(op1 | op2), -1);
624 /* logical exclusive or */
626 case ETIR_S_C_OPR_EOR:
627 op1 = (long)_bfd_evax_pop (abfd, NULL);
628 op2 = (long)_bfd_evax_pop (abfd, NULL);
629 _bfd_evax_push (abfd, (uquad)(op1 ^ op2), -1);
634 case ETIR_S_C_OPR_NEG:
635 op1 = (long)_bfd_evax_pop (abfd, NULL);
636 _bfd_evax_push (abfd, (uquad)(-op1), -1);
641 case ETIR_S_C_OPR_COM:
642 op1 = (long)_bfd_evax_pop (abfd, NULL);
643 _bfd_evax_push (abfd, (uquad)(op1 ^ -1L), -1);
648 case ETIR_S_C_OPR_INSV:
649 (void)_bfd_evax_pop (abfd, NULL);
650 (*_bfd_error_handler) ("ETIR_S_C_OPR_INSV: Not supported");
653 /* arithmetic shift */
655 case ETIR_S_C_OPR_ASH:
656 op1 = (long)_bfd_evax_pop (abfd, NULL);
657 op2 = (long)_bfd_evax_pop (abfd, NULL);
658 if (op2 < 0) /* shift right */
660 else /* shift left */
662 _bfd_evax_push (abfd, (uquad)op1, -1);
667 case ETIR_S_C_OPR_USH:
668 (*_bfd_error_handler) ("ETIR_S_C_OPR_USH: Not supported");
673 case ETIR_S_C_OPR_ROT:
674 (*_bfd_error_handler) ("ETIR_S_C_OPR_ROT: Not supported");
679 case ETIR_S_C_OPR_SEL:
680 if ((long)_bfd_evax_pop (abfd, NULL) & 0x01L)
681 (void)_bfd_evax_pop (abfd, NULL);
684 op1 = (long)_bfd_evax_pop (abfd, NULL);
685 (void)_bfd_evax_pop (abfd, NULL);
686 _bfd_evax_push (abfd, (uquad)op1, -1);
690 /* redefine symbol to current location */
692 case ETIR_S_C_OPR_REDEF:
693 (*_bfd_error_handler) ("ETIR_S_C_OPR_REDEF: Not supported");
696 /* define a literal */
698 case ETIR_S_C_OPR_DFLIT:
699 (*_bfd_error_handler) ("ETIR_S_C_OPR_DFLIT: Not supported");
703 (*_bfd_error_handler) ("Reserved OPR cmd %d", cmd);
713 see table B-11 of the openVMS linker manual */
716 etir_ctl (abfd, cmd, ptr)
726 /* set relocation base: pop stack, set image location counter
729 case ETIR_S_C_CTL_SETRB:
730 dummy = _bfd_evax_pop (abfd, &psect);
731 image_set_ptr (abfd, psect, dummy);
734 /* augment relocation base: increment image location counter by offset
735 arg: lw offset value */
737 case ETIR_S_C_CTL_AUGRB:
738 dummy = bfd_getl32 (ptr);
739 image_inc_ptr (abfd, dummy);
742 /* define location: pop index, save location counter under index
745 case ETIR_S_C_CTL_DFLOC:
746 dummy = _bfd_evax_pop (abfd, NULL);
750 /* set location: pop index, restore location counter from index
753 case ETIR_S_C_CTL_STLOC:
754 dummy = _bfd_evax_pop (abfd, &psect);
758 /* stack defined location: pop index, push location counter from index
761 case ETIR_S_C_CTL_STKDL:
762 dummy = _bfd_evax_pop (abfd, &psect);
767 (*_bfd_error_handler) ("Reserved CTL cmd %d", cmd);
774 /* store conditional commands
776 see table B-12 and B-13 of the openVMS linker manual */
779 etir_stc (abfd, cmd, ptr)
787 /* 200 Store-conditional Linkage Pair
790 case ETIR_S_C_STC_LP:
791 (*_bfd_error_handler) ("ETIR_S_C_STC_LP: not supported");
794 /* 201 Store-conditional Linkage Pair with Procedure Signature
795 arg: lw linkage index
800 case ETIR_S_C_STC_LP_PSB:
801 image_inc_ptr (abfd, 16); /* skip entry,procval */
804 /* 202 Store-conditional Address at global address
805 arg: lw linkage index
808 case ETIR_S_C_STC_GBL:
809 (*_bfd_error_handler) ("ETIR_S_C_STC_GBL: not supported");
812 /* 203 Store-conditional Code Address at global address
813 arg: lw linkage index
816 case ETIR_S_C_STC_GCA:
817 (*_bfd_error_handler) ("ETIR_S_C_STC_GCA: not supported");
820 /* 204 Store-conditional Address at psect + offset
821 arg: lw linkage index
825 case ETIR_S_C_STC_PS:
826 (*_bfd_error_handler) ("ETIR_S_C_STC_PS: not supported");
829 /* 205 Store-conditional NOP at address of global
832 case ETIR_S_C_STC_NOP_GBL:
834 /* 206 Store-conditional NOP at pect + offset
837 case ETIR_S_C_STC_NOP_PS:
839 /* 207 Store-conditional BSR at global address
842 case ETIR_S_C_STC_BSR_GBL:
844 /* 208 Store-conditional BSR at pect + offset
847 case ETIR_S_C_STC_BSR_PS:
849 /* 209 Store-conditional LDA at global address
852 case ETIR_S_C_STC_LDA_GBL:
854 /* 210 Store-conditional LDA at psect + offset
857 case ETIR_S_C_STC_LDA_PS:
859 /* 211 Store-conditional BSR or Hint at global address
862 case ETIR_S_C_STC_BOH_GBL:
864 /* 212 Store-conditional BSR or Hint at pect + offset
867 case ETIR_S_C_STC_BOH_PS:
869 /* 213 Store-conditional NOP,BSR or HINT at global address
872 case ETIR_S_C_STC_NBH_GBL:
874 /* 214 Store-conditional NOP,BSR or HINT at psect + offset
877 case ETIR_S_C_STC_NBH_PS:
878 /* FIXME (*_bfd_error_handler) ("ETIR_S_C_STC_xx: (%d) not supported", cmd); */
883 evax_debug (3, "Reserved STC cmd %d", cmd);
891 /* handle command from ETIR section */
894 tir_cmd (abfd, cmd, ptr)
902 boolean (*explain) PARAMS((bfd *, int, unsigned char *));
904 { ETIR_S_C_MINSTACOD, ETIR_S_C_MAXSTACOD, etir_sta },
905 { ETIR_S_C_MINSTOCOD, ETIR_S_C_MAXSTOCOD, etir_sto },
906 { ETIR_S_C_MINOPRCOD, ETIR_S_C_MAXOPRCOD, etir_opr },
907 { ETIR_S_C_MINCTLCOD, ETIR_S_C_MAXCTLCOD, etir_ctl },
908 { ETIR_S_C_MINSTCCOD, ETIR_S_C_MAXSTCCOD, etir_stc },
915 while (tir_table[i].mincod >= 0)
917 if ( (tir_table[i].mincod <= cmd)
918 && (cmd <= tir_table[i].maxcod))
920 res = tir_table[i].explain (abfd, cmd, ptr);
930 /* Text Information and Relocation Records (OBJ$C_TIR)
931 handle etir record */
934 analyze_etir (abfd, ptr, length)
940 unsigned char *maxptr;
943 maxptr = ptr + length;
947 cmd = bfd_getl16 (ptr);
948 length = bfd_getl16 (ptr + 2);
949 res = tir_cmd (abfd, cmd, ptr+4);
958 /* process ETIR record
960 return 0 on success, -1 on error */
963 _bfd_evax_slurp_etir (abfd)
968 evax_debug (2, "ETIR\n");
971 PRIV(evax_rec) += 4; /* skip type, size */
973 if (analyze_etir (abfd, PRIV(evax_rec), PRIV(rec_size)))
980 /* process EDBG record
981 return 0 on success, -1 on error
983 not implemented yet */
986 _bfd_evax_slurp_edbg (abfd)
990 evax_debug (2, "EDBG\n");
993 abfd->flags |= (HAS_DEBUG | HAS_LINENO);
998 /* process ETBT record
999 return 0 on success, -1 on error
1001 not implemented yet */
1004 _bfd_evax_slurp_etbt (abfd)
1008 evax_debug (2, "ETBT\n");
1014 /*----------------------------------------------------------------------*/
1016 /* WRITE ETIR SECTION */
1018 /* this is still under construction and therefore not documented */
1020 /*----------------------------------------------------------------------*/
1022 static void start_etir_record PARAMS ((bfd *abfd, int index, uquad offset, boolean justoffset));
1023 static void sto_imm PARAMS ((bfd *abfd, evax_section *sptr, bfd_vma vaddr, int index));
1024 static void end_etir_record PARAMS ((bfd *abfd));
1027 sto_imm (abfd, sptr, vaddr, index)
1035 unsigned char *cptr;
1038 evax_debug (8, "sto_imm %d bytes\n", sptr->size);
1039 _bfd_hexdump (9, sptr->contents, (int)sptr->size, (int)vaddr);
1043 cptr = sptr->contents;
1048 size = ssize; /* try all the rest */
1050 if (_bfd_evax_output_check (abfd, size) < 0)
1051 { /* doesn't fit, split ! */
1052 end_etir_record (abfd);
1053 start_etir_record (abfd, index, vaddr, false);
1054 size = _bfd_evax_output_check (abfd, 0); /* get max size */
1055 if (size > ssize) /* more than what's left ? */
1059 _bfd_evax_output_begin (abfd, ETIR_S_C_STO_IMM, -1);
1060 _bfd_evax_output_long (abfd, (unsigned long)(size));
1061 _bfd_evax_output_dump (abfd, cptr, size);
1062 _bfd_evax_output_flush (abfd);
1065 evax_debug (10, "dumped %d bytes\n", size);
1066 _bfd_hexdump (10, cptr, (int)size, (int)vaddr);
1077 /*-------------------------------------------------------------------*/
1079 /* start ETIR record for section #index at virtual addr offset. */
1082 start_etir_record (abfd, index, offset, justoffset)
1090 _bfd_evax_output_begin (abfd, EOBJ_S_C_ETIR, -1); /* one ETIR per section */
1091 _bfd_evax_output_push (abfd);
1094 _bfd_evax_output_begin (abfd, ETIR_S_C_STA_PQ, -1); /* push start offset */
1095 _bfd_evax_output_long (abfd, (unsigned long)index);
1096 _bfd_evax_output_quad (abfd, (uquad)offset);
1097 _bfd_evax_output_flush (abfd);
1099 _bfd_evax_output_begin (abfd, ETIR_S_C_CTL_SETRB, -1); /* start = pop() */
1100 _bfd_evax_output_flush (abfd);
1106 /* end etir record */
1108 end_etir_record (abfd)
1111 _bfd_evax_output_pop (abfd);
1112 _bfd_evax_output_end (abfd);
1115 /* write section contents for bfd abfd */
1118 _bfd_evax_write_etir (abfd)
1126 evax_debug (2, "evax_write_etir(%p)\n", abfd);
1129 _bfd_evax_output_alignment (abfd, 4);
1132 PRIV(evax_linkage_index) = 1;
1134 /* dump all other sections */
1136 section = abfd->sections;
1138 while (section != NULL)
1142 evax_debug (4, "writing %d. section '%s' (%d bytes)\n", section->index, section->name, (int)(section->_raw_size));
1145 if (section->flags & SEC_RELOC)
1149 if ((i = section->reloc_count) <= 0)
1151 (*_bfd_error_handler) ("SEC_RELOC with no relocs in section %s",
1158 evax_debug (4, "%d relocations:\n", i);
1159 rptr = section->orelocation;
1162 evax_debug (4, "sym %s in sec %s, value %08lx, addr %08lx, off %08lx, len %d: %s\n",
1163 (*(*rptr)->sym_ptr_ptr)->name,
1164 (*(*rptr)->sym_ptr_ptr)->section->name,
1165 (long)(*(*rptr)->sym_ptr_ptr)->value,
1166 (*rptr)->address, (*rptr)->addend,
1167 bfd_get_reloc_size((*rptr)->howto),
1168 (*rptr)->howto->name);
1175 if (section->flags & SEC_HAS_CONTENTS)
1177 bfd_vma vaddr; /* virtual addr in section */
1179 sptr = _bfd_get_evax_section (abfd, section->index);
1182 bfd_set_error (bfd_error_no_contents);
1186 vaddr = (bfd_vma)(sptr->offset);
1188 start_etir_record (abfd, section->index, (uquad) sptr->offset,
1191 while (sptr != NULL) /* one STA_PQ, CTL_SETRB per evax_section */
1194 if (section->flags & SEC_RELOC) /* check for relocs */
1196 arelent **rptr = section->orelocation;
1197 int i = section->reloc_count;
1200 bfd_size_type addr = (*rptr)->address;
1201 int len = bfd_get_reloc_size ((*rptr)->howto);
1202 if (sptr->offset < addr) /* sptr starts before reloc */
1204 int before = addr - sptr->offset;
1205 if (sptr->size <= before) /* complete before */
1207 sto_imm (abfd, sptr, vaddr, section->index);
1208 vaddr += sptr->size;
1211 else /* partly before */
1213 int after = sptr->size - before;
1214 sptr->size = before;
1215 sto_imm (abfd, sptr, vaddr, section->index);
1216 vaddr += sptr->size;
1217 sptr->contents += before;
1218 sptr->offset += before;
1222 else if (sptr->offset == addr) /* sptr starts at reloc */
1224 asymbol *sym = *(*rptr)->sym_ptr_ptr;
1225 asection *sec = sym->section;
1227 switch ((*rptr)->howto->type)
1229 case ALPHA_R_IGNORE:
1232 case ALPHA_R_REFLONG:
1234 if (bfd_is_und_section (sym->section))
1236 if (_bfd_evax_output_check (abfd,
1237 strlen((char *)sym->name))
1240 end_etir_record (abfd);
1241 start_etir_record (abfd,
1245 _bfd_evax_output_begin (abfd,
1246 ETIR_S_C_STO_GBL_LW,
1248 _bfd_evax_output_counted (abfd,
1249 _bfd_evax_case_hack_symbol (abfd, sym->name));
1250 _bfd_evax_output_flush (abfd);
1252 else if (bfd_is_abs_section (sym->section))
1254 if (_bfd_evax_output_check (abfd, 16) < 0)
1256 end_etir_record (abfd);
1257 start_etir_record (abfd,
1261 _bfd_evax_output_begin (abfd,
1264 _bfd_evax_output_quad (abfd,
1266 _bfd_evax_output_flush (abfd);
1267 _bfd_evax_output_begin (abfd,
1270 _bfd_evax_output_flush (abfd);
1274 if (_bfd_evax_output_check (abfd, 32) < 0)
1276 end_etir_record (abfd);
1277 start_etir_record (abfd,
1281 _bfd_evax_output_begin (abfd,
1284 _bfd_evax_output_long (abfd,
1285 (unsigned long)(sec->index));
1286 _bfd_evax_output_quad (abfd,
1287 ((uquad)(*rptr)->addend
1288 + (uquad)sym->value));
1289 _bfd_evax_output_flush (abfd);
1290 _bfd_evax_output_begin (abfd,
1293 _bfd_evax_output_flush (abfd);
1298 case ALPHA_R_REFQUAD:
1300 if (bfd_is_und_section (sym->section))
1302 if (_bfd_evax_output_check (abfd,
1303 strlen((char *)sym->name))
1306 end_etir_record (abfd);
1307 start_etir_record (abfd,
1311 _bfd_evax_output_begin (abfd,
1314 _bfd_evax_output_counted (abfd,
1315 _bfd_evax_case_hack_symbol (abfd, sym->name));
1316 _bfd_evax_output_flush (abfd);
1318 else if (bfd_is_abs_section (sym->section))
1320 if (_bfd_evax_output_check (abfd, 16) < 0)
1322 end_etir_record (abfd);
1323 start_etir_record (abfd,
1327 _bfd_evax_output_begin (abfd,
1330 _bfd_evax_output_quad (abfd,
1332 _bfd_evax_output_flush (abfd);
1333 _bfd_evax_output_begin (abfd,
1336 _bfd_evax_output_flush (abfd);
1340 if (_bfd_evax_output_check (abfd, 32) < 0)
1342 end_etir_record (abfd);
1343 start_etir_record (abfd,
1347 _bfd_evax_output_begin (abfd,
1350 _bfd_evax_output_long (abfd,
1351 (unsigned long)(sec->index));
1352 _bfd_evax_output_quad (abfd,
1353 ((uquad)(*rptr)->addend
1354 + (uquad)sym->value));
1355 _bfd_evax_output_flush (abfd);
1356 _bfd_evax_output_begin (abfd,
1359 _bfd_evax_output_flush (abfd);
1368 hint_size = sptr->size;
1370 sto_imm (abfd, sptr, vaddr, section->index);
1371 sptr->size = hint_size;
1373 evax_output_begin(abfd, ETIR_S_C_STO_HINT_GBL, -1);
1374 evax_output_long(abfd, (unsigned long)(sec->index));
1375 evax_output_quad(abfd, (uquad)addr);
1377 evax_output_counted(abfd, _bfd_evax_case_hack_symbol (abfd, sym->name));
1378 evax_output_flush(abfd);
1383 case ALPHA_R_BRADDR:
1385 case ALPHA_R_SREL16:
1387 case ALPHA_R_SREL32:
1389 case ALPHA_R_SREL64:
1391 case ALPHA_R_OP_PUSH:
1393 case ALPHA_R_OP_STORE:
1395 case ALPHA_R_OP_PSUB:
1397 case ALPHA_R_OP_PRSHIFT:
1400 case ALPHA_R_LINKAGE:
1402 if (_bfd_evax_output_check (abfd, 64) < 0)
1404 end_etir_record (abfd);
1405 start_etir_record (abfd, section->index,
1408 _bfd_evax_output_begin (abfd,
1409 ETIR_S_C_STC_LP_PSB,
1411 _bfd_evax_output_long (abfd,
1412 (unsigned long)PRIV(evax_linkage_index));
1413 PRIV(evax_linkage_index) += 2;
1414 _bfd_evax_output_counted (abfd,
1415 _bfd_evax_case_hack_symbol (abfd, sym->name));
1416 _bfd_evax_output_byte (abfd, 0);
1417 _bfd_evax_output_flush (abfd);
1422 (*_bfd_error_handler) ("Unhandled relocation %s",
1423 (*rptr)->howto->name);
1429 if (len == sptr->size)
1435 sptr->contents += len;
1436 sptr->offset += len;
1442 else /* sptr starts after reloc */
1444 i--; /* check next reloc */
1448 if (i==0) /* all reloc checked */
1452 sto_imm (abfd, sptr, vaddr, section->index); /* dump rest */
1453 vaddr += sptr->size;
1458 } /* if SEC_RELOC */
1459 else /* no relocs, just dump */
1461 sto_imm (abfd, sptr, vaddr, section->index);
1462 vaddr += sptr->size;
1467 } /* while (sptr != 0) */
1469 end_etir_record (abfd);
1471 } /* has_contents */
1473 section = section->next;
1476 _bfd_evax_output_alignment(abfd, 2);
1481 /* write traceback data for bfd abfd */
1484 _bfd_evax_write_etbt (abfd)
1488 evax_debug (2, "evax_write_etbt(%p)\n", abfd);
1495 /* write debug info for bfd abfd */
1498 _bfd_evax_write_edbg (abfd)
1502 evax_debug (2, "evax_write_edbg(%p)\n", abfd);