Automatic date update in version.in
[binutils-gdb.git] / ld / emultempl / pdp11.em
blob62404038a2da2297c631190bb53791cc8cb03f87
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,
19 # MA 02110-1301, USA.
21 fragment <<EOF
23 /* --- \begin{pdp11.em} */
24 #include "libiberty.h"
25 #include "getopt.h"
27 static void
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
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)
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   };
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));
62 static void
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"));
71 static bool
72 gld${EMULATION_NAME}_handle_option (int optc)
74   switch (optc)
75     {
76     default:
77       return false;
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     }
88   return true;
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
99 if test x"$COMPILE_IN" = xyes
100 then
101 # Scripts compiled in.
103 # sed commands to quote an ld script as a C string.
104 sc="-f ${srcdir}/emultempl/stringify.sed"
106 fragment <<EOF
108   *isfile = 0;
110   if (bfd_link_relocatable (&link_info) && config.build_constructors)
111     return
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
126 else
127 # Scripts read from the filesystem.
129 fragment <<EOF
131   *isfile = 1;
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";
149 fragment <<EOF
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