Blame SOURCES/binutils-2.27-s390-pgste-marker.patch

58725c
diff -rup binutils.orig/bfd/elf64-s390.c binutils-2.27/bfd/elf64-s390.c
58725c
--- binutils.orig/bfd/elf64-s390.c	2017-08-29 13:09:44.135143399 +0100
58725c
+++ binutils-2.27/bfd/elf64-s390.c	2017-08-29 13:10:37.272554164 +0100
58725c
@@ -25,6 +25,7 @@
58725c
 #include "libbfd.h"
58725c
 #include "elf-bfd.h"
58725c
 #include "elf/s390.h"
58725c
+#include "elf-s390.h"
58725c
 
58725c
 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
58725c
    from smaller values.  Start with zero, widen, *then* decrement.  */
58725c
@@ -660,6 +661,9 @@ struct elf_s390_link_hash_table
58725c
 
58725c
   /* Small local sym cache.  */
58725c
   struct sym_cache sym_cache;
58725c
+
58725c
+  /* Options passed from the linker.  */
58725c
+  struct s390_elf_params *params;
58725c
 };
58725c
 
58725c
 /* Get the s390 ELF linker hash table from a link_info structure.  */
58725c
@@ -3883,6 +3887,70 @@ elf64_s390_merge_private_bfd_data (bfd *
58725c
   return TRUE;
58725c
 }
58725c
 
58725c
+/* We may add a PT_S390_PGSTE program header.  */
58725c
+
58725c
+static int
58725c
+elf_s390_additional_program_headers (bfd *abfd ATTRIBUTE_UNUSED,
58725c
+				     struct bfd_link_info *info)
58725c
+{
58725c
+  struct elf_s390_link_hash_table *htab;
58725c
+
58725c
+  htab = elf_s390_hash_table (info);
58725c
+  return htab->params->pgste;
58725c
+}
58725c
+
58725c
+
58725c
+/* Add the PT_S390_PGSTE program header.  */
58725c
+
58725c
+static bfd_boolean
58725c
+elf_s390_modify_segment_map (bfd *abfd ATTRIBUTE_UNUSED,
58725c
+			     struct bfd_link_info *info)
58725c
+{
58725c
+  struct elf_s390_link_hash_table *htab;
58725c
+  struct elf_segment_map *m, *pm = NULL;
58725c
+
58725c
+  htab = elf_s390_hash_table (info);
58725c
+  if (!htab->params->pgste)
58725c
+    return TRUE;
58725c
+
58725c
+  /* If there is already a PT_S390_PGSTE header, avoid adding
58725c
+     another.  */
58725c
+  m = elf_seg_map (abfd);
58725c
+  while (m && m->p_type != PT_S390_PGSTE)
58725c
+    {
58725c
+      pm = m;
58725c
+      m = m->next;
58725c
+    }
58725c
+
58725c
+  if (m)
58725c
+    return TRUE;
58725c
+
58725c
+  m = (struct elf_segment_map *)
58725c
+    bfd_zalloc (abfd, sizeof (struct elf_segment_map));
58725c
+  if (m == NULL)
58725c
+    return FALSE;
58725c
+  m->p_type = PT_S390_PGSTE;
58725c
+  m->count = 0;
58725c
+  m->next = NULL;
58725c
+  if (pm)
58725c
+    pm->next = m;
58725c
+
58725c
+  return TRUE;
58725c
+}
58725c
+
58725c
+bfd_boolean
58725c
+bfd_elf_s390_set_options (struct bfd_link_info *info,
58725c
+			  struct s390_elf_params *params)
58725c
+{
58725c
+  struct elf_s390_link_hash_table *htab;
58725c
+
58725c
+  htab = elf_s390_hash_table (info);
58725c
+  htab->params = params;
58725c
+
58725c
+  return TRUE;
58725c
+}
58725c
+
58725c
+
58725c
 /* Why was the hash table entry size definition changed from
58725c
    ARCH_SIZE/8 to 4? This breaks the 64 bit dynamic linker and
58725c
    this is the only reason for the s390_elf64_size_info structure.  */
58725c
@@ -3959,6 +4027,8 @@ const struct elf_size_info s390_elf64_si
58725c
 #define elf_backend_plt_sym_val		      elf_s390_plt_sym_val
58725c
 #define elf_backend_add_symbol_hook           elf_s390_add_symbol_hook
