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, 2009 Free Software Foundation, Inc.
6 GSD record handling functions
7 EGSD record handling functions
9 Go and read the openVMS linker manual (esp. appendix B)
10 if you don't know what's going on here :-)
12 Written by Klaus K"ampf (kkaempf@rmi.de)
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
27 MA 02110-1301, USA. */
36 /* Typical sections for vax object files. */
38 #define VAX_CODE_NAME "$CODE"
39 #define VAX_DATA_NAME "$DATA"
40 #define VAX_ADDRESS_DATA_NAME "$ADDRESS_DATA"
42 /* Typical sections for evax object files. */
44 #define EVAX_ABS_NAME "$ABS$"
45 #define EVAX_CODE_NAME "$CODE$"
46 #define EVAX_LINK_NAME "$LINK$"
47 #define EVAX_DATA_NAME "$DATA$"
48 #define EVAX_BSS_NAME "$BSS$"
49 #define EVAX_READONLYADDR_NAME "$READONLY_ADDR$"
50 #define EVAX_READONLY_NAME "$READONLY$"
51 #define EVAX_LITERAL_NAME "$LITERAL$"
52 #define EVAX_LITERALS_NAME "$LITERALS"
53 #define EVAX_COMMON_NAME "$COMMON$"
54 #define EVAX_LOCAL_NAME "$LOCAL$"
56 struct sec_flags_struct
58 char *name
; /* Name of section. */
60 flagword flags_always
; /* Flags we set always. */
62 flagword flags_hassize
; /* Flags we set if the section has a size > 0. */
65 /* These flags are deccrtl/vaxcrtl (openVMS 6.2 VAX) compatible. */
67 static struct sec_flags_struct vax_section_flags
[] =
70 (GPS_S_M_PIC
| GPS_S_M_REL
| GPS_S_M_SHR
| GPS_S_M_EXE
| GPS_S_M_RD
),
72 (GPS_S_M_PIC
| GPS_S_M_REL
| GPS_S_M_SHR
| GPS_S_M_EXE
| GPS_S_M_RD
),
73 (SEC_IN_MEMORY
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
) },
75 (GPS_S_M_PIC
| GPS_S_M_REL
| GPS_S_M_RD
| GPS_S_M_WRT
),
77 (GPS_S_M_PIC
| GPS_S_M_REL
| GPS_S_M_RD
| GPS_S_M_WRT
),
78 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
) },
79 { VAX_ADDRESS_DATA_NAME
,
80 (GPS_S_M_PIC
| GPS_S_M_REL
| GPS_S_M_RD
),
81 (SEC_DATA
| SEC_READONLY
),
82 (GPS_S_M_PIC
| GPS_S_M_REL
| GPS_S_M_RD
),
83 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_READONLY
| SEC_LOAD
) },
85 (GPS_S_M_PIC
| GPS_S_M_OVR
| GPS_S_M_REL
| GPS_S_M_GBL
| GPS_S_M_RD
| GPS_S_M_WRT
),
87 (GPS_S_M_PIC
| GPS_S_M_OVR
| GPS_S_M_REL
| GPS_S_M_GBL
| GPS_S_M_RD
| GPS_S_M_WRT
),
88 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
) }
91 /* These flags are deccrtl/vaxcrtl (openVMS 6.2 Alpha) compatible. */
93 static struct sec_flags_struct evax_section_flags
[] =
99 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
) },
101 (EGPS_S_V_PIC
| EGPS_S_V_REL
| EGPS_S_V_SHR
| EGPS_S_V_EXE
),
103 (EGPS_S_V_PIC
| EGPS_S_V_REL
| EGPS_S_V_SHR
| EGPS_S_V_EXE
),
104 (SEC_IN_MEMORY
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
) },
106 (EGPS_S_V_PIC
| EGPS_S_V_REL
| EGPS_S_V_SHR
| EGPS_S_V_RD
| EGPS_S_V_NOMOD
),
107 (SEC_DATA
| SEC_READONLY
),
108 (EGPS_S_V_PIC
| EGPS_S_V_REL
| EGPS_S_V_SHR
| EGPS_S_V_RD
),
109 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_READONLY
| SEC_LOAD
) },
111 (EGPS_S_V_REL
| EGPS_S_V_RD
),
112 (SEC_DATA
| SEC_READONLY
),
113 (EGPS_S_V_REL
| EGPS_S_V_RD
),
114 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_READONLY
| SEC_LOAD
) },
116 (EGPS_S_V_REL
| EGPS_S_V_RD
| EGPS_S_V_WRT
| EGPS_S_V_NOMOD
),
118 (EGPS_S_V_REL
| EGPS_S_V_RD
| EGPS_S_V_WRT
),
119 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
) },
121 (EGPS_S_V_REL
| EGPS_S_V_RD
| EGPS_S_V_WRT
| EGPS_S_V_NOMOD
),
123 (EGPS_S_V_REL
| EGPS_S_V_RD
| EGPS_S_V_WRT
| EGPS_S_V_NOMOD
),
124 (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
) },
125 { EVAX_READONLYADDR_NAME
,
126 (EGPS_S_V_PIC
| EGPS_S_V_REL
| EGPS_S_V_RD
),
127 (SEC_DATA
| SEC_READONLY
),
128 (EGPS_S_V_PIC
| EGPS_S_V_REL
| EGPS_S_V_RD
),
129 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_READONLY
| SEC_LOAD
) },
130 { EVAX_READONLY_NAME
,
131 (EGPS_S_V_PIC
| EGPS_S_V_REL
| EGPS_S_V_SHR
| EGPS_S_V_RD
| EGPS_S_V_NOMOD
),
132 (SEC_DATA
| SEC_READONLY
),
133 (EGPS_S_V_PIC
| EGPS_S_V_REL
| EGPS_S_V_SHR
| EGPS_S_V_RD
),
134 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_READONLY
| SEC_LOAD
) },
136 (EGPS_S_V_REL
| EGPS_S_V_RD
| EGPS_S_V_WRT
),
138 (EGPS_S_V_REL
| EGPS_S_V_RD
| EGPS_S_V_WRT
),
139 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
) },
140 { EVAX_LITERALS_NAME
,
141 (EGPS_S_V_PIC
| EGPS_S_V_OVR
),
142 (SEC_DATA
| SEC_READONLY
),
143 (EGPS_S_V_PIC
| EGPS_S_V_OVR
),
144 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_READONLY
| SEC_LOAD
) },
146 (EGPS_S_V_REL
| EGPS_S_V_RD
| EGPS_S_V_WRT
),
148 (EGPS_S_V_REL
| EGPS_S_V_RD
| EGPS_S_V_WRT
),
149 (SEC_IN_MEMORY
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
) }
152 /* Retrieve bfd section flags by name and size. */
155 vms_secflag_by_name (bfd
*abfd
,
156 struct sec_flags_struct
*section_flags
,
162 while (section_flags
[i
].name
!= NULL
)
165 strcasecmp (name
, section_flags
[i
].name
):
166 strcmp (name
, section_flags
[i
].name
)) == 0)
169 return section_flags
[i
].flags_hassize
;
171 return section_flags
[i
].flags_always
;
176 return section_flags
[i
].flags_hassize
;
177 return section_flags
[i
].flags_always
;
180 /* Retrieve vms section flags by name and size. */
183 vms_esecflag_by_name (struct sec_flags_struct
*section_flags
,
189 while (section_flags
[i
].name
!= NULL
)
191 if (strcmp (name
, section_flags
[i
].name
) == 0)
194 return section_flags
[i
].vflags_hassize
;
196 return section_flags
[i
].vflags_always
;
201 return section_flags
[i
].vflags_hassize
;
202 return section_flags
[i
].vflags_always
;
207 struct flagdescstruct
{ const char *name
; flagword value
; };
209 static const struct flagdescstruct gpsflagdesc
[] =
211 { "PIC", GPS_S_M_PIC
},
212 { "LIB", GPS_S_M_LIB
},
213 { "OVR", GPS_S_M_OVR
},
214 { "REL", GPS_S_M_REL
},
215 { "GBL", GPS_S_M_GBL
},
216 { "SHR", GPS_S_M_SHR
},
217 { "EXE", GPS_S_M_EXE
},
218 { "RD", GPS_S_M_RD
},
219 { "WRT", GPS_S_M_WRT
},
220 { "VEC", GPS_S_M_VEC
},
221 { "NOMOD", EGPS_S_V_NOMOD
},
222 { "COM", EGPS_S_V_COM
},
226 static const struct flagdescstruct gsyflagdesc
[] =
228 { "WEAK", GSY_S_M_WEAK
},
229 { "DEF", GSY_S_M_DEF
},
230 { "UNI", GSY_S_M_UNI
},
231 { "REL", GSY_S_M_REL
},
232 { "COMM", EGSY_S_V_COMM
},
233 { "VECEP", EGSY_S_V_VECEP
},
234 { "NORM", EGSY_S_V_NORM
},
238 static char *flag2str (struct flagdescstruct
*, flagword
);
240 /* Convert flag to printable string. */
243 flag2str (struct flagdescstruct
* flagdesc
, flagword flags
)
249 while (flagdesc
->name
!= NULL
)
251 if ((flags
& flagdesc
->value
) != 0)
257 strcat (res
, flagdesc
->name
);
265 /* Input routines. */
267 static int register_universal_symbol (bfd
*abfd
, asymbol
*symbol
,
270 /* Process GSD/EGSD record
271 return 0 on success, -1 on error. */
274 _bfd_vms_slurp_gsd (bfd
* abfd
, int objtype
)
276 int gsd_type
, gsd_size
;
278 unsigned char *vms_rec
;
279 flagword new_flags
, old_flags
;
282 vms_symbol_entry
*entry
;
283 unsigned long base_addr
;
284 unsigned long align_addr
;
285 static unsigned int psect_idx
= 0;
288 vms_debug (2, "GSD/EGSD (%d/%x)\n", objtype
, objtype
);
294 PRIV (vms_rec
) += 8; /* Skip type, size, l_temp. */
295 PRIV (rec_size
) -= 8;
299 PRIV (rec_size
) -= 1;
305 /* Calculate base address for each section. */
310 while (PRIV (rec_size
) > 0)
312 vms_rec
= PRIV (vms_rec
);
314 if (objtype
== OBJ_S_C_GSD
)
315 gsd_type
= vms_rec
[0];
318 _bfd_vms_get_header_values (abfd
, vms_rec
, &gsd_type
, &gsd_size
);
319 gsd_type
+= EVAX_OFFSET
;
323 vms_debug (3, "gsd_type %d\n", gsd_type
);
330 /* Program section definition. */
331 asection
*old_section
= 0;
334 vms_debug (4, "GSD_S_C_PSC\n");
336 /* If this section isn't a bfd section. */
337 if (PRIV (is_vax
) && (psect_idx
< (abfd
->section_count
- 1)))
339 /* Check for temporary section from TIR record. */
340 if (psect_idx
< PRIV (section_count
))
341 old_section
= PRIV (sections
)[psect_idx
];
346 name
= _bfd_vms_save_counted_string (vms_rec
+ 8);
347 section
= bfd_make_section (abfd
, name
);
350 (*_bfd_error_handler
) (_("bfd_make_section (%s) failed"),
354 old_flags
= bfd_getl16 (vms_rec
+ 2);
355 section
->size
= bfd_getl32 (vms_rec
+ 4); /* allocation */
356 new_flags
= vms_secflag_by_name (abfd
, vax_section_flags
, name
,
358 if (old_flags
& EGPS_S_V_REL
)
359 new_flags
|= SEC_RELOC
;
360 if (old_flags
& GPS_S_M_OVR
)
361 new_flags
|= SEC_IS_COMMON
;
362 if (!bfd_set_section_flags (abfd
, section
, new_flags
))
364 (*_bfd_error_handler
)
365 (_("bfd_set_section_flags (%s, %x) failed"),
369 section
->alignment_power
= vms_rec
[1];
370 align_addr
= (1 << section
->alignment_power
);
371 if ((base_addr
% align_addr
) != 0)
372 base_addr
+= (align_addr
- (base_addr
% align_addr
));
373 section
->vma
= (bfd_vma
)base_addr
;
374 base_addr
+= section
->size
;
376 /* Global section is common symbol. */
377 if (old_flags
& GPS_S_M_GBL
)
379 entry
= _bfd_vms_enter_symbol (abfd
, name
);
382 bfd_set_error (bfd_error_no_memory
);
385 symbol
= entry
->symbol
;
388 symbol
->section
= section
;
389 symbol
->flags
= (BSF_GLOBAL
| BSF_SECTION_SYM
| BSF_OLD_COMMON
);
392 /* Copy saved contents if old_section set. */
393 if (old_section
!= 0)
395 section
->contents
= old_section
->contents
;
396 if (section
->size
< old_section
->size
)
398 (*_bfd_error_handler
)
399 (_("Size mismatch section %s=%lx, %s=%lx"),
401 (unsigned long) old_section
->size
,
403 (unsigned long) section
->size
);
406 else if (section
->size
> old_section
->size
)
408 section
->contents
= bfd_realloc (old_section
->contents
,
410 if (section
->contents
== NULL
)
412 bfd_set_error (bfd_error_no_memory
);
419 section
->contents
= bfd_zmalloc (section
->size
);
420 if (section
->contents
== NULL
)
422 bfd_set_error (bfd_error_no_memory
);
427 vms_debug (4, "gsd psc %d (%s, flags %04x=%s) ",
428 section
->index
, name
, old_flags
, flag2str (gpsflagdesc
, old_flags
));
429 vms_debug (4, "%d bytes at 0x%08lx (mem %p)\n",
430 section
->size
, section
->vma
, section
->contents
);
433 gsd_size
= vms_rec
[8] + 9;
442 vms_debug (4, "gsd epm\n");
448 int name_offset
= 0, value_offset
= 0;
450 /* Symbol specification (definition or reference). */
452 vms_debug (4, "GSD_S_C_SYM(W)\n");
454 old_flags
= bfd_getl16 (vms_rec
+ 2);
455 new_flags
= BSF_NO_FLAGS
;
457 if (old_flags
& GSY_S_M_WEAK
)
458 new_flags
|= BSF_WEAK
;
465 new_flags
|= BSF_FUNCTION
;
470 new_flags
|= BSF_FUNCTION
;
473 if (old_flags
& GSY_S_M_DEF
) /* Symbol definition. */
480 if (old_flags
& GSY_S_M_DEF
) /* Symbol definition. */
488 /* Save symbol in vms_symbol_table. */
489 entry
= _bfd_vms_enter_symbol
490 (abfd
, _bfd_vms_save_counted_string (vms_rec
+ name_offset
));
493 bfd_set_error (bfd_error_no_memory
);
496 symbol
= entry
->symbol
;
498 if (old_flags
& GSY_S_M_DEF
)
500 /* Symbol definition. */
503 symbol
->value
= bfd_getl32 (vms_rec
+ value_offset
);
504 if ((gsd_type
== GSD_S_C_SYMW
)
505 || (gsd_type
== GSD_S_C_EPMW
))
506 psect
= bfd_getl16 (vms_rec
+ value_offset
- 2);
508 psect
= vms_rec
[value_offset
-1];
510 symbol
->section
= (asection
*)(unsigned long)psect
;
512 vms_debug (4, "gsd sym def #%d (%s, %ld, %04x=%s)\n", abfd
->symcount
,
513 symbol
->name
, (long)symbol
->section
, old_flags
, flag2str(gsyflagdesc
, old_flags
));
518 /* Symbol reference. */
520 vms_debug (4, "gsd sym ref #%d (%s, %04x=%s)\n", abfd
->symcount
,
521 symbol
->name
, old_flags
, flag2str (gsyflagdesc
, old_flags
));
523 symbol
->section
= (asection
*)(unsigned long)-1;
526 gsd_size
= vms_rec
[name_offset
] + name_offset
+ 1;
527 symbol
->flags
= new_flags
;
535 vms_debug (4, "gsd pro\n");
540 vms_debug (4, "gsd idc\n");
545 vms_debug (4, "gsd env\n");
550 vms_debug (4, "gsd lsy\n");
555 vms_debug (4, "gsd lepm\n");
560 vms_debug (4, "gsd lpro\n");
565 vms_debug (4, "gsd spsc\n");
570 vms_debug (4, "gsd symv\n");
575 vms_debug (4, "gsd epmv\n");
580 vms_debug (4, "gsd prov\n");
584 case EGSD_S_C_PSC
+ EVAX_OFFSET
:
586 /* Program section definition. */
587 name
= _bfd_vms_save_counted_string (vms_rec
+ EGPS_S_B_NAMLNG
);
588 section
= bfd_make_section (abfd
, name
);
591 old_flags
= bfd_getl16 (vms_rec
+ EGPS_S_W_FLAGS
);
592 section
->size
= bfd_getl32 (vms_rec
+ EGPS_S_L_ALLOC
);
593 new_flags
= vms_secflag_by_name (abfd
, evax_section_flags
, name
,
595 if (old_flags
& EGPS_S_V_REL
)
596 new_flags
|= SEC_RELOC
;
597 if (!bfd_set_section_flags (abfd
, section
, new_flags
))
599 section
->alignment_power
= vms_rec
[EGPS_S_B_ALIGN
];
600 align_addr
= (1 << section
->alignment_power
);
601 if ((base_addr
% align_addr
) != 0)
602 base_addr
+= (align_addr
- (base_addr
% align_addr
));
603 section
->vma
= (bfd_vma
)base_addr
;
604 base_addr
+= section
->size
;
605 section
->contents
= bfd_zmalloc (section
->size
);
606 if (section
->contents
== NULL
)
608 section
->filepos
= (unsigned int)-1;
610 vms_debug (4, "EGSD P-section %d (%s, flags %04x=%s) ",
611 section
->index
, name
, old_flags
, flag2str(gpsflagdesc
, old_flags
));
612 vms_debug (4, "%d bytes at 0x%08lx (mem %p)\n",
613 section
->size
, section
->vma
, section
->contents
);
618 case EGSD_S_C_SYM
+ EVAX_OFFSET
:
620 /* Global symbol specification (definition or reference). */
621 symbol
= bfd_make_empty_symbol (abfd
);
625 old_flags
= bfd_getl16 (vms_rec
+ EGSY_S_W_FLAGS
);
626 new_flags
= BSF_NO_FLAGS
;
628 if (old_flags
& EGSY_S_V_WEAK
)
629 new_flags
|= BSF_WEAK
;
631 if (old_flags
& EGSY_S_V_DEF
)
633 /* Symbol definition. */
634 if (old_flags
& EGSY_S_V_NORM
)
635 new_flags
|= BSF_FUNCTION
;
637 _bfd_vms_save_counted_string (vms_rec
+ ESDF_S_B_NAMLNG
);
638 symbol
->value
= bfd_getl64 (vms_rec
+ ESDF_S_L_VALUE
);
640 (asection
*)(unsigned long) bfd_getl32 (vms_rec
+ ESDF_S_L_PSINDX
);
642 vms_debug (4, "EGSD sym def #%d (%s, %ld, %04x=%s)\n",
643 abfd
->symcount
, symbol
->name
, (long)symbol
->section
,
644 old_flags
, flag2str (gsyflagdesc
, old_flags
));
649 /* Symbol reference. */
651 _bfd_vms_save_counted_string (vms_rec
+ ESRF_S_B_NAMLNG
);
653 vms_debug (4, "EGSD sym ref #%d (%s, %04x=%s)\n",
654 abfd
->symcount
, symbol
->name
, old_flags
,
655 flag2str (gsyflagdesc
, old_flags
));
657 symbol
->section
= (asection
*)(unsigned long)-1;
660 symbol
->flags
= new_flags
;
662 /* Register symbol in VMS symbol table. */
663 entry
= (vms_symbol_entry
*) bfd_hash_lookup
664 (PRIV (vms_symbol_table
), symbol
->name
, TRUE
, FALSE
);
668 bfd_set_error (bfd_error_no_memory
);
672 if (entry
->symbol
!= NULL
)
674 /* FIXME ?, DEC C generates this. */
676 vms_debug (4, "EGSD_S_C_SYM: duplicate \"%s\"\n", symbol
->name
);
681 entry
->symbol
= symbol
;
682 PRIV (gsd_sym_count
)++;
688 case EGSD_S_C_SYMG
+ EVAX_OFFSET
:
690 /* Universal symbol specification (definition). */
691 symbol
= bfd_make_empty_symbol (abfd
);
695 old_flags
= bfd_getl16 (vms_rec
+ EGST_S_W_FLAGS
);
696 new_flags
= BSF_NO_FLAGS
;
698 if (old_flags
& EGSY_S_V_WEAK
)
699 new_flags
|= BSF_WEAK
;
701 if (old_flags
& EGSY_S_V_DEF
) /* symbol definition */
703 if (old_flags
& EGSY_S_V_NORM
)
704 new_flags
|= BSF_FUNCTION
;
707 _bfd_vms_save_counted_string (vms_rec
+ EGST_S_B_NAMLNG
);
709 /* For BSF_FUNCTION symbols, the entry point is in LP_1
710 and the descriptor in LP_2. For other symbols, the
711 unique value is in LP_2. */
712 symbol
->value
= bfd_getl64 (vms_rec
+ EGST_S_Q_LP_2
);
714 /* Adding this offset is necessary in order for GDB to
715 read the DWARF-2 debug info from shared libraries. */
716 if (abfd
->flags
& DYNAMIC
717 && strstr (symbol
->name
, "$DWARF2.DEBUG") != 0)
718 symbol
->value
+= PRIV (symvva
);
720 else /* symbol reference */
721 (*_bfd_error_handler
) ("Invalid EGST reference");
723 symbol
->flags
= new_flags
;
725 if (register_universal_symbol (abfd
, symbol
, old_flags
) < 0)
728 /* Make a second symbol for the entry point. */
729 if (symbol
->flags
& BSF_FUNCTION
)
733 name
= bfd_alloc (abfd
, strlen (symbol
->name
) + 5);
735 en_sym
= bfd_make_empty_symbol (abfd
);
739 strcpy (name
, symbol
->name
);
740 strcat (name
, "..en");
743 en_sym
->value
= bfd_getl64 (vms_rec
+ EGST_S_Q_LP_1
);
745 if (register_universal_symbol (abfd
, en_sym
, old_flags
) < 0)
751 case EGSD_S_C_IDC
+ EVAX_OFFSET
:
755 (*_bfd_error_handler
) (_("Unknown GSD/EGSD subtype %d"), gsd_type
);
756 bfd_set_error (bfd_error_bad_value
);
760 PRIV (rec_size
) -= gsd_size
;
761 PRIV (vms_rec
) += gsd_size
;
764 if (abfd
->symcount
> 0)
765 abfd
->flags
|= HAS_SYMS
;
770 /* Register a universal symbol in the VMS symbol table. */
773 register_universal_symbol (bfd
*abfd
, asymbol
*symbol
, int vms_flags
)
776 asection
*s
, *sec
= NULL
;
777 vms_symbol_entry
*entry
;
779 /* A universal symbol is by definition global... */
780 symbol
->flags
|= BSF_GLOBAL
;
782 /* ...and dynamic in shared libraries. */
783 if (abfd
->flags
& DYNAMIC
)
784 symbol
->flags
|= BSF_DYNAMIC
;
786 /* Find containing section. */
787 for (s
= abfd
->sections
; s
; s
= s
->next
)
789 if (symbol
->value
>= s
->vma
791 && !(s
->flags
& SEC_COFF_SHARED_LIBRARY
)
792 && (s
->size
> 0 || !(vms_flags
& EGSY_S_V_REL
)))
799 symbol
->value
-= sbase
;
800 symbol
->section
= sec
;
803 vms_debug (4, "EGST sym def #%d (%s, 0x%llx => 0x%llx, %04x=%s)\n",
804 abfd
->symcount
, symbol
->name
, symbol
->value
+ sbase
,
805 symbol
->value
, vms_flags
,
806 flag2str(gsyflagdesc
, vms_flags
));
809 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV (vms_symbol_table
),
815 bfd_set_error (bfd_error_no_memory
);
819 if (entry
->symbol
) /* FIXME: DEC C generates this */
822 vms_debug (4, "EGSD_S_C_SYMG: duplicate \"%s\"\n", symbol
->name
);
827 entry
->symbol
= symbol
;
828 PRIV (gsd_sym_count
)++;
835 /* Set section VMS flags. */
838 bfd_vms_set_section_flags (bfd
*abfd ATTRIBUTE_UNUSED
,
839 asection
*sec
, flagword flags
)
841 vms_section_data (sec
)->vflags
= flags
;
844 /* Write section and symbol directory of bfd abfd. */
847 _bfd_vms_write_gsd (bfd
*abfd
, int objtype ATTRIBUTE_UNUSED
)
855 flagword new_flags
, old_flags
;
856 int abs_section_index
= 0;
859 vms_debug (2, "vms_write_gsd (%p, %d)\n", abfd
, objtype
);
862 /* Output sections. */
863 section
= abfd
->sections
;
865 vms_debug (3, "%d sections found\n", abfd
->section_count
);
868 /* Egsd is quadword aligned. */
869 _bfd_vms_output_alignment (abfd
, 8);
871 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EGSD
, -1);
872 _bfd_vms_output_long (abfd
, 0);
873 /* Prepare output for subrecords. */
874 _bfd_vms_output_push (abfd
);
879 vms_debug (3, "Section #%d %s, %d bytes\n", section
->index
, section
->name
, (int)section
->size
);
882 /* Don't write out the VMS debug info section since it is in the
883 ETBT and EDBG sections in etir. */
884 if (!strcmp (section
->name
, ".vmsdebug"))
887 /* 13 bytes egsd, max 31 chars name -> should be 44 bytes. */
888 if (_bfd_vms_output_check (abfd
, 64) < 0)
890 _bfd_vms_output_pop (abfd
);
891 _bfd_vms_output_end (abfd
);
892 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EGSD
, -1);
893 _bfd_vms_output_long (abfd
, 0);
894 /* Prepare output for subrecords. */
895 _bfd_vms_output_push (abfd
);
898 /* Create dummy sections to keep consecutive indices. */
899 while (section
->index
- last_index
> 1)
902 vms_debug (3, "index %d, last %d\n", section
->index
, last_index
);
904 _bfd_vms_output_begin (abfd
, EGSD_S_C_PSC
, -1);
905 _bfd_vms_output_short (abfd
, 0);
906 _bfd_vms_output_short (abfd
, 0);
907 _bfd_vms_output_long (abfd
, 0);
908 sprintf (dummy_name
, ".DUMMY%02d", last_index
);
909 _bfd_vms_output_counted (abfd
, dummy_name
);
910 _bfd_vms_output_flush (abfd
);
914 /* Don't know if this is necessary for the linker but for now it keeps
915 vms_slurp_gsd happy */
916 sname
= (char *)section
->name
;
920 if ((*sname
== 't') && (strcmp (sname
, "text") == 0))
921 sname
= PRIV (is_vax
)?VAX_CODE_NAME
:EVAX_CODE_NAME
;
922 else if ((*sname
== 'd') && (strcmp (sname
, "data") == 0))
923 sname
= PRIV (is_vax
)?VAX_DATA_NAME
:EVAX_DATA_NAME
;
924 else if ((*sname
== 'b') && (strcmp (sname
, "bss") == 0))
925 sname
= EVAX_BSS_NAME
;
926 else if ((*sname
== 'l') && (strcmp (sname
, "link") == 0))
927 sname
= EVAX_LINK_NAME
;
928 else if ((*sname
== 'r') && (strcmp (sname
, "rdata") == 0))
929 sname
= EVAX_READONLY_NAME
;
930 else if ((*sname
== 'l') && (strcmp (sname
, "literal") == 0))
931 sname
= EVAX_LITERAL_NAME
;
932 else if ((*sname
== 'l') && (strcmp (sname
, "literals") == 0))
934 sname
= EVAX_LITERALS_NAME
;
935 abs_section_index
= section
->index
;
937 else if ((*sname
== 'c') && (strcmp (sname
, "comm") == 0))
938 sname
= EVAX_COMMON_NAME
;
939 else if ((*sname
== 'l') && (strcmp (sname
, "lcomm") == 0))
940 sname
= EVAX_LOCAL_NAME
;
943 sname
= _bfd_vms_length_hash_symbol (abfd
, sname
, EOBJ_S_C_SECSIZ
);
945 _bfd_vms_output_begin (abfd
, EGSD_S_C_PSC
, -1);
946 _bfd_vms_output_short (abfd
, section
->alignment_power
& 0xff);
948 if (bfd_is_com_section (section
))
949 new_flags
= (EGPS_S_V_OVR
| EGPS_S_V_REL
| EGPS_S_V_GBL
| EGPS_S_V_RD
950 | EGPS_S_V_WRT
| EGPS_S_V_NOMOD
| EGPS_S_V_COM
);
952 new_flags
= vms_esecflag_by_name (evax_section_flags
, sname
,
955 /* Modify them as directed. */
956 if (section
->flags
& SEC_READONLY
)
957 new_flags
&= ~EGPS_S_V_WRT
;
959 new_flags
|= vms_section_data (section
)->vflags
& 0xffff;
961 ~((vms_section_data (section
)->vflags
>> EGPS_S_V_NO_SHIFT
) & 0xffff);
964 vms_debug (3, "sec flags %x\n", section
->flags
);
965 vms_debug (3, "new_flags %x, _raw_size %d\n", new_flags
, section
->size
);
968 _bfd_vms_output_short (abfd
, new_flags
);
969 _bfd_vms_output_long (abfd
, (unsigned long) section
->size
);
970 _bfd_vms_output_counted (abfd
, sname
);
971 _bfd_vms_output_flush (abfd
);
973 last_index
= section
->index
;
975 section
= section
->next
;
978 /* Output symbols. */
980 vms_debug (3, "%d symbols found\n", abfd
->symcount
);
983 bfd_set_start_address (abfd
, (bfd_vma
) -1);
985 for (symnum
= 0; symnum
< abfd
->symcount
; symnum
++)
989 symbol
= abfd
->outsymbols
[symnum
];
990 if (*(symbol
->name
) == '_')
992 if (strcmp (symbol
->name
, "__main") == 0)
993 bfd_set_start_address (abfd
, (bfd_vma
)symbol
->value
);
995 old_flags
= symbol
->flags
;
997 if (old_flags
& BSF_FILE
)
1000 if ((old_flags
& BSF_GLOBAL
) == 0 /* Not xdef... */
1001 && !bfd_is_und_section (symbol
->section
) /* and not xref... */
1002 && !((old_flags
& BSF_SECTION_SYM
) != 0 /* and not LIB$INITIALIZE. */
1003 && strcmp (symbol
->section
->name
, "LIB$INITIALIZE") == 0))
1006 /* 13 bytes egsd, max 64 chars name -> should be 77 bytes. */
1007 if (_bfd_vms_output_check (abfd
, 80) < 0)
1009 _bfd_vms_output_pop (abfd
);
1010 _bfd_vms_output_end (abfd
);
1011 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EGSD
, -1);
1012 _bfd_vms_output_long (abfd
, 0);
1013 /* Prepare output for subrecords. */
1014 _bfd_vms_output_push (abfd
);
1017 _bfd_vms_output_begin (abfd
, EGSD_S_C_SYM
, -1);
1019 /* Data type, alignment. */
1020 _bfd_vms_output_short (abfd
, 0);
1024 if (old_flags
& BSF_WEAK
)
1025 new_flags
|= EGSY_S_V_WEAK
;
1026 if (bfd_is_com_section (symbol
->section
)) /* .comm */
1027 new_flags
|= (EGSY_S_V_WEAK
| EGSY_S_V_COMM
);
1029 if (old_flags
& BSF_FUNCTION
)
1031 new_flags
|= EGSY_S_V_NORM
;
1032 new_flags
|= EGSY_S_V_REL
;
1034 if (old_flags
& BSF_GLOBAL
)
1036 new_flags
|= EGSY_S_V_DEF
;
1037 if (!bfd_is_abs_section (symbol
->section
))
1038 new_flags
|= EGSY_S_V_REL
;
1040 _bfd_vms_output_short (abfd
, new_flags
);
1042 if (old_flags
& BSF_GLOBAL
)
1044 /* Symbol definition. */
1045 uquad code_address
= 0;
1046 unsigned long ca_psindx
= 0;
1047 unsigned long psindx
;
1049 if ((old_flags
& BSF_FUNCTION
) && symbol
->udata
.p
!= NULL
)
1053 if (bfd_get_flavour (abfd
) == bfd_target_evax_flavour
)
1054 sym
= ((struct evax_private_udata_struct
*)symbol
->udata
.p
)->enbsym
;
1056 sym
= (asymbol
*)symbol
->udata
.p
;
1057 code_address
= sym
->value
;
1058 ca_psindx
= sym
->section
->index
;
1060 if (bfd_is_abs_section (symbol
->section
))
1061 psindx
= abs_section_index
;
1063 psindx
= symbol
->section
->index
;
1065 _bfd_vms_output_quad (abfd
, symbol
->value
);
1066 _bfd_vms_output_quad (abfd
, code_address
);
1067 _bfd_vms_output_long (abfd
, ca_psindx
);
1068 _bfd_vms_output_long (abfd
, psindx
);
1070 hash
= _bfd_vms_length_hash_symbol (abfd
, symbol
->name
, EOBJ_S_C_SYMSIZ
);
1071 _bfd_vms_output_counted (abfd
, hash
);
1073 _bfd_vms_output_flush (abfd
);
1077 _bfd_vms_output_alignment (abfd
, 8);
1078 _bfd_vms_output_pop (abfd
);
1079 _bfd_vms_output_end (abfd
);