aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorStephen Casner <casner@acm.org>2020-04-14 14:41:27 +0100
committerNick Clifton <nickc@redhat.com>2020-04-14 14:41:27 +0100
commitfa1477dc34e6ce19b90ff0171074c295133730a3 (patch)
tree165b1472d16c8efe22cacada145a841f5247ac28 /bfd
parent194d088fb1fa6c3c341994ca247d172c3f08c2da (diff)
downloadgdb-fa1477dc34e6ce19b90ff0171074c295133730a3.zip
gdb-fa1477dc34e6ce19b90ff0171074c295133730a3.tar.gz
gdb-fa1477dc34e6ce19b90ff0171074c295133730a3.tar.bz2
Fixes for the magic number used in PDP11 AOUT binaries.
PR ld/25677 include * aout/aout64.h (N_DATADDR): Add IMAGIC case. bfd * pdp11.c: Add implementation of --imagic option. (adjust_o_magic): Fix objcopy --extract-symbol test. * libaout.h (enum aout_magic): Add i_magic. ld * 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.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog7
-rw-r--r--bfd/libaout.h3
-rw-r--r--bfd/pdp11.c62
3 files changed, 68 insertions, 4 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 120fb38..0ef3b2f 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,10 @@
+2020-04-14 Stephen Casner <casner@acm.org>
+
+ PR ld/25677
+ * pdp11.c: Add implementation of --imagic option.
+ (adjust_o_magic): Fix objcopy --extract-symbol test.
+ * libaout.h (enum aout_magic): Add i_magic.
+
2020-04-07 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
Nick Clifton <nickc@redhat.com>
diff --git a/bfd/libaout.h b/bfd/libaout.h
index bdf917e..61746db 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 c13e742..1f8c406 100644
--- a/bfd/pdp11.c
+++ b/bfd/pdp11.c
@@ -63,6 +63,7 @@
#define N_SET_FLAGS(execp, flags) do { } while (0)
#define N_BADMAG(x) (N_MAGIC(x) != OMAGIC \
&& N_MAGIC(x) != NMAGIC \
+ && N_MAGIC(x) != IMAGIC \
&& N_MAGIC(x) != ZMAGIC)
#include "sysdep.h"
@@ -90,7 +91,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 +244,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 */
@@ -498,6 +504,8 @@ NAME (aout, some_aout_object_p) (bfd *abfd,
}
else if (N_MAGIC (execp) == OMAGIC)
adata (abfd).magic = o_magic;
+ else if (N_MAGIC (execp) == IMAGIC)
+ adata (abfd).magic = i_magic;
else
{
/* Should have been checked with N_BADMAG before this routine
@@ -825,7 +833,7 @@ adjust_o_magic (bfd *abfd, struct internal_exec *execp)
vma += pad;
bss->vma = vma;
}
- else
+ else if (data->size > 0 || bss->size > 0) /* PR25677: for objcopy --extract-symbol */
{
/* The VMA of the .bss section is set by the VMA of the
.data section plus the size of the .data section. We may
@@ -988,6 +996,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 +1067,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 +1082,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 +1108,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 +3679,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;