58725c
 #define elf_backend_sort_relocs_p             elf_s390_elf_sort_relocs_p
58725c
+#define elf_backend_additional_program_headers elf_s390_additional_program_headers
58725c
+#define elf_backend_modify_segment_map	      elf_s390_modify_segment_map
58725c
 
58725c
 #define bfd_elf64_mkobject		elf_s390_mkobject
58725c
 #define elf_backend_object_p		elf_s390_object_p
58725c
diff -rup binutils.orig/binutils/readelf.c binutils-2.27/binutils/readelf.c
58725c
--- binutils.orig/binutils/readelf.c	2017-08-29 13:09:44.138143366 +0100
58725c
+++ binutils-2.27/binutils/readelf.c	2017-08-29 13:09:53.384040839 +0100
58725c
@@ -3610,6 +3610,16 @@ get_arm_segment_type (unsigned long type
58725c
 }
58725c
 
58725c
 static const char *
58725c
+get_s390_segment_type (unsigned long type)
58725c
+{
58725c
+  switch (type)
58725c
+    {
58725c
+    case PT_S390_PGSTE: return "S390_PGSTE";
58725c
+    default:            return NULL;
58725c
+    }
58725c
+}
58725c
+
58725c
+static const char *
58725c
 get_mips_segment_type (unsigned long type)
58725c
 {
58725c
   switch (type)
58725c
@@ -3755,6 +3765,10 @@ get_segment_type (unsigned long p_type)
58725c
 	    case EM_TI_C6000:
58725c
 	      result = get_tic6x_segment_type (p_type);
58725c
 	      break;
58725c
+	    case EM_S390:
58725c
+	    case EM_S390_OLD:
58725c
+	      result = get_s390_segment_type (p_type);
58725c
+	      break;
58725c
 	    default:
58725c
 	      result = NULL;
58725c
 	      break;
58725c
diff -rup binutils.orig/elfcpp/elfcpp.h binutils-2.27/elfcpp/elfcpp.h
58725c
--- binutils.orig/elfcpp/elfcpp.h	2017-08-29 13:09:44.182142878 +0100
58725c
+++ binutils-2.27/elfcpp/elfcpp.h	2017-08-29 13:09:53.385040828 +0100
58725c
@@ -514,7 +514,9 @@ enum PT
58725c
   // Platform architecture compatibility information
58725c
   PT_AARCH64_ARCHEXT = 0x70000000,
58725c
   // Exception unwind tables
58725c
-  PT_AARCH64_UNWIND = 0x70000001
58725c
+  PT_AARCH64_UNWIND = 0x70000001,
58725c
+  // 4k page table size
58725c
+  PT_S390_PGSTE = 0x70000000,
58725c
 };
58725c
 
58725c
 // The valid bit flags found in the Phdr p_flags field.
58725c
diff -rup binutils.orig/include/elf/s390.h binutils-2.27/include/elf/s390.h
58725c
--- binutils.orig/include/elf/s390.h	2017-08-29 13:09:44.434140083 +0100
58725c
+++ binutils-2.27/include/elf/s390.h	2017-08-29 13:09:53.385040828 +0100
58725c
@@ -37,6 +37,9 @@
58725c
 
58725c
 #define EF_S390_HIGH_GPRS        0x00000001
58725c
 
58725c
+/* Request 4k page table size.  */
58725c
+#define PT_S390_PGSTE (PT_LOPROC + 0)
58725c
+
58725c
 /* Relocation types.  */
58725c
 
58725c
 START_RELOC_NUMBERS (elf_s390_reloc_type)
58725c
diff -rup binutils.orig/ld/emulparams/elf64_s390.sh binutils-2.27/ld/emulparams/elf64_s390.sh
58725c
--- binutils.orig/ld/emulparams/elf64_s390.sh	2017-08-29 13:09:44.441140006 +0100
58725c
+++ binutils-2.27/ld/emulparams/elf64_s390.sh	2017-08-29 13:09:53.385040828 +0100
58725c
@@ -12,6 +12,7 @@ TEMPLATE_NAME=elf32
58725c
 GENERATE_SHLIB_SCRIPT=yes
58725c
 GENERATE_PIE_SCRIPT=yes
58725c
 NO_SMALL_DATA=yes
58725c
+EXTRA_EM_FILE=s390
58725c
 IREL_IN_PLT=
