diff --git a/bfd/libaout.h b/bfd/libaout.h index 81ef4cffd5..04efd9b08e 100644 --- a/bfd/libaout.h +++ b/bfd/libaout.h @@ -359,7 +359,8 @@ enum aout_magic { undecided_magic = 0, z_magic, o_magic, - n_magic + n_magic, + i_magic }; struct aoutdata diff --git a/bfd/pdp11.c b/bfd/pdp11.c index 50d006f085..7ee9f94193 100644 --- a/bfd/pdp11.c +++ b/bfd/pdp11.c @@ -90,7 +90,8 @@ struct pdp11_external_exec #define A_MAGIC2 NMAGIC #define NMAGIC 0410 /* Pure executable. */ #define ZMAGIC 0413 /* Demand-paged executable. */ -#define A_MAGIC3 0411 /* Separated I&D. */ +#define IMAGIC 0411 /* Separated I&D. */ +#define A_MAGIC3 IMAGIC #define A_MAGIC4 0405 /* Overlay. */ #define A_MAGIC5 0430 /* Auto-overlay (nonseparate). */ #define A_MAGIC6 0431 /* Auto-overlay (separate). */ @@ -242,6 +243,10 @@ struct aout_final_link_info struct external_nlist *output_syms; }; +/* Copy of the link_info.separate_code boolean to select the output format with + separate instruction and data spaces selected by --imagic */ +static bfd_boolean separate_i_d = FALSE; + reloc_howto_type howto_table_pdp11[] = { /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone */ @@ -988,6 +993,47 @@ adjust_n_magic (bfd *abfd, struct internal_exec *execp) N_SET_MAGIC (execp, NMAGIC); } +static void +adjust_i_magic (bfd *abfd, struct internal_exec *execp) +{ + file_ptr pos = adata (abfd).exec_bytes_size; + bfd_vma vma = 0; + int pad; + asection *text = obj_textsec (abfd); + asection *data = obj_datasec (abfd); + asection *bss = obj_bsssec (abfd); + + /* Text. */ + text->filepos = pos; + if (!text->user_set_vma) + text->vma = vma; + else + vma = text->vma; + pos += execp->a_text; + + /* Data. */ + data->filepos = pos; + if (!data->user_set_vma) + data->vma = 0; + vma = data->vma; + + /* Since BSS follows data immediately, see if it needs alignment. */ + vma += data->size; + pad = align_power (vma, bss->alignment_power) - vma; + execp->a_data = data->size + pad; + pos += execp->a_data; + + /* BSS. */ + if (!bss->user_set_vma) + bss->vma = vma; + else + vma = bss->vma; + + /* Fix up exec header. */ + execp->a_bss = bss->size; + N_SET_MAGIC (execp, IMAGIC); +} + bfd_boolean NAME (aout, adjust_sizes_and_vmas) (bfd *abfd) { @@ -1018,7 +1064,9 @@ NAME (aout, adjust_sizes_and_vmas) (bfd *abfd) I understand it better now, but I haven't time to do the cleanup this minute. */ - if (abfd->flags & WP_TEXT) + if (separate_i_d) + adata (abfd).magic = i_magic; + else if (abfd->flags & WP_TEXT) adata (abfd).magic = n_magic; else adata (abfd).magic = o_magic; @@ -1031,6 +1079,7 @@ NAME (aout, adjust_sizes_and_vmas) (bfd *abfd) { case n_magic: str = "NMAGIC"; break; case o_magic: str = "OMAGIC"; break; + case i_magic: str = "IMAGIC"; break; case z_magic: str = "ZMAGIC"; break; default: abort (); } @@ -1056,6 +1105,9 @@ NAME (aout, adjust_sizes_and_vmas) (bfd *abfd) case n_magic: adjust_n_magic (abfd, execp); break; + case i_magic: + adjust_i_magic (abfd, execp); + break; default: abort (); } @@ -3624,6 +3676,7 @@ NAME (aout, final_link) (bfd *abfd, if (bfd_link_pic (info)) abfd->flags |= DYNAMIC; + separate_i_d = info->separate_code; aout_info.info = info; aout_info.output_bfd = abfd; aout_info.contents = NULL; diff --git a/ld/emulparams/pdp11.sh b/ld/emulparams/pdp11.sh index 9b6bbbbd25..3f3326d121 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 0000000000..ac1f9805dc --- /dev/null +++ b/ld/emultempl/pdp11.em @@ -0,0 +1,130 @@ +# 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. + +LDEMUL_BEFORE_PARSE=gldpdp11_before_parse + +fragment <> 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 <