1 /* vms-gsd.c -- BFD back-end for VAX (openVMS/VAX) and
2 EVAX (openVMS/Alpha) files.
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 2007 Free Software Foundation, Inc.
6 go and read the openVMS linker manual (esp. appendix B)
7 if you don't know what's going on here :-)
9 Written by Klaus K"ampf (kkaempf@rmi.de)
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 3 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., 51 Franklin Street - Fifth Floor, Boston,
24 MA 02110-1301, USA. */
33 /* Typical sections for vax object files. */
35 #define VAX_CODE_NAME "$CODE"
36 #define VAX_DATA_NAME "$DATA"
37 #define VAX_ADDRESS_DATA_NAME "$ADDRESS_DATA"
39 /* Typical sections for evax object files. */
41 #define EVAX_ABS_NAME "$ABS$"
42 #define EVAX_CODE_NAME "$CODE$"
43 #define EVAX_LINK_NAME "$LINK$"
44 #define EVAX_DATA_NAME "$DATA$"
45 #define EVAX_BSS_NAME "$BSS$"
46 #define EVAX_READONLYADDR_NAME "$READONLY_ADDR$"
47 #define EVAX_READONLY_NAME "$READONLY$"
48 #define EVAX_LITERAL_NAME "$LITERAL$"
49 #define EVAX_COMMON_NAME "$COMMON$"
50 #define EVAX_LOCAL_NAME "$LOCAL$"
52 struct sec_flags_struct
54 char *name
; /* Name of section. */
56 flagword flags_always
; /* Flags we set always. */
58 flagword flags_hassize
; /* Flags we set if the section has a size > 0. */
61 /* These flags are deccrtl/vaxcrtl (openVMS 6.2 VAX) compatible. */
63 static struct sec_flags_struct vax_section_flags
[] =
66 (GPS_S_M_PIC
| GPS_S_M_REL
| GPS_S_M_SHR
| GPS_S_M_EXE
| GPS_S_M_RD
),
68 (GPS_S_M_PIC
| GPS_S_M_REL
| GPS_S_M_SHR
| GPS_S_M_EXE
| GPS_S_M_RD
),
69 (SEC_IN_MEMORY
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
) },
71 (GPS_S_M_PIC
| GPS_S_M_REL
| GPS_S_M_RD
| GPS_S_M_WRT
),
73 (GPS_S_M_PIC
| GPS_S_M_REL
| GPS_S_M_RD
| GPS_S_M_WRT
),
74 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
) },
75 { VAX_ADDRESS_DATA_NAME
,
76 (GPS_S_M_PIC
| GPS_S_M_REL
| GPS_S_M_RD
),
77 (SEC_DATA
| SEC_READONLY
),
78 (GPS_S_M_PIC
| GPS_S_M_REL
| GPS_S_M_RD
),
79 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_READONLY
| SEC_LOAD
) },
81 (GPS_S_M_PIC
| GPS_S_M_OVR
| GPS_S_M_REL
| GPS_S_M_GBL
| GPS_S_M_RD
| GPS_S_M_WRT
),
83 (GPS_S_M_PIC
| GPS_S_M_OVR
| GPS_S_M_REL
| GPS_S_M_GBL
| GPS_S_M_RD
| GPS_S_M_WRT
),
84 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
) }
87 /* These flags are deccrtl/vaxcrtl (openVMS 6.2 Alpha) compatible. */
89 static struct sec_flags_struct evax_section_flags
[] =
95 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
) },
97 (EGPS_S_V_PIC
| EGPS_S_V_REL
| EGPS_S_V_SHR
| EGPS_S_V_EXE
),
99 (EGPS_S_V_PIC
| EGPS_S_V_REL
| EGPS_S_V_SHR
| EGPS_S_V_EXE
),
100 (SEC_IN_MEMORY
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
) },
102 (EGPS_S_V_PIC
| EGPS_S_V_REL
| EGPS_S_V_SHR
| EGPS_S_V_RD
| EGPS_S_V_NOMOD
),
103 (SEC_DATA
| SEC_READONLY
),
104 (EGPS_S_V_PIC
| EGPS_S_V_REL
| EGPS_S_V_SHR
| EGPS_S_V_RD
),
105 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_READONLY
| SEC_LOAD
) },
107 (EGPS_S_V_REL
| EGPS_S_V_RD
),
108 (SEC_DATA
| SEC_READONLY
),
109 (EGPS_S_V_REL
| EGPS_S_V_RD
),
110 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_READONLY
| SEC_LOAD
) },
112 (EGPS_S_V_REL
| EGPS_S_V_RD
| EGPS_S_V_WRT
| EGPS_S_V_NOMOD
),
114 (EGPS_S_V_REL
| EGPS_S_V_RD
| EGPS_S_V_WRT
),
115 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
) },
117 (EGPS_S_V_REL
| EGPS_S_V_RD
| EGPS_S_V_WRT
| EGPS_S_V_NOMOD
),
119 (EGPS_S_V_REL
| EGPS_S_V_RD
| EGPS_S_V_WRT
| EGPS_S_V_NOMOD
),
120 (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
) },
121 { EVAX_READONLYADDR_NAME
,
122 (EGPS_S_V_PIC
| EGPS_S_V_REL
| EGPS_S_V_RD
),
123 (SEC_DATA
| SEC_READONLY
),
124 (EGPS_S_V_PIC
| EGPS_S_V_REL
| EGPS_S_V_RD
),
125 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_READONLY
| SEC_LOAD
) },
126 { EVAX_READONLY_NAME
,
127 (EGPS_S_V_PIC
| EGPS_S_V_REL
| EGPS_S_V_SHR
| EGPS_S_V_RD
| EGPS_S_V_NOMOD
),
128 (SEC_DATA
| SEC_READONLY
),
129 (EGPS_S_V_PIC
| EGPS_S_V_REL
| EGPS_S_V_SHR
| EGPS_S_V_RD
),
130 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_READONLY
| SEC_LOAD
) },
132 (EGPS_S_V_REL
| EGPS_S_V_RD
| EGPS_S_V_WRT
),
134 (EGPS_S_V_REL
| EGPS_S_V_RD
| EGPS_S_V_WRT
),
135 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
) },
137 (EGPS_S_V_REL
| EGPS_S_V_RD
| EGPS_S_V_WRT
),
139 (EGPS_S_V_REL
| EGPS_S_V_RD
| EGPS_S_V_WRT
),
140 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
) }
143 /* Retrieve bfd section flags by name and size. */
146 vms_secflag_by_name (bfd
*abfd
,
147 struct sec_flags_struct
*section_flags
,
153 while (section_flags
[i
].name
!= NULL
)
156 strcasecmp (name
, section_flags
[i
].name
):
157 strcmp (name
, section_flags
[i
].name
)) == 0)
160 return section_flags
[i
].flags_hassize
;
162 return section_flags
[i
].flags_always
;
167 return section_flags
[i
].flags_hassize
;
168 return section_flags
[i
].flags_always
;
171 /* Retrieve vms section flags by name and size. */
174 vms_esecflag_by_name (struct sec_flags_struct
*section_flags
,
180 while (section_flags
[i
].name
!= NULL
)
182 if (strcmp (name
, section_flags
[i
].name
) == 0)
185 return section_flags
[i
].vflags_hassize
;
187 return section_flags
[i
].vflags_always
;
192 return section_flags
[i
].vflags_hassize
;
193 return section_flags
[i
].vflags_always
;
198 struct flagdescstruct
{ char *name
; flagword value
; };
200 /* Convert flag to printable string. */
203 flag2str (struct flagdescstruct
* flagdesc
, flagword flags
)
209 while (flagdesc
->name
!= NULL
)
211 if ((flags
& flagdesc
->value
) != 0)
217 strcat (res
, flagdesc
->name
);
225 /* Input routines. */
227 /* Process GSD/EGSD record
228 return 0 on success, -1 on error. */
231 _bfd_vms_slurp_gsd (bfd
* abfd
, int objtype
)
234 static struct flagdescstruct gpsflagdesc
[] =
251 static struct flagdescstruct gsyflagdesc
[] =
264 int gsd_type
, gsd_size
;
266 unsigned char *vms_rec
;
267 flagword new_flags
, old_flags
;
270 vms_symbol_entry
*entry
;
271 unsigned long base_addr
;
272 unsigned long align_addr
;
273 static unsigned int psect_idx
= 0;
276 vms_debug (2, "GSD/EGSD (%d/%x)\n", objtype
, objtype
);
282 PRIV (vms_rec
) += 8; /* Skip type, size, l_temp. */
283 PRIV (rec_size
) -= 8;
287 PRIV (rec_size
) -= 1;
293 /* Calculate base address for each section. */
298 while (PRIV (rec_size
) > 0)
300 vms_rec
= PRIV (vms_rec
);
302 if (objtype
== OBJ_S_C_GSD
)
306 _bfd_vms_get_header_values (abfd
, vms_rec
, &gsd_type
, &gsd_size
);
307 gsd_type
+= EVAX_OFFSET
;
311 vms_debug (3, "gsd_type %d\n", gsd_type
);
318 /* Program section definition. */
319 asection
*old_section
= 0;
322 vms_debug (4, "GSD_S_C_PSC\n");
324 /* If this section isn't a bfd section. */
325 if (PRIV (is_vax
) && (psect_idx
< (abfd
->section_count
-1)))
327 /* Check for temporary section from TIR record. */
328 if (psect_idx
< PRIV (section_count
))
329 old_section
= PRIV (sections
)[psect_idx
];
334 name
= _bfd_vms_save_counted_string (vms_rec
+ 8);
335 section
= bfd_make_section (abfd
, name
);
338 (*_bfd_error_handler
) (_("bfd_make_section (%s) failed"),
342 old_flags
= bfd_getl16 (vms_rec
+ 2);
343 section
->size
= bfd_getl32 (vms_rec
+ 4); /* allocation */
344 new_flags
= vms_secflag_by_name (abfd
, vax_section_flags
, name
,
346 if (old_flags
& EGPS_S_V_REL
)
347 new_flags
|= SEC_RELOC
;
348 if (old_flags
& GPS_S_M_OVR
)
349 new_flags
|= SEC_IS_COMMON
;
350 if (!bfd_set_section_flags (abfd
, section
, new_flags
))
352 (*_bfd_error_handler
)
353 (_("bfd_set_section_flags (%s, %x) failed"),
357 section
->alignment_power
= vms_rec
[1];
358 align_addr
= (1 << section
->alignment_power
);
359 if ((base_addr
% align_addr
) != 0)
360 base_addr
+= (align_addr
- (base_addr
% align_addr
));
361 section
->vma
= (bfd_vma
)base_addr
;
362 base_addr
+= section
->size
;
364 /* Global section is common symbol. */
366 if (old_flags
& GPS_S_M_GBL
)
368 entry
= _bfd_vms_enter_symbol (abfd
, name
);
371 bfd_set_error (bfd_error_no_memory
);
374 symbol
= entry
->symbol
;
377 symbol
->section
= section
;
378 symbol
->flags
= (BSF_GLOBAL
| BSF_SECTION_SYM
| BSF_OLD_COMMON
);
381 /* Copy saved contents if old_section set. */
382 if (old_section
!= 0)
384 section
->contents
= old_section
->contents
;
385 if (section
->size
< old_section
->size
)
387 (*_bfd_error_handler
)
388 (_("Size mismatch section %s=%lx, %s=%lx"),
390 (unsigned long) old_section
->size
,
392 (unsigned long) section
->size
);
395 else if (section
->size
> old_section
->size
)
397 section
->contents
= bfd_realloc (old_section
->contents
,
399 if (section
->contents
== NULL
)
401 bfd_set_error (bfd_error_no_memory
);
408 section
->contents
= bfd_zmalloc (section
->size
);
409 if (section
->contents
== NULL
)
411 bfd_set_error (bfd_error_no_memory
);
416 vms_debug (4, "gsd psc %d (%s, flags %04x=%s) ",
417 section
->index
, name
, old_flags
, flag2str (gpsflagdesc
, old_flags
));
418 vms_debug (4, "%d bytes at 0x%08lx (mem %p)\n",
419 section
->size
, section
->vma
, section
->contents
);
422 gsd_size
= vms_rec
[8] + 9;
431 vms_debug (4, "gsd epm\n");
437 int name_offset
= 0, value_offset
= 0;
439 /* Symbol specification (definition or reference). */
441 vms_debug (4, "GSD_S_C_SYM(W)\n");
443 old_flags
= bfd_getl16 (vms_rec
+ 2);
444 new_flags
= BSF_NO_FLAGS
;
446 if (old_flags
& GSY_S_M_WEAK
)
447 new_flags
|= BSF_WEAK
;
454 new_flags
|= BSF_FUNCTION
;
459 new_flags
|= BSF_FUNCTION
;
462 if (old_flags
& GSY_S_M_DEF
) /* Symbol definition. */
469 if (old_flags
& GSY_S_M_DEF
) /* Symbol definition. */
477 /* Save symbol in vms_symbol_table. */
478 entry
= _bfd_vms_enter_symbol
479 (abfd
, _bfd_vms_save_counted_string (vms_rec
+ name_offset
));
482 bfd_set_error (bfd_error_no_memory
);
485 symbol
= entry
->symbol
;
487 if (old_flags
& GSY_S_M_DEF
)
489 /* Symbol definition. */
492 symbol
->value
= bfd_getl32 (vms_rec
+ value_offset
);
493 if ((gsd_type
== GSD_S_C_SYMW
)
494 || (gsd_type
== GSD_S_C_EPMW
))
495 psect
= bfd_getl16 (vms_rec
+ value_offset
- 2);
497 psect
= vms_rec
[value_offset
-1];
499 symbol
->section
= (asection
*) (size_t) psect
;
501 vms_debug (4, "gsd sym def #%d (%s, %d [%p], %04x=%s)\n", abfd
->symcount
,
502 symbol
->name
, (int)symbol
->section
, symbol
->section
, old_flags
, flag2str (gsyflagdesc
, old_flags
));
507 /* Symbol reference. */
508 symbol
->section
= bfd_make_section (abfd
, BFD_UND_SECTION_NAME
);
510 vms_debug (4, "gsd sym ref #%d (%s, %s [%p], %04x=%s)\n",
511 abfd
->symcount
, symbol
->name
, symbol
->section
->name
,
512 symbol
->section
, old_flags
, flag2str (gsyflagdesc
, old_flags
));
516 gsd_size
= vms_rec
[name_offset
] + name_offset
+ 1;
517 symbol
->flags
= new_flags
;
525 vms_debug (4, "gsd pro\n");
530 vms_debug (4, "gsd idc\n");
535 vms_debug (4, "gsd env\n");
540 vms_debug (4, "gsd lsy\n");
545 vms_debug (4, "gsd lepm\n");
550 vms_debug (4, "gsd lpro\n");
555 vms_debug (4, "gsd spsc\n");
560 vms_debug (4, "gsd symv\n");
565 vms_debug (4, "gsd epmv\n");
570 vms_debug (4, "gsd prov\n");
574 case EGSD_S_C_PSC
+ EVAX_OFFSET
:
576 /* Program section definition. */
577 name
= _bfd_vms_save_counted_string (vms_rec
+ 12);
578 section
= bfd_make_section (abfd
, name
);
581 old_flags
= bfd_getl16 (vms_rec
+ 6);
582 section
->size
= bfd_getl32 (vms_rec
+ 8); /* Allocation. */
583 new_flags
= vms_secflag_by_name (abfd
, evax_section_flags
, name
,
585 if (old_flags
& EGPS_S_V_REL
)
586 new_flags
|= SEC_RELOC
;
587 if (!bfd_set_section_flags (abfd
, section
, new_flags
))
589 section
->alignment_power
= vms_rec
[4];
590 align_addr
= (1 << section
->alignment_power
);
591 if ((base_addr
% align_addr
) != 0)
592 base_addr
+= (align_addr
- (base_addr
% align_addr
));
593 section
->vma
= (bfd_vma
)base_addr
;
594 base_addr
+= section
->size
;
595 section
->contents
= bfd_zmalloc (section
->size
);
596 if (section
->contents
== NULL
)
599 vms_debug (4, "egsd psc %d (%s, flags %04x=%s) ",
600 section
->index
, name
, old_flags
, flag2str (gpsflagdesc
, old_flags
));
601 vms_debug (4, "%d bytes at 0x%08lx (mem %p)\n",
602 section
->size
, section
->vma
, section
->contents
);
607 case EGSD_S_C_SYM
+ EVAX_OFFSET
:
609 /* Symbol specification (definition or reference). */
610 symbol
= bfd_make_empty_symbol (abfd
);
614 old_flags
= bfd_getl16 (vms_rec
+ 6);
615 new_flags
= BSF_NO_FLAGS
;
617 if (old_flags
& EGSY_S_V_WEAK
)
618 new_flags
|= BSF_WEAK
;
620 if (vms_rec
[6] & EGSY_S_V_DEF
)
622 /* Symbol definition. */
623 symbol
->name
= _bfd_vms_save_counted_string (vms_rec
+ 32);
624 if (old_flags
& EGSY_S_V_NORM
)
626 new_flags
|= BSF_FUNCTION
;
628 symbol
->value
= bfd_getl64 (vms_rec
+ 8);
629 symbol
->section
= (asection
*) ((unsigned long) bfd_getl32 (vms_rec
+ 28));
631 vms_debug (4, "egsd sym def #%d (%s, %d, %04x=%s)\n", abfd
->symcount
,
632 symbol
->name
, (int) symbol
->section
, old_flags
,
633 flag2str (gsyflagdesc
, old_flags
));
638 /* Symbol reference. */
639 symbol
->name
= _bfd_vms_save_counted_string (vms_rec
+ 8);
641 vms_debug (4, "egsd sym ref #%d (%s, %04x=%s)\n", abfd
->symcount
,
642 symbol
->name
, old_flags
, flag2str (gsyflagdesc
, old_flags
));
644 symbol
->section
= bfd_make_section (abfd
, BFD_UND_SECTION_NAME
);
647 symbol
->flags
= new_flags
;
649 /* Save symbol in vms_symbol_table. */
650 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV (vms_symbol_table
),
655 bfd_set_error (bfd_error_no_memory
);
659 if (entry
->symbol
!= NULL
)
661 /* FIXME ?, DEC C generates this. */
663 vms_debug (4, "EGSD_S_C_SYM: duplicate \"%s\"\n", symbol
->name
);
668 entry
->symbol
= symbol
;
669 PRIV (gsd_sym_count
)++;
675 case EGSD_S_C_IDC
+ EVAX_OFFSET
:
679 (*_bfd_error_handler
) (_("unknown gsd/egsd subtype %d"), gsd_type
);
680 bfd_set_error (bfd_error_bad_value
);
684 PRIV (rec_size
) -= gsd_size
;
685 PRIV (vms_rec
) += gsd_size
;
688 if (abfd
->symcount
> 0)
689 abfd
->flags
|= HAS_SYMS
;
694 /* Output routines. */
696 /* Write section and symbol directory of bfd abfd. */
699 _bfd_vms_write_gsd (bfd
*abfd
, int objtype ATTRIBUTE_UNUSED
)
707 flagword new_flags
, old_flags
;
710 vms_debug (2, "vms_write_gsd (%p, %d)\n", abfd
, objtype
);
713 /* Output sections. */
714 section
= abfd
->sections
;
716 vms_debug (3, "%d sections found\n", abfd
->section_count
);
719 /* Egsd is quadword aligned. */
720 _bfd_vms_output_alignment (abfd
, 8);
722 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EGSD
, -1);
723 _bfd_vms_output_long (abfd
, 0);
724 /* Prepare output for subrecords. */
725 _bfd_vms_output_push (abfd
);
730 vms_debug (3, "Section #%d %s, %d bytes\n", section
->index
, section
->name
, (int)section
->size
);
733 /* 13 bytes egsd, max 31 chars name -> should be 44 bytes. */
734 if (_bfd_vms_output_check (abfd
, 64) < 0)
736 _bfd_vms_output_pop (abfd
);
737 _bfd_vms_output_end (abfd
);
738 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EGSD
, -1);
739 _bfd_vms_output_long (abfd
, 0);
740 /* Prepare output for subrecords. */
741 _bfd_vms_output_push (abfd
);
744 /* Create dummy sections to keep consecutive indices. */
745 while (section
->index
- last_index
> 1)
748 vms_debug (3, "index %d, last %d\n", section
->index
, last_index
);
750 _bfd_vms_output_begin (abfd
, EGSD_S_C_PSC
, -1);
751 _bfd_vms_output_short (abfd
, 0);
752 _bfd_vms_output_short (abfd
, 0);
753 _bfd_vms_output_long (abfd
, 0);
754 sprintf (dummy_name
, ".DUMMY%02d", last_index
);
755 _bfd_vms_output_counted (abfd
, dummy_name
);
756 _bfd_vms_output_flush (abfd
);
760 /* Don't know if this is necessary for the linker but for now it keeps
761 vms_slurp_gsd happy */
762 sname
= (char *)section
->name
;
766 if ((*sname
== 't') && (strcmp (sname
, "text") == 0))
767 sname
= PRIV (is_vax
)?VAX_CODE_NAME
:EVAX_CODE_NAME
;
768 else if ((*sname
== 'd') && (strcmp (sname
, "data") == 0))
769 sname
= PRIV (is_vax
)?VAX_DATA_NAME
:EVAX_DATA_NAME
;
770 else if ((*sname
== 'b') && (strcmp (sname
, "bss") == 0))
771 sname
= EVAX_BSS_NAME
;
772 else if ((*sname
== 'l') && (strcmp (sname
, "link") == 0))
773 sname
= EVAX_LINK_NAME
;
774 else if ((*sname
== 'r') && (strcmp (sname
, "rdata") == 0))
775 sname
= EVAX_READONLY_NAME
;
776 else if ((*sname
== 'l') && (strcmp (sname
, "literal") == 0))
777 sname
= EVAX_LITERAL_NAME
;
778 else if ((*sname
== 'c') && (strcmp (sname
, "comm") == 0))
779 sname
= EVAX_COMMON_NAME
;
780 else if ((*sname
== 'l') && (strcmp (sname
, "lcomm") == 0))
781 sname
= EVAX_LOCAL_NAME
;
784 sname
= _bfd_vms_length_hash_symbol (abfd
, sname
, EOBJ_S_C_SECSIZ
);
786 _bfd_vms_output_begin (abfd
, EGSD_S_C_PSC
, -1);
787 _bfd_vms_output_short (abfd
, section
->alignment_power
& 0xff);
788 if (bfd_is_com_section (section
))
789 new_flags
= (EGPS_S_V_OVR
| EGPS_S_V_REL
| EGPS_S_V_GBL
| EGPS_S_V_RD
| EGPS_S_V_WRT
| EGPS_S_V_NOMOD
| EGPS_S_V_COM
);
791 new_flags
= vms_esecflag_by_name (evax_section_flags
, sname
,
794 _bfd_vms_output_short (abfd
, new_flags
);
795 _bfd_vms_output_long (abfd
, (unsigned long) section
->size
);
796 _bfd_vms_output_counted (abfd
, sname
);
797 _bfd_vms_output_flush (abfd
);
799 last_index
= section
->index
;
800 section
= section
->next
;
803 /* Output symbols. */
805 vms_debug (3, "%d symbols found\n", abfd
->symcount
);
808 bfd_set_start_address (abfd
, (bfd_vma
) -1);
810 for (symnum
= 0; symnum
< abfd
->symcount
; symnum
++)
814 symbol
= abfd
->outsymbols
[symnum
];
815 if (*(symbol
->name
) == '_')
817 if (strcmp (symbol
->name
, "__main") == 0)
818 bfd_set_start_address (abfd
, (bfd_vma
)symbol
->value
);
820 old_flags
= symbol
->flags
;
822 if (old_flags
& BSF_FILE
)
825 if (((old_flags
& (BSF_GLOBAL
| BSF_WEAK
)) == 0) /* Not xdef... */
826 && (!bfd_is_und_section (symbol
->section
))) /* ...and not xref. */
827 continue; /* Dont output. */
829 /* 13 bytes egsd, max 64 chars name -> should be 77 bytes. */
830 if (_bfd_vms_output_check (abfd
, 80) < 0)
832 _bfd_vms_output_pop (abfd
);
833 _bfd_vms_output_end (abfd
);
834 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EGSD
, -1);
835 _bfd_vms_output_long (abfd
, 0);
836 /* Prepare output for subrecords. */
837 _bfd_vms_output_push (abfd
);
840 _bfd_vms_output_begin (abfd
, EGSD_S_C_SYM
, -1);
842 /* Data type, alignment. */
843 _bfd_vms_output_short (abfd
, 0);
847 if (old_flags
& BSF_WEAK
)
848 new_flags
|= EGSY_S_V_WEAK
;
849 if (bfd_is_com_section (symbol
->section
))
850 new_flags
|= (EGSY_S_V_WEAK
| EGSY_S_V_COMM
);
852 if (old_flags
& BSF_FUNCTION
)
854 new_flags
|= EGSY_S_V_NORM
;
855 new_flags
|= EGSY_S_V_REL
;
857 if (old_flags
& (BSF_GLOBAL
| BSF_WEAK
))
859 new_flags
|= EGSY_S_V_DEF
;
860 if (!bfd_is_abs_section (symbol
->section
))
861 new_flags
|= EGSY_S_V_REL
;
863 _bfd_vms_output_short (abfd
, new_flags
);
865 if (old_flags
& (BSF_GLOBAL
| BSF_WEAK
))
867 /* Symbol definition. */
868 uquad code_address
= 0;
869 unsigned long ca_psindx
= 0;
870 unsigned long psindx
;
872 if ((old_flags
& BSF_FUNCTION
) && symbol
->udata
.p
!= NULL
)
874 code_address
= ((asymbol
*) (symbol
->udata
.p
))->value
;
875 ca_psindx
= ((asymbol
*) (symbol
->udata
.p
))->section
->index
;
877 psindx
= symbol
->section
->index
;
879 _bfd_vms_output_quad (abfd
, symbol
->value
);
880 _bfd_vms_output_quad (abfd
, code_address
);
881 _bfd_vms_output_long (abfd
, ca_psindx
);
882 _bfd_vms_output_long (abfd
, psindx
);
884 hash
= _bfd_vms_length_hash_symbol (abfd
, symbol
->name
, EOBJ_S_C_SYMSIZ
);
885 _bfd_vms_output_counted (abfd
, hash
);
887 _bfd_vms_output_flush (abfd
);
891 _bfd_vms_output_alignment (abfd
, 8);
892 _bfd_vms_output_pop (abfd
);
893 _bfd_vms_output_end (abfd
);