elf: Strip zero-sized dynamic sections
[deliverable/binutils-gdb.git] / ld / emultempl / pdp11.em
1 # This shell script emits a C file. -*- C -*-
2 # Copyright (C) 2006-2020 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 "getopt.h"
25
26 static void
27 gld${EMULATION_NAME}_before_parse (void)
28 {
29 ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
30 /* for PDP11 Unix compatibility, default to --omagic */
31 config.magic_demand_paged = FALSE;
32 config.text_read_only = FALSE;
33 }
34
35 /* PDP11 specific options. */
36 #define OPTION_IMAGIC 301
37
38 static void
39 gld${EMULATION_NAME}_add_options
40 (int ns ATTRIBUTE_UNUSED,
41 char **shortopts,
42 int nl,
43 struct option **longopts,
44 int nrl ATTRIBUTE_UNUSED,
45 struct option **really_longopts ATTRIBUTE_UNUSED)
46 {
47 static const char xtra_short[] = "z";
48 static const struct option xtra_long[] =
49 {
50 {"imagic", no_argument, NULL, OPTION_IMAGIC},
51 {NULL, no_argument, NULL, 0}
52 };
53
54 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
55 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
56 *longopts
57 = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
58 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
59 }
60
61 static void
62 gld${EMULATION_NAME}_list_options (FILE *file)
63 {
64 fprintf (file, _(" -N, --omagic Do not make text readonly, do not page align data (default)\n"));
65 fprintf (file, _(" -n, --nmagic Make text readonly, align data to next page\n"));
66 fprintf (file, _(" -z, --imagic Make text readonly, separate instruction and data spaces\n"));
67 fprintf (file, _(" --no-omagic Equivalent to --nmagic\n"));
68 }
69
70 static bfd_boolean
71 gld${EMULATION_NAME}_handle_option (int optc)
72 {
73 switch (optc)
74 {
75 default:
76 return FALSE;
77
78 case 'z':
79 case OPTION_IMAGIC:
80 link_info.separate_code = 1;
81 /* The --imagic format causes the .text and .data sections to occupy the
82 same memory addresses in separate spaces, so don't check overlap. */
83 command_line.check_section_addresses = 0;
84 break;
85 }
86
87 return TRUE;
88 }
89
90 /* We need a special case to prepare an additional linker script for option
91 * --imagic where the .data section starts at address 0 rather than directly
92 * following the .text section or being aligned to the next page after the
93 * .text section. */
94 static char *
95 gld${EMULATION_NAME}_get_script (int *isfile)
96 EOF
97 # Scripts compiled in.
98 # sed commands to quote an ld script as a C string.
99 sc="-f stringify.sed"
100
101 fragment <<EOF
102 {
103 *isfile = 0;
104
105 if (bfd_link_relocatable (&link_info) && config.build_constructors)
106 return
107 EOF
108 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
109 echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
110 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
111 echo ' ; else if (link_info.separate_code) return' >> e${EMULATION_NAME}.c
112 sed $sc ldscripts/${EMULATION_NAME}.xn | \
113 sed -e "s/ALIGN($TARGET_PAGE_SIZE)/0/" >> e${EMULATION_NAME}.c
114 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
115 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
116 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
117 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
118 echo ' ; else return' >> e${EMULATION_NAME}.c
119 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
120 echo '; }' >> e${EMULATION_NAME}.c
121
122 fragment <<EOF
123
124 /* --- \end{pdp11.em} */
125
126 EOF
127
128 LDEMUL_BEFORE_PARSE=gld"$EMULATION_NAME"_before_parse
129 LDEMUL_ADD_OPTIONS=gld"$EMULATION_NAME"_add_options
130 LDEMUL_HANDLE_OPTION=gld"$EMULATION_NAME"_handle_option
131 LDEMUL_LIST_OPTIONS=gld"$EMULATION_NAME"_list_options
132 LDEMUL_GET_SCRIPT=gld"$EMULATION_NAME"_get_script
This page took 0.072778 seconds and 4 git commands to generate.