58725c
 
58725c
 # Treat a host that matches the target with the possible exception of "x"
58725c
diff -rup binutils.orig/ld/gen-doc.texi binutils-2.27/ld/gen-doc.texi
58725c
--- binutils.orig/ld/gen-doc.texi	2017-08-29 13:09:44.445139961 +0100
58725c
+++ binutils-2.27/ld/gen-doc.texi	2017-08-29 13:09:53.385040828 +0100
58725c
@@ -21,6 +21,7 @@
58725c
 @set POWERPC
58725c
 @set POWERPC64
58725c
 @set Renesas
58725c
+@set S/390
58725c
 @set SPU
58725c
 @set TICOFF
58725c
 @set WIN32
58725c
diff -rup binutils.orig/ld/ld.texinfo binutils-2.27/ld/ld.texinfo
58725c
--- binutils.orig/ld/ld.texinfo	2017-08-29 13:09:44.445139961 +0100
58725c
+++ binutils-2.27/ld/ld.texinfo	2017-08-29 13:09:53.385040828 +0100
58725c
@@ -34,6 +34,7 @@
58725c
 @set POWERPC
58725c
 @set POWERPC64
58725c
 @set Renesas
58725c
+@set S/390
58725c
 @set SPU
58725c
 @set TICOFF
58725c
 @set WIN32
58725c
@@ -158,6 +159,9 @@ in the section entitled ``GNU Free Docum
58725c
 @ifset POWERPC64
58725c
 * PowerPC64 ELF64::             ld and PowerPC64 64-bit ELF Support
58725c
 @end ifset
58725c
+@ifset S/390
58725c
+* S/390 ELF::			ld and S/390 ELF Support
58725c
+@end ifset
58725c
 @ifset SPU
58725c
 * SPU ELF::			ld and SPU ELF Support
58725c
 @end ifset
58725c
@@ -6380,6 +6384,9 @@ functionality are not listed.
58725c
 @ifset POWERPC64
58725c
 * PowerPC64 ELF64::		@command{ld} and PowerPC64 64-bit ELF Support
58725c
 @end ifset
58725c
+@ifset S/390
58725c
+* S/390 ELF::			@command{ld} and S/390 ELF Support
58725c
+@end ifset
58725c
 @ifset SPU
58725c
 * SPU ELF::			@command{ld} and SPU ELF Support
58725c
 @end ifset
58725c
@@ -7373,6 +7380,30 @@ default behaviour.
58725c
 @end table
58725c
 
58725c
 @ifclear GENERIC
58725c
+@lowersections
58725c
+@end ifclear
58725c
+@end ifset
58725c
+
58725c
+@ifset S/390
58725c
+@ifclear GENERIC
58725c
+@raisesections
58725c
+@end ifclear
58725c
+
58725c
+@node S/390 ELF
58725c
+@section @command{ld} and S/390 ELF Support
58725c
+
58725c
+@cindex S/390 ELF options
58725c
+@table @option
58725c
+
58725c
+@cindex S/390
58725c
+@kindex --s390-pgste
58725c
+@item --s390-pgste
58725c
+This option marks the result file with a @code{PT_S390_PGSTE}
58725c
+segment.  The Linux kernel is supposed to allocate 4k page tables for
58725c
+binaries marked that way.
58725c
+@end table
58725c
+
58725c
+@ifclear GENERIC
58725c
 @lowersections
58725c
 @end ifclear
58725c
 @end ifset
58725c
diff -rup binutils.orig/ld/Makefile.in binutils-2.27/ld/Makefile.in
58725c
--- binutils.orig/ld/Makefile.in	2017-08-29 13:09:44.446139950 +0100
58725c
+++ binutils-2.27/ld/Makefile.in	2017-08-29 13:09:53.385040828 +0100
58725c
@@ -3490,6 +3490,7 @@ eelf64_ia64_vms.c: $(srcdir)/emulparams/
58725c
   $(srcdir)/scripttempl/ia64vms.sc ${GEN_DEPENDS}
58725c
 
58725c
 eelf64_s390.c: $(srcdir)/emulparams/elf64_s390.sh \
58725c
+  $(srcdir)/emultempl/s390.em \
58725c
   $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
58725c
 
58725c
 eelf64_sparc.c: $(srcdir)/emulparams/elf64_sparc.sh \
