aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
Diffstat (limited to 'ld')
-rw-r--r--ld/ChangeLog22
-rw-r--r--ld/NEWS4
-rw-r--r--ld/emulparams/pdp11.sh3
-rw-r--r--ld/emultempl/pdp11.em132
-rw-r--r--ld/gen-doc.texi1
-rw-r--r--ld/ld.texi70
-rw-r--r--ld/lexsup.c1
-rw-r--r--ld/scripttempl/pdp11.sc56
-rw-r--r--ld/testsuite/ld-pdp11/imagic.d12
-rw-r--r--ld/testsuite/ld-pdp11/imagicz.d12
-rw-r--r--ld/testsuite/ld-pdp11/nmagic.d11
-rw-r--r--ld/testsuite/ld-pdp11/omagic.d12
-rw-r--r--ld/testsuite/ld-pdp11/pdp11.exp33
-rw-r--r--ld/testsuite/ld-pdp11/sections.s13
14 files changed, 380 insertions, 2 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 62c0e0d..f53b226 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,25 @@
+2020-04-14 Stephen Casner <casner@acm.org>
+
+ PR ld/25677
+ * emulparams/pdp11.sh (SCRIPT_NAME): Change to pdp11.
+ (EXTRA_EM_FILE): New, add emulation file pdp11.
+ * scripttempl/pdp11.sc: New, derived from aout.sc without
+ irrelevant input sections.
+ * emultempl/pdp11.em (_add_options, _handle_option)
+ (_list_options): New. Add options -z, --imagic for pdp11-aout.
+ (_before_parse): Make --omagic be default instead of --nmagic.
+ (_get_script): Modify special-case linker script for --imagic.
+ * lexsup.c (parse_args): Explictly set config.text_read_only for -n.
+ * ld.texi (Options): Add documentation of PDP11-specific options.
+ (Options): Fix unrelated typo to --no-compact-branches.
+ * gen-doc.texi: @set PDP11.
+ * testsuite/ld-pdp11/pdp11.exp: New, start pdp11 testing.
+ * testsuite/ld-pdp11/sections.s: New, source for options tests.
+ * testsuite/ld-pdp11/imagic.d: New, test --imagic format.
+ * testsuite/ld-pdp11/imagicz.d: New, test -z (imagic) format.
+ * testsuite/ld-pdp11/nmagic.d: New, test --nmagic format.
+ * testsuite/ld-pdp11/omagic.d: New, test --omagic format.
+
2020-04-14 H.J. Lu <hongjiu.lu@intel.com>
PR binutils/25707
diff --git a/ld/NEWS b/ld/NEWS
index 563af67..9795b58 100644
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -3,6 +3,10 @@
* Add command-line options --enable-non-contiguous-regions and
--enable-non-contiguous-regions-warnings.
+* Add command-line option --imagic for the pdp11-aout target to output format
+ IMAGIC (0411) for separate instruction and data spaces, and change the
+ default format option for pdp11-aout to be --omagic.
+
Changes in 2.34:
* The ld check for "PHDR segment not covered by LOAD segment" is more
diff --git a/ld/emulparams/pdp11.sh b/ld/emulparams/pdp11.sh
index 9b6bbbb..3f3326d 100644
--- a/ld/emulparams/pdp11.sh
+++ b/ld/emulparams/pdp11.sh
@@ -1,5 +1,6 @@
-SCRIPT_NAME=aout
+SCRIPT_NAME=pdp11
OUTPUT_FORMAT="a.out-pdp11"
TEXT_START_ADDR=0
TARGET_PAGE_SIZE=8192
+EXTRA_EM_FILE=pdp11
ARCH=pdp11
diff --git a/ld/emultempl/pdp11.em b/ld/emultempl/pdp11.em
new file mode 100644
index 0000000..d18a420
--- /dev/null
+++ b/ld/emultempl/pdp11.em
@@ -0,0 +1,132 @@
+# This shell script emits a C file. -*- C -*-
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+#
+# This file is part of the GNU Binutils.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+fragment <<EOF
+
+/* --- \begin{pdp11.em} */
+#include "getopt.h"
+
+static void
+gld${EMULATION_NAME}_before_parse (void)
+{
+ ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
+ /* for PDP11 Unix compatibility, default to --omagic */
+ config.magic_demand_paged = FALSE;
+ config.text_read_only = FALSE;
+}
+
+/* PDP11 specific options. */
+#define OPTION_IMAGIC 301
+
+static void
+gld${EMULATION_NAME}_add_options
+ (int ns ATTRIBUTE_UNUSED,
+ char **shortopts,
+ int nl,
+ struct option **longopts,
+ int nrl ATTRIBUTE_UNUSED,
+ struct option **really_longopts ATTRIBUTE_UNUSED)
+{
+ static const char xtra_short[] = "z";
+ static const struct option xtra_long[] =
+ {
+ {"imagic", no_argument, NULL, OPTION_IMAGIC},
+ {NULL, no_argument, NULL, 0}
+ };
+
+ *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
+ memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
+ *longopts
+ = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
+ memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
+}
+
+static void
+gld${EMULATION_NAME}_list_options (FILE *file)
+{
+ fprintf (file, _(" -N, --omagic Do not make text readonly, do not page align data (default)\n"));
+ fprintf (file, _(" -n, --nmagic Make text readonly, align data to next page\n"));
+ fprintf (file, _(" -z, --imagic Make text readonly, separate instruction and data spaces\n"));
+ fprintf (file, _(" --no-omagic Equivalent to --nmagic\n"));
+}
+
+static bfd_boolean
+gld${EMULATION_NAME}_handle_option (int optc)
+{
+ switch (optc)
+ {
+ default:
+ return FALSE;
+
+ case 'z':
+ case OPTION_IMAGIC:
+ link_info.separate_code = 1;
+ /* The --imagic format causes the .text and .data sections to occupy the
+ same memory addresses in separate spaces, so don't check overlap. */
+ command_line.check_section_addresses = 0;
+ break;
+ }
+
+ return TRUE;
+}
+
+/* We need a special case to prepare an additional linker script for option
+ * --imagic where the .data section starts at address 0 rather than directly
+ * following the .text section or being aligned to the next page after the
+ * .text section. */
+static char *
+gld${EMULATION_NAME}_get_script (int *isfile)
+EOF
+# Scripts compiled in.
+# sed commands to quote an ld script as a C string.
+sc="-f stringify.sed"
+
+fragment <<EOF
+{
+ *isfile = 0;
+
+ if (bfd_link_relocatable (&link_info) && config.build_constructors)
+ return
+EOF
+sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
+echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
+echo ' ; else if (link_info.separate_code) return' >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.xn | \
+ sed -e "s/ALIGN($TARGET_PAGE_SIZE)/0/" >> e${EMULATION_NAME}.c
+echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
+echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
+echo ' ; else return' >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
+echo '; }' >> e${EMULATION_NAME}.c
+
+fragment <<EOF
+
+/* --- \end{pdp11.em} */
+
+EOF
+
+LDEMUL_BEFORE_PARSE=gld"$EMULATION_NAME"_before_parse
+LDEMUL_ADD_OPTIONS=gld"$EMULATION_NAME"_add_options
+LDEMUL_HANDLE_OPTION=gld"$EMULATION_NAME"_handle_option
+LDEMUL_LIST_OPTIONS=gld"$EMULATION_NAME"_list_options
+LDEMUL_GET_SCRIPT=gld"$EMULATION_NAME"_get_script
diff --git a/ld/gen-doc.texi b/ld/gen-doc.texi
index 850b227..d47a0a9 100644
--- a/ld/gen-doc.texi
+++ b/ld/gen-doc.texi
@@ -19,6 +19,7 @@
@set MSP430
@set NDS32
@set NIOSII
+@set PDP11
@set POWERPC
@set POWERPC64
@set Renesas
diff --git a/ld/ld.texi b/ld/ld.texi
index 9f56293..8286af6 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -31,6 +31,7 @@
@set MSP430
@set NDS32
@set NIOSII
+@set PDP11
@set POWERPC
@set POWERPC64
@set Renesas
@@ -3260,7 +3261,7 @@ an error.
@kindex --compact-branches
@item --compact-branches
@kindex --no-compact-branches
-@item --compact-branches
+@itemx --no-compact-branches
These options control the generation of compact instructions by the linker
in the PLT entries for MIPS R6.
@@ -3269,6 +3270,73 @@ in the PLT entries for MIPS R6.
@c man end
@end ifset
+
+@ifset PDP11
+@subsection Options specific to PDP11 targets
+
+@c man begin OPTIONS
+
+For the pdp11-aout target, three variants of the output format can be
+produced as selected by the following options. The default variant
+for pdp11-aout is the @samp{--omagic} option, whereas for other
+targets @samp{--nmagic} is the default. The @samp{--imagic} option is
+defined only for the pdp11-aout target, while the others are described
+here as they apply to the pdp11-aout target.
+
+@table @gcctabopt
+
+@kindex -N
+@item -N
+@kindex --omagic
+@itemx --omagic
+
+Mark the output as @code{OMAGIC} (0407) in the @file{a.out} header to
+indicate that the text segment is not to be write-protected and
+shared. Since the text and data sections are both readable and
+writable, the data section is allocated immediately contiguous after
+the text segment. This is the oldest format for PDP11 executable
+programs and is the default for @command{ld} on PDP11 Unix systems
+from the beginning through 2.11BSD.
+
+@kindex -n
+@item -n
+@kindex --nmagic
+@itemx --nmagic
+
+Mark the output as @code{NMAGIC} (0410) in the @file{a.out} header to
+indicate that when the output file is executed, the text portion will
+be read-only and shareable among all processes executing the same
+file. This involves moving the data areas up to the first possible 8K
+byte page boundary following the end of the text. This option creates
+a @emph{pure executable} format.
+
+@kindex -z
+@item -z
+@kindex --imagic
+@itemx --imagic
+
+Mark the output as @code{IMAGIC} (0411) in the @file{a.out} header to
+indicate that when the output file is executed, the program text and
+data areas will be loaded into separate address spaces using the split
+instruction and data space feature of the memory management unit in
+larger models of the PDP11. This doubles the address space available
+to the program. The text segment is again pure, write-protected, and
+shareable. The only difference in the output format between this
+option and the others, besides the magic number, is that both the text
+and data sections start at location 0. The @samp{-z} option selected
+this format in 2.11BSD. This option creates a @emph{separate
+executable} format.
+
+@kindex --no-omagic
+@item --no-omagic
+
+Equivalent to @samp{--nmagic} for pdp11-aout.
+
+@end table
+
+@c man end
+@end ifset
+
@ifset UsesEnvVars
@node Environment
@section Environment Variables
diff --git a/ld/lexsup.c b/ld/lexsup.c
index 2597e2d..adbf2ab7a 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -938,6 +938,7 @@ parse_args (unsigned argc, char **argv)
Use --call-shared or -Bdynamic for this. */
break;
case 'n':
+ config.text_read_only = TRUE;
config.magic_demand_paged = FALSE;
input_flags.dynamic = FALSE;
break;
diff --git a/ld/scripttempl/pdp11.sc b/ld/scripttempl/pdp11.sc
new file mode 100644
index 0000000..995e582
--- /dev/null
+++ b/ld/scripttempl/pdp11.sc
@@ -0,0 +1,56 @@
+# Copyright (C) 2014-2020 Free Software Foundation, Inc.
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+#
+test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
+test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
+test -z "${ALIGNMENT}" && ALIGNMENT="2"
+
+cat <<EOF
+/* Copyright (C) 2014-2020 Free Software Foundation, Inc.
+
+ Copying and distribution of this script, with or without modification,
+ are permitted in any medium without royalty provided the copyright
+ notice and this notice are preserved. */
+
+OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
+ "${LITTLE_OUTPUT_FORMAT}")
+OUTPUT_ARCH(${ARCH})
+
+${RELOCATING+${LIB_SEARCH_DIRS}}
+${STACKZERO+${RELOCATING+${STACKZERO}}}
+${SHLIB_PATH+${RELOCATING+${SHLIB_PATH}}}
+${RELOCATING+${EXECUTABLE_SYMBOLS}}
+${RELOCATING+PROVIDE (__stack = 0);}
+SECTIONS
+{
+ ${RELOCATING+. = ${TEXT_START_ADDR};}
+ .text :
+ {
+ CREATE_OBJECT_SYMBOLS
+ *(.text)
+ ${RELOCATING+_etext = .;}
+ ${RELOCATING+__etext = .;}
+ ${PAD_TEXT+${RELOCATING+. = ${DATA_ALIGNMENT};}}
+ }
+ ${RELOCATING+. = ${DATA_ALIGNMENT};}
+ .data :
+ {
+ *(.data)
+ ${CONSTRUCTING+CONSTRUCTORS}
+ ${RELOCATING+_edata = .;}
+ ${RELOCATING+__edata = .;}
+ }
+ .bss :
+ {
+ ${RELOCATING+ __bss_start = .};
+ *(.bss)
+ *(COMMON)
+ ${RELOCATING+. = ALIGN(${ALIGNMENT});}
+ ${RELOCATING+_end = . };
+ ${RELOCATING+__end = . };
+ }
+}
+EOF
diff --git a/ld/testsuite/ld-pdp11/imagic.d b/ld/testsuite/ld-pdp11/imagic.d
new file mode 100644
index 0000000..2e1566c2
--- /dev/null
+++ b/ld/testsuite/ld-pdp11/imagic.d
@@ -0,0 +1,12 @@
+#name: pdp11-aout imagic format
+# nm sort alphabetically since both _start and _data are 0
+#source: sections.s
+#ld: --imagic
+#DUMPPROG: nm
+#...
+0+2 B _bss
+#...
+0+0 D _data
+#...
+0+0 T _start
+#pass
diff --git a/ld/testsuite/ld-pdp11/imagicz.d b/ld/testsuite/ld-pdp11/imagicz.d
new file mode 100644
index 0000000..38a11b4
--- /dev/null
+++ b/ld/testsuite/ld-pdp11/imagicz.d
@@ -0,0 +1,12 @@
+#name: pdp11-aout imagic format -z
+# nm sort alphabetically since both _start and _data are 0
+#source: sections.s
+#ld: -z
+#DUMPPROG: nm
+#...
+0+2 B _bss
+#...
+0+0 D _data
+#...
+0+0 T _start
+#pass
diff --git a/ld/testsuite/ld-pdp11/nmagic.d b/ld/testsuite/ld-pdp11/nmagic.d
new file mode 100644
index 0000000..acdae24
--- /dev/null
+++ b/ld/testsuite/ld-pdp11/nmagic.d
@@ -0,0 +1,11 @@
+#name: pdp11-aout nmagic format
+#source: sections.s
+#ld: --nmagic
+#nm: -n
+#...
+0+0 T _start
+#...
+0*2000 D _data
+#...
+0*2002 B _bss
+#pass
diff --git a/ld/testsuite/ld-pdp11/omagic.d b/ld/testsuite/ld-pdp11/omagic.d
new file mode 100644
index 0000000..ed3a423
--- /dev/null
+++ b/ld/testsuite/ld-pdp11/omagic.d
@@ -0,0 +1,12 @@
+#name: pdp11-aout omagic format
+# also testing that --omagic is the default
+#source: sections.s
+#ld:
+#nm: -n
+#...
+0+0 T _start
+#...
+0+6 D _data
+#...
+0+8 B _bss
+#pass
diff --git a/ld/testsuite/ld-pdp11/pdp11.exp b/ld/testsuite/ld-pdp11/pdp11.exp
new file mode 100644
index 0000000..90c82df
--- /dev/null
+++ b/ld/testsuite/ld-pdp11/pdp11.exp
@@ -0,0 +1,33 @@
+# Expect script for ld-pdp11 tests
+# Copyright (C) 2016-2020 Free Software Foundation, Inc.
+#
+# This file is part of the GNU Binutils.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+#
+
+# Test pdp11 linking; at this point just the options for the three
+# a.out format variants.
+
+if ![istarget "pdp11-*-*"] then {
+ return
+}
+
+set pdp11_test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
+foreach pdp11_test $pdp11_test_list {
+ verbose [file rootname $pdp11_test]
+ run_dump_test [file rootname $pdp11_test]
+}
diff --git a/ld/testsuite/ld-pdp11/sections.s b/ld/testsuite/ld-pdp11/sections.s
new file mode 100644
index 0000000..c6e40a0
--- /dev/null
+++ b/ld/testsuite/ld-pdp11/sections.s
@@ -0,0 +1,13 @@
+ .globl _start
+ .text
+_start:
+ mov _data,_bss
+ .globl _data
+ .data
+_data:
+ .word 1
+ .globl _bss
+ .bss
+_bss:
+ .=.+2
+ .end