Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsutsui/2be834e6b3ab56cb6ac4476dc66b9c27 to your computer and use it in GitHub Desktop.
Save tsutsui/2be834e6b3ab56cb6ac4476dc66b9c27 to your computer and use it in GitHub Desktop.
diffs to binutils 2.27 in netbsd-8 source tree to add support of m68k-a.out-hp300hpux (HP-UX "HP s200 pure executable" binaries), based on diffs for 2.12 or 2.14 by Miod Vallat
Index: external/gpl3/binutils/dist/bfd/aoutx.h
===================================================================
RCS file: /cvsroot/src/external/gpl3/binutils/dist/bfd/aoutx.h,v
retrieving revision 1.7
diff -u -p -d -r1.7 aoutx.h
--- external/gpl3/binutils/dist/bfd/aoutx.h 26 Oct 2016 18:42:52 -0000 1.7
+++ external/gpl3/binutils/dist/bfd/aoutx.h 29 Apr 2020 20:35:17 -0000
@@ -502,7 +502,11 @@ NAME (aout, some_aout_object_p) (bfd *ab
adata (abfd).magic = z_magic;
adata (abfd).subformat = q_magic_format;
}
- else if (N_MAGIC (execp) == NMAGIC)
+ else if (N_MAGIC (execp) == NMAGIC
+#ifdef BMAGIC2
+ || N_MAGIC (execp) == BMAGIC2
+#endif
+ )
{
abfd->flags |= WP_TEXT;
adata (abfd).magic = n_magic;
Index: external/gpl3/binutils/dist/bfd/config.bfd
===================================================================
RCS file: /cvsroot/src/external/gpl3/binutils/dist/bfd/config.bfd,v
retrieving revision 1.23
diff -u -p -d -r1.23 config.bfd
--- external/gpl3/binutils/dist/bfd/config.bfd 26 Oct 2016 18:42:52 -0000 1.23
+++ external/gpl3/binutils/dist/bfd/config.bfd 29 Apr 2020 20:35:17 -0000
@@ -924,7 +924,7 @@ case "${targ}" in
;;
m68k4k*-*-netbsd*)
targ_defvec=m68k4knetbsd_vec
- targ_selvecs="m68knetbsd_vec hp300bsd_vec sunos_big_vec bfd_elf32_m68k_vec"
+ targ_selvecs="m68knetbsd_vec hp300bsd_vec m68k_aout_hp300hpux_vec sunos_big_vec bfd_elf32_m68k_vec"
targ_underscore=yes
;;
m68*-hp*-netbsd*)
@@ -934,16 +934,16 @@ case "${targ}" in
;;
m68*-*-netbsdelf* | m5407-*-netbsdelf*)
targ_defvec=m68k_elf32_vec
- targ_selvecs="m68k_aout_nbsd_vec m68k_aout_4knbsd_vec m68k_aout_hp300bsd_vec sparc_aout_sunos_be_vec"
+ targ_selvecs="m68k_aout_nbsd_vec m68k_aout_4knbsd_vec m68k_aout_hp300bsd_vec m68k_aout_hp300hpux_vec sparc_aout_sunos_be_vec"
;;
m68*-*-netbsdaout* | m68*-*-netbsd*)
targ_defvec=m68k_aout_nbsd_vec
- targ_selvecs="m68k_aout_4knbsd_vec m68k_elf32_vec m68k_aout_hp300bsd_vec sparc_aout_sunos_be_vec"
+ targ_selvecs="m68k_aout_4knbsd_vec m68k_elf32_vec m68k_aout_hp300bsd_vec m68k_aout_hp300hpux_vec sparc_aout_sunos_be_vec"
targ_underscore=yes
;;
m68*-*-openbsd*)
targ_defvec=m68k_aout_nbsd_vec
- targ_selvecs="m68k_aout_4knbsd_vec m68k_aout_hp300bsd_vec sparc_aout_sunos_be_vec"
+ targ_selvecs="m68k_aout_4knbsd_vec m68k_aout_hp300bsd_vec m68k_aout_hp300hpux_vec sparc_aout_sunos_be_vec"
targ_underscore=yes
;;
m68*-*-sunos* | m68*-*-os68k* | m68*-*-vxworks* | m68*-netx-* | \
Index: external/gpl3/binutils/dist/bfd/hp300hpux.c
===================================================================
RCS file: /cvsroot/src/external/gpl3/binutils/dist/bfd/Attic/hp300hpux.c,v
retrieving revision 1.1.1.5
diff -u -p -d -r1.1.1.5 hp300hpux.c
--- external/gpl3/binutils/dist/bfd/hp300hpux.c 26 Oct 2016 17:29:41 -0000 1.1.1.5
+++ external/gpl3/binutils/dist/bfd/hp300hpux.c 29 Apr 2020 20:35:17 -0000
@@ -188,8 +188,9 @@
#define NAME(x,y) CONCAT3 (hp300hpux,_32_,y)
#define ARCH_SIZE 32
-/* aoutx.h requires definitions for BMAGIC and QMAGIC. */
+/* aoutx.h requires definitions for BMAGIC, BMAGIC2 and QMAGIC. */
#define BMAGIC HPUX_DOT_O_MAGIC
+#define BMAGIC2 HPUX_DOT_SL_MAGIC
#define QMAGIC 0314
#include "aoutx.h"
Index: external/gpl3/binutils/dist/include/aout/hp300hpux.h
===================================================================
RCS file: /cvsroot/src/external/gpl3/binutils/dist/include/aout/Attic/hp300hpux.h,v
retrieving revision 1.1.1.4
diff -u -p -d -r1.1.1.4 hp300hpux.h
--- external/gpl3/binutils/dist/include/aout/hp300hpux.h 26 Oct 2016 17:30:15 -0000 1.1.1.4
+++ external/gpl3/binutils/dist/include/aout/hp300hpux.h 29 Apr 2020 20:35:18 -0000
@@ -71,10 +71,12 @@ struct hp300hpux_header_extension
/* read hpux .o files, we add an special define and use it below in */
/* offset and address calculations. */
-#define HPUX_DOT_O_MAGIC 0x106
+#define HPUX_DOT_O_MAGIC 0x106 /* relocatable executable. */
#define OMAGIC 0x107 /* object file or impure executable. */
#define NMAGIC 0x108 /* Code indicating pure executable. */
#define ZMAGIC 0x10B /* demand-paged executable. */
+#define HPUX_DOT_DL_MAGIC 0x10d /* dynamic library. */
+#define HPUX_DOT_SL_MAGIC 0x10e /* shared library. */
#define N_HEADER_IN_TEXT(x) 0
@@ -87,24 +89,61 @@ struct hp300hpux_header_extension
#define N_BADMAG(x) ((_N_BADMAG (x)) || (_N_BADMACH (x)))
+#if 0
#define N_DATADDR(x) \
((N_MAGIC (x) == OMAGIC || N_MAGIC (x) == HPUX_DOT_O_MAGIC) \
? (N_TXTADDR (x) + N_TXTSIZE (x)) \
: (N_SEGSIZE (x) + ((N_TXTADDR (x) + N_TXTSIZE (x) - 1) \
& ~ (bfd_vma) (N_SEGSIZE (x) - 1))))
+#endif
#define _N_BADMACH(x) \
(((N_MACHTYPE (x)) != HP9000S200_ID) && ((N_MACHTYPE (x)) != HP98x6_ID))
#define _N_BADMAG(x) (N_MAGIC(x) != HPUX_DOT_O_MAGIC \
+ && N_MAGIC(x) != HPUX_DOT_SL_MAGIC \
&& N_MAGIC(x) != OMAGIC \
&& N_MAGIC(x) != NMAGIC \
&& N_MAGIC(x) != ZMAGIC )
+/*
+ * header, data and text sections are padedd to a multiple of SEGMENT_SIZE
+ * in demand-load files, as well as shared and dynamic libraries.
+ */
+
+#define _N_PADDED(x) \
+ (N_MAGIC (x) == ZMAGIC || N_MAGIC (x) == HPUX_DOT_DL_MAGIC || \
+ N_MAGIC (x) == HPUX_DOT_SL_MAGIC)
+
#undef _N_HDROFF
-#define _N_HDROFF(x) (SEGMENT_SIZE - (sizeof (struct exec)))
+#define _N_HDROFF(x) \
+ (_N_PADDED (x) ? (SEGMENT_SIZE - EXEC_BYTES_SIZE) : 0)
+
+#undef N_TXTOFF
+#define N_TXTOFF(x) \
+ (_N_PADDED (x) ? SEGMENT_SIZE : EXEC_BYTES_SIZE)
+
+#undef N_TXTSIZE
+#define N_TXTSIZE(x) \
+ (_N_PADDED (x) \
+ ? (((x)->a_text + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1)) \
+ : (x)->a_text)
#undef N_DATOFF
+#define N_DATOFF(x) ( N_TXTOFF(x) + N_TXTSIZE(x) )
+
+#undef N_DATSIZE
+#define N_DATSIZE(x) \
+ (_N_PADDED (x) \
+ ? (((x)->a_data + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1)) \
+ : (x)->a_data)
+
+#define N_DATADDR(x) \
+ (_N_PADDED (x) || N_MAGIC (x) == OMAGIC || N_MAGIC (x) == HPUX_DOT_O_MAGIC \
+ ? (N_TXTADDR (x) + N_TXTSIZE (x)) \
+ : (N_SEGSIZE (x) + ((N_TXTADDR (x) + N_TXTSIZE (x) - 1) \
+ & ~ (bfd_vma) (N_SEGSIZE (x) - 1))))
+
#undef N_PASOFF
#undef N_SYMOFF
#undef N_SUPOFF
@@ -112,8 +151,7 @@ struct hp300hpux_header_extension
#undef N_DRELOFF
#undef N_STROFF
-#define N_DATOFF(x) ( N_TXTOFF(x) + N_TXTSIZE(x) )
-#define N_PASOFF(x) ( N_DATOFF(x) + (x)->a_data)
+#define N_PASOFF(x) ( N_DATOFF(x) + N_DATSIZE(x))
#define N_SYMOFF(x) ( N_PASOFF(x) /* + (x)->a_passize*/ )
#define N_SUPOFF(x) ( N_SYMOFF(x) + (x)->a_syms )
#define N_TRELOFF(x) ( N_SUPOFF(x) /* + (x)->a_supsize*/ )
@@ -129,3 +167,6 @@ struct hp300hpux_header_extension
#define TARGET_PAGE_SIZE 0x1000
#define SEGMENT_SIZE 0x1000
#define TEXT_START_ADDR 0
+
+#undef N_SHARED_LIB
+#define N_SHARED_(x) ( N_MAGIC(x) == HPUX_DOT_SL_MAGIC )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment