1 # This shell script emits a C file. -*- C -*-
2 # Copyright (C) 2006-2024 Free Software Foundation, Inc.
4 # This file is part of the GNU Binutils.
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.
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.
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,
23 /* --- \begin{pdp11.em} */
24 #include "libiberty.h"
28 gld${EMULATION_NAME}_before_parse (void)
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;
36 /* PDP11 specific options. */
37 #define OPTION_IMAGIC 301
40 gld${EMULATION_NAME}_add_options
41 (int ns ATTRIBUTE_UNUSED,
44 struct option **longopts,
45 int nrl ATTRIBUTE_UNUSED,
46 struct option **really_longopts ATTRIBUTE_UNUSED)
48 static const char xtra_short[] = "z";
49 static const struct option xtra_long[] =
51 {"imagic", no_argument, NULL, OPTION_IMAGIC},
52 {NULL, no_argument, NULL, 0}
55 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
56 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
58 = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
59 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
63 gld${EMULATION_NAME}_list_options (FILE *file)
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"));
72 gld${EMULATION_NAME}_handle_option (int optc)
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;
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
96 gld${EMULATION_NAME}_get_script (int *isfile)
99 if test x"$COMPILE_IN" = xyes
101 # Scripts compiled in.
103 # sed commands to quote an ld script as a C string.
104 sc="-f ${srcdir}/emultempl/stringify.sed"
110 if (bfd_link_relocatable (&link_info) && config.build_constructors)
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
127 # Scripts read from the filesystem.
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";
144 return "ldscripts/${EMULATION_NAME}.x";
151 /* --- \end{pdp11.em} */
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