]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/emultempl/pdp11.em
c6dbdeedd6a267a25fab8ec19e35d64652245917
[thirdparty/binutils-gdb.git] / ld / emultempl / pdp11.em
1 # This shell script emits a C file. -*- C -*-
2 # Copyright (C) 2006-2023 Free Software Foundation, Inc.
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 fragment <<EOF
22
23 /* --- \begin{pdp11.em} */
24 #include "libiberty.h"
25 #include "getopt.h"
26
27 static void
28 gld${EMULATION_NAME}_before_parse (void)
29 {
30 ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
31 /* for PDP11 Unix compatibility, default to --omagic */
32 config.magic_demand_paged = false;
33 config.text_read_only = false;
34 }
35
36 /* PDP11 specific options. */
37 #define OPTION_IMAGIC 301
38
39 static void
40 gld${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
62 static void
63 gld${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
71 static bool
72 gld${EMULATION_NAME}_handle_option (int optc)
73 {
74 switch (optc)
75 {
76 default:
77 return false;
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
88 return true;
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. */
95 static char *
96 gld${EMULATION_NAME}_get_script (int *isfile)
97 EOF
98
99 if test x"$COMPILE_IN" = xyes
100 then
101 # Scripts compiled in.
102
103 # sed commands to quote an ld script as a C string.
104 sc="-f stringify.sed"
105
106 fragment <<EOF
107 {
108 *isfile = 0;
109
110 if (bfd_link_relocatable (&link_info) && config.build_constructors)
111 return
112 EOF
113 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
114 echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
115 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
116 echo ' ; else if (link_info.separate_code) return' >> e${EMULATION_NAME}.c
117 sed $sc ldscripts/${EMULATION_NAME}.xe >> e${EMULATION_NAME}.c
118 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
119 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
120 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
121 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
122 echo ' ; else return' >> e${EMULATION_NAME}.c
123 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
124 echo '; }' >> e${EMULATION_NAME}.c
125
126 else
127 # Scripts read from the filesystem.
128
129 fragment <<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 }
146 EOF
147 fi
148
149 fragment <<EOF
150
151 /* --- \end{pdp11.em} */
152
153 EOF
154
155 LDEMUL_BEFORE_PARSE=gld"$EMULATION_NAME"_before_parse
156 LDEMUL_ADD_OPTIONS=gld"$EMULATION_NAME"_add_options
157 LDEMUL_HANDLE_OPTION=gld"$EMULATION_NAME"_handle_option
158 LDEMUL_LIST_OPTIONS=gld"$EMULATION_NAME"_list_options
159 LDEMUL_GET_SCRIPT=gld"$EMULATION_NAME"_get_script