1 /* vms-tir.c -- BFD back-end for VAX (openVMS/VAX) and
2 EVAX (openVMS/Alpha) files.
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5 TIR record handling functions
6 ETIR record handling functions
8 go and read the openVMS linker manual (esp. appendix B)
9 if you don't know what's going on here :-)
11 Written by Klaus K"ampf (kkaempf@rmi.de)
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 /* The following type abbreviations are used:
29 cs counted string (ascii string with length byte)
31 sh short (2 byte, 16 bit)
32 lw longword (4 byte, 32 bit)
33 qw quadword (8 byte, 64 bit)
43 static void image_set_ptr
PARAMS ((bfd
*abfd
, int psect
, uquad offset
));
44 static void image_inc_ptr
PARAMS ((bfd
*abfd
, uquad offset
));
45 static void image_dump
PARAMS ((bfd
*abfd
, unsigned char *ptr
, int size
, int offset
));
46 static void image_write_b
PARAMS ((bfd
*abfd
, unsigned int value
));
47 static void image_write_w
PARAMS ((bfd
*abfd
, unsigned int value
));
48 static void image_write_l
PARAMS ((bfd
*abfd
, unsigned long value
));
49 static void image_write_q
PARAMS ((bfd
*abfd
, uquad value
));
50 static int check_section
PARAMS ((bfd
*, int));
51 static boolean etir_sta
PARAMS ((bfd
*, int, unsigned char *));
52 static boolean etir_sto
PARAMS ((bfd
*, int, unsigned char *));
53 static boolean etir_opr
PARAMS ((bfd
*, int, unsigned char *));
54 static boolean etir_ctl
PARAMS ((bfd
*, int, unsigned char *));
55 static boolean etir_stc
PARAMS ((bfd
*, int, unsigned char *));
56 static asection
*new_section
PARAMS ((bfd
*, int));
57 static int alloc_section
PARAMS ((bfd
*, unsigned int));
58 static int etir_cmd
PARAMS ((bfd
*, int, unsigned char *));
59 static int analyze_tir
PARAMS ((bfd
*, unsigned char *, unsigned int));
60 static int analyze_etir
PARAMS ((bfd
*, unsigned char *, unsigned int));
62 /*-----------------------------------------------------------------------------*/
65 check_section (abfd
, size
)
71 offset
= PRIV (image_ptr
) - PRIV (image_section
)->contents
;
72 if (offset
+ size
> PRIV (image_section
)->_raw_size
)
74 PRIV (image_section
)->contents
75 = bfd_realloc (PRIV (image_section
)->contents
, offset
+ size
);
76 if (PRIV (image_section
)->contents
== 0)
78 (*_bfd_error_handler
) (_("No Mem !"));
81 PRIV (image_section
)->_raw_size
= offset
+ size
;
82 PRIV (image_ptr
) = PRIV (image_section
)->contents
+ offset
;
88 /* routines to fill sections contents during tir/etir read */
90 /* Initialize image buffer pointer to be filled */
93 image_set_ptr (abfd
, psect
, offset
)
99 _bfd_vms_debug (4, "image_set_ptr (%d=%s, %d)\n",
100 psect
, PRIV (sections
)[psect
]->name
, offset
);
103 PRIV (image_ptr
) = PRIV (sections
)[psect
]->contents
+ offset
;
104 PRIV (image_section
) = PRIV (sections
)[psect
];
108 /* Increment image buffer pointer by offset */
111 image_inc_ptr (abfd
, offset
)
116 _bfd_vms_debug (4, "image_inc_ptr (%d)\n", offset
);
119 PRIV (image_ptr
) += offset
;
124 /* Dump multiple bytes to section image */
127 image_dump (abfd
, ptr
, size
, offset
)
131 int offset ATTRIBUTE_UNUSED
;
134 _bfd_vms_debug (8, "image_dump from (%p, %d) to (%p)\n", ptr
, size
,
136 _bfd_hexdump (9, ptr
, size
, offset
);
139 if (PRIV (is_vax
) && check_section (abfd
, size
))
143 *PRIV (image_ptr
)++ = *ptr
++;
147 /* Write byte to section image */
150 image_write_b (abfd
, value
)
155 _bfd_vms_debug (6, "image_write_b(%02x)\n", (int) value
);
158 if (PRIV (is_vax
) && check_section (abfd
, 1))
161 *PRIV (image_ptr
)++ = (value
& 0xff);
165 /* Write 2-byte word to image */
168 image_write_w (abfd
, value
)
173 _bfd_vms_debug (6, "image_write_w(%04x)\n", (int) value
);
176 if (PRIV (is_vax
) && check_section (abfd
, 2))
179 bfd_putl16 ((bfd_vma
) value
, PRIV (image_ptr
));
180 PRIV (image_ptr
) += 2;
185 /* Write 4-byte long to image */
188 image_write_l (abfd
, value
)
193 _bfd_vms_debug (6, "image_write_l (%08lx)\n", value
);
196 if (PRIV (is_vax
) && check_section (abfd
, 4))
199 bfd_putl32 ((bfd_vma
) value
, PRIV (image_ptr
));
200 PRIV (image_ptr
) += 4;
205 /* Write 8-byte quad to image */
208 image_write_q (abfd
, value
)
213 _bfd_vms_debug (6, "image_write_q (%016lx)\n", value
);
216 if (PRIV (is_vax
) && check_section (abfd
, 8))
219 bfd_putl64 (value
, PRIV (image_ptr
));
220 PRIV (image_ptr
) += 8;
226 #define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L)
232 handle sta_xxx commands in etir section
233 ptr points to data area in record
235 see table B-8 of the openVMS linker manual */
238 etir_sta (abfd
, cmd
, ptr
)
245 _bfd_vms_debug (5, "etir_sta %d/%x\n", cmd
, cmd
);
246 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
256 stack 32 bit value of symbol (high bits set to 0) */
258 case ETIR_S_C_STA_GBL
:
261 vms_symbol_entry
*entry
;
263 name
= _bfd_vms_save_counted_string (ptr
);
264 entry
= (vms_symbol_entry
*)
265 bfd_hash_lookup (PRIV (vms_symbol_table
), name
, false, false);
266 if (entry
== (vms_symbol_entry
*) NULL
)
269 _bfd_vms_debug (3, "ETIR_S_C_STA_GBL: no symbol \"%s\"\n", name
);
271 _bfd_vms_push (abfd
, (uquad
) 0, -1);
275 _bfd_vms_push (abfd
, (uquad
) (entry
->symbol
->value
), -1);
283 stack 32 bit value, sign extend to 64 bit */
285 case ETIR_S_C_STA_LW
:
286 _bfd_vms_push (abfd
, (uquad
) bfd_getl32 (ptr
), -1);
292 stack 64 bit value of symbol */
294 case ETIR_S_C_STA_QW
:
295 _bfd_vms_push (abfd
, (uquad
) bfd_getl64 (ptr
), -1);
298 /* stack psect base plus quadword offset
299 arg: lw section index
300 qw signed quadword offset (low 32 bits)
302 stack qw argument and section index
303 (see ETIR_S_C_STO_OFF, ETIR_S_C_CTL_SETRB) */
305 case ETIR_S_C_STA_PQ
:
310 psect
= bfd_getl32 (ptr
);
311 if (psect
>= PRIV (section_count
))
313 (*_bfd_error_handler
) (_("Bad section index in ETIR_S_C_STA_PQ"));
314 bfd_set_error (bfd_error_bad_value
);
317 dummy
= bfd_getl64 (ptr
+4);
318 _bfd_vms_push (abfd
, dummy
, (int) psect
);
322 /* all not supported */
324 case ETIR_S_C_STA_LI
:
325 case ETIR_S_C_STA_MOD
:
326 case ETIR_S_C_STA_CKARG
:
328 (*_bfd_error_handler
) (_("Unsupported STA cmd %d"), cmd
);
333 (*_bfd_error_handler
) (_("Reserved STA cmd %d"), cmd
);
338 _bfd_vms_debug (5, "etir_sta true\n");
348 handle sto_xxx commands in etir section
349 ptr points to data area in record
351 see table B-9 of the openVMS linker manual */
354 etir_sto (abfd
, cmd
, ptr
)
363 _bfd_vms_debug (5, "etir_sto %d/%x\n", cmd
, cmd
);
364 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
370 /* store byte: pop stack, write byte
374 dummy
= _bfd_vms_pop (abfd
, &psect
);
376 if (is_share
) /* FIXME */
377 (*_bfd_error_handler
) ("ETIR_S_C_STO_B: byte fixups not supported");
379 /* FIXME: check top bits */
380 image_write_b (abfd
, (unsigned int) dummy
& 0xff);
383 /* store word: pop stack, write word
387 dummy
= _bfd_vms_pop (abfd
, &psect
);
389 if (is_share
) /* FIXME */
390 (*_bfd_error_handler
) ("ETIR_S_C_STO_B: word fixups not supported");
392 /* FIXME: check top bits */
393 image_write_w (abfd
, (unsigned int) dummy
& 0xffff);
396 /* store longword: pop stack, write longword
399 case ETIR_S_C_STO_LW
:
400 dummy
= _bfd_vms_pop (abfd
, &psect
);
401 dummy
+= (PRIV (sections
)[psect
])->vma
;
402 /* FIXME: check top bits */
403 image_write_l (abfd
, (unsigned int) dummy
& 0xffffffff);
406 /* store quadword: pop stack, write quadword
409 case ETIR_S_C_STO_QW
:
410 dummy
= _bfd_vms_pop (abfd
, &psect
);
411 dummy
+= (PRIV (sections
)[psect
])->vma
;
412 image_write_q (abfd
, dummy
); /* FIXME: check top bits */
415 /* store immediate repeated: pop stack for repeat count
419 case ETIR_S_C_STO_IMMR
:
423 size
= bfd_getl32 (ptr
);
424 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
426 image_dump (abfd
, ptr
+4, size
, 0);
430 /* store global: write symbol value
431 arg: cs global symbol name */
433 case ETIR_S_C_STO_GBL
:
435 vms_symbol_entry
*entry
;
438 name
= _bfd_vms_save_counted_string (ptr
);
439 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV (vms_symbol_table
),
441 if (entry
== (vms_symbol_entry
*) NULL
)
443 (*_bfd_error_handler
) (_("ETIR_S_C_STO_GBL: no symbol \"%s\""),
448 image_write_q (abfd
, (uquad
) (entry
->symbol
->value
)); /* FIXME, reloc */
452 /* store code address: write address of entry point
453 arg: cs global symbol name (procedure) */
455 case ETIR_S_C_STO_CA
:
457 vms_symbol_entry
*entry
;
460 name
= _bfd_vms_save_counted_string (ptr
);
461 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV (vms_symbol_table
),
463 if (entry
== (vms_symbol_entry
*) NULL
)
465 (*_bfd_error_handler
) (_("ETIR_S_C_STO_CA: no symbol \"%s\""),
470 image_write_q (abfd
, (uquad
) (entry
->symbol
->value
)); /* FIXME, reloc */
476 case ETIR_S_C_STO_RB
:
477 case ETIR_S_C_STO_AB
:
478 (*_bfd_error_handler
) (_("ETIR_S_C_STO_RB/AB: Not supported"));
481 /* store offset to psect: pop stack, add low 32 bits to base of psect
484 case ETIR_S_C_STO_OFF
:
489 q
= _bfd_vms_pop (abfd
, &psect1
);
490 q
+= (PRIV (sections
)[psect1
])->vma
;
491 image_write_q (abfd
, q
);
496 arg: lw count of bytes
499 case ETIR_S_C_STO_IMM
:
503 size
= bfd_getl32 (ptr
);
504 image_dump (abfd
, ptr
+4, size
, 0);
508 /* this code is 'reserved to digital' according to the openVMS
509 linker manual, however it is generated by the DEC C compiler
510 and defined in the include file.
511 FIXME, since the following is just a guess
512 store global longword: store 32bit value of symbol
513 arg: cs symbol name */
515 case ETIR_S_C_STO_GBL_LW
:
517 vms_symbol_entry
*entry
;
520 name
= _bfd_vms_save_counted_string (ptr
);
521 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV (vms_symbol_table
),
523 if (entry
== (vms_symbol_entry
*) NULL
)
526 _bfd_vms_debug (3, "ETIR_S_C_STO_GBL_LW: no symbol \"%s\"\n", name
);
528 image_write_l (abfd
, (unsigned long) 0); /* FIXME, reloc */
531 image_write_l (abfd
, (unsigned long) (entry
->symbol
->value
)); /* FIXME, reloc */
537 case ETIR_S_C_STO_LP_PSB
:
538 (*_bfd_error_handler
) (_("ETIR_S_C_STO_LP_PSB: Not supported"));
543 case ETIR_S_C_STO_HINT_GBL
:
544 (*_bfd_error_handler
) (_("ETIR_S_C_STO_HINT_GBL: not implemented"));
549 case ETIR_S_C_STO_HINT_PS
:
550 (*_bfd_error_handler
) (_("ETIR_S_C_STO_HINT_PS: not implemented"));
554 (*_bfd_error_handler
) (_("Reserved STO cmd %d"), cmd
);
561 /* stack operator commands
562 all 32 bit signed arithmetic
563 all word just like a stack calculator
564 arguments are popped from stack, results are pushed on stack
566 see table B-10 of the openVMS linker manual */
569 etir_opr (abfd
, cmd
, ptr
)
572 unsigned char *ptr ATTRIBUTE_UNUSED
;
577 _bfd_vms_debug (5, "etir_opr %d/%x\n", cmd
, cmd
);
578 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
587 case ETIR_S_C_OPR_NOP
:
592 case ETIR_S_C_OPR_ADD
:
593 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
594 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
595 _bfd_vms_push (abfd
, (uquad
) (op1
+ op2
), -1);
600 case ETIR_S_C_OPR_SUB
:
601 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
602 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
603 _bfd_vms_push (abfd
, (uquad
) (op2
- op1
), -1);
608 case ETIR_S_C_OPR_MUL
:
609 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
610 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
611 _bfd_vms_push (abfd
, (uquad
) (op1
* op2
), -1);
616 case ETIR_S_C_OPR_DIV
:
617 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
618 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
620 _bfd_vms_push (abfd
, (uquad
) 0, -1);
622 _bfd_vms_push (abfd
, (uquad
) (op2
/ op1
), -1);
627 case ETIR_S_C_OPR_AND
:
628 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
629 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
630 _bfd_vms_push (abfd
, (uquad
) (op1
& op2
), -1);
633 /* logical inclusive or */
635 case ETIR_S_C_OPR_IOR
:
636 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
637 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
638 _bfd_vms_push (abfd
, (uquad
) (op1
| op2
), -1);
641 /* logical exclusive or */
643 case ETIR_S_C_OPR_EOR
:
644 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
645 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
646 _bfd_vms_push (abfd
, (uquad
) (op1
^ op2
), -1);
651 case ETIR_S_C_OPR_NEG
:
652 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
653 _bfd_vms_push (abfd
, (uquad
) (-op1
), -1);
658 case ETIR_S_C_OPR_COM
:
659 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
660 _bfd_vms_push (abfd
, (uquad
) (op1
^ -1L), -1);
665 case ETIR_S_C_OPR_INSV
:
666 (void) _bfd_vms_pop (abfd
, NULL
);
667 (*_bfd_error_handler
) (_("ETIR_S_C_OPR_INSV: Not supported"));
670 /* arithmetic shift */
672 case ETIR_S_C_OPR_ASH
:
673 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
674 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
675 if (op2
< 0) /* shift right */
677 else /* shift left */
679 _bfd_vms_push (abfd
, (uquad
) op1
, -1);
684 case ETIR_S_C_OPR_USH
:
685 (*_bfd_error_handler
) (_("ETIR_S_C_OPR_USH: Not supported"));
690 case ETIR_S_C_OPR_ROT
:
691 (*_bfd_error_handler
) (_("ETIR_S_C_OPR_ROT: Not supported"));
696 case ETIR_S_C_OPR_SEL
:
697 if ((long) _bfd_vms_pop (abfd
, NULL
) & 0x01L
)
698 (void) _bfd_vms_pop (abfd
, NULL
);
701 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
702 (void) _bfd_vms_pop (abfd
, NULL
);
703 _bfd_vms_push (abfd
, (uquad
) op1
, -1);
707 /* redefine symbol to current location */
709 case ETIR_S_C_OPR_REDEF
:
710 (*_bfd_error_handler
) (_("ETIR_S_C_OPR_REDEF: Not supported"));
713 /* define a literal */
715 case ETIR_S_C_OPR_DFLIT
:
716 (*_bfd_error_handler
) (_("ETIR_S_C_OPR_DFLIT: Not supported"));
720 (*_bfd_error_handler
) (_("Reserved OPR cmd %d"), cmd
);
729 see table B-11 of the openVMS linker manual */
732 etir_ctl (abfd
, cmd
, ptr
)
741 _bfd_vms_debug (5, "etir_ctl %d/%x\n", cmd
, cmd
);
742 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
747 /* set relocation base: pop stack, set image location counter
750 case ETIR_S_C_CTL_SETRB
:
751 dummy
= _bfd_vms_pop (abfd
, &psect
);
752 image_set_ptr (abfd
, psect
, dummy
);
755 /* augment relocation base: increment image location counter by offset
756 arg: lw offset value */
758 case ETIR_S_C_CTL_AUGRB
:
759 dummy
= bfd_getl32 (ptr
);
760 image_inc_ptr (abfd
, dummy
);
763 /* define location: pop index, save location counter under index
766 case ETIR_S_C_CTL_DFLOC
:
767 dummy
= _bfd_vms_pop (abfd
, NULL
);
771 /* set location: pop index, restore location counter from index
774 case ETIR_S_C_CTL_STLOC
:
775 dummy
= _bfd_vms_pop (abfd
, &psect
);
779 /* stack defined location: pop index, push location counter from index
782 case ETIR_S_C_CTL_STKDL
:
783 dummy
= _bfd_vms_pop (abfd
, &psect
);
788 (*_bfd_error_handler
) (_("Reserved CTL cmd %d"), cmd
);
794 /* store conditional commands
796 see table B-12 and B-13 of the openVMS linker manual */
799 etir_stc (abfd
, cmd
, ptr
)
802 unsigned char *ptr ATTRIBUTE_UNUSED
;
806 _bfd_vms_debug (5, "etir_stc %d/%x\n", cmd
, cmd
);
807 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
812 /* 200 Store-conditional Linkage Pair
815 case ETIR_S_C_STC_LP
:
816 (*_bfd_error_handler
) (_("ETIR_S_C_STC_LP: not supported"));
819 /* 201 Store-conditional Linkage Pair with Procedure Signature
820 arg: lw linkage index
825 case ETIR_S_C_STC_LP_PSB
:
826 image_inc_ptr (abfd
, (uquad
) 16); /* skip entry,procval */
829 /* 202 Store-conditional Address at global address
830 arg: lw linkage index
833 case ETIR_S_C_STC_GBL
:
834 (*_bfd_error_handler
) (_("ETIR_S_C_STC_GBL: not supported"));
837 /* 203 Store-conditional Code Address at global address
838 arg: lw linkage index
841 case ETIR_S_C_STC_GCA
:
842 (*_bfd_error_handler
) (_("ETIR_S_C_STC_GCA: not supported"));
845 /* 204 Store-conditional Address at psect + offset
846 arg: lw linkage index
850 case ETIR_S_C_STC_PS
:
851 (*_bfd_error_handler
) (_("ETIR_S_C_STC_PS: not supported"));
854 /* 205 Store-conditional NOP at address of global
857 case ETIR_S_C_STC_NOP_GBL
:
859 /* 206 Store-conditional NOP at pect + offset
862 case ETIR_S_C_STC_NOP_PS
:
864 /* 207 Store-conditional BSR at global address
867 case ETIR_S_C_STC_BSR_GBL
:
869 /* 208 Store-conditional BSR at pect + offset
872 case ETIR_S_C_STC_BSR_PS
:
874 /* 209 Store-conditional LDA at global address
877 case ETIR_S_C_STC_LDA_GBL
:
879 /* 210 Store-conditional LDA at psect + offset
882 case ETIR_S_C_STC_LDA_PS
:
884 /* 211 Store-conditional BSR or Hint at global address
887 case ETIR_S_C_STC_BOH_GBL
:
889 /* 212 Store-conditional BSR or Hint at pect + offset
892 case ETIR_S_C_STC_BOH_PS
:
894 /* 213 Store-conditional NOP,BSR or HINT at global address
897 case ETIR_S_C_STC_NBH_GBL
:
899 /* 214 Store-conditional NOP,BSR or HINT at psect + offset
902 case ETIR_S_C_STC_NBH_PS
:
905 (*_bfd_error_handler
) ("ETIR_S_C_STC_xx: (%d) not supported", cmd
);
911 _bfd_vms_debug (3, "Reserved STC cmd %d", cmd
);
919 new_section (abfd
, idx
)
920 bfd
*abfd ATTRIBUTE_UNUSED
;
928 _bfd_vms_debug (5, "new_section %d\n", idx
);
930 sprintf (sname
, SECTION_NAME_TEMPLATE
, idx
);
932 name
= bfd_malloc ((bfd_size_type
) strlen (sname
) + 1);
935 strcpy (name
, sname
);
937 section
= bfd_malloc ((bfd_size_type
) sizeof (asection
));
941 _bfd_vms_debug (6, "bfd_make_section (%s) failed", name
);
946 section
->_raw_size
= 0;
948 section
->contents
= 0;
949 section
->_cooked_size
= 0;
950 section
->name
= name
;
951 section
->index
= idx
;
957 alloc_section (abfd
, idx
)
964 _bfd_vms_debug (4, "alloc_section %d\n", idx
);
968 amt
*= sizeof (asection
*);
969 PRIV (sections
) = (asection
**) bfd_realloc (PRIV (sections
), amt
);
970 if (PRIV (sections
) == 0)
973 while (PRIV (section_count
) <= idx
)
975 PRIV (sections
)[PRIV (section_count
)]
976 = new_section (abfd
, (int) PRIV (section_count
));
977 if (PRIV (sections
)[PRIV (section_count
)] == 0)
979 PRIV (section_count
)++;
990 * handle sta_xxx commands in tir section
991 * ptr points to data area in record
993 * see table 7-3 of the VAX/VMS linker manual
996 static unsigned char *
997 tir_sta (bfd
*abfd
, unsigned char *ptr
)
1002 _bfd_vms_debug (5, "tir_sta %d\n", cmd
);
1008 case TIR_S_C_STA_GBL
:
1011 * arg: cs symbol name
1013 * stack 32 bit value of symbol (high bits set to 0)
1017 vms_symbol_entry
*entry
;
1019 name
= _bfd_vms_save_counted_string (ptr
);
1021 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1022 if (entry
== (vms_symbol_entry
*) NULL
)
1025 _bfd_vms_push (abfd
, (uquad
) (entry
->symbol
->value
), -1);
1030 case TIR_S_C_STA_SB
:
1035 * stack byte value, sign extend to 32 bit
1037 _bfd_vms_push (abfd
, (uquad
) *ptr
++, -1);
1040 case TIR_S_C_STA_SW
:
1042 * stack signed short word
1045 * stack 16 bit value, sign extend to 32 bit
1047 _bfd_vms_push (abfd
, (uquad
) bfd_getl16 (ptr
), -1);
1051 case TIR_S_C_STA_LW
:
1053 * stack signed longword
1056 * stack 32 bit value
1058 _bfd_vms_push (abfd
, (uquad
) bfd_getl32 (ptr
), -1);
1062 case TIR_S_C_STA_PB
:
1063 case TIR_S_C_STA_WPB
:
1065 * stack psect base plus byte offset (word index)
1066 * arg: by section index
1067 * (sh section index)
1068 * by signed byte offset
1072 unsigned long dummy
;
1075 if (cmd
== TIR_S_C_STA_PB
)
1079 psect
= bfd_getl16 (ptr
);
1083 if (psect
>= PRIV (section_count
))
1085 alloc_section (abfd
, psect
);
1088 dummy
= (long) *ptr
++;
1089 dummy
+= (PRIV (sections
)[psect
])->vma
;
1090 _bfd_vms_push (abfd
, (uquad
) dummy
, (int) psect
);
1094 case TIR_S_C_STA_PW
:
1095 case TIR_S_C_STA_WPW
:
1097 * stack psect base plus word offset (word index)
1098 * arg: by section index
1099 * (sh section index)
1100 * sh signed short offset
1104 unsigned long dummy
;
1107 if (cmd
== TIR_S_C_STA_PW
)
1111 psect
= bfd_getl16 (ptr
);
1115 if (psect
>= PRIV (section_count
))
1117 alloc_section (abfd
, psect
);
1120 dummy
= bfd_getl16 (ptr
); ptr
+=2;
1121 dummy
+= (PRIV (sections
)[psect
])->vma
;
1122 _bfd_vms_push (abfd
, (uquad
) dummy
, (int) psect
);
1126 case TIR_S_C_STA_PL
:
1127 case TIR_S_C_STA_WPL
:
1129 * stack psect base plus long offset (word index)
1130 * arg: by section index
1131 * (sh section index)
1132 * lw signed longword offset
1136 unsigned long dummy
;
1139 if (cmd
== TIR_S_C_STA_PL
)
1143 psect
= bfd_getl16 (ptr
);
1147 if (psect
>= PRIV (section_count
))
1149 alloc_section (abfd
, psect
);
1152 dummy
= bfd_getl32 (ptr
); ptr
+= 4;
1153 dummy
+= (PRIV (sections
)[psect
])->vma
;
1154 _bfd_vms_push (abfd
, (uquad
) dummy
, (int) psect
);
1158 case TIR_S_C_STA_UB
:
1160 * stack unsigned byte
1165 _bfd_vms_push (abfd
, (uquad
) *ptr
++, -1);
1168 case TIR_S_C_STA_UW
:
1170 * stack unsigned short word
1173 * stack 16 bit value
1175 _bfd_vms_push (abfd
, (uquad
) bfd_getl16 (ptr
), -1);
1179 case TIR_S_C_STA_BFI
:
1181 * stack byte from image
1186 case TIR_S_C_STA_WFI
:
1188 * stack byte from image
1193 case TIR_S_C_STA_LFI
:
1195 * stack byte from image
1199 (*_bfd_error_handler
) (_("Stack-from-image not implemented"));
1202 case TIR_S_C_STA_EPM
:
1204 * stack entry point mask
1205 * arg: cs symbol name
1207 * stack (unsigned) entry point mask of symbol
1208 * err if symbol is no entry point
1212 vms_symbol_entry
*entry
;
1214 name
= _bfd_vms_save_counted_string (ptr
);
1215 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1216 if (entry
== (vms_symbol_entry
*) NULL
)
1219 (*_bfd_error_handler
) (_("Stack-entry-mask not fully implemented"));
1220 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1225 case TIR_S_C_STA_CKARG
:
1227 * compare procedure argument
1228 * arg: cs symbol name
1230 * da argument descriptor
1232 * compare argument descriptor with symbol argument (ARG$V_PASSMECH)
1233 * and stack TRUE (args match) or FALSE (args dont match) value
1235 (*_bfd_error_handler
) (_("PASSMECH not fully implemented"));
1236 _bfd_vms_push (abfd
, (uquad
) 1, -1);
1239 case TIR_S_C_STA_LSY
:
1241 * stack local symbol value
1242 * arg: sh environment index
1248 vms_symbol_entry
*entry
;
1250 envidx
= bfd_getl16 (ptr
);
1252 name
= _bfd_vms_save_counted_string (ptr
);
1253 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1254 if (entry
== (vms_symbol_entry
*) NULL
)
1256 (*_bfd_error_handler
) (_("Stack-local-symbol not fully implemented"));
1257 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1262 case TIR_S_C_STA_LIT
:
1265 * arg: by literal index
1270 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1271 (*_bfd_error_handler
) (_("Stack-literal not fully implemented"));
1274 case TIR_S_C_STA_LEPM
:
1276 * stack local symbol entry point mask
1277 * arg: sh environment index
1280 * stack (unsigned) entry point mask of symbol
1281 * err if symbol is no entry point
1286 vms_symbol_entry
*entry
;
1288 envidx
= bfd_getl16 (ptr
);
1290 name
= _bfd_vms_save_counted_string (ptr
);
1291 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1292 if (entry
== (vms_symbol_entry
*) NULL
)
1294 (*_bfd_error_handler
) (_("Stack-local-symbol-entry-point-mask not fully implemented"));
1295 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1301 (*_bfd_error_handler
) (_("Reserved STA cmd %d"), ptr
[-1]);
1312 * vax store commands
1314 * handle sto_xxx commands in tir section
1315 * ptr points to data area in record
1317 * see table 7-4 of the VAX/VMS linker manual
1320 static unsigned char *
1321 tir_sto (bfd
*abfd
, unsigned char *ptr
)
1323 unsigned long dummy
;
1328 _bfd_vms_debug (5, "tir_sto %d\n", *ptr
);
1333 case TIR_S_C_STO_SB
:
1335 * store signed byte: pop stack, write byte
1338 dummy
= _bfd_vms_pop (abfd
, &psect
);
1339 image_write_b (abfd
, dummy
& 0xff); /* FIXME: check top bits */
1342 case TIR_S_C_STO_SW
:
1344 * store signed word: pop stack, write word
1347 dummy
= _bfd_vms_pop (abfd
, &psect
);
1348 image_write_w (abfd
, dummy
& 0xffff); /* FIXME: check top bits */
1351 case TIR_S_C_STO_LW
:
1353 * store longword: pop stack, write longword
1356 dummy
= _bfd_vms_pop (abfd
, &psect
);
1357 image_write_l (abfd
, dummy
& 0xffffffff); /* FIXME: check top bits */
1360 case TIR_S_C_STO_BD
:
1362 * store byte displaced: pop stack, sub lc+1, write byte
1365 dummy
= _bfd_vms_pop (abfd
, &psect
);
1366 dummy
-= ((PRIV (sections
)[psect
])->vma
+ 1);
1367 image_write_b (abfd
, dummy
& 0xff);/* FIXME: check top bits */
1370 case TIR_S_C_STO_WD
:
1372 * store word displaced: pop stack, sub lc+2, write word
1375 dummy
= _bfd_vms_pop (abfd
, &psect
);
1376 dummy
-= ((PRIV (sections
)[psect
])->vma
+ 2);
1377 image_write_w (abfd
, dummy
& 0xffff);/* FIXME: check top bits */
1379 case TIR_S_C_STO_LD
:
1381 * store long displaced: pop stack, sub lc+4, write long
1384 dummy
= _bfd_vms_pop (abfd
, &psect
);
1385 dummy
-= ((PRIV (sections
)[psect
])->vma
+ 4);
1386 image_write_l (abfd
, dummy
& 0xffffffff);/* FIXME: check top bits */
1388 case TIR_S_C_STO_LI
:
1390 * store short literal: pop stack, write byte
1393 dummy
= _bfd_vms_pop (abfd
, &psect
);
1394 image_write_b (abfd
, dummy
& 0xff);/* FIXME: check top bits */
1396 case TIR_S_C_STO_PIDR
:
1398 * store position independent data reference: pop stack, write longword
1400 * FIXME: incomplete !
1402 dummy
= _bfd_vms_pop (abfd
, &psect
);
1403 image_write_l (abfd
, dummy
& 0xffffffff);
1405 case TIR_S_C_STO_PICR
:
1407 * store position independent code reference: pop stack, write longword
1409 * FIXME: incomplete !
1411 dummy
= _bfd_vms_pop (abfd
, &psect
);
1412 image_write_b (abfd
, 0x9f);
1413 image_write_l (abfd
, dummy
& 0xffffffff);
1415 case TIR_S_C_STO_RIVB
:
1417 * store repeated immediate variable bytes
1418 * 1-byte count n field followed by n bytes of data
1419 * pop stack, write n bytes <stack> times
1422 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1423 while (dummy
-- > 0L)
1424 image_dump (abfd
, ptr
, size
, 0);
1429 * store byte from top longword
1431 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1432 image_write_b (abfd
, dummy
& 0xff);
1436 * store word from top longword
1438 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1439 image_write_w (abfd
, dummy
& 0xffff);
1441 case TIR_S_C_STO_RB
:
1443 * store repeated byte from top longword
1445 size
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1446 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1448 image_write_b (abfd
, dummy
& 0xff);
1450 case TIR_S_C_STO_RW
:
1452 * store repeated word from top longword
1454 size
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1455 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1457 image_write_w (abfd
, dummy
& 0xffff);
1460 case TIR_S_C_STO_RSB
:
1461 case TIR_S_C_STO_RSW
:
1462 case TIR_S_C_STO_RL
:
1463 case TIR_S_C_STO_VPS
:
1464 case TIR_S_C_STO_USB
:
1465 case TIR_S_C_STO_USW
:
1466 case TIR_S_C_STO_RUB
:
1467 case TIR_S_C_STO_RUW
:
1468 case TIR_S_C_STO_PIRR
:
1469 (*_bfd_error_handler
) (_("Unimplemented STO cmd %d"), ptr
[-1]);
1473 (*_bfd_error_handler
) (_("Reserved STO cmd %d"), ptr
[-1]);
1481 * stack operator commands
1482 * all 32 bit signed arithmetic
1483 * all word just like a stack calculator
1484 * arguments are popped from stack, results are pushed on stack
1486 * see table 7-5 of the VAX/VMS linker manual
1489 static unsigned char *
1490 tir_opr (bfd
*abfd
, unsigned char *ptr
)
1495 _bfd_vms_debug (5, "tir_opr %d\n", *ptr
);
1501 case TIR_S_C_OPR_NOP
:
1507 case TIR_S_C_OPR_ADD
:
1511 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1512 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1513 _bfd_vms_push (abfd
, (uquad
) (op1
+ op2
), -1);
1516 case TIR_S_C_OPR_SUB
:
1520 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1521 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1522 _bfd_vms_push (abfd
, (uquad
) (op2
- op1
), -1);
1525 case TIR_S_C_OPR_MUL
:
1529 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1530 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1531 _bfd_vms_push (abfd
, (uquad
) (op1
* op2
), -1);
1534 case TIR_S_C_OPR_DIV
:
1538 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1539 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1541 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1543 _bfd_vms_push (abfd
, (uquad
) (op2
/ op1
), -1);
1546 case TIR_S_C_OPR_AND
:
1550 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1551 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1552 _bfd_vms_push (abfd
, (uquad
) (op1
& op2
), -1);
1555 case TIR_S_C_OPR_IOR
:
1556 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1558 * logical inclusive or
1560 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1561 _bfd_vms_push (abfd
, (uquad
) (op1
| op2
), -1);
1564 case TIR_S_C_OPR_EOR
:
1566 * logical exclusive or
1568 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1569 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1570 _bfd_vms_push (abfd
, (uquad
) (op1
^ op2
), -1);
1573 case TIR_S_C_OPR_NEG
:
1577 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1578 _bfd_vms_push (abfd
, (uquad
) (-op1
), -1);
1581 case TIR_S_C_OPR_COM
:
1585 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1586 _bfd_vms_push (abfd
, (uquad
) (op1
^ -1L), -1);
1589 case TIR_S_C_OPR_INSV
:
1593 (void) _bfd_vms_pop (abfd
, NULL
);
1594 (*_bfd_error_handler
) ("TIR_S_C_OPR_INSV incomplete");
1597 case TIR_S_C_OPR_ASH
:
1601 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1602 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1603 if (HIGHBIT (op1
)) /* shift right */
1605 else /* shift left */
1607 _bfd_vms_push (abfd
, (uquad
) op2
, -1);
1608 (*_bfd_error_handler
) (_("TIR_S_C_OPR_ASH incomplete"));
1611 case TIR_S_C_OPR_USH
:
1615 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1616 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1617 if (HIGHBIT (op1
)) /* shift right */
1619 else /* shift left */
1621 _bfd_vms_push (abfd
, (uquad
) op2
, -1);
1622 (*_bfd_error_handler
) (_("TIR_S_C_OPR_USH incomplete"));
1625 case TIR_S_C_OPR_ROT
:
1629 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1630 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1631 if (HIGHBIT (0)) /* shift right */
1633 else /* shift left */
1635 _bfd_vms_push (abfd
, (uquad
) op2
, -1);
1636 (*_bfd_error_handler
) (_("TIR_S_C_OPR_ROT incomplete"));
1639 case TIR_S_C_OPR_SEL
:
1643 if ((long) _bfd_vms_pop (abfd
, NULL
) & 0x01L
)
1644 (void) _bfd_vms_pop (abfd
, NULL
);
1647 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1648 (void) _bfd_vms_pop (abfd
, NULL
);
1649 _bfd_vms_push (abfd
, (uquad
) op1
, -1);
1653 case TIR_S_C_OPR_REDEF
:
1655 * redefine symbol to current location
1657 (*_bfd_error_handler
) (_("TIR_S_C_OPR_REDEF not supported"));
1660 case TIR_S_C_OPR_DFLIT
:
1664 (*_bfd_error_handler
) (_("TIR_S_C_OPR_DFLIT not supported"));
1668 (*_bfd_error_handler
) (_("Reserved OPR cmd %d"), ptr
[-1]);
1675 static unsigned char *
1676 tir_ctl (bfd
*abfd
, unsigned char *ptr
)
1680 * see table 7-6 of the VAX/VMS linker manual
1683 unsigned long dummy
;
1687 _bfd_vms_debug (5, "tir_ctl %d\n", *ptr
);
1692 case TIR_S_C_CTL_SETRB
:
1694 * set relocation base: pop stack, set image location counter
1697 dummy
= _bfd_vms_pop (abfd
, &psect
);
1698 if (psect
>= PRIV (section_count
))
1700 alloc_section (abfd
, psect
);
1702 image_set_ptr (abfd
, (int) psect
, (uquad
) dummy
);
1704 case TIR_S_C_CTL_AUGRB
:
1706 * augment relocation base: increment image location counter by offset
1707 * arg: lw offset value
1709 dummy
= bfd_getl32 (ptr
);
1710 image_inc_ptr (abfd
, (uquad
) dummy
);
1712 case TIR_S_C_CTL_DFLOC
:
1714 * define location: pop index, save location counter under index
1717 dummy
= _bfd_vms_pop (abfd
, NULL
);
1718 (*_bfd_error_handler
) (_("TIR_S_C_CTL_DFLOC not fully implemented"));
1720 case TIR_S_C_CTL_STLOC
:
1722 * set location: pop index, restore location counter from index
1725 dummy
= _bfd_vms_pop (abfd
, &psect
);
1726 (*_bfd_error_handler
) (_("TIR_S_C_CTL_STLOC not fully implemented"));
1728 case TIR_S_C_CTL_STKDL
:
1730 * stack defined location: pop index, push location counter from index
1733 dummy
= _bfd_vms_pop (abfd
, &psect
);
1734 (*_bfd_error_handler
) (_("TIR_S_C_CTL_STKDL not fully implemented"));
1737 (*_bfd_error_handler
) (_("Reserved CTL cmd %d"), ptr
[-1]);
1744 * handle command from TIR section
1747 static unsigned char *
1748 tir_cmd (bfd
*abfd
, unsigned char *ptr
)
1754 unsigned char * (*explain
) (bfd
*, unsigned char *);
1758 { 0, TIR_S_C_MAXSTACOD
, tir_sta
},
1759 { TIR_S_C_MINSTOCOD
, TIR_S_C_MAXSTOCOD
, tir_sto
},
1760 { TIR_S_C_MINOPRCOD
, TIR_S_C_MAXOPRCOD
, tir_opr
},
1761 { TIR_S_C_MINCTLCOD
, TIR_S_C_MAXCTLCOD
, tir_ctl
},
1767 _bfd_vms_debug (4, "tir_cmd %d/%x\n", *ptr
, *ptr
);
1768 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
1771 if (*ptr
& 0x80) /* store immediate */
1773 i
= 128 - (*ptr
++ & 0x7f);
1774 image_dump (abfd
, ptr
, i
, 0);
1779 while (tir_table
[i
].mincod
>= 0)
1781 if ( (tir_table
[i
].mincod
<= *ptr
)
1782 && (*ptr
<= tir_table
[i
].maxcod
))
1784 ptr
= tir_table
[i
].explain (abfd
, ptr
);
1789 if (tir_table
[i
].mincod
< 0)
1791 (*_bfd_error_handler
) (_("Obj code %d not found"), *ptr
);
1799 /* handle command from ETIR section */
1802 etir_cmd (abfd
, cmd
, ptr
)
1811 boolean (*explain
) PARAMS ((bfd
*, int, unsigned char *));
1815 { ETIR_S_C_MINSTACOD
, ETIR_S_C_MAXSTACOD
, etir_sta
},
1816 { ETIR_S_C_MINSTOCOD
, ETIR_S_C_MAXSTOCOD
, etir_sto
},
1817 { ETIR_S_C_MINOPRCOD
, ETIR_S_C_MAXOPRCOD
, etir_opr
},
1818 { ETIR_S_C_MINCTLCOD
, ETIR_S_C_MAXCTLCOD
, etir_ctl
},
1819 { ETIR_S_C_MINSTCCOD
, ETIR_S_C_MAXSTCCOD
, etir_stc
},
1826 _bfd_vms_debug (4, "etir_cmd %d/%x\n", cmd
, cmd
);
1827 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
1830 while (etir_table
[i
].mincod
>= 0)
1832 if ( (etir_table
[i
].mincod
<= cmd
)
1833 && (cmd
<= etir_table
[i
].maxcod
))
1835 if (!etir_table
[i
].explain (abfd
, cmd
, ptr
))
1843 _bfd_vms_debug (4, "etir_cmd: = 0\n");
1848 /* Text Information and Relocation Records (OBJ$C_TIR)
1849 handle tir record */
1852 analyze_tir (abfd
, ptr
, length
)
1855 unsigned int length
;
1857 unsigned char *maxptr
;
1860 _bfd_vms_debug (3, "analyze_tir: %d bytes\n", length
);
1863 maxptr
= ptr
+ length
;
1865 while (ptr
< maxptr
)
1867 ptr
= tir_cmd (abfd
, ptr
);
1875 /* Text Information and Relocation Records (EOBJ$C_ETIR)
1876 handle etir record */
1879 analyze_etir (abfd
, ptr
, length
)
1882 unsigned int length
;
1885 unsigned char *maxptr
;
1889 _bfd_vms_debug (3, "analyze_etir: %d bytes\n", length
);
1892 maxptr
= ptr
+ length
;
1894 while (ptr
< maxptr
)
1896 cmd
= bfd_getl16 (ptr
);
1897 length
= bfd_getl16 (ptr
+ 2);
1898 result
= etir_cmd (abfd
, cmd
, ptr
+4);
1905 _bfd_vms_debug (3, "analyze_etir: = %d\n", result
);
1911 /* process ETIR record
1913 return 0 on success, -1 on error */
1916 _bfd_vms_slurp_tir (abfd
, objtype
)
1923 _bfd_vms_debug (2, "TIR/ETIR\n");
1929 PRIV (vms_rec
) += 4; /* skip type, size */
1930 PRIV (rec_size
) -= 4;
1931 result
= analyze_etir (abfd
, PRIV (vms_rec
), (unsigned) PRIV (rec_size
));
1934 PRIV (vms_rec
) += 1; /* skip type */
1935 PRIV (rec_size
) -= 1;
1936 result
= analyze_tir (abfd
, PRIV (vms_rec
), (unsigned) PRIV (rec_size
));
1946 /* process EDBG record
1947 return 0 on success, -1 on error
1949 not implemented yet */
1952 _bfd_vms_slurp_dbg (abfd
, objtype
)
1954 int objtype ATTRIBUTE_UNUSED
;
1957 _bfd_vms_debug (2, "DBG/EDBG\n");
1960 abfd
->flags
|= (HAS_DEBUG
| HAS_LINENO
);
1964 /* process ETBT record
1965 return 0 on success, -1 on error
1967 not implemented yet */
1970 _bfd_vms_slurp_tbt (abfd
, objtype
)
1971 bfd
*abfd ATTRIBUTE_UNUSED
;
1972 int objtype ATTRIBUTE_UNUSED
;
1975 _bfd_vms_debug (2, "TBT/ETBT\n");
1981 /* process LNK record
1982 return 0 on success, -1 on error
1984 not implemented yet */
1987 _bfd_vms_slurp_lnk (abfd
, objtype
)
1988 bfd
*abfd ATTRIBUTE_UNUSED
;
1989 int objtype ATTRIBUTE_UNUSED
;
1992 _bfd_vms_debug (2, "LNK\n");
1998 /*----------------------------------------------------------------------*/
2000 /* WRITE ETIR SECTION */
2002 /* this is still under construction and therefore not documented */
2004 /*----------------------------------------------------------------------*/
2006 static void start_etir_record
PARAMS ((bfd
*abfd
, int index
, uquad offset
, boolean justoffset
));
2007 static void sto_imm
PARAMS ((bfd
*abfd
, vms_section
*sptr
, bfd_vma vaddr
, int index
));
2008 static void end_etir_record
PARAMS ((bfd
*abfd
));
2011 sto_imm (abfd
, sptr
, vaddr
, index
)
2019 unsigned char *cptr
;
2022 _bfd_vms_debug (8, "sto_imm %d bytes\n", sptr
->size
);
2023 _bfd_hexdump (9, sptr
->contents
, (int) sptr
->size
, (int) vaddr
);
2027 cptr
= sptr
->contents
;
2032 size
= ssize
; /* try all the rest */
2034 if (_bfd_vms_output_check (abfd
, size
) < 0)
2035 { /* doesn't fit, split ! */
2036 end_etir_record (abfd
);
2037 start_etir_record (abfd
, index
, vaddr
, false);
2038 size
= _bfd_vms_output_check (abfd
, 0); /* get max size */
2039 if (size
> ssize
) /* more than what's left ? */
2043 _bfd_vms_output_begin (abfd
, ETIR_S_C_STO_IMM
, -1);
2044 _bfd_vms_output_long (abfd
, (unsigned long) (size
));
2045 _bfd_vms_output_dump (abfd
, cptr
, size
);
2046 _bfd_vms_output_flush (abfd
);
2049 _bfd_vms_debug (10, "dumped %d bytes\n", size
);
2050 _bfd_hexdump (10, cptr
, (int) size
, (int) vaddr
);
2061 /*-------------------------------------------------------------------*/
2063 /* start ETIR record for section #index at virtual addr offset. */
2066 start_etir_record (abfd
, index
, offset
, justoffset
)
2074 _bfd_vms_output_begin (abfd
, EOBJ_S_C_ETIR
, -1); /* one ETIR per section */
2075 _bfd_vms_output_push (abfd
);
2078 _bfd_vms_output_begin (abfd
, ETIR_S_C_STA_PQ
, -1); /* push start offset */
2079 _bfd_vms_output_long (abfd
, (unsigned long) index
);
2080 _bfd_vms_output_quad (abfd
, (uquad
) offset
);
2081 _bfd_vms_output_flush (abfd
);
2083 _bfd_vms_output_begin (abfd
, ETIR_S_C_CTL_SETRB
, -1); /* start = pop () */
2084 _bfd_vms_output_flush (abfd
);
2089 /* end etir record */
2091 end_etir_record (abfd
)
2094 _bfd_vms_output_pop (abfd
);
2095 _bfd_vms_output_end (abfd
);
2098 /* write section contents for bfd abfd */
2101 _bfd_vms_write_tir (abfd
, objtype
)
2103 int objtype ATTRIBUTE_UNUSED
;
2110 _bfd_vms_debug (2, "vms_write_tir (%p, %d)\n", abfd
, objtype
);
2113 _bfd_vms_output_alignment (abfd
, 4);
2116 PRIV (vms_linkage_index
) = 1;
2118 /* dump all other sections */
2120 section
= abfd
->sections
;
2122 while (section
!= NULL
)
2126 _bfd_vms_debug (4, "writing %d. section '%s' (%d bytes)\n",
2127 section
->index
, section
->name
,
2128 (int) (section
->_raw_size
));
2131 if (section
->flags
& SEC_RELOC
)
2135 if ((i
= section
->reloc_count
) <= 0)
2137 (*_bfd_error_handler
) (_("SEC_RELOC with no relocs in section %s"),
2144 _bfd_vms_debug (4, "%d relocations:\n", i
);
2145 rptr
= section
->orelocation
;
2148 _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, addr %08lx, off %08lx, len %d: %s\n",
2149 (*(*rptr
)->sym_ptr_ptr
)->name
,
2150 (*(*rptr
)->sym_ptr_ptr
)->section
->name
,
2151 (long) (*(*rptr
)->sym_ptr_ptr
)->value
,
2152 (*rptr
)->address
, (*rptr
)->addend
,
2153 bfd_get_reloc_size ((*rptr
)->howto
),
2154 (*rptr
)->howto
->name
);
2161 if ((section
->flags
& SEC_HAS_CONTENTS
)
2162 && (! bfd_is_com_section (section
)))
2164 bfd_vma vaddr
; /* virtual addr in section */
2166 sptr
= _bfd_get_vms_section (abfd
, section
->index
);
2169 bfd_set_error (bfd_error_no_contents
);
2173 vaddr
= (bfd_vma
) (sptr
->offset
);
2175 start_etir_record (abfd
, section
->index
, (uquad
) sptr
->offset
,
2178 while (sptr
!= NULL
) /* one STA_PQ, CTL_SETRB per vms_section */
2181 if (section
->flags
& SEC_RELOC
) /* check for relocs */
2183 arelent
**rptr
= section
->orelocation
;
2184 int i
= section
->reloc_count
;
2187 bfd_size_type addr
= (*rptr
)->address
;
2188 bfd_size_type len
= bfd_get_reloc_size ((*rptr
)->howto
);
2189 if (sptr
->offset
< addr
) /* sptr starts before reloc */
2191 bfd_size_type before
= addr
- sptr
->offset
;
2192 if (sptr
->size
<= before
) /* complete before */
2194 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2195 vaddr
+= sptr
->size
;
2198 else /* partly before */
2200 int after
= sptr
->size
- before
;
2201 sptr
->size
= before
;
2202 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2203 vaddr
+= sptr
->size
;
2204 sptr
->contents
+= before
;
2205 sptr
->offset
+= before
;
2209 else if (sptr
->offset
== addr
) /* sptr starts at reloc */
2211 asymbol
*sym
= *(*rptr
)->sym_ptr_ptr
;
2212 asection
*sec
= sym
->section
;
2214 switch ((*rptr
)->howto
->type
)
2216 case ALPHA_R_IGNORE
:
2219 case ALPHA_R_REFLONG
:
2221 if (bfd_is_und_section (sym
->section
))
2223 int slen
= strlen ((char *) sym
->name
);
2226 if (_bfd_vms_output_check (abfd
, slen
) < 0)
2228 end_etir_record (abfd
);
2229 start_etir_record (abfd
,
2233 _bfd_vms_output_begin (abfd
,
2234 ETIR_S_C_STO_GBL_LW
,
2236 hash
= (_bfd_vms_length_hash_symbol
2237 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2238 _bfd_vms_output_counted (abfd
, hash
);
2239 _bfd_vms_output_flush (abfd
);
2241 else if (bfd_is_abs_section (sym
->section
))
2243 if (_bfd_vms_output_check (abfd
, 16) < 0)
2245 end_etir_record (abfd
);
2246 start_etir_record (abfd
,
2250 _bfd_vms_output_begin (abfd
,
2253 _bfd_vms_output_quad (abfd
,
2254 (uquad
) sym
->value
);
2255 _bfd_vms_output_flush (abfd
);
2256 _bfd_vms_output_begin (abfd
,
2259 _bfd_vms_output_flush (abfd
);
2263 if (_bfd_vms_output_check (abfd
, 32) < 0)
2265 end_etir_record (abfd
);
2266 start_etir_record (abfd
,
2270 _bfd_vms_output_begin (abfd
,
2273 _bfd_vms_output_long (abfd
,
2274 (unsigned long) (sec
->index
));
2275 _bfd_vms_output_quad (abfd
,
2276 ((uquad
) (*rptr
)->addend
2277 + (uquad
) sym
->value
));
2278 _bfd_vms_output_flush (abfd
);
2279 _bfd_vms_output_begin (abfd
,
2282 _bfd_vms_output_flush (abfd
);
2287 case ALPHA_R_REFQUAD
:
2289 if (bfd_is_und_section (sym
->section
))
2291 int slen
= strlen ((char *) sym
->name
);
2293 if (_bfd_vms_output_check (abfd
, slen
) < 0)
2295 end_etir_record (abfd
);
2296 start_etir_record (abfd
,
2300 _bfd_vms_output_begin (abfd
,
2303 hash
= (_bfd_vms_length_hash_symbol
2304 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2305 _bfd_vms_output_counted (abfd
, hash
);
2306 _bfd_vms_output_flush (abfd
);
2308 else if (bfd_is_abs_section (sym
->section
))
2310 if (_bfd_vms_output_check (abfd
, 16) < 0)
2312 end_etir_record (abfd
);
2313 start_etir_record (abfd
,
2317 _bfd_vms_output_begin (abfd
,
2320 _bfd_vms_output_quad (abfd
,
2321 (uquad
) sym
->value
);
2322 _bfd_vms_output_flush (abfd
);
2323 _bfd_vms_output_begin (abfd
,
2326 _bfd_vms_output_flush (abfd
);
2330 if (_bfd_vms_output_check (abfd
, 32) < 0)
2332 end_etir_record (abfd
);
2333 start_etir_record (abfd
,
2337 _bfd_vms_output_begin (abfd
,
2340 _bfd_vms_output_long (abfd
,
2341 (unsigned long) (sec
->index
));
2342 _bfd_vms_output_quad (abfd
,
2343 ((uquad
) (*rptr
)->addend
2344 + (uquad
) sym
->value
));
2345 _bfd_vms_output_flush (abfd
);
2346 _bfd_vms_output_begin (abfd
,
2349 _bfd_vms_output_flush (abfd
);
2357 char *hash ATTRIBUTE_UNUSED
;
2359 hint_size
= sptr
->size
;
2361 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2362 sptr
->size
= hint_size
;
2364 vms_output_begin (abfd
,
2365 ETIR_S_C_STO_HINT_GBL
, -1);
2366 vms_output_long (abfd
,
2367 (unsigned long) (sec
->index
));
2368 vms_output_quad (abfd
, (uquad
) addr
);
2370 hash
= (_bfd_vms_length_hash_symbol
2371 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2372 vms_output_counted (abfd
, hash
);
2374 vms_output_flush (abfd
);
2378 case ALPHA_R_LINKAGE
:
2382 if (_bfd_vms_output_check (abfd
, 64) < 0)
2384 end_etir_record (abfd
);
2385 start_etir_record (abfd
, section
->index
,
2388 _bfd_vms_output_begin (abfd
,
2389 ETIR_S_C_STC_LP_PSB
,
2391 _bfd_vms_output_long (abfd
,
2392 (unsigned long) PRIV (vms_linkage_index
));
2393 PRIV (vms_linkage_index
) += 2;
2394 hash
= (_bfd_vms_length_hash_symbol
2395 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2396 _bfd_vms_output_counted (abfd
, hash
);
2397 _bfd_vms_output_byte (abfd
, 0);
2398 _bfd_vms_output_flush (abfd
);
2402 case ALPHA_R_CODEADDR
:
2404 int slen
= strlen ((char *) sym
->name
);
2406 if (_bfd_vms_output_check (abfd
, slen
) < 0)
2408 end_etir_record (abfd
);
2409 start_etir_record (abfd
,
2413 _bfd_vms_output_begin (abfd
,
2416 hash
= (_bfd_vms_length_hash_symbol
2417 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2418 _bfd_vms_output_counted (abfd
, hash
);
2419 _bfd_vms_output_flush (abfd
);
2424 (*_bfd_error_handler
) (_("Unhandled relocation %s"),
2425 (*rptr
)->howto
->name
);
2431 if (len
== sptr
->size
)
2437 sptr
->contents
+= len
;
2438 sptr
->offset
+= len
;
2444 else /* sptr starts after reloc */
2446 i
--; /* check next reloc */
2450 if (i
==0) /* all reloc checked */
2455 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2456 vaddr
+= sptr
->size
;
2461 } /* if SEC_RELOC */
2462 else /* no relocs, just dump */
2464 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2465 vaddr
+= sptr
->size
;
2470 } /* while (sptr != 0) */
2472 end_etir_record (abfd
);
2474 } /* has_contents */
2476 section
= section
->next
;
2479 _bfd_vms_output_alignment (abfd
, 2);
2483 /* write traceback data for bfd abfd */
2486 _bfd_vms_write_tbt (abfd
, objtype
)
2487 bfd
*abfd ATTRIBUTE_UNUSED
;
2488 int objtype ATTRIBUTE_UNUSED
;
2491 _bfd_vms_debug (2, "vms_write_tbt (%p, %d)\n", abfd
, objtype
);
2497 /* write debug info for bfd abfd */
2500 _bfd_vms_write_dbg (abfd
, objtype
)
2501 bfd
*abfd ATTRIBUTE_UNUSED
;
2502 int objtype ATTRIBUTE_UNUSED
;
2505 _bfd_vms_debug (2, "vms_write_dbg (%p, objtype)\n", abfd
, objtype
);