Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/gpl3 stopgap fix: revert bfd PT_PHDR without PT_INT...



details:   https://anonhg.NetBSD.org/src/rev/b56e1c940c12
branches:  trunk
changeset: 324040:b56e1c940c12
user:      maya <maya%NetBSD.org@localhost>
date:      Fri Jul 13 10:49:17 2018 +0000

description:
stopgap fix: revert bfd PT_PHDR without PT_INTERP changes.
This currently results in most binaries being broken. Give more time to
debug without -current being badly broken.

The reverted commit message was:
PT_PHDR is useful without PT_INTERP, i.e. for static PIE. It removes the
need for platform-specific computations of _DYNAMIC and friends.

ok martin, mrg

diffstat:

 external/gpl3/binutils.old/dist/bfd/elf.c |  41 ++++++++++--------------------
 external/gpl3/binutils/dist/bfd/elf.c     |  41 ++++++++++--------------------
 2 files changed, 28 insertions(+), 54 deletions(-)

diffs (172 lines):

diff -r d2523b504025 -r b56e1c940c12 external/gpl3/binutils.old/dist/bfd/elf.c
--- a/external/gpl3/binutils.old/dist/bfd/elf.c Fri Jul 13 09:58:49 2018 +0000
+++ b/external/gpl3/binutils.old/dist/bfd/elf.c Fri Jul 13 10:49:17 2018 +0000
@@ -4159,7 +4159,7 @@
 get_program_header_size (bfd *abfd, struct bfd_link_info *info)
 {
   size_t segs;
-  asection *s, *s2;
+  asection *s;
   const struct elf_backend_data *bed;
 
   /* Assume we will need exactly two PT_LOAD segments: one for text
@@ -4167,28 +4167,21 @@
   segs = 2;
 
   s = bfd_get_section_by_name (abfd, ".interp");
-  s2 = bfd_get_section_by_name (abfd, ".dynamic");
   if (s != NULL && (s->flags & SEC_LOAD) != 0)
     {
-      ++segs;
-    }
-
-  if (s2 != NULL && (s2->flags & SEC_LOAD) != 0)
+      /* If we have a loadable interpreter section, we need a
+        PT_INTERP segment.  In this case, assume we also need a
+        PT_PHDR segment, although that may not be true for all
+        targets.  */
+      segs += 2;
+    }
+
+  if (bfd_get_section_by_name (abfd, ".dynamic") != NULL)
     {
       /* We need a PT_DYNAMIC segment.  */
       ++segs;
     }
 
-  if ((s != NULL && (s->flags & SEC_LOAD) != 0) ||
-      (s2 != NULL && (s2->flags & SEC_LOAD) != 0))
-    {
-      /*
-       * If either a PT_INTERP or PT_DYNAMIC segment is created,
-       * also create a PT_PHDR segment.
-       */
-      ++segs;
-    }
-
   if (info != NULL && info->relro)
     {
       /* We need a PT_GNU_RELRO segment.  */
@@ -4455,13 +4448,6 @@
         section.  */
       s = bfd_get_section_by_name (abfd, ".interp");
       if (s != NULL && (s->flags & SEC_LOAD) != 0)
-       s = NULL;
-      dynsec = bfd_get_section_by_name (abfd, ".dynamic");
-      if (dynsec != NULL
-         && (dynsec->flags & SEC_LOAD) == 0)
-       dynsec = NULL;
-
-      if (s != NULL || dynsec != NULL)
        {
          amt = sizeof (struct elf_segment_map);
          m = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
@@ -4476,10 +4462,7 @@
 
          *pm = m;
          pm = &m->next;
-       }
-
-      if (s != NULL)
-       {
+
          amt = sizeof (struct elf_segment_map);
          m = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
          if (m == NULL)
@@ -4506,6 +4489,10 @@
       if (maxpagesize == 0)
        maxpagesize = 1;
       writable = FALSE;
+      dynsec = bfd_get_section_by_name (abfd, ".dynamic");
+      if (dynsec != NULL
+         && (dynsec->flags & SEC_LOAD) == 0)
+       dynsec = NULL;
 
       /* Deal with -Ttext or something similar such that the first section
         is not adjacent to the program headers.  This is an
diff -r d2523b504025 -r b56e1c940c12 external/gpl3/binutils/dist/bfd/elf.c
--- a/external/gpl3/binutils/dist/bfd/elf.c     Fri Jul 13 09:58:49 2018 +0000
+++ b/external/gpl3/binutils/dist/bfd/elf.c     Fri Jul 13 10:49:17 2018 +0000
@@ -4301,7 +4301,7 @@
 get_program_header_size (bfd *abfd, struct bfd_link_info *info)
 {
   size_t segs;
-  asection *s, *s2;
+  asection *s;
   const struct elf_backend_data *bed;
 
   /* Assume we will need exactly two PT_LOAD segments: one for text
@@ -4309,28 +4309,21 @@
   segs = 2;
 
   s = bfd_get_section_by_name (abfd, ".interp");
-  s2 = bfd_get_section_by_name (abfd, ".dynamic");
   if (s != NULL && (s->flags & SEC_LOAD) != 0)
     {
-      ++segs;
-    }
-
-  if (s2 != NULL && (s2->flags & SEC_LOAD) != 0)
+      /* If we have a loadable interpreter section, we need a
+        PT_INTERP segment.  In this case, assume we also need a
+        PT_PHDR segment, although that may not be true for all
+        targets.  */
+      segs += 2;
+    }
+
+  if (bfd_get_section_by_name (abfd, ".dynamic") != NULL)
     {
       /* We need a PT_DYNAMIC segment.  */
       ++segs;
     }
 
-  if ((s != NULL && (s->flags & SEC_LOAD) != 0) ||
-      (s2 != NULL && (s2->flags & SEC_LOAD) != 0))
-    {
-      /*
-       * If either a PT_INTERP or PT_DYNAMIC segment is created,
-       * also create a PT_PHDR segment.
-       */
-      ++segs;
-    }
-
   if (info != NULL && info->relro)
     {
       /* We need a PT_GNU_RELRO segment.  */
@@ -4627,13 +4620,6 @@
         section.  */
       s = bfd_get_section_by_name (abfd, ".interp");
       if (s != NULL && (s->flags & SEC_LOAD) != 0)
-       s = NULL;
-      dynsec = bfd_get_section_by_name (abfd, ".dynamic");
-      if (dynsec != NULL
-         && (dynsec->flags & SEC_LOAD) == 0)
-       dynsec = NULL;
-
-      if (s != NULL || dynsec != NULL)
        {
          amt = sizeof (struct elf_segment_map);
          m = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
@@ -4647,10 +4633,7 @@
          linker_created_pt_phdr_segment = TRUE;
          *pm = m;
          pm = &m->next;
-       }
-
-      if (s != NULL)
-       {
+
          amt = sizeof (struct elf_segment_map);
          m = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
          if (m == NULL)
@@ -4678,6 +4661,10 @@
        maxpagesize = 1;
       writable = FALSE;
       executable = FALSE;
+      dynsec = bfd_get_section_by_name (abfd, ".dynamic");
+      if (dynsec != NULL
+         && (dynsec->flags & SEC_LOAD) == 0)
+       dynsec = NULL;
 
       /* Deal with -Ttext or something similar such that the first section
         is not adjacent to the program headers.  This is an



Home | Main Index | Thread Index | Old Index