Blame SOURCES/gdb-rhbz1878810-bfd-suppress-loadable-section-outside-ELF-sections.patch

be07d7
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
be07d7
From: Keith Seitz <keiths@redhat.com>
be07d7
Date: Fri, 23 Oct 2020 17:12:26 -0400
be07d7
Subject: 
be07d7
 gdb-rhbz1878810-bfd-suppress-loadable-section-outside-ELF-sections.patch
be07d7
be07d7
;; Backport "Stop the BFD library from issuing a warning message when
be07d7
;; processing allocated sections in debuginfo files that lie outside of
be07d7
;; Nick Clifton and Keith Seitz, RH BZ 1878810
be07d7
be07d7
   Stop the BFD library from issuing a warning message when processing allocated sections in debuginfo files that lie outside of any loadable segment.
be07d7
be07d7
   bfd/ChangeLog
be07d7
   PR 24717
be07d7
   * elf.c (is_debuginfo_file): New function.
be07d7
   (assign_file_positions_for_non_load_sections): Do not warn about
be07d7
   allocated sections outside of loadable segments if they are found
be07d7
   in a debuginfo file.
be07d7
   * elf-bfd.h (is_debuginfo_file): Prototype.
be07d7
be07d7
   gdb/ChangeLog
be07d7
   https://bugzilla.redhat.com/show_bug.cgi?id=1553086
be07d7
   * elfread.c (elf_symfile_segments): Omit "Loadable section ...
be07d7
     outside of ELF segments" warning for debugin
be07d7
be07d7
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
be07d7
--- a/bfd/elf-bfd.h
be07d7
+++ b/bfd/elf-bfd.h
be07d7
@@ -2740,6 +2740,8 @@ extern bfd_vma elf64_r_sym (bfd_vma);
be07d7
 extern bfd_vma elf32_r_info (bfd_vma, bfd_vma);
be07d7
 extern bfd_vma elf32_r_sym (bfd_vma);
be07d7
 
be07d7
+extern bfd_boolean is_debuginfo_file (bfd *);
be07d7
+
be07d7
 /* Large common section.  */
be07d7
 extern asection _bfd_elf_large_com_section;
be07d7
 
be07d7
diff --git a/bfd/elf.c b/bfd/elf.c
be07d7
--- a/bfd/elf.c
be07d7
+++ b/bfd/elf.c
be07d7
@@ -5725,6 +5725,35 @@ assign_file_positions_for_load_sections (bfd *abfd,
be07d7
   return TRUE;
be07d7
 }
be07d7
 
be07d7
+/* Determine if a bfd is a debuginfo file.  Unfortunately there
be07d7
+   is no defined method for detecting such files, so we have to
be07d7
+   use heuristics instead.  */
be07d7
+
be07d7
+bfd_boolean
be07d7
+is_debuginfo_file (bfd *abfd)
be07d7
+{
be07d7
+  if (abfd == NULL || bfd_get_flavour (abfd) != bfd_target_elf_flavour)
be07d7
+    return FALSE;
be07d7
+
be07d7
+  Elf_Internal_Shdr **start_headers = elf_elfsections (abfd);
be07d7
+  Elf_Internal_Shdr **end_headers = start_headers + elf_numsections (abfd);
be07d7
+  Elf_Internal_Shdr **headerp;
be07d7
+
be07d7
+  for (headerp = start_headers; headerp < end_headers; headerp ++)
be07d7
+    {
be07d7
+      Elf_Internal_Shdr *header = * headerp;
be07d7
+
be07d7
+      /* Debuginfo files do not have any allocated SHT_PROGBITS sections.
be07d7
+	 The only allocated sections are SHT_NOBITS or SHT_NOTES.  */
be07d7
+      if ((header->sh_flags & SHF_ALLOC) == SHF_ALLOC
be07d7
+	  && header->sh_type != SHT_NOBITS
be07d7
+	  && header->sh_type != SHT_NOTE)
be07d7
+	return FALSE;
be07d7
+    }
be07d7
+
be07d7
+  return TRUE;
be07d7
+}
be07d7
+
be07d7
 /* Assign file positions for the other sections.  */
be07d7
 
be07d7
 static bfd_boolean
be07d7
@@ -5758,7 +5787,13 @@ assign_file_positions_for_non_load_sections (bfd *abfd,
be07d7
 	BFD_ASSERT (hdr->sh_offset == hdr->bfd_section->filepos);
be07d7
       else if ((hdr->sh_flags & SHF_ALLOC) != 0)
be07d7
 	{
be07d7
-	  if (hdr->sh_size != 0)
be07d7
+	  if (hdr->sh_size != 0
be07d7
+	      /* PR 24717 - debuginfo files are known to be not strictly
be07d7
+		 compliant with the ELF standard.  In particular they often
be07d7
+		 have .note.gnu.property sections that are outside of any
be07d7
+		 loadable segment.  This is not a problem for such files,
be07d7
+		 so do not warn about them.  */
be07d7
+	      && ! is_debuginfo_file (abfd))
be07d7
 	    _bfd_error_handler
be07d7
 	      /* xgettext:c-format */
be07d7
 	      (_("%pB: warning: allocated section `%s' not in segment"),
be07d7
diff --git a/gdb/elfread.c b/gdb/elfread.c
be07d7
--- a/gdb/elfread.c
be07d7
+++ b/gdb/elfread.c
be07d7
@@ -143,7 +143,12 @@ elf_symfile_segments (bfd *abfd)
be07d7
 	 RealView) use SHT_NOBITS for uninitialized data.  Since it is
be07d7
 	 uninitialized, it doesn't need a program header.  Such
be07d7
 	 binaries are not relocatable.  */
be07d7
-      if (bfd_get_section_size (sect) > 0 && j == num_segments
be07d7
+
be07d7
+      /* Exclude debuginfo files from this warning, too, since those
be07d7
+	 are often not strictly compliant with the standard. See, e.g.,
be07d7
+	 ld/24717 for more discussion.  */
be07d7
+      if (!is_debuginfo_file (abfd)
be07d7
+	  && bfd_get_section_size (sect) > 0 && j == num_segments
be07d7
 	  && (bfd_get_section_flags (abfd, sect) & SEC_LOAD) != 0)
be07d7
 	warning (_("Loadable section \"%s\" outside of ELF segments"),
be07d7
 		 bfd_section_name (abfd, sect));