]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/emultempl/pdp11.em
Don't declare xmalloc and others in ldmisc.h
[thirdparty/binutils-gdb.git] / ld / emultempl / pdp11.em
CommitLineData
fa1477dc 1# This shell script emits a C file. -*- C -*-
d87bef3a 2# Copyright (C) 2006-2023 Free Software Foundation, Inc.
fa1477dc
SC
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
21fragment <<EOF
22
23/* --- \begin{pdp11.em} */
44f8d229 24#include "libiberty.h"
fa1477dc
SC
25#include "getopt.h"
26
27static void
28gld${EMULATION_NAME}_before_parse (void)
29{
30 ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
31 /* for PDP11 Unix compatibility, default to --omagic */
f38a2680
AM
32 config.magic_demand_paged = false;
33 config.text_read_only = false;
fa1477dc
SC
34}
35
36/* PDP11 specific options. */
37#define OPTION_IMAGIC 301
38
39static void
40gld${EMULATION_NAME}_add_options
41 (int ns ATTRIBUTE_UNUSED,
42 char **shortopts,
43 int nl,
44 struct option **longopts,
45 int nrl ATTRIBUTE_UNUSED,
46 struct option **really_longopts ATTRIBUTE_UNUSED)
47{
48 static const char xtra_short[] = "z";
49 static const struct option xtra_long[] =
50 {
51 {"imagic", no_argument, NULL, OPTION_IMAGIC},
52 {NULL, no_argument, NULL, 0}
53 };
54
55 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
56 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
57 *longopts
58 = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
59 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
60}
61
62static void
63gld${EMULATION_NAME}_list_options (FILE *file)
64{
65 fprintf (file, _(" -N, --omagic Do not make text readonly, do not page align data (default)\n"));
66 fprintf (file, _(" -n, --nmagic Make text readonly, align data to next page\n"));
67 fprintf (file, _(" -z, --imagic Make text readonly, separate instruction and data spaces\n"));
68 fprintf (file, _(" --no-omagic Equivalent to --nmagic\n"));
69}
70
f38a2680 71static bool
fa1477dc
SC
72gld${EMULATION_NAME}_handle_option (int optc)
73{
74 switch (optc)
75 {
76 default:
f38a2680 77 return false;
fa1477dc
SC
78
79 case 'z':
80 case OPTION_IMAGIC:
81 link_info.separate_code = 1;
82 /* The --imagic format causes the .text and .data sections to occupy the
83 same memory addresses in separate spaces, so don't check overlap. */
84 command_line.check_section_addresses = 0;
85 break;
86 }
87
f38a2680 88 return true;
fa1477dc
SC
89}
90
91/* We need a special case to prepare an additional linker script for option
92 * --imagic where the .data section starts at address 0 rather than directly
93 * following the .text section or being aligned to the next page after the
94 * .text section. */
95static char *
96gld${EMULATION_NAME}_get_script (int *isfile)
97EOF
1c9c9b9b
AM
98
99if test x"$COMPILE_IN" = xyes
100then
fa1477dc 101# Scripts compiled in.
1c9c9b9b 102
fa1477dc
SC
103# sed commands to quote an ld script as a C string.
104sc="-f stringify.sed"
105
106fragment <<EOF
107{
108 *isfile = 0;
109
110 if (bfd_link_relocatable (&link_info) && config.build_constructors)
111 return
112EOF
113sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
114echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
115sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
116echo ' ; else if (link_info.separate_code) return' >> e${EMULATION_NAME}.c
1c9c9b9b 117sed $sc ldscripts/${EMULATION_NAME}.xe >> e${EMULATION_NAME}.c
fa1477dc
SC
118echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
119sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
120echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
121sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
122echo ' ; else return' >> e${EMULATION_NAME}.c
123sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
124echo '; }' >> e${EMULATION_NAME}.c
125
1c9c9b9b
AM
126else
127# Scripts read from the filesystem.
128
129fragment <<EOF
130{
131 *isfile = 1;
132
133 if (bfd_link_relocatable (&link_info) && config.build_constructors)
134 return "ldscripts/${EMULATION_NAME}.xu";
135 else if (bfd_link_relocatable (&link_info))
136 return "ldscripts/${EMULATION_NAME}.xr";
137 else if (link_info.separate_code)
138 return "ldscripts/${EMULATION_NAME}.xe";
139 else if (!config.text_read_only)
140 return "ldscripts/${EMULATION_NAME}.xbn";
141 else if (!config.magic_demand_paged)
142 return "ldscripts/${EMULATION_NAME}.xn";
143 else
144 return "ldscripts/${EMULATION_NAME}.x";
145}
146EOF
147fi
148
fa1477dc
SC
149fragment <<EOF
150
151/* --- \end{pdp11.em} */
152
153EOF
154
155LDEMUL_BEFORE_PARSE=gld"$EMULATION_NAME"_before_parse
156LDEMUL_ADD_OPTIONS=gld"$EMULATION_NAME"_add_options
157LDEMUL_HANDLE_OPTION=gld"$EMULATION_NAME"_handle_option
158LDEMUL_LIST_OPTIONS=gld"$EMULATION_NAME"_list_options
159LDEMUL_GET_SCRIPT=gld"$EMULATION_NAME"_get_script