]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/emultempl/vms.em
Revert "2.41 Release sources"
[thirdparty/binutils-gdb.git] / ld / emultempl / vms.em
CommitLineData
8b351884 1# This shell script emits a C file. -*- C -*-
d87bef3a 2# Copyright (C) 2010-2023 Free Software Foundation, Inc.
8b351884
TG
3#
4# This file is part of the GNU Binutils.
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19# MA 02110-1301, USA.
20#
21
22# This file is sourced from generic.em.
23
24fragment <<EOF
b5c37946 25#include "libiberty.h"
45cfb56c
TG
26#include "getopt.h"
27
8b351884
TG
28static void
29gld${EMULATION_NAME}_before_parse (void)
30{
31 ldfile_set_output_arch ("${ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
f38a2680
AM
32 input_flags.dynamic = true;
33 config.has_shared = false; /* Not yet. */
202e2356
NC
34
35 /* For ia64, harmless for alpha. */
f38a2680 36 link_info.emit_hash = false;
202e2356 37 link_info.spare_dynamic_tags = 0;
8b351884
TG
38}
39
40/* This is called before the input files are opened. We add the
41 standard library. */
42
43static void
44gld${EMULATION_NAME}_create_output_section_statements (void)
45{
46 lang_add_input_file ("imagelib", lang_input_file_is_l_enum, NULL);
47 lang_add_input_file ("starlet", lang_input_file_is_l_enum, NULL);
48 lang_add_input_file ("sys\$public_vectors", lang_input_file_is_l_enum, NULL);
49}
50
51/* Try to open a dynamic archive. This is where we know that VMS
52 shared images (dynamic libraries) have an extension of .exe. */
53
f38a2680 54static bool
8b351884 55gld${EMULATION_NAME}_open_dynamic_archive (const char *arch ATTRIBUTE_UNUSED,
6c19b93b
AM
56 search_dirs_type *search,
57 lang_input_statement_type *entry)
8b351884
TG
58{
59 char *string;
60
d4ae5fb0 61 if (! entry->flags.maybe_archive || entry->flags.full_name_provided)
f38a2680 62 return false;
8b351884
TG
63
64 string = (char *) xmalloc (strlen (search->name)
65 + strlen (entry->filename)
66 + sizeof "/.exe");
67
68 sprintf (string, "%s/%s.exe", search->name, entry->filename);
69
70 if (! ldfile_try_open_bfd (string, entry))
71 {
72 free (string);
f38a2680 73 return false;
8b351884
TG
74 }
75
76 entry->filename = string;
77
f38a2680 78 return true;
8b351884
TG
79}
80
81static int
82gld${EMULATION_NAME}_find_potential_libraries
83 (char *name, lang_input_statement_type *entry)
84{
85 return ldfile_open_file_search (name, entry, "", ".olb");
86}
87
88/* Place an orphan section. We use this to put random OVR sections.
075a2b89 89 Much borrowed from elf.em. */
8b351884
TG
90
91static lang_output_section_statement_type *
92vms_place_orphan (asection *s,
93 const char *secname ATTRIBUTE_UNUSED,
94 int constraint ATTRIBUTE_UNUSED)
95{
96 static struct orphan_save hold_data =
97 {
98 "\$DATA\$",
99 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
100 0, 0, 0, 0
101 };
102
46d00b8a
TG
103 /* We have nothing to say for anything other than a final link or an excluded
104 section. */
0e1862bb 105 if (bfd_link_relocatable (&link_info)
8b351884
TG
106 || (s->flags & (SEC_EXCLUDE | SEC_LOAD)) != SEC_LOAD)
107 return NULL;
108
46d00b8a
TG
109 /* FIXME: we should place sections by VMS program section flags. */
110
8b351884
TG
111 /* Only handle data sections. */
112 if ((s->flags & SEC_DATA) == 0)
113 return NULL;
114
115 if (hold_data.os == NULL)
116 hold_data.os = lang_output_section_find (hold_data.name);
117
118 if (hold_data.os != NULL)
119 {
b209b5a6 120 lang_add_section (&hold_data.os->children, s, NULL, NULL, hold_data.os);
8b351884
TG
121 return hold_data.os;
122 }
123 else
124 return NULL;
125}
45cfb56c
TG
126
127/* VMS specific options. */
128#define OPTION_IDENTIFICATION (300 + 1)
129
130static void
131gld${EMULATION_NAME}_add_options
132 (int ns ATTRIBUTE_UNUSED,
133 char **shortopts ATTRIBUTE_UNUSED,
134 int nl,
135 struct option **longopts,
136 int nrl ATTRIBUTE_UNUSED,
137 struct option **really_longopts ATTRIBUTE_UNUSED)
138{
202e2356
NC
139 static const struct option xtra_long[] =
140 {
45cfb56c
TG
141 {"identification", required_argument, NULL, OPTION_IDENTIFICATION},
142 {NULL, no_argument, NULL, 0}
143 };
144
145 *longopts
146 = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
147 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
148}
149
150static void
151gld${EMULATION_NAME}_list_options (FILE *file)
152{
153 fprintf (file, _(" --identification <string> Set the identification of the output\n"));
154}
155
f38a2680 156static bool
45cfb56c
TG
157gld${EMULATION_NAME}_handle_option (int optc)
158{
159 switch (optc)
160 {
161 default:
f38a2680 162 return false;
45cfb56c
TG
163
164 case OPTION_IDENTIFICATION:
165 /* Currently ignored. */
166 break;
167 }
168
f38a2680 169 return true;
45cfb56c
TG
170}
171
8b351884
TG
172EOF
173
202e2356
NC
174if test "$OUTPUT_FORMAT" = "elf64-ia64-vms"; then
175
176fragment <<EOF
177#include "elf-bfd.h"
d871d478 178#include "ldelfgen.h"
202e2356
NC
179EOF
180
181source_em ${srcdir}/emultempl/elf-generic.em
182
183fragment <<EOF
184
185/* This is called after the sections have been attached to output
186 sections, but before any sizes or addresses have been set. */
187
188static void
189gld${EMULATION_NAME}_before_allocation (void)
190{
191 const struct elf_backend_data *bed;
192
193 if (!is_elf_hash_table (link_info.hash))
194 return;
195
196 bed = get_elf_backend_data (link_info.output_bfd);
197
198 /* The backend must work out the sizes of all the other dynamic
199 sections. */
200 if (elf_hash_table (&link_info)->dynamic_sections_created
201 && bed->elf_backend_size_dynamic_sections
202 && ! (*bed->elf_backend_size_dynamic_sections) (link_info.output_bfd,
6c19b93b 203 &link_info))
df5f2391 204 einfo (_("%F%P: failed to set dynamic section sizes: %E\n"));
202e2356
NC
205
206 before_allocation_default ();
207}
208
209static void
210gld${EMULATION_NAME}_after_allocation (void)
211{
75938853
AM
212 int need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info);
213
214 if (need_layout < 0)
d003af55 215 einfo (_("%X%P: .eh_frame/.stab edit: %E\n"));
75938853 216 else
d871d478 217 ldelf_map_segments (need_layout);
202e2356
NC
218}
219
220static void
221gld${EMULATION_NAME}_after_parse (void)
222{
223 link_info.relax_pass = 2;
224 after_parse_default ();
225}
226EOF
227
228LDEMUL_BEFORE_ALLOCATION=gld"$EMULATION_NAME"_before_allocation
229LDEMUL_AFTER_ALLOCATION=gld"$EMULATION_NAME"_after_allocation
230
231LDEMUL_AFTER_PARSE=gld${EMULATION_NAME}_after_parse
232source_em ${srcdir}/emultempl/needrelax.em
233fi
234
8b351884
TG
235LDEMUL_PLACE_ORPHAN=vms_place_orphan
236LDEMUL_BEFORE_PARSE=gld"$EMULATION_NAME"_before_parse
237LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=gld"$EMULATION_NAME"_create_output_section_statements
238LDEMUL_FIND_POTENTIAL_LIBRARIES=gld"$EMULATION_NAME"_find_potential_libraries
239LDEMUL_OPEN_DYNAMIC_ARCHIVE=gld"$EMULATION_NAME"_open_dynamic_archive
45cfb56c
TG
240LDEMUL_ADD_OPTIONS=gld"$EMULATION_NAME"_add_options
241LDEMUL_HANDLE_OPTION=gld"$EMULATION_NAME"_handle_option
242LDEMUL_LIST_OPTIONS=gld"$EMULATION_NAME"_list_options