Module Name:    src
Committed By:   maya
Date:           Fri Jul 13 10:49:17 UTC 2018

Modified Files:
        src/external/gpl3/binutils.old/dist/bfd: elf.c
        src/external/gpl3/binutils/dist/bfd: elf.c

Log Message:
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


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/external/gpl3/binutils.old/dist/bfd/elf.c
cvs rdiff -u -r1.10 -r1.11 src/external/gpl3/binutils/dist/bfd/elf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/gpl3/binutils.old/dist/bfd/elf.c
diff -u src/external/gpl3/binutils.old/dist/bfd/elf.c:1.6 src/external/gpl3/binutils.old/dist/bfd/elf.c:1.7
--- src/external/gpl3/binutils.old/dist/bfd/elf.c:1.6	Thu Jul 12 21:38:16 2018
+++ src/external/gpl3/binutils.old/dist/bfd/elf.c	Fri Jul 13 10:49:17 2018
@@ -4159,7 +4159,7 @@ static bfd_size_type
 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 @@ get_program_header_size (bfd *abfd, stru
   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 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 (s2 != NULL && (s2->flags & SEC_LOAD) != 0)
+  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 @@ _bfd_elf_map_sections_to_segments (bfd *
 	 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 @@ _bfd_elf_map_sections_to_segments (bfd *
 
 	  *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 @@ _bfd_elf_map_sections_to_segments (bfd *
       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

Index: src/external/gpl3/binutils/dist/bfd/elf.c
diff -u src/external/gpl3/binutils/dist/bfd/elf.c:1.10 src/external/gpl3/binutils/dist/bfd/elf.c:1.11
--- src/external/gpl3/binutils/dist/bfd/elf.c:1.10	Thu Jul 12 21:38:16 2018
+++ src/external/gpl3/binutils/dist/bfd/elf.c	Fri Jul 13 10:49:17 2018
@@ -4301,7 +4301,7 @@ static bfd_size_type
 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 @@ get_program_header_size (bfd *abfd, stru
   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 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 (s2 != NULL && (s2->flags & SEC_LOAD) != 0)
+  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 @@ _bfd_elf_map_sections_to_segments (bfd *
 	 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 @@ _bfd_elf_map_sections_to_segments (bfd *
 	  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 @@ _bfd_elf_map_sections_to_segments (bfd *
 	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

Reply via email to