8bf40c6
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
8bf40c6
From: Nick Clifton <nickc@redhat.com>
8bf40c6
Date: Tue, 2 Jul 2019 15:58:29 +0100
8bf40c6
Subject: gdb-rhbz1553086-binutils-warning-loadable-section-outside-elf.patch
8bf40c6
8bf40c6
;; Fix 'gdb: warning: Loadable section ".note.gnu.property" outside of
8bf40c6
;; ELF segments' (Nick Clifton, RH BZ 1553086).
8bf40c6
;; This is a binutils patch.
8bf40c6
8bf40c6
Stop the BFD library from issuing a warning message when processing allocated sections in debuginfo files that lie outside of any loadable segment.
8bf40c6
8bf40c6
	PR 24717
8bf40c6
	* elf.c (is_debuginfo_file): New function.
8bf40c6
	(assign_file_positions_for_non_load_sections): Do not warn about
8bf40c6
	allocated sections outside of loadable segments if they are found
8bf40c6
	in a debuginfo file.
8bf40c6
	* elf-bfd.h (is_debuginfo_file): Prototype.
8bf40c6
8bf40c6
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
8bf40c6
--- a/bfd/ChangeLog
8bf40c6
+++ b/bfd/ChangeLog
8bf40c6
@@ -1,3 +1,12 @@
8bf40c6
+2019-07-02  Nick Clifton  <nickc@redhat.com>
8bf40c6
+
8bf40c6
+	PR 24717
8bf40c6
+	* elf.c (is_debuginfo_file): New function.
8bf40c6
+	(assign_file_positions_for_non_load_sections): Do not warn about
8bf40c6
+	allocated sections outside of loadable segments if they are found
8bf40c6
+	in a debuginfo file.
8bf40c6
+	* elf-bfd.h (is_debuginfo_file): Prototype.
8bf40c6
+
8bf40c6
 2019-05-02  Nick Clifton  <nickc@redhat.com>
8bf40c6
 
8bf40c6
 	PR 24493
8bf40c6
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
8bf40c6
--- a/bfd/elf-bfd.h
8bf40c6
+++ b/bfd/elf-bfd.h
8bf40c6
@@ -2751,6 +2751,8 @@ extern bfd_vma elf64_r_sym (bfd_vma);
8bf40c6
 extern bfd_vma elf32_r_info (bfd_vma, bfd_vma);
8bf40c6
 extern bfd_vma elf32_r_sym (bfd_vma);
8bf40c6
 
8bf40c6
+extern bfd_boolean is_debuginfo_file (bfd *);
8bf40c6
+
8bf40c6
 /* Large common section.  */
8bf40c6
 extern asection _bfd_elf_large_com_section;
8bf40c6
 
8bf40c6
diff --git a/bfd/elf.c b/bfd/elf.c
8bf40c6
--- a/bfd/elf.c
8bf40c6
+++ b/bfd/elf.c
8bf40c6
@@ -5800,6 +5800,35 @@ assign_file_positions_for_load_sections (bfd *abfd,
8bf40c6
   return TRUE;
8bf40c6
 }
8bf40c6
 
8bf40c6
+/* Determine if a bfd is a debuginfo file.  Unfortunately there
8bf40c6
+   is no defined method for detecting such files, so we have to
8bf40c6
+   use heuristics instead.  */
8bf40c6
+
8bf40c6
+bfd_boolean
8bf40c6
+is_debuginfo_file (bfd *abfd)
8bf40c6
+{
8bf40c6
+  if (abfd == NULL || bfd_get_flavour (abfd) != bfd_target_elf_flavour)
8bf40c6
+    return FALSE;
8bf40c6
+
8bf40c6
+  Elf_Internal_Shdr **start_headers = elf_elfsections (abfd);
8bf40c6
+  Elf_Internal_Shdr **end_headers = start_headers + elf_numsections (abfd);
8bf40c6
+  Elf_Internal_Shdr **headerp;
8bf40c6
+
8bf40c6
+  for (headerp = start_headers; headerp < end_headers; headerp ++)
8bf40c6
+    {
8bf40c6
+      Elf_Internal_Shdr *header = * headerp;
8bf40c6
+
8bf40c6
+      /* Debuginfo files do not have any allocated SHT_PROGBITS sections.
8bf40c6
+	 The only allocated sections are SHT_NOBITS or SHT_NOTES.  */
8bf40c6
+      if ((header->sh_flags & SHF_ALLOC) == SHF_ALLOC
8bf40c6
+	  && header->sh_type != SHT_NOBITS
8bf40c6
+	  && header->sh_type != SHT_NOTE)
8bf40c6
+	return FALSE;
8bf40c6
+    }
8bf40c6
+
8bf40c6
+  return TRUE;
8bf40c6
+}
8bf40c6
+
8bf40c6
 /* Assign file positions for the other sections.  */
8bf40c6
 
8bf40c6
 static bfd_boolean
8bf40c6
@@ -5833,7 +5862,13 @@ assign_file_positions_for_non_load_sections (bfd *abfd,
8bf40c6
 	BFD_ASSERT (hdr->sh_offset == hdr->bfd_section->filepos);
8bf40c6
       else if ((hdr->sh_flags & SHF_ALLOC) != 0)
8bf40c6
 	{
8bf40c6
-	  if (hdr->sh_size != 0)
8bf40c6
+	  if (hdr->sh_size != 0
8bf40c6
+	      /* PR 24717 - debuginfo files are known to be not strictly
8bf40c6
+		 compliant with the ELF standard.  In particular they often
8bf40c6
+		 have .note.gnu.property sections that are outside of any
8bf40c6
+		 loadable segment.  This is not a problem for such files,
8bf40c6
+		 so do not warn about them.  */
8bf40c6
+	      && ! is_debuginfo_file (abfd))
8bf40c6
 	    _bfd_error_handler
8bf40c6
 	      /* xgettext:c-format */
8bf40c6
 	      (_("%pB: warning: allocated section `%s' not in segment"),