58725c
58725c
--- /dev/null	2017-08-29 08:03:33.387685165 +0100
58725c
+++ binutils-2.27/bfd/elf-s390.h	2017-08-29 13:19:31.705627899 +0100
58725c
@@ -0,0 +1,29 @@
58725c
+/* S/390-specific support for ELF.
58725c
+   Copyright (C) 2017 Free Software Foundation, Inc.
58725c
+
58725c
+   This file is part of BFD, the Binary File Descriptor library.
58725c
+
58725c
+   This program is free software; you can redistribute it and/or modify
58725c
+   it under the terms of the GNU General Public License as published by
58725c
+   the Free Software Foundation; either version 3 of the License, or
58725c
+   (at your option) any later version.
58725c
+
58725c
+   This program is distributed in the hope that it will be useful,
58725c
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
58725c
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
58725c
+   GNU General Public License for more details.
58725c
+
58725c
+   You should have received a copy of the GNU General Public License
58725c
+   along with this program; if not, write to the Free Software
58725c
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
58725c
+   MA 02110-1301, USA.  */
58725c
+
58725c
+/* Used to pass info between ld and bfd.  */
58725c
+struct s390_elf_params
58725c
+{
58725c
+  /* Tell the kernel to allocate 4k page tables.  */
58725c
+  int pgste;
58725c
+};
58725c
+
58725c
+bfd_boolean bfd_elf_s390_set_options (struct bfd_link_info *info,
58725c
+				      struct s390_elf_params *params);
58725c
--- /dev/null	2017-08-29 08:03:33.387685165 +0100
58725c
+++ binutils-2.27/ld/emultempl/s390.em	2017-08-29 13:26:01.797302217 +0100
58725c
@@ -0,0 +1,64 @@
58725c
+# This shell script emits a C file. -*- C -*-
58725c
+# Copyright (C) 2017 Free Software Foundation, Inc.
58725c
+#
58725c
+# This file is part of the GNU Binutils.
58725c
+#
58725c
+# This program is free software; you can redistribute it and/or modify
58725c
+# it under the terms of the GNU General Public License as published by
58725c
+# the Free Software Foundation; either version 3 of the license, or
58725c
+# (at your option) any later version.
58725c
+#
58725c
+# This program is distributed in the hope that it will be useful,
58725c
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
58725c
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
58725c
+# GNU General Public License for more details.
58725c
+#
58725c
+# You should have received a copy of the GNU General Public License
58725c
+# along with this program; see the file COPYING3. If not,
58725c
+# see <http://www.gnu.org/licenses/>.
58725c
+#
58725c
+
58725c
+# This file is sourced from elf-generic.em, and defines S/390
58725c
+# specific routines.
58725c
+#
58725c
+fragment <
58725c
+
58725c
+#include "ldctor.h"
58725c
+#include "elf-s390.h"
58725c
+
58725c
+static struct s390_elf_params params = { 0 };
58725c
+
58725c
+/* This is a convenient point to tell BFD about target specific flags.
58725c
+   After the output has been created, but before inputs are read.  */
58725c
+static void
58725c
+s390_elf_create_output_section_statements (void)
58725c
+{
58725c
+  if (!bfd_elf_s390_set_options (&link_info, &params))
58725c
+    einfo ("%F%P: can not init BFD: %E\n");
58725c
+}
58725c
+
58725c
+EOF
58725c
+
58725c
+# Define some shell vars to insert bits of code into the standard elf
58725c
+# parse_args and list_options functions.
58725c
+#
58725c
+PARSE_AND_LIST_PROLOGUE='
58725c
+#define OPTION_PGSTE	301
58725c
+'
58725c
+
58725c
+PARSE_AND_LIST_LONGOPTS='
58725c
+  { "s390-pgste", no_argument, NULL, OPTION_PGSTE},
58725c
+'
58725c
+
58725c
+PARSE_AND_LIST_OPTIONS='
58725c
+  fprintf (file, _("  --s390-pgste                Tell the kernel to "
58725c
+		   "allocate 4k page tables\n"));
58725c
+'
58725c
+
58725c
+PARSE_AND_LIST_ARGS_CASES='
58725c
+    case OPTION_PGSTE:
58725c
+      params.pgste = 1;
58725c
+      break;
58725c
+'
58725c
+
58725c
+LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=s390_elf_create_output_section_statements