gdb/
[binutils-gdb.git] / ld / emultempl / vms.em
1 # This shell script emits a C file. -*- C -*-
2 # Copyright 2010
3 # Free Software Foundation, Inc.
4 #
5 # This file is part of the GNU Binutils.
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 # MA 02110-1301, USA.
21 #
22
23 # This file is sourced from generic.em.
24
25 fragment <<EOF
26 static void
27 gld${EMULATION_NAME}_before_parse (void)
28 {
29 ldfile_set_output_arch ("${ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
30 config.dynamic_link = TRUE;
31 config.has_shared = FALSE; /* Not yet. */
32 }
33
34 /* This is called before the input files are opened. We add the
35 standard library. */
36
37 static void
38 gld${EMULATION_NAME}_create_output_section_statements (void)
39 {
40 lang_add_input_file ("imagelib", lang_input_file_is_l_enum, NULL);
41 lang_add_input_file ("starlet", lang_input_file_is_l_enum, NULL);
42 lang_add_input_file ("sys\$public_vectors", lang_input_file_is_l_enum, NULL);
43 }
44
45 /* Try to open a dynamic archive. This is where we know that VMS
46 shared images (dynamic libraries) have an extension of .exe. */
47
48 static bfd_boolean
49 gld${EMULATION_NAME}_open_dynamic_archive (const char *arch ATTRIBUTE_UNUSED,
50 search_dirs_type *search,
51 lang_input_statement_type *entry)
52 {
53 char *string;
54
55 if (! entry->is_archive)
56 return FALSE;
57
58 string = (char *) xmalloc (strlen (search->name)
59 + strlen (entry->filename)
60 + sizeof "/.exe");
61
62 sprintf (string, "%s/%s.exe", search->name, entry->filename);
63
64 if (! ldfile_try_open_bfd (string, entry))
65 {
66 free (string);
67 return FALSE;
68 }
69
70 entry->filename = string;
71
72 return TRUE;
73 }
74
75 static int
76 gld${EMULATION_NAME}_find_potential_libraries
77 (char *name, lang_input_statement_type *entry)
78 {
79 return ldfile_open_file_search (name, entry, "", ".olb");
80 }
81
82 /* Place an orphan section. We use this to put random OVR sections.
83 Much borrowed from elf32.em. */
84
85 static lang_output_section_statement_type *
86 vms_place_orphan (asection *s,
87 const char *secname ATTRIBUTE_UNUSED,
88 int constraint ATTRIBUTE_UNUSED)
89 {
90 static struct orphan_save hold_data =
91 {
92 "\$DATA\$",
93 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
94 0, 0, 0, 0
95 };
96
97 /* We have nothing to say for anything other than a final link or an excluded
98 section. */
99 if (link_info.relocatable
100 || (s->flags & (SEC_EXCLUDE | SEC_LOAD)) != SEC_LOAD)
101 return NULL;
102
103 /* FIXME: we should place sections by VMS program section flags. */
104
105 /* Only handle data sections. */
106 if ((s->flags & SEC_DATA) == 0)
107 return NULL;
108
109 if (hold_data.os == NULL)
110 hold_data.os = lang_output_section_find (hold_data.name);
111
112 if (hold_data.os != NULL)
113 {
114 lang_add_section (&hold_data.os->children, s, hold_data.os);
115 return hold_data.os;
116 }
117 else
118 return NULL;
119 }
120 EOF
121
122 LDEMUL_PLACE_ORPHAN=vms_place_orphan
123 LDEMUL_BEFORE_PARSE=gld"$EMULATION_NAME"_before_parse
124 LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=gld"$EMULATION_NAME"_create_output_section_statements
125 LDEMUL_FIND_POTENTIAL_LIBRARIES=gld"$EMULATION_NAME"_find_potential_libraries
126 LDEMUL_OPEN_DYNAMIC_ARCHIVE=gld"$EMULATION_NAME"_open_dynamic_archive