public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: David Stubbs <stubbs@IceraSemi.com>
Cc: binutils@sourceware.org
Subject: Re: VMA section overlap warnings for overlays
Date: Sat, 24 Apr 2010 02:18:00 -0000	[thread overview]
Message-ID: <20100424021750.GQ3510@bubble.grove.modra.org> (raw)
In-Reply-To: <4D60B0700D1DB54A8C0C6E9BE69163700E7F2F15@EXCHANGEVS.IceraSemi.local>

This patch silences the "section can't be allocated in segment"
warning in cases where people pack overlays into one segment.

I also took the opportunity to tidy associated SECTION_IN_SEGMENT
macros.

include/elf/
	* internal.h (ELF_SECTION_SIZE): Protect macro args with parentheses.
	Invert logic to clarify test for .tbss.
	(ELF_IS_SECTION_IN_SEGMENT): Rename to..
	(ELF_SECTION_IN_SEGMENT_1): ..this.  Add check_vma param.  Protect
	macro args with parentheses.
	(ELF_SECTION_IN_SEGMENT): Define.
	(ELF_IS_SECTION_IN_SEGMENT_FILE): Delete.
	(ELF_IS_SECTION_IN_SEGMENT_MEMORY): Delete.
bfd/
	* elf.c: Replace use of ELF_IS_SECTION_IN_SEGMENT and
	ELF_IS_SECTION_IN_SEGMENT_FILE with ELF_SECTION_IN_SEGMENT
	throughout file.
	(assign_file_positions_for_load_sections): Modify section in
	segment warning to ignore overlay vmas.
	* elf32-spu.c (spu_elf_object_p): Replace use of
	ELF_IS_SECTION_IN_SEGMENT_MEMORY with ELF_SECTION_IN_SEGMENT.
binutils/
	* readelf.c (process_program_headers): Replace use of
	ELF_IS_SECTION_IN_SEGMENT_MEMORY with ELF_SECTION_IN_SEGMENT.

Index: include/elf/internal.h
===================================================================
RCS file: /cvs/src/src/include/elf/internal.h,v
retrieving revision 1.24
diff -u -p -r1.24 internal.h
--- include/elf/internal.h	15 Apr 2010 10:26:08 -0000	1.24
+++ include/elf/internal.h	24 Apr 2010 01:03:03 -0000
@@ -292,42 +292,36 @@ struct elf_segment_map
 /* .tbss is special.  It doesn't contribute memory space to normal
    segments and it doesn't take file space in normal segments.  */
 #define ELF_SECTION_SIZE(sec_hdr, segment)			\
-   (((sec_hdr->sh_flags & SHF_TLS) == 0				\
-     || sec_hdr->sh_type != SHT_NOBITS				\
-     || segment->p_type == PT_TLS) ? sec_hdr->sh_size : 0)
+  ((!(((sec_hdr)->sh_flags & SHF_TLS) != 0			\
+      && (sec_hdr)->sh_type == SHT_NOBITS)			\
+    || (segment)->p_type == PT_TLS) ? (sec_hdr)->sh_size : 0)
 
 /* Decide if the given sec_hdr is in the given segment.  PT_TLS segment
    contains only SHF_TLS sections.  Only PT_LOAD, PT_GNU_RELRO and
    and PT_TLS segments can contain SHF_TLS sections.  */
