Source-Changes-HG archive

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

[src/trunk]: src/external/gpl3 Reapply with fixed condition:



details:   https://anonhg.NetBSD.org/src/rev/21602d4d8405
branches:  trunk
changeset: 320617:21602d4d8405
user:      joerg <joerg%NetBSD.org@localhost>
date:      Fri Jul 13 19:54:13 2018 +0000

description:
Reapply with fixed condition:
PT_PHDR is useful without PT_INTERP, i.e. for static PIE. It removes the
need for platform-specific computations of _DYNAMIC and friends.

diffstat:

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

diffs (174 lines):

diff -r e9672ef687b8 -r 21602d4d8405 external/gpl3/binutils.old/dist/bfd/elf.c
--- a/external/gpl3/binutils.old/dist/bfd/elf.c Fri Jul 13 19:50:21 2018 +0000
+++ b/external/gpl3/binutils.old/dist/bfd/elf.c Fri Jul 13 19:54:13 2018 +0000
@@ -4159,7 +4159,7 @@
 get_program_header_size (bfd *abfd, struct bfd_link_info *info)
 {
   size_t segs;
-  asection *s;
+  asection *s, *s2;
   const struct elf_backend_data *bed;
 
   /* Assume we will need exactly two PT_LOAD segments: one for text
@@ -4167,21 +4167,28 @@
   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)
     {
-      /* 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)
+      ++segs;
+    }
+
+  if (s2 != NULL && (s2->flags & SEC_LOAD) != 0)
     {
       /* 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.  */
@@ -4447,7 +4454,13 @@
         the program headers and a PT_INTERP segment for the .interp
         section.  */
       s = bfd_get_section_by_name (abfd, ".interp");
-      if (s != NULL && (s->flags & SEC_LOAD) != 0)
+      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);
@@ -4462,7 +4475,10 @@
 
          *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)
@@ -4489,10 +4505,6 @@
       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 e9672ef687b8 -r 21602d4d8405 external/gpl3/binutils/dist/bfd/elf.c
--- a/external/gpl3/binutils/dist/bfd/elf.c     Fri Jul 13 19:50:21 2018 +0000
+++ b/external/gpl3/binutils/dist/bfd/elf.c     Fri Jul 13 19:54:13 2018 +0000
@@ -4301,7 +4301,7 @@
 get_program_header_size (bfd *abfd, struct bfd_link_info *info)
 {
   size_t segs;
-  asection *s;
+  asection *s, *s2;
   const struct elf_backend_data *bed;
 
   /* Assume we will need exactly two PT_LOAD segments: one for text
@@ -4309,21 +4309,28 @@
   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)
     {
-      /* 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)
+      ++segs;
+    }
+
+  if (s2 != NULL && (s2->flags & SEC_LOAD) != 0)
     {
       /* 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.  */
@@ -4619,7 +4626,13 @@
         the program headers and a PT_INTERP segment for the .interp
         section.  */
       s = bfd_get_section_by_name (abfd, ".interp");
-      if (s != NULL && (s->flags & SEC_LOAD) != 0)
+      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);
@@ -4633,7 +4646,10 @@
          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)
@@ -4661,10 +4677,6 @@
        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