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)
45 static void image_set_ptr
PARAMS ((bfd
*abfd
, int psect
, uquad offset
));
46 static void image_inc_ptr
PARAMS ((bfd
*abfd
, uquad offset
));
47 static void image_dump
PARAMS ((bfd
*abfd
, unsigned char *ptr
, int size
, int offset
));
48 static void image_write_b
PARAMS ((bfd
*abfd
, unsigned int value
));
49 static void image_write_w
PARAMS ((bfd
*abfd
, unsigned int value
));
50 static void image_write_l
PARAMS ((bfd
*abfd
, unsigned long value
));
51 static void image_write_q
PARAMS ((bfd
*abfd
, uquad value
));
52 static int check_section
PARAMS ((bfd
*, int));
53 static boolean etir_sta
PARAMS ((bfd
*, int, unsigned char *));
54 static boolean etir_sto
PARAMS ((bfd
*, int, unsigned char *));
55 static boolean etir_opr
PARAMS ((bfd
*, int, unsigned char *));
56 static boolean etir_ctl
PARAMS ((bfd
*, int, unsigned char *));
57 static boolean etir_stc
PARAMS ((bfd
*, int, unsigned char *));
58 static asection
*new_section
PARAMS ((bfd
*, int));
59 static int alloc_section
PARAMS ((bfd
*, unsigned int));
60 static int etir_cmd
PARAMS ((bfd
*, int, unsigned char *));
61 static int analyze_tir
PARAMS ((bfd
*, unsigned char *, unsigned int));
62 static int analyze_etir
PARAMS ((bfd
*, unsigned char *, unsigned int));
64 /*-----------------------------------------------------------------------------*/
67 check_section (abfd
, size
)
73 offset
= PRIV (image_ptr
) - PRIV (image_section
)->contents
;
74 if (offset
+ size
> PRIV (image_section
)->_raw_size
)
76 PRIV (image_section
)->contents
77 = bfd_realloc (PRIV (image_section
)->contents
, offset
+ size
);
78 if (PRIV (image_section
)->contents
== 0)
80 (*_bfd_error_handler
) (_("No Mem !"));
83 PRIV (image_section
)->_raw_size
= offset
+ size
;
84 PRIV (image_ptr
) = PRIV (image_section
)->contents
+ offset
;
90 /* routines to fill sections contents during tir/etir read */
92 /* Initialize image buffer pointer to be filled */
95 image_set_ptr (abfd
, psect
, offset
)
101 _bfd_vms_debug (4, "image_set_ptr (%d=%s, %d)\n",
102 psect
, PRIV (sections
)[psect
]->name
, offset
);
105 PRIV (image_ptr
) = PRIV (sections
)[psect
]->contents
+ offset
;
106 PRIV (image_section
) = PRIV (sections
)[psect
];
110 /* Increment image buffer pointer by offset */
113 image_inc_ptr (abfd
, offset
)
118 _bfd_vms_debug (4, "image_inc_ptr (%d)\n", offset
);
121 PRIV (image_ptr
) += offset
;
126 /* Dump multiple bytes to section image */
129 image_dump (abfd
, ptr
, size
, offset
)
133 int offset ATTRIBUTE_UNUSED
;
136 _bfd_vms_debug (8, "image_dump from (%p, %d) to (%p)\n", ptr
, size
,
138 _bfd_hexdump (9, ptr
, size
, offset
);
141 if (PRIV (is_vax
) && check_section (abfd
, size
))
145 *PRIV (image_ptr
)++ = *ptr
++;
149 /* Write byte to section image */
152 image_write_b (abfd
, value
)
157 _bfd_vms_debug (6, "image_write_b(%02x)\n", (int) value
);
160 if (PRIV (is_vax
) && check_section (abfd
, 1))
163 *PRIV (image_ptr
)++ = (value
& 0xff);
167 /* Write 2-byte word to image */
170 image_write_w (abfd
, value
)
175 _bfd_vms_debug (6, "image_write_w(%04x)\n", (int) value
);
178 if (PRIV (is_vax
) && check_section (abfd
, 2))
181 bfd_putl16 ((bfd_vma
) value
, PRIV (image_ptr
));
182 PRIV (image_ptr
) += 2;
187 /* Write 4-byte long to image */
190 image_write_l (abfd
, value
)
195 _bfd_vms_debug (6, "image_write_l (%08lx)\n", value
);
198 if (PRIV (is_vax
) && check_section (abfd
, 4))
201 bfd_putl32 ((bfd_vma
) value
, PRIV (image_ptr
));
202 PRIV (image_ptr
) += 4;
207 /* Write 8-byte quad to image */
210 image_write_q (abfd
, value
)
215 _bfd_vms_debug (6, "image_write_q (%016lx)\n", value
);
218 if (PRIV (is_vax
) && check_section (abfd
, 8))
221 bfd_putl64 (value
, PRIV (image_ptr
));
222 PRIV (image_ptr
) += 8;
228 #define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L)
234 handle sta_xxx commands in etir section
235 ptr points to data area in record
237 see table B-8 of the openVMS linker manual */
240 etir_sta (abfd
, cmd
, ptr
)
247 _bfd_vms_debug (5, "etir_sta %d/%x\n", cmd
, cmd
);
248 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
258 stack 32 bit value of symbol (high bits set to 0) */
260 case ETIR_S_C_STA_GBL
:
263 vms_symbol_entry
*entry
;
265 name
= _bfd_vms_save_counted_string (ptr
);
266 entry
= (vms_symbol_entry
*)
267 bfd_hash_lookup (PRIV (vms_symbol_table
), name
, false, false);
268 if (entry
== (vms_symbol_entry
*) NULL
)
271 _bfd_vms_debug (3, "ETIR_S_C_STA_GBL: no symbol \"%s\"\n", name
);
273 _bfd_vms_push (abfd
, (uquad
) 0, -1);
277 _bfd_vms_push (abfd
, (uquad
) (entry
->symbol
->value
), -1);
285 stack 32 bit value, sign extend to 64 bit */
287 case ETIR_S_C_STA_LW
:
288 _bfd_vms_push (abfd
, (uquad
) bfd_getl32 (ptr
), -1);
294 stack 64 bit value of symbol */
296 case ETIR_S_C_STA_QW
:
297 _bfd_vms_push (abfd
, (uquad
) bfd_getl64 (ptr
), -1);
300 /* stack psect base plus quadword offset
301 arg: lw section index
302 qw signed quadword offset (low 32 bits)
304 stack qw argument and section index
305 (see ETIR_S_C_STO_OFF, ETIR_S_C_CTL_SETRB) */
307 case ETIR_S_C_STA_PQ
:
312 psect
= bfd_getl32 (ptr
);
313 if (psect
>= PRIV (section_count
))
315 (*_bfd_error_handler
) (_("Bad section index in ETIR_S_C_STA_PQ"));
316 bfd_set_error (bfd_error_bad_value
);
319 dummy
= bfd_getl64 (ptr
+4);
320 _bfd_vms_push (abfd
, dummy
, (int) psect
);
324 /* all not supported */
326 case ETIR_S_C_STA_LI
:
327 case ETIR_S_C_STA_MOD
:
328 case ETIR_S_C_STA_CKARG
:
330 (*_bfd_error_handler
) (_("Unsupported STA cmd %d"), cmd
);
335 (*_bfd_error_handler
) (_("Reserved STA cmd %d"), cmd
);
340 _bfd_vms_debug (5, "etir_sta true\n");
350 handle sto_xxx commands in etir section
351 ptr points to data area in record
353 see table B-9 of the openVMS linker manual */
356 etir_sto (abfd
, cmd
, ptr
)
365 _bfd_vms_debug (5, "etir_sto %d/%x\n", cmd
, cmd
);
366 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
372 /* store byte: pop stack, write byte
376 dummy
= _bfd_vms_pop (abfd
, &psect
);
378 if (is_share
) /* FIXME */
379 (*_bfd_error_handler
) ("ETIR_S_C_STO_B: byte fixups not supported");
381 /* FIXME: check top bits */
382 image_write_b (abfd
, (unsigned int) dummy
& 0xff);
385 /* store word: pop stack, write word
389 dummy
= _bfd_vms_pop (abfd
, &psect
);
391 if (is_share
) /* FIXME */
392 (*_bfd_error_handler
) ("ETIR_S_C_STO_B: word fixups not supported");
394 /* FIXME: check top bits */
395 image_write_w (abfd
, (unsigned int) dummy
& 0xffff);
398 /* store longword: pop stack, write longword
401 case ETIR_S_C_STO_LW
:
402 dummy
= _bfd_vms_pop (abfd
, &psect
);
403 dummy
+= (PRIV (sections
)[psect
])->vma
;
404 /* FIXME: check top bits */
405 image_write_l (abfd
, (unsigned int) dummy
& 0xffffffff);
408 /* store quadword: pop stack, write quadword
411 case ETIR_S_C_STO_QW
:
412 dummy
= _bfd_vms_pop (abfd
, &psect
);
413 dummy
+= (PRIV (sections
)[psect
])->vma
;
414 image_write_q (abfd
, dummy
); /* FIXME: check top bits */
417 /* store immediate repeated: pop stack for repeat count
421 case ETIR_S_C_STO_IMMR
:
425 size
= bfd_getl32 (ptr
);
426 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
428 image_dump (abfd
, ptr
+4, size
, 0);
432 /* store global: write symbol value
433 arg: cs global symbol name */
435 case ETIR_S_C_STO_GBL
:
437 vms_symbol_entry
*entry
;
440 name
= _bfd_vms_save_counted_string (ptr
);
441 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV (vms_symbol_table
),
443 if (entry
== (vms_symbol_entry
*) NULL
)
445 (*_bfd_error_handler
) (_("ETIR_S_C_STO_GBL: no symbol \"%s\""),
450 image_write_q (abfd
, (uquad
) (entry
->symbol
->value
)); /* FIXME, reloc */
454 /* store code address: write address of entry point
455 arg: cs global symbol name (procedure) */
457 case ETIR_S_C_STO_CA
:
459 vms_symbol_entry
*entry
;
462 name
= _bfd_vms_save_counted_string (ptr
);
463 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV (vms_symbol_table
),
465 if (entry
== (vms_symbol_entry
*) NULL
)
467 (*_bfd_error_handler
) (_("ETIR_S_C_STO_CA: no symbol \"%s\""),
472 image_write_q (abfd
, (uquad
) (entry
->symbol
->value
)); /* FIXME, reloc */
478 case ETIR_S_C_STO_RB
:
479 case ETIR_S_C_STO_AB
:
480 (*_bfd_error_handler
) (_("ETIR_S_C_STO_RB/AB: Not supported"));
483 /* store offset to psect: pop stack, add low 32 bits to base of psect
486 case ETIR_S_C_STO_OFF
:
491 q
= _bfd_vms_pop (abfd
, &psect1
);
492 q
+= (PRIV (sections
)[psect1
])->vma
;
493 image_write_q (abfd
, q
);
498 arg: lw count of bytes
501 case ETIR_S_C_STO_IMM
:
505 size
= bfd_getl32 (ptr
);
506 image_dump (abfd
, ptr
+4, size
, 0);
510 /* this code is 'reserved to digital' according to the openVMS
511 linker manual, however it is generated by the DEC C compiler
512 and defined in the include file.
513 FIXME, since the following is just a guess
514 store global longword: store 32bit value of symbol
515 arg: cs symbol name */
517 case ETIR_S_C_STO_GBL_LW
:
519 vms_symbol_entry
*entry
;
522 name
= _bfd_vms_save_counted_string (ptr
);
523 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV (vms_symbol_table
),
525 if (entry
== (vms_symbol_entry
*) NULL
)
528 _bfd_vms_debug (3, "ETIR_S_C_STO_GBL_LW: no symbol \"%s\"\n", name
);
530 image_write_l (abfd
, (unsigned long) 0); /* FIXME, reloc */
533 image_write_l (abfd
, (unsigned long) (entry
->symbol
->value
)); /* FIXME, reloc */
539 case ETIR_S_C_STO_LP_PSB
:
540 (*_bfd_error_handler
) (_("ETIR_S_C_STO_LP_PSB: Not supported"));
545 case ETIR_S_C_STO_HINT_GBL
:
546 (*_bfd_error_handler
) (_("ETIR_S_C_STO_HINT_GBL: not implemented"));
551 case ETIR_S_C_STO_HINT_PS
:
552 (*_bfd_error_handler
) (_("ETIR_S_C_STO_HINT_PS: not implemented"));
556 (*_bfd_error_handler
) (_("Reserved STO cmd %d"), cmd
);
563 /* stack operator commands
564 all 32 bit signed arithmetic
565 all word just like a stack calculator
566 arguments are popped from stack, results are pushed on stack
568 see table B-10 of the openVMS linker manual */
571 etir_opr (abfd
, cmd
, ptr
)
574 unsigned char *ptr ATTRIBUTE_UNUSED
;
579 _bfd_vms_debug (5, "etir_opr %d/%x\n", cmd
, cmd
);
580 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
589 case ETIR_S_C_OPR_NOP
:
594 case ETIR_S_C_OPR_ADD
:
595 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
596 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
597 _bfd_vms_push (abfd
, (uquad
) (op1
+ op2
), -1);
602 case ETIR_S_C_OPR_SUB
:
603 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
604 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
605 _bfd_vms_push (abfd
, (uquad
) (op2
- op1
), -1);
610 case ETIR_S_C_OPR_MUL
:
611 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
612 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
613 _bfd_vms_push (abfd
, (uquad
) (op1
* op2
), -1);
618 case ETIR_S_C_OPR_DIV
:
619 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
620 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
622 _bfd_vms_push (abfd
, (uquad
) 0, -1);
624 _bfd_vms_push (abfd
, (uquad
) (op2
/ op1
), -1);
629 case ETIR_S_C_OPR_AND
:
630 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
631 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
632 _bfd_vms_push (abfd
, (uquad
) (op1
& op2
), -1);
635 /* logical inclusive or */
637 case ETIR_S_C_OPR_IOR
:
638 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
639 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
640 _bfd_vms_push (abfd
, (uquad
) (op1
| op2
), -1);
643 /* logical exclusive or */
645 case ETIR_S_C_OPR_EOR
:
646 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
647 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
648 _bfd_vms_push (abfd
, (uquad
) (op1
^ op2
), -1);
653 case ETIR_S_C_OPR_NEG
:
654 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
655 _bfd_vms_push (abfd
, (uquad
) (-op1
), -1);
660 case ETIR_S_C_OPR_COM
:
661 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
662 _bfd_vms_push (abfd
, (uquad
) (op1
^ -1L), -1);
667 case ETIR_S_C_OPR_INSV
:
668 (void) _bfd_vms_pop (abfd
, NULL
);
669 (*_bfd_error_handler
) (_("ETIR_S_C_OPR_INSV: Not supported"));
672 /* arithmetic shift */
674 case ETIR_S_C_OPR_ASH
:
675 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
676 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
677 if (op2
< 0) /* shift right */
679 else /* shift left */
681 _bfd_vms_push (abfd
, (uquad
) op1
, -1);
686 case ETIR_S_C_OPR_USH
:
687 (*_bfd_error_handler
) (_("ETIR_S_C_OPR_USH: Not supported"));
692 case ETIR_S_C_OPR_ROT
:
693 (*_bfd_error_handler
) (_("ETIR_S_C_OPR_ROT: Not supported"));
698 case ETIR_S_C_OPR_SEL
:
699 if ((long) _bfd_vms_pop (abfd
, NULL
) & 0x01L
)
700 (void) _bfd_vms_pop (abfd
, NULL
);
703 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
704 (void) _bfd_vms_pop (abfd
, NULL
);
705 _bfd_vms_push (abfd
, (uquad
) op1
, -1);
709 /* redefine symbol to current location */
711 case ETIR_S_C_OPR_REDEF
:
712 (*_bfd_error_handler
) (_("ETIR_S_C_OPR_REDEF: Not supported"));
715 /* define a literal */
717 case ETIR_S_C_OPR_DFLIT
:
718 (*_bfd_error_handler
) (_("ETIR_S_C_OPR_DFLIT: Not supported"));
722 (*_bfd_error_handler
) (_("Reserved OPR cmd %d"), cmd
);
731 see table B-11 of the openVMS linker manual */
734 etir_ctl (abfd
, cmd
, ptr
)
743 _bfd_vms_debug (5, "etir_ctl %d/%x\n", cmd
, cmd
);
744 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
749 /* set relocation base: pop stack, set image location counter
752 case ETIR_S_C_CTL_SETRB
:
753 dummy
= _bfd_vms_pop (abfd
, &psect
);
754 image_set_ptr (abfd
, psect
, dummy
);
757 /* augment relocation base: increment image location counter by offset
758 arg: lw offset value */
760 case ETIR_S_C_CTL_AUGRB
:
761 dummy
= bfd_getl32 (ptr
);
762 image_inc_ptr (abfd
, dummy
);
765 /* define location: pop index, save location counter under index
768 case ETIR_S_C_CTL_DFLOC
:
769 dummy
= _bfd_vms_pop (abfd
, NULL
);
773 /* set location: pop index, restore location counter from index
776 case ETIR_S_C_CTL_STLOC
:
777 dummy
= _bfd_vms_pop (abfd
, &psect
);
781 /* stack defined location: pop index, push location counter from index
784 case ETIR_S_C_CTL_STKDL
:
785 dummy
= _bfd_vms_pop (abfd
, &psect
);
790 (*_bfd_error_handler
) (_("Reserved CTL cmd %d"), cmd
);
796 /* store conditional commands
798 see table B-12 and B-13 of the openVMS linker manual */
801 etir_stc (abfd
, cmd
, ptr
)
804 unsigned char *ptr ATTRIBUTE_UNUSED
;
808 _bfd_vms_debug (5, "etir_stc %d/%x\n", cmd
, cmd
);
809 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
814 /* 200 Store-conditional Linkage Pair
817 case ETIR_S_C_STC_LP
:
818 (*_bfd_error_handler
) (_("ETIR_S_C_STC_LP: not supported"));
821 /* 201 Store-conditional Linkage Pair with Procedure Signature
822 arg: lw linkage index
827 case ETIR_S_C_STC_LP_PSB
:
828 image_inc_ptr (abfd
, (uquad
) 16); /* skip entry,procval */
831 /* 202 Store-conditional Address at global address
832 arg: lw linkage index
835 case ETIR_S_C_STC_GBL
:
836 (*_bfd_error_handler
) (_("ETIR_S_C_STC_GBL: not supported"));
839 /* 203 Store-conditional Code Address at global address
840 arg: lw linkage index
843 case ETIR_S_C_STC_GCA
:
844 (*_bfd_error_handler
) (_("ETIR_S_C_STC_GCA: not supported"));
847 /* 204 Store-conditional Address at psect + offset
848 arg: lw linkage index
852 case ETIR_S_C_STC_PS
:
853 (*_bfd_error_handler
) (_("ETIR_S_C_STC_PS: not supported"));
856 /* 205 Store-conditional NOP at address of global
859 case ETIR_S_C_STC_NOP_GBL
:
861 /* 206 Store-conditional NOP at pect + offset
864 case ETIR_S_C_STC_NOP_PS
:
866 /* 207 Store-conditional BSR at global address
869 case ETIR_S_C_STC_BSR_GBL
:
871 /* 208 Store-conditional BSR at pect + offset
874 case ETIR_S_C_STC_BSR_PS
:
876 /* 209 Store-conditional LDA at global address
879 case ETIR_S_C_STC_LDA_GBL
:
881 /* 210 Store-conditional LDA at psect + offset
884 case ETIR_S_C_STC_LDA_PS
:
886 /* 211 Store-conditional BSR or Hint at global address
889 case ETIR_S_C_STC_BOH_GBL
:
891 /* 212 Store-conditional BSR or Hint at pect + offset
894 case ETIR_S_C_STC_BOH_PS
:
896 /* 213 Store-conditional NOP,BSR or HINT at global address
899 case ETIR_S_C_STC_NBH_GBL
:
901 /* 214 Store-conditional NOP,BSR or HINT at psect + offset
904 case ETIR_S_C_STC_NBH_PS
:
907 (*_bfd_error_handler
) ("ETIR_S_C_STC_xx: (%d) not supported", cmd
);
913 _bfd_vms_debug (3, "Reserved STC cmd %d", cmd
);
921 new_section (abfd
, idx
)
922 bfd
*abfd ATTRIBUTE_UNUSED
;
930 _bfd_vms_debug (5, "new_section %d\n", idx
);
932 sprintf (sname
, SECTION_NAME_TEMPLATE
, idx
);
934 name
= bfd_malloc ((bfd_size_type
) strlen (sname
) + 1);
937 strcpy (name
, sname
);
939 section
= bfd_malloc ((bfd_size_type
) sizeof (asection
));
943 _bfd_vms_debug (6, "bfd_make_section (%s) failed", name
);
948 section
->_raw_size
= 0;
950 section
->contents
= 0;
951 section
->_cooked_size
= 0;
952 section
->name
= name
;
953 section
->index
= idx
;
959 alloc_section (abfd
, idx
)
966 _bfd_vms_debug (4, "alloc_section %d\n", idx
);
970 amt
*= sizeof (asection
*);
971 PRIV (sections
) = (asection
**) bfd_realloc (PRIV (sections
), amt
);
972 if (PRIV (sections
) == 0)
975 while (PRIV (section_count
) <= idx
)
977 PRIV (sections
)[PRIV (section_count
)]
978 = new_section (abfd
, (int) PRIV (section_count
));
979 if (PRIV (sections
)[PRIV (section_count
)] == 0)
981 PRIV (section_count
)++;
992 * handle sta_xxx commands in tir section
993 * ptr points to data area in record
995 * see table 7-3 of the VAX/VMS linker manual
998 static unsigned char *
999 tir_sta (bfd
*abfd
, unsigned char *ptr
)
1004 _bfd_vms_debug (5, "tir_sta %d\n", cmd
);
1010 case TIR_S_C_STA_GBL
:
1013 * arg: cs symbol name
1015 * stack 32 bit value of symbol (high bits set to 0)
1019 vms_symbol_entry
*entry
;
1021 name
= _bfd_vms_save_counted_string (ptr
);
1023 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1024 if (entry
== (vms_symbol_entry
*) NULL
)
1027 _bfd_vms_push (abfd
, (uquad
) (entry
->symbol
->value
), -1);
1032 case TIR_S_C_STA_SB
:
1037 * stack byte value, sign extend to 32 bit
1039 _bfd_vms_push (abfd
, (uquad
) *ptr
++, -1);
1042 case TIR_S_C_STA_SW
:
1044 * stack signed short word
1047 * stack 16 bit value, sign extend to 32 bit
1049 _bfd_vms_push (abfd
, (uquad
) bfd_getl16 (ptr
), -1);
1053 case TIR_S_C_STA_LW
:
1055 * stack signed longword
1058 * stack 32 bit value
1060 _bfd_vms_push (abfd
, (uquad
) bfd_getl32 (ptr
), -1);
1064 case TIR_S_C_STA_PB
:
1065 case TIR_S_C_STA_WPB
:
1067 * stack psect base plus byte offset (word index)
1068 * arg: by section index
1069 * (sh section index)
1070 * by signed byte offset
1074 unsigned long dummy
;
1077 if (cmd
== TIR_S_C_STA_PB
)
1081 psect
= bfd_getl16 (ptr
);
1085 if (psect
>= PRIV (section_count
))
1087 alloc_section (abfd
, psect
);
1090 dummy
= (long) *ptr
++;
1091 dummy
+= (PRIV (sections
)[psect
])->vma
;
1092 _bfd_vms_push (abfd
, (uquad
) dummy
, (int) psect
);
1096 case TIR_S_C_STA_PW
:
1097 case TIR_S_C_STA_WPW
:
1099 * stack psect base plus word offset (word index)
1100 * arg: by section index
1101 * (sh section index)
1102 * sh signed short offset
1106 unsigned long dummy
;
1109 if (cmd
== TIR_S_C_STA_PW
)
1113 psect
= bfd_getl16 (ptr
);
1117 if (psect
>= PRIV (section_count
))
1119 alloc_section (abfd
, psect
);
1122 dummy
= bfd_getl16 (ptr
); ptr
+=2;
1123 dummy
+= (PRIV (sections
)[psect
])->vma
;
1124 _bfd_vms_push (abfd
, (uquad
) dummy
, (int) psect
);
1128 case TIR_S_C_STA_PL
:
1129 case TIR_S_C_STA_WPL
:
1131 * stack psect base plus long offset (word index)
1132 * arg: by section index
1133 * (sh section index)
1134 * lw signed longword offset
1138 unsigned long dummy
;
1141 if (cmd
== TIR_S_C_STA_PL
)
1145 psect
= bfd_getl16 (ptr
);
1149 if (psect
>= PRIV (section_count
))
1151 alloc_section (abfd
, psect
);
1154 dummy
= bfd_getl32 (ptr
); ptr
+= 4;
1155 dummy
+= (PRIV (sections
)[psect
])->vma
;
1156 _bfd_vms_push (abfd
, (uquad
) dummy
, (int) psect
);
1160 case TIR_S_C_STA_UB
:
1162 * stack unsigned byte
1167 _bfd_vms_push (abfd
, (uquad
) *ptr
++, -1);
1170 case TIR_S_C_STA_UW
:
1172 * stack unsigned short word
1175 * stack 16 bit value
1177 _bfd_vms_push (abfd
, (uquad
) bfd_getl16 (ptr
), -1);
1181 case TIR_S_C_STA_BFI
:
1183 * stack byte from image
1188 case TIR_S_C_STA_WFI
:
1190 * stack byte from image
1195 case TIR_S_C_STA_LFI
:
1197 * stack byte from image
1201 (*_bfd_error_handler
) (_("Stack-from-image not implemented"));
1204 case TIR_S_C_STA_EPM
:
1206 * stack entry point mask
1207 * arg: cs symbol name
1209 * stack (unsigned) entry point mask of symbol
1210 * err if symbol is no entry point
1214 vms_symbol_entry
*entry
;
1216 name
= _bfd_vms_save_counted_string (ptr
);
1217 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1218 if (entry
== (vms_symbol_entry
*) NULL
)
1221 (*_bfd_error_handler
) (_("Stack-entry-mask not fully implemented"));
1222 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1227 case TIR_S_C_STA_CKARG
:
1229 * compare procedure argument
1230 * arg: cs symbol name
1232 * da argument descriptor
1234 * compare argument descriptor with symbol argument (ARG$V_PASSMECH)
1235 * and stack TRUE (args match) or FALSE (args dont match) value
1237 (*_bfd_error_handler
) (_("PASSMECH not fully implemented"));
1238 _bfd_vms_push (abfd
, (uquad
) 1, -1);
1241 case TIR_S_C_STA_LSY
:
1243 * stack local symbol value
1244 * arg: sh environment index
1250 vms_symbol_entry
*entry
;
1252 envidx
= bfd_getl16 (ptr
);
1254 name
= _bfd_vms_save_counted_string (ptr
);
1255 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1256 if (entry
== (vms_symbol_entry
*) NULL
)
1258 (*_bfd_error_handler
) (_("Stack-local-symbol not fully implemented"));
1259 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1264 case TIR_S_C_STA_LIT
:
1267 * arg: by literal index
1272 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1273 (*_bfd_error_handler
) (_("Stack-literal not fully implemented"));
1276 case TIR_S_C_STA_LEPM
:
1278 * stack local symbol entry point mask
1279 * arg: sh environment index
1282 * stack (unsigned) entry point mask of symbol
1283 * err if symbol is no entry point
1288 vms_symbol_entry
*entry
;
1290 envidx
= bfd_getl16 (ptr
);
1292 name
= _bfd_vms_save_counted_string (ptr
);
1293 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1294 if (entry
== (vms_symbol_entry
*) NULL
)
1296 (*_bfd_error_handler
) (_("Stack-local-symbol-entry-point-mask not fully implemented"));
1297 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1303 (*_bfd_error_handler
) (_("Reserved STA cmd %d"), ptr
[-1]);
1314 * vax store commands
1316 * handle sto_xxx commands in tir section
1317 * ptr points to data area in record
1319 * see table 7-4 of the VAX/VMS linker manual
1322 static unsigned char *
1323 tir_sto (bfd
*abfd
, unsigned char *ptr
)
1325 unsigned long dummy
;
1330 _bfd_vms_debug (5, "tir_sto %d\n", *ptr
);
1335 case TIR_S_C_STO_SB
:
1337 * store signed byte: pop stack, write byte
1340 dummy
= _bfd_vms_pop (abfd
, &psect
);
1341 image_write_b (abfd
, dummy
& 0xff); /* FIXME: check top bits */
1344 case TIR_S_C_STO_SW
:
1346 * store signed word: pop stack, write word
1349 dummy
= _bfd_vms_pop (abfd
, &psect
);
1350 image_write_w (abfd
, dummy
& 0xffff); /* FIXME: check top bits */
1353 case TIR_S_C_STO_LW
:
1355 * store longword: pop stack, write longword
1358 dummy
= _bfd_vms_pop (abfd
, &psect
);
1359 image_write_l (abfd
, dummy
& 0xffffffff); /* FIXME: check top bits */
1362 case TIR_S_C_STO_BD
:
1364 * store byte displaced: pop stack, sub lc+1, write byte
1367 dummy
= _bfd_vms_pop (abfd
, &psect
);
1368 dummy
-= ((PRIV (sections
)[psect
])->vma
+ 1);
1369 image_write_b (abfd
, dummy
& 0xff);/* FIXME: check top bits */
1372 case TIR_S_C_STO_WD
:
1374 * store word displaced: pop stack, sub lc+2, write word
1377 dummy
= _bfd_vms_pop (abfd
, &psect
);
1378 dummy
-= ((PRIV (sections
)[psect
])->vma
+ 2);
1379 image_write_w (abfd
, dummy
& 0xffff);/* FIXME: check top bits */
1381 case TIR_S_C_STO_LD
:
1383 * store long displaced: pop stack, sub lc+4, write long
1386 dummy
= _bfd_vms_pop (abfd
, &psect
);
1387 dummy
-= ((PRIV (sections
)[psect
])->vma
+ 4);
1388 image_write_l (abfd
, dummy
& 0xffffffff);/* FIXME: check top bits */
1390 case TIR_S_C_STO_LI
:
1392 * store short literal: pop stack, write byte
1395 dummy
= _bfd_vms_pop (abfd
, &psect
);
1396 image_write_b (abfd
, dummy
& 0xff);/* FIXME: check top bits */
1398 case TIR_S_C_STO_PIDR
:
1400 * store position independent data reference: pop stack, write longword
1402 * FIXME: incomplete !
1404 dummy
= _bfd_vms_pop (abfd
, &psect
);
1405 image_write_l (abfd
, dummy
& 0xffffffff);
1407 case TIR_S_C_STO_PICR
:
1409 * store position independent code reference: pop stack, write longword
1411 * FIXME: incomplete !
1413 dummy
= _bfd_vms_pop (abfd
, &psect
);
1414 image_write_b (abfd
, 0x9f);
1415 image_write_l (abfd
, dummy
& 0xffffffff);
1417 case TIR_S_C_STO_RIVB
:
1419 * store repeated immediate variable bytes
1420 * 1-byte count n field followed by n bytes of data
1421 * pop stack, write n bytes <stack> times
1424 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1425 while (dummy
-- > 0L)
1426 image_dump (abfd
, ptr
, size
, 0);
1431 * store byte from top longword
1433 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1434 image_write_b (abfd
, dummy
& 0xff);
1438 * store word from top longword
1440 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1441 image_write_w (abfd
, dummy
& 0xffff);
1443 case TIR_S_C_STO_RB
:
1445 * store repeated byte from top longword
1447 size
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1448 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1450 image_write_b (abfd
, dummy
& 0xff);
1452 case TIR_S_C_STO_RW
:
1454 * store repeated word from top longword
1456 size
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1457 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1459 image_write_w (abfd
, dummy
& 0xffff);
1462 case TIR_S_C_STO_RSB
:
1463 case TIR_S_C_STO_RSW
:
1464 case TIR_S_C_STO_RL
:
1465 case TIR_S_C_STO_VPS
:
1466 case TIR_S_C_STO_USB
:
1467 case TIR_S_C_STO_USW
:
1468 case TIR_S_C_STO_RUB
:
1469 case TIR_S_C_STO_RUW
:
1470 case TIR_S_C_STO_PIRR
:
1471 (*_bfd_error_handler
) (_("Unimplemented STO cmd %d"), ptr
[-1]);
1475 (*_bfd_error_handler
) (_("Reserved STO cmd %d"), ptr
[-1]);
1483 * stack operator commands
1484 * all 32 bit signed arithmetic
1485 * all word just like a stack calculator
1486 * arguments are popped from stack, results are pushed on stack
1488 * see table 7-5 of the VAX/VMS linker manual
1491 static unsigned char *
1492 tir_opr (bfd
*abfd
, unsigned char *ptr
)
1497 _bfd_vms_debug (5, "tir_opr %d\n", *ptr
);
1503 case TIR_S_C_OPR_NOP
:
1509 case TIR_S_C_OPR_ADD
:
1513 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1514 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1515 _bfd_vms_push (abfd
, (uquad
) (op1
+ op2
), -1);
1518 case TIR_S_C_OPR_SUB
:
1522 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1523 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1524 _bfd_vms_push (abfd
, (uquad
) (op2
- op1
), -1);
1527 case TIR_S_C_OPR_MUL
:
1531 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1532 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1533 _bfd_vms_push (abfd
, (uquad
) (op1
* op2
), -1);
1536 case TIR_S_C_OPR_DIV
:
1540 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1541 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1543 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1545 _bfd_vms_push (abfd
, (uquad
) (op2
/ op1
), -1);
1548 case TIR_S_C_OPR_AND
:
1552 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1553 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1554 _bfd_vms_push (abfd
, (uquad
) (op1
& op2
), -1);
1557 case TIR_S_C_OPR_IOR
:
1558 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1560 * logical inclusive or
1562 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1563 _bfd_vms_push (abfd
, (uquad
) (op1
| op2
), -1);
1566 case TIR_S_C_OPR_EOR
:
1568 * logical exclusive or
1570 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1571 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1572 _bfd_vms_push (abfd
, (uquad
) (op1
^ op2
), -1);
1575 case TIR_S_C_OPR_NEG
:
1579 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1580 _bfd_vms_push (abfd
, (uquad
) (-op1
), -1);
1583 case TIR_S_C_OPR_COM
:
1587 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1588 _bfd_vms_push (abfd
, (uquad
) (op1
^ -1L), -1);
1591 case TIR_S_C_OPR_INSV
:
1595 (void) _bfd_vms_pop (abfd
, NULL
);
1596 (*_bfd_error_handler
) ("TIR_S_C_OPR_INSV incomplete");
1599 case TIR_S_C_OPR_ASH
:
1603 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1604 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1605 if (HIGHBIT (op1
)) /* shift right */
1607 else /* shift left */
1609 _bfd_vms_push (abfd
, (uquad
) op2
, -1);
1610 (*_bfd_error_handler
) (_("TIR_S_C_OPR_ASH incomplete"));
1613 case TIR_S_C_OPR_USH
:
1617 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1618 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1619 if (HIGHBIT (op1
)) /* shift right */
1621 else /* shift left */
1623 _bfd_vms_push (abfd
, (uquad
) op2
, -1);
1624 (*_bfd_error_handler
) (_("TIR_S_C_OPR_USH incomplete"));
1627 case TIR_S_C_OPR_ROT
:
1631 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1632 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1633 if (HIGHBIT (0)) /* shift right */
1635 else /* shift left */
1637 _bfd_vms_push (abfd
, (uquad
) op2
, -1);
1638 (*_bfd_error_handler
) (_("TIR_S_C_OPR_ROT incomplete"));
1641 case TIR_S_C_OPR_SEL
:
1645 if ((long) _bfd_vms_pop (abfd
, NULL
) & 0x01L
)
1646 (void) _bfd_vms_pop (abfd
, NULL
);
1649 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1650 (void) _bfd_vms_pop (abfd
, NULL
);
1651 _bfd_vms_push (abfd
, (uquad
) op1
, -1);
1655 case TIR_S_C_OPR_REDEF
:
1657 * redefine symbol to current location
1659 (*_bfd_error_handler
) (_("TIR_S_C_OPR_REDEF not supported"));
1662 case TIR_S_C_OPR_DFLIT
:
1666 (*_bfd_error_handler
) (_("TIR_S_C_OPR_DFLIT not supported"));
1670 (*_bfd_error_handler
) (_("Reserved OPR cmd %d"), ptr
[-1]);
1677 static unsigned char *
1678 tir_ctl (bfd
*abfd
, unsigned char *ptr
)
1682 * see table 7-6 of the VAX/VMS linker manual
1685 unsigned long dummy
;
1689 _bfd_vms_debug (5, "tir_ctl %d\n", *ptr
);
1694 case TIR_S_C_CTL_SETRB
:
1696 * set relocation base: pop stack, set image location counter
1699 dummy
= _bfd_vms_pop (abfd
, &psect
);
1700 if (psect
>= PRIV (section_count
))
1702 alloc_section (abfd
, psect
);
1704 image_set_ptr (abfd
, (int) psect
, (uquad
) dummy
);
1706 case TIR_S_C_CTL_AUGRB
:
1708 * augment relocation base: increment image location counter by offset
1709 * arg: lw offset value
1711 dummy
= bfd_getl32 (ptr
);
1712 image_inc_ptr (abfd
, (uquad
) dummy
);
1714 case TIR_S_C_CTL_DFLOC
:
1716 * define location: pop index, save location counter under index
1719 dummy
= _bfd_vms_pop (abfd
, NULL
);
1720 (*_bfd_error_handler
) (_("TIR_S_C_CTL_DFLOC not fully implemented"));
1722 case TIR_S_C_CTL_STLOC
:
1724 * set location: pop index, restore location counter from index
1727 dummy
= _bfd_vms_pop (abfd
, &psect
);
1728 (*_bfd_error_handler
) (_("TIR_S_C_CTL_STLOC not fully implemented"));
1730 case TIR_S_C_CTL_STKDL
:
1732 * stack defined location: pop index, push location counter from index
1735 dummy
= _bfd_vms_pop (abfd
, &psect
);
1736 (*_bfd_error_handler
) (_("TIR_S_C_CTL_STKDL not fully implemented"));
1739 (*_bfd_error_handler
) (_("Reserved CTL cmd %d"), ptr
[-1]);
1746 * handle command from TIR section
1749 static unsigned char *
1750 tir_cmd (bfd
*abfd
, unsigned char *ptr
)
1756 unsigned char * (*explain
) (bfd
*, unsigned char *);
1760 { 0, TIR_S_C_MAXSTACOD
, tir_sta
},
1761 { TIR_S_C_MINSTOCOD
, TIR_S_C_MAXSTOCOD
, tir_sto
},
1762 { TIR_S_C_MINOPRCOD
, TIR_S_C_MAXOPRCOD
, tir_opr
},
1763 { TIR_S_C_MINCTLCOD
, TIR_S_C_MAXCTLCOD
, tir_ctl
},
1769 _bfd_vms_debug (4, "tir_cmd %d/%x\n", *ptr
, *ptr
);
1770 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
1773 if (*ptr
& 0x80) /* store immediate */
1775 i
= 128 - (*ptr
++ & 0x7f);
1776 image_dump (abfd
, ptr
, i
, 0);
1781 while (tir_table
[i
].mincod
>= 0)
1783 if ( (tir_table
[i
].mincod
<= *ptr
)
1784 && (*ptr
<= tir_table
[i
].maxcod
))
1786 ptr
= tir_table
[i
].explain (abfd
, ptr
);
1791 if (tir_table
[i
].mincod
< 0)
1793 (*_bfd_error_handler
) (_("Obj code %d not found"), *ptr
);
1801 /* handle command from ETIR section */
1804 etir_cmd (abfd
, cmd
, ptr
)
1813 boolean (*explain
) PARAMS ((bfd
*, int, unsigned char *));
1817 { ETIR_S_C_MINSTACOD
, ETIR_S_C_MAXSTACOD
, etir_sta
},
1818 { ETIR_S_C_MINSTOCOD
, ETIR_S_C_MAXSTOCOD
, etir_sto
},
1819 { ETIR_S_C_MINOPRCOD
, ETIR_S_C_MAXOPRCOD
, etir_opr
},
1820 { ETIR_S_C_MINCTLCOD
, ETIR_S_C_MAXCTLCOD
, etir_ctl
},
1821 { ETIR_S_C_MINSTCCOD
, ETIR_S_C_MAXSTCCOD
, etir_stc
},
1828 _bfd_vms_debug (4, "etir_cmd %d/%x\n", cmd
, cmd
);
1829 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
1832 while (etir_table
[i
].mincod
>= 0)
1834 if ( (etir_table
[i
].mincod
<= cmd
)
1835 && (cmd
<= etir_table
[i
].maxcod
))
1837 if (!etir_table
[i
].explain (abfd
, cmd
, ptr
))
1845 _bfd_vms_debug (4, "etir_cmd: = 0\n");
1850 /* Text Information and Relocation Records (OBJ$C_TIR)
1851 handle tir record */
1854 analyze_tir (abfd
, ptr
, length
)
1857 unsigned int length
;
1859 unsigned char *maxptr
;
1862 _bfd_vms_debug (3, "analyze_tir: %d bytes\n", length
);
1865 maxptr
= ptr
+ length
;
1867 while (ptr
< maxptr
)
1869 ptr
= tir_cmd (abfd
, ptr
);
1877 /* Text Information and Relocation Records (EOBJ$C_ETIR)
1878 handle etir record */
1881 analyze_etir (abfd
, ptr
, length
)
1884 unsigned int length
;
1887 unsigned char *maxptr
;
1891 _bfd_vms_debug (3, "analyze_etir: %d bytes\n", length
);
1894 maxptr
= ptr
+ length
;
1896 while (ptr
< maxptr
)
1898 cmd
= bfd_getl16 (ptr
);
1899 length
= bfd_getl16 (ptr
+ 2);
1900 result
= etir_cmd (abfd
, cmd
, ptr
+4);
1907 _bfd_vms_debug (3, "analyze_etir: = %d\n", result
);
1913 /* process ETIR record
1915 return 0 on success, -1 on error */
1918 _bfd_vms_slurp_tir (abfd
, objtype
)
1925 _bfd_vms_debug (2, "TIR/ETIR\n");
1931 PRIV (vms_rec
) += 4; /* skip type, size */
1932 PRIV (rec_size
) -= 4;
1933 result
= analyze_etir (abfd
, PRIV (vms_rec
), (unsigned) PRIV (rec_size
));
1936 PRIV (vms_rec
) += 1; /* skip type */
1937 PRIV (rec_size
) -= 1;
1938 result
= analyze_tir (abfd
, PRIV (vms_rec
), (unsigned) PRIV (rec_size
));
1948 /* process EDBG record
1949 return 0 on success, -1 on error
1951 not implemented yet */
1954 _bfd_vms_slurp_dbg (abfd
, objtype
)
1956 int objtype ATTRIBUTE_UNUSED
;
1959 _bfd_vms_debug (2, "DBG/EDBG\n");
1962 abfd
->flags
|= (HAS_DEBUG
| HAS_LINENO
);
1966 /* process ETBT record
1967 return 0 on success, -1 on error
1969 not implemented yet */
1972 _bfd_vms_slurp_tbt (abfd
, objtype
)
1973 bfd
*abfd ATTRIBUTE_UNUSED
;
1974 int objtype ATTRIBUTE_UNUSED
;
1977 _bfd_vms_debug (2, "TBT/ETBT\n");
1983 /* process LNK record
1984 return 0 on success, -1 on error
1986 not implemented yet */
1989 _bfd_vms_slurp_lnk (abfd
, objtype
)
1990 bfd
*abfd ATTRIBUTE_UNUSED
;
1991 int objtype ATTRIBUTE_UNUSED
;
1994 _bfd_vms_debug (2, "LNK\n");
2000 /*----------------------------------------------------------------------*/
2002 /* WRITE ETIR SECTION */
2004 /* this is still under construction and therefore not documented */
2006 /*----------------------------------------------------------------------*/
2008 static void start_etir_record
PARAMS ((bfd
*abfd
, int index
, uquad offset
, boolean justoffset
));
2009 static void sto_imm
PARAMS ((bfd
*abfd
, vms_section
*sptr
, bfd_vma vaddr
, int index
));
2010 static void end_etir_record
PARAMS ((bfd
*abfd
));
2013 sto_imm (abfd
, sptr
, vaddr
, index
)
2021 unsigned char *cptr
;
2024 _bfd_vms_debug (8, "sto_imm %d bytes\n", sptr
->size
);
2025 _bfd_hexdump (9, sptr
->contents
, (int) sptr
->size
, (int) vaddr
);
2029 cptr
= sptr
->contents
;
2034 size
= ssize
; /* try all the rest */
2036 if (_bfd_vms_output_check (abfd
, size
) < 0)
2037 { /* doesn't fit, split ! */
2038 end_etir_record (abfd
);
2039 start_etir_record (abfd
, index
, vaddr
, false);
2040 size
= _bfd_vms_output_check (abfd
, 0); /* get max size */
2041 if (size
> ssize
) /* more than what's left ? */
2045 _bfd_vms_output_begin (abfd
, ETIR_S_C_STO_IMM
, -1);
2046 _bfd_vms_output_long (abfd
, (unsigned long) (size
));
2047 _bfd_vms_output_dump (abfd
, cptr
, size
);
2048 _bfd_vms_output_flush (abfd
);
2051 _bfd_vms_debug (10, "dumped %d bytes\n", size
);
2052 _bfd_hexdump (10, cptr
, (int) size
, (int) vaddr
);
2063 /*-------------------------------------------------------------------*/
2065 /* start ETIR record for section #index at virtual addr offset. */
2068 start_etir_record (abfd
, index
, offset
, justoffset
)
2076 _bfd_vms_output_begin (abfd
, EOBJ_S_C_ETIR
, -1); /* one ETIR per section */
2077 _bfd_vms_output_push (abfd
);
2080 _bfd_vms_output_begin (abfd
, ETIR_S_C_STA_PQ
, -1); /* push start offset */
2081 _bfd_vms_output_long (abfd
, (unsigned long) index
);
2082 _bfd_vms_output_quad (abfd
, (uquad
) offset
);
2083 _bfd_vms_output_flush (abfd
);
2085 _bfd_vms_output_begin (abfd
, ETIR_S_C_CTL_SETRB
, -1); /* start = pop () */
2086 _bfd_vms_output_flush (abfd
);
2091 /* end etir record */
2093 end_etir_record (abfd
)
2096 _bfd_vms_output_pop (abfd
);
2097 _bfd_vms_output_end (abfd
);
2100 /* write section contents for bfd abfd */
2103 _bfd_vms_write_tir (abfd
, objtype
)
2105 int objtype ATTRIBUTE_UNUSED
;
2112 _bfd_vms_debug (2, "vms_write_tir (%p, %d)\n", abfd
, objtype
);
2115 _bfd_vms_output_alignment (abfd
, 4);
2118 PRIV (vms_linkage_index
) = 1;
2120 /* dump all other sections */
2122 section
= abfd
->sections
;
2124 while (section
!= NULL
)
2128 _bfd_vms_debug (4, "writing %d. section '%s' (%d bytes)\n",
2129 section
->index
, section
->name
,
2130 (int) (section
->_raw_size
));
2133 if (section
->flags
& SEC_RELOC
)
2137 if ((i
= section
->reloc_count
) <= 0)
2139 (*_bfd_error_handler
) (_("SEC_RELOC with no relocs in section %s"),
2146 _bfd_vms_debug (4, "%d relocations:\n", i
);
2147 rptr
= section
->orelocation
;
2150 _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, addr %08lx, off %08lx, len %d: %s\n",
2151 (*(*rptr
)->sym_ptr_ptr
)->name
,
2152 (*(*rptr
)->sym_ptr_ptr
)->section
->name
,
2153 (long) (*(*rptr
)->sym_ptr_ptr
)->value
,
2154 (*rptr
)->address
, (*rptr
)->addend
,
2155 bfd_get_reloc_size ((*rptr
)->howto
),
2156 (*rptr
)->howto
->name
);
2163 if ((section
->flags
& SEC_HAS_CONTENTS
)
2164 && (! bfd_is_com_section (section
)))
2166 bfd_vma vaddr
; /* virtual addr in section */
2168 sptr
= _bfd_get_vms_section (abfd
, section
->index
);
2171 bfd_set_error (bfd_error_no_contents
);
2175 vaddr
= (bfd_vma
) (sptr
->offset
);
2177 start_etir_record (abfd
, section
->index
, (uquad
) sptr
->offset
,
2180 while (sptr
!= NULL
) /* one STA_PQ, CTL_SETRB per vms_section */
2183 if (section
->flags
& SEC_RELOC
) /* check for relocs */
2185 arelent
**rptr
= section
->orelocation
;
2186 int i
= section
->reloc_count
;
2189 bfd_size_type addr
= (*rptr
)->address
;
2190 bfd_size_type len
= bfd_get_reloc_size ((*rptr
)->howto
);
2191 if (sptr
->offset
< addr
) /* sptr starts before reloc */
2193 bfd_size_type before
= addr
- sptr
->offset
;
2194 if (sptr
->size
<= before
) /* complete before */
2196 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2197 vaddr
+= sptr
->size
;
2200 else /* partly before */
2202 int after
= sptr
->size
- before
;
2203 sptr
->size
= before
;
2204 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2205 vaddr
+= sptr
->size
;
2206 sptr
->contents
+= before
;
2207 sptr
->offset
+= before
;
2211 else if (sptr
->offset
== addr
) /* sptr starts at reloc */
2213 asymbol
*sym
= *(*rptr
)->sym_ptr_ptr
;
2214 asection
*sec
= sym
->section
;
2216 switch ((*rptr
)->howto
->type
)
2218 case ALPHA_R_IGNORE
:
2221 case ALPHA_R_REFLONG
:
2223 if (bfd_is_und_section (sym
->section
))
2225 int slen
= strlen ((char *) sym
->name
);
2228 if (_bfd_vms_output_check (abfd
, slen
) < 0)
2230 end_etir_record (abfd
);
2231 start_etir_record (abfd
,
2235 _bfd_vms_output_begin (abfd
,
2236 ETIR_S_C_STO_GBL_LW
,
2238 hash
= (_bfd_vms_length_hash_symbol
2239 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2240 _bfd_vms_output_counted (abfd
, hash
);
2241 _bfd_vms_output_flush (abfd
);
2243 else if (bfd_is_abs_section (sym
->section
))
2245 if (_bfd_vms_output_check (abfd
, 16) < 0)
2247 end_etir_record (abfd
);
2248 start_etir_record (abfd
,
2252 _bfd_vms_output_begin (abfd
,
2255 _bfd_vms_output_quad (abfd
,
2256 (uquad
) sym
->value
);
2257 _bfd_vms_output_flush (abfd
);
2258 _bfd_vms_output_begin (abfd
,
2261 _bfd_vms_output_flush (abfd
);
2265 if (_bfd_vms_output_check (abfd
, 32) < 0)
2267 end_etir_record (abfd
);
2268 start_etir_record (abfd
,
2272 _bfd_vms_output_begin (abfd
,
2275 _bfd_vms_output_long (abfd
,
2276 (unsigned long) (sec
->index
));
2277 _bfd_vms_output_quad (abfd
,
2278 ((uquad
) (*rptr
)->addend
2279 + (uquad
) sym
->value
));
2280 _bfd_vms_output_flush (abfd
);
2281 _bfd_vms_output_begin (abfd
,
2284 _bfd_vms_output_flush (abfd
);
2289 case ALPHA_R_REFQUAD
:
2291 if (bfd_is_und_section (sym
->section
))
2293 int slen
= strlen ((char *) sym
->name
);
2295 if (_bfd_vms_output_check (abfd
, slen
) < 0)
2297 end_etir_record (abfd
);
2298 start_etir_record (abfd
,
2302 _bfd_vms_output_begin (abfd
,
2305 hash
= (_bfd_vms_length_hash_symbol
2306 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2307 _bfd_vms_output_counted (abfd
, hash
);
2308 _bfd_vms_output_flush (abfd
);
2310 else if (bfd_is_abs_section (sym
->section
))
2312 if (_bfd_vms_output_check (abfd
, 16) < 0)
2314 end_etir_record (abfd
);
2315 start_etir_record (abfd
,
2319 _bfd_vms_output_begin (abfd
,
2322 _bfd_vms_output_quad (abfd
,
2323 (uquad
) sym
->value
);
2324 _bfd_vms_output_flush (abfd
);
2325 _bfd_vms_output_begin (abfd
,
2328 _bfd_vms_output_flush (abfd
);
2332 if (_bfd_vms_output_check (abfd
, 32) < 0)
2334 end_etir_record (abfd
);
2335 start_etir_record (abfd
,
2339 _bfd_vms_output_begin (abfd
,
2342 _bfd_vms_output_long (abfd
,
2343 (unsigned long) (sec
->index
));
2344 _bfd_vms_output_quad (abfd
,
2345 ((uquad
) (*rptr
)->addend
2346 + (uquad
) sym
->value
));
2347 _bfd_vms_output_flush (abfd
);
2348 _bfd_vms_output_begin (abfd
,
2351 _bfd_vms_output_flush (abfd
);
2359 char *hash ATTRIBUTE_UNUSED
;
2361 hint_size
= sptr
->size
;
2363 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2364 sptr
->size
= hint_size
;
2366 vms_output_begin (abfd
,
2367 ETIR_S_C_STO_HINT_GBL
, -1);
2368 vms_output_long (abfd
,
2369 (unsigned long) (sec
->index
));
2370 vms_output_quad (abfd
, (uquad
) addr
);
2372 hash
= (_bfd_vms_length_hash_symbol
2373 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2374 vms_output_counted (abfd
, hash
);
2376 vms_output_flush (abfd
);
2380 case ALPHA_R_LINKAGE
:
2384 if (_bfd_vms_output_check (abfd
, 64) < 0)
2386 end_etir_record (abfd
);
2387 start_etir_record (abfd
, section
->index
,
2390 _bfd_vms_output_begin (abfd
,
2391 ETIR_S_C_STC_LP_PSB
,
2393 _bfd_vms_output_long (abfd
,
2394 (unsigned long) PRIV (vms_linkage_index
));
2395 PRIV (vms_linkage_index
) += 2;
2396 hash
= (_bfd_vms_length_hash_symbol
2397 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2398 _bfd_vms_output_counted (abfd
, hash
);
2399 _bfd_vms_output_byte (abfd
, 0);
2400 _bfd_vms_output_flush (abfd
);
2404 case ALPHA_R_CODEADDR
:
2406 int slen
= strlen ((char *) sym
->name
);
2408 if (_bfd_vms_output_check (abfd
, slen
) < 0)
2410 end_etir_record (abfd
);
2411 start_etir_record (abfd
,
2415 _bfd_vms_output_begin (abfd
,
2418 hash
= (_bfd_vms_length_hash_symbol
2419 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2420 _bfd_vms_output_counted (abfd
, hash
);
2421 _bfd_vms_output_flush (abfd
);
2426 (*_bfd_error_handler
) (_("Unhandled relocation %s"),
2427 (*rptr
)->howto
->name
);
2433 if (len
== sptr
->size
)
2439 sptr
->contents
+= len
;
2440 sptr
->offset
+= len
;
2446 else /* sptr starts after reloc */
2448 i
--; /* check next reloc */
2452 if (i
==0) /* all reloc checked */
2457 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2458 vaddr
+= sptr
->size
;
2463 } /* if SEC_RELOC */
2464 else /* no relocs, just dump */
2466 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2467 vaddr
+= sptr
->size
;
2472 } /* while (sptr != 0) */
2474 end_etir_record (abfd
);
2476 } /* has_contents */
2478 section
= section
->next
;
2481 _bfd_vms_output_alignment (abfd
, 2);
2485 /* write traceback data for bfd abfd */
2488 _bfd_vms_write_tbt (abfd
, objtype
)
2489 bfd
*abfd ATTRIBUTE_UNUSED
;
2490 int objtype ATTRIBUTE_UNUSED
;
2493 _bfd_vms_debug (2, "vms_write_tbt (%p, %d)\n", abfd
, objtype
);
2499 /* write debug info for bfd abfd */
2502 _bfd_vms_write_dbg (abfd
, objtype
)
2503 bfd
*abfd ATTRIBUTE_UNUSED
;
2504 int objtype ATTRIBUTE_UNUSED
;
2507 _bfd_vms_debug (2, "vms_write_dbg (%p, objtype)\n", abfd
, objtype
);