-#define ELF_IS_SECTION_IN_SEGMENT(sec_hdr, segment)			\
-  (((((sec_hdr->sh_flags & SHF_TLS) != 0)				\
-     && (segment->p_type == PT_TLS					\
-	 || segment->p_type == PT_GNU_RELRO				\
-	 || segment->p_type == PT_LOAD))				\
-    || ((sec_hdr->sh_flags & SHF_TLS) == 0				\
-	&& segment->p_type != PT_TLS					\
-	&& segment->p_type != PT_PHDR))					\
+#define ELF_SECTION_IN_SEGMENT_1(sec_hdr, segment, check_vma)		\
+  ((((((sec_hdr)->sh_flags & SHF_TLS) != 0)				\
+     && ((segment)->p_type == PT_TLS					\
+	 || (segment)->p_type == PT_GNU_RELRO				\
+	 || (segment)->p_type == PT_LOAD))				\
+    || (((sec_hdr)->sh_flags & SHF_TLS) == 0				\
+	&& (segment)->p_type != PT_TLS					\
+	&& (segment)->p_type != PT_PHDR))				\
    /* Any section besides one of type SHT_NOBITS must have a file	\
       offset within the segment.  */					\
-   && (sec_hdr->sh_type == SHT_NOBITS					\
-       || ((bfd_vma) sec_hdr->sh_offset >= segment->p_offset		\
-	   && (sec_hdr->sh_offset + ELF_SECTION_SIZE(sec_hdr, segment)	\
-	       <= segment->p_offset + segment->p_filesz)))		\
+   && ((sec_hdr)->sh_type == SHT_NOBITS					\
+       || ((bfd_vma) (sec_hdr)->sh_offset >= (segment)->p_offset	\
+	   && ((sec_hdr)->sh_offset + ELF_SECTION_SIZE(sec_hdr, segment) \
+	       <= (segment)->p_offset + (segment)->p_filesz)))		\
    /* SHF_ALLOC sections must have VMAs within the segment.  Be		\
       careful about segments right at the end of memory.  */		\
-   && ((sec_hdr->sh_flags & SHF_ALLOC) == 0				\
-       || (sec_hdr->sh_addr >= segment->p_vaddr				\
-	   && (sec_hdr->sh_addr - segment->p_vaddr			\
-	       + ELF_SECTION_SIZE(sec_hdr, segment) <= segment->p_memsz))))
+   && (!(check_vma)							\
+       || ((sec_hdr)->sh_flags & SHF_ALLOC) == 0			\
+       || ((sec_hdr)->sh_addr >= (segment)->p_vaddr			\
+	   && ((sec_hdr)->sh_addr - (segment)->p_vaddr			\
+	       + ELF_SECTION_SIZE(sec_hdr, segment) <= (segment)->p_memsz))))
 
