Source-Changes-HG archive

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

[src/trunk]: src/external/gpl3 PT_PHDR is useful without PT_INTERP, i.e. for ...



details:   https://anonhg.NetBSD.org/src/rev/7353f6b54eba
branches:  trunk
changeset: 320580:7353f6b54eba
user:      joerg <joerg%NetBSD.org@localhost>
date:      Thu Jul 12 21:38:16 2018 +0000

description:
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 |  41 ++++++++++++++++++++----------
 external/gpl3/binutils/dist/bfd/elf.c     |  41 ++++++++++++++++++++----------
 2 files changed, 54 insertions(+), 28 deletions(-)

diffs (172 lines):

diff -r 00e6e6354282 -r 7353f6b54eba external/gpl3/binutils.old/dist/bfd/elf.c
--- a/external/gpl3/binutils.old/dist/bfd/elf.c Thu Jul 12 21:36:45 2018 +0000
+++ b/external/gpl3/binutils.old/dist/bfd/elf.c Thu Jul 12 21:38:16 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.  */
@@ -4448,6 +4455,13 @@
         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);
@@ -4462,7 +4476,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 +4506,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 00e6e6354282 -r 7353f6b54eba external/gpl3/binutils/dist/bfd/elf.c
--- a/external/gpl3/binutils/dist/bfd/elf.c     Thu Jul 12 21:36:45 2018 +0000
+++ b/external/gpl3/binutils/dist/bfd/elf.c     Thu Jul 12 21:38:16 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.  */
@@ -4620,6 +4627,13 @@
         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);
@@ -4633,7 +4647,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 +4678,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