-/* Decide if the given sec_hdr is in the given segment in file.  */
-#define ELF_IS_SECTION_IN_SEGMENT_FILE(sec_hdr, segment)	\
-  (sec_hdr->sh_size > 0						\
-   && ELF_IS_SECTION_IN_SEGMENT (sec_hdr, segment))
-
-/* Decide if the given sec_hdr is in the given segment in memory.  */
-#define ELF_IS_SECTION_IN_SEGMENT_MEMORY(sec_hdr, segment)	\
-  (ELF_SECTION_SIZE(sec_hdr, segment) > 0			\
-   && ELF_IS_SECTION_IN_SEGMENT (sec_hdr, segment))
+#define ELF_SECTION_IN_SEGMENT(sec_hdr, segment)			\
+  (ELF_SECTION_IN_SEGMENT_1 (sec_hdr, segment, 1))
 
 #endif /* _ELF_INTERNAL_H */
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.509
diff -u -p -r1.509 elf.c
--- bfd/elf.c	22 Apr 2010 01:51:00 -0000	1.509
+++ bfd/elf.c	24 Apr 2010 01:03:06 -0000
@@ -978,7 +978,7 @@ _bfd_elf_make_section_from_shdr (bfd *ab
       for (i = 0; i < elf_elfheader (abfd)->e_phnum; i++, phdr++)
 	{
 	  if (phdr->p_type == PT_LOAD
-	      && ELF_IS_SECTION_IN_SEGMENT (hdr, phdr))
+	      && ELF_SECTION_IN_SEGMENT (hdr, phdr))
 	    {
 	      if ((flags & SEC_LOAD) == 0)
 		newsect->lma = (phdr->p_paddr
@@ -4552,22 +4552,38 @@ assign_file_positions_for_load_sections 
       /* Check that all sections are in a PT_LOAD segment.
 	 Don't check funky gdb generated core files.  */
       if (p->p_type == PT_LOAD && bfd_get_format (abfd) != bfd_core)
-	for (i = 0, secpp = m->sections; i < m->count; i++, secpp++)
-	  {
-	    Elf_Internal_Shdr *this_hdr;
-	    asection *sec;
+	{
+	  bfd_boolean check_vma = TRUE;
 
-	    sec = *secpp;
-	    this_hdr = &(elf_section_data(sec)->this_hdr);
-	    if (this_hdr->sh_size != 0
-		&& !ELF_IS_SECTION_IN_SEGMENT_FILE (this_hdr, p))
+	  for (i = 1; i < m->count; i++)
+	    if (m->sections[i]->vma == m->sections[i - 1]->vma
+		&& ELF_SECTION_SIZE (&(elf_section_data (m->sections[i])
+				       ->this_hdr), p) != 0
+		&& ELF_SECTION_SIZE (&(elf_section_data (m->sections[i - 1])
+				       ->this_hdr), p) != 0)
 	      {
-		(*_bfd_error_handler)
-		  (_("%B: section `%A' can't be allocated in segment %d"),
-		   abfd, sec, j);
-		print_segment_map (m);
+		/* Looks like we have overlays packed into the segment.  */
+		check_vma = FALSE;
+		break;
 	      }
-	  }
+
+	  for (i = 0; i < m->count; i++)
+	    {
+	      Elf_Internal_Shdr *this_hdr;
+	      asection *sec;
+
+	      sec = m->sections[i];
+	      this_hdr = &(elf_section_data(sec)->this_hdr);
+	      if (this_hdr->sh_size != 0
+		  && !ELF_SECTION_IN_SEGMENT_1 (this_hdr, p, check_vma))
+		{
+		  (*_bfd_error_handler)
+		    (_("%B: section `%A' can't be allocated in segment %d"),
+		     abfd, sec, j);
+		  print_segment_map (m);
+		}
+	    }
+	}
     }
 
   elf_tdata (abfd)->next_file_pos = off;
@@ -5837,7 +5853,8 @@ copy_elf_program_header (bfd *ibfd, bfd 
 	   section = section->next)
 	{
 	  this_hdr = &(elf_section_data(section)->this_hdr);
-	  if (ELF_IS_SECTION_IN_SEGMENT_FILE (this_hdr, segment))
+	  if (this_hdr->sh_size != 0
+	      && ELF_SECTION_IN_SEGMENT (this_hdr, segment))
 	    {
 	      if (!first_section)
 		first_section = lowest_section = section;
@@ -5916,7 +5933,8 @@ copy_elf_program_header (bfd *ibfd, bfd 
 	       section = section->next)
 	    {
 	      this_hdr = &(elf_section_data(section)->this_hdr);
-	      if (ELF_IS_SECTION_IN_SEGMENT_FILE (this_hdr, segment))
+	      if (this_hdr->sh_size != 0
+		  && ELF_SECTION_IN_SEGMENT (this_hdr, segment))
 		{
 		  map->sections[isec++] = section->output_section;
 		  if (isec == section_count)
@@ -5993,7 +6011,8 @@ copy_private_bfd_data (bfd *ibfd, bfd *o
 
 	      /* Check if this section is covered by the segment.  */
 	      this_hdr = &(elf_section_data(section)->this_hdr);
-	      if (ELF_IS_SECTION_IN_SEGMENT_FILE (this_hdr, segment))
+	      if (this_hdr->sh_size != 0
+		  && ELF_SECTION_IN_SEGMENT (this_hdr, segment))
 		{
 		  /* FIXME: Check if its output section is changed or
 		     removed.  What else do we need to check?  */
Index: bfd/elf32-spu.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-spu.c,v
retrieving revision 1.94
diff -u -p -r1.94 elf32-spu.c
--- bfd/elf32-spu.c	4 Feb 2010 09:16:40 -0000	1.94
+++ bfd/elf32-spu.c	24 Apr 2010 01:03:08 -0000
@@ -272,7 +272,8 @@ spu_elf_object_p (bfd *abfd)
 	      {
 		Elf_Internal_Shdr *shdr = elf_elfsections (abfd)[j];
 
-		if (ELF_IS_SECTION_IN_SEGMENT_MEMORY (shdr, phdr))
+		if (ELF_SECTION_SIZE (shdr, phdr) != 0
+		    && ELF_SECTION_IN_SEGMENT (shdr, phdr))
 		  {
 		    asection *sec = shdr->bfd_section;
 		    spu_elf_section_data (sec)->u.o.ovl_index = num_ovl;
Index: binutils/readelf.c
===================================================================
RCS file: /cvs/src/src/binutils/readelf.c,v
retrieving revision 1.494
diff -u -p -r1.494 readelf.c
--- binutils/readelf.c	20 Apr 2010 08:21:54 -0000	1.494
+++ binutils/readelf.c	24 Apr 2010 01:03:12 -0000
@@ -3850,7 +3850,8 @@ process_program_headers (FILE * file)
 
 	  for (j = 1; j < elf_header.e_shnum; j++, section++)
 	    {
-	      if (ELF_IS_SECTION_IN_SEGMENT_MEMORY (section, segment))
+	      if (ELF_SECTION_SIZE (section, segment) != 0
+		  && ELF_SECTION_IN_SEGMENT (section, segment))
 		printf ("%s ", SECTION_NAME (section));
 	    }
 

-- 
Alan Modra
Australia Development Lab, IBM

  reply	other threads:[~2010-04-24  2:18 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-16 13:29 David Stubbs
2010-04-21  8:25 ` Alan Modra
2010-04-21 14:44   ` David Stubbs
2010-04-22  1:11     ` Alan Modra
2010-04-22  1:53       ` Alan Modra
2010-04-22 12:39         ` David Stubbs
2010-04-24  2:18           ` Alan Modra [this message]
2010-05-07 16:14             ` David Stubbs
2010-05-08 11:49               ` Alan Modra
2010-05-12 13:19                 ` David Stubbs
2010-05-13  3:37                   ` Alan Modra
2010-07-15  8:11             ` Andreas Schwab
2010-07-15 13:10               ` Alan Modra
2010-07-15 13:46                 ` Andreas Schwab
2010-07-15 13:53                   ` H.J. Lu
2010-07-15 14:12                     ` Andreas Schwab
2010-07-15 14:17                       ` H.J. Lu
2010-07-15 14:18                     ` Alan Modra
2010-07-15 14:26                       ` H.J. Lu
2010-07-15 14:36                         ` Andreas Schwab
2010-07-15 19:09                           ` H.J. Lu
2010-07-16  7:39                             ` Andreas Schwab
2010-07-16 10:04                               ` Alan Modra
2010-07-19 12:43                                 ` Andreas Schwab
2010-07-20  5:45                                   ` Alan Modra
2010-07-20 14:11                                     ` Alan Modra
2011-02-24 23:49                                       ` H.J. Lu
2011-02-25  7:49                                         ` Alan Modra
2011-02-25 10:17                                           ` Andreas Schwab
2011-02-25 12:30                                           ` H.J. Lu
2011-02-25 15:55                                           ` H.J. Lu
2011-02-25 16:23                                             ` Andreas Schwab
2011-02-25 16:34                                               ` H.J. Lu
2010-08-28  1:02         ` H.J. Lu
2010-08-28 11:00           ` Alan Modra
2010-08-28 13:39             ` Alan Modra
2010-08-28 17:25               ` H.J. Lu
2010-08-30  4:46                 ` Alan Modra
2010-08-30  5:11                   ` H.J. Lu
2010-08-30  6:30                     ` Alan Modra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100424021750.GQ3510@bubble.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=stubbs@IceraSemi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).