From: Alan Modra <amodra@gmail.com>
To: Andreas Schwab <schwab@redhat.com>,
"H.J. Lu" <hjl.tools@gmail.com>,
David Stubbs <stubbs@icerasemi.com>,
binutils@sourceware.org
Subject: Re: VMA section overlap warnings for overlays
Date: Tue, 20 Jul 2010 14:11:00 -0000 [thread overview]
Message-ID: <20100720141031.GI19525@bubble.grove.modra.org> (raw)
In-Reply-To: <20100720054451.GF19525@bubble.grove.modra.org>
This removes all the special treatment for zero size sections when
using ELF_SECTION_IN_SEGMENT in elf.c, and makes readelf display
section to segment mapping for zero size sections. I chose to not
include a zero size section in readelf's mapping if the section was at
the end of a segment. eg. if the segment covers 0x1000 to 0x1fff,
then a zero sized section located at 0x2000 is not shown as part of
the segment. That seems reasonable to me, but I'm open to
suggestions. I'll note that omitting sections like this in elf.c, ie.
using ELF_SECTION_IN_SEGMENT_STRICT there, causes testsuite failures
on x86. A zero length .got.plt sometimes ends up as the last section
mapped to a load segment.
include/elf/
* internal.h (ELF_TBSS_SPECIAL): New macro, extracted from..
(ELF_SECTION_SIZE): ..here.
(ELF_SECTION_IN_SEGMENT_1): Add "strict" arg.
(ELF_SECTION_IN_SEGMENT_STRICT): New macro.
bfd/
* elf.c (assign_file_positions_for_load_sections): Check that
zero size sections are allocated in segments too.
(assign_file_positions_for_non_load_sections): Warn if zero
size alloc sections are found here.
(copy_elf_program_header): Don't drop zero size sections from
segment map.
(copy_private_bfd_data): Check for changes in zero size sections.
binutils/
* readelf.c (process_program_headers): Don't ignore all zero size
sections.
ld/testsuite/
* ld-powerpc/tlsexe.r: Update.
* ld-powerpc/tlsexetoc.r: Update.
* ld-powerpc/tlsso.r: Update.
* ld-powerpc/tlstocso.r: Update.
Index: include/elf/internal.h
===================================================================
RCS file: /cvs/src/src/include/elf/internal.h,v
retrieving revision 1.25
diff -u -p -r1.25 internal.h
--- include/elf/internal.h 24 Apr 2010 01:05:22 -0000 1.25
+++ include/elf/internal.h 20 Jul 2010 13:53:26 -0000
@@ -291,37 +291,55 @@ 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_TBSS_SPECIAL(sec_hdr, segment) \
+ (((sec_hdr)->sh_flags & SHF_TLS) != 0 \
+ && (sec_hdr)->sh_type == SHT_NOBITS \
+ && (segment)->p_type != PT_TLS)
+
#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)
+ (ELF_TBSS_SPECIAL(sec_hdr, segment) ? 0 : (sec_hdr)->sh_size)
-/* 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_SECTION_IN_SEGMENT_1(sec_hdr, segment, check_vma) \
- ((((((sec_hdr)->sh_flags & SHF_TLS) != 0) \
+/* Decide if the section SEC_HDR is in SEGMENT. If CHECK_VMA, then
+ VMAs are checked for alloc sections. If STRICT, then a zero size
+ section won't match at the end of a segment, unless the segment
+ is also zero size. */
+#define ELF_SECTION_IN_SEGMENT_1(sec_hdr, segment, check_vma, strict) \
+ ((/* Only PT_LOAD, PT_GNU_RELRO and PT_TLS segments can contain \
+ SHF_TLS sections. */ \
+ ((((sec_hdr)->sh_flags & SHF_TLS) != 0) \
&& ((segment)->p_type == PT_TLS \
|| (segment)->p_type == PT_GNU_RELRO \
|| (segment)->p_type == PT_LOAD)) \
+ /* PT_TLS segment contains only SHF_TLS sections, PT_PHDR no \
+ sections at all. */ \
|| (((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. */ \
+ /* Any section besides one of type SHT_NOBITS must have file \
+ offsets 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))) \
- /* SHF_ALLOC sections must have VMAs within the segment. Be \
- careful about segments right at the end of memory. */ \
+ && (!(strict) \
+ || ((sec_hdr)->sh_offset - (segment)->p_offset \
+ <= (segment)->p_filesz - 1)) \
+ && (((sec_hdr)->sh_offset - (segment)->p_offset \
+ + ELF_SECTION_SIZE(sec_hdr, segment)) \
+ <= (segment)->p_filesz))) \
+ /* SHF_ALLOC sections must have VMAs within the segment. */ \
&& (!(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))))
+ && (!(strict) \
+ || ((sec_hdr)->sh_addr - (segment)->p_vaddr \
+ <= (segment)->p_memsz - 1)) \
+ && (((sec_hdr)->sh_addr - (segment)->p_vaddr \
+ + ELF_SECTION_SIZE(sec_hdr, segment)) \
+ <= (segment)->p_memsz))))
#define ELF_SECTION_IN_SEGMENT(sec_hdr, segment) \
- (ELF_SECTION_IN_SEGMENT_1 (sec_hdr, segment, 1))
+ (ELF_SECTION_IN_SEGMENT_1 (sec_hdr, segment, 1, 0))
+
+#define ELF_SECTION_IN_SEGMENT_STRICT(sec_hdr, segment) \
+ (ELF_SECTION_IN_SEGMENT_1 (sec_hdr, segment, 1, 1))
#endif /* _ELF_INTERNAL_H */
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.512
diff -u -p -r1.512 elf.c
--- bfd/elf.c 17 Jul 2010 03:10:50 -0000 1.512
+++ bfd/elf.c 20 Jul 2010 13:53:29 -0000
@@ -4589,8 +4589,7 @@ assign_file_positions_for_load_sections
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))
+ if (!ELF_SECTION_IN_SEGMENT_1 (this_hdr, p, check_vma, 0))
{
(*_bfd_error_handler)
(_("%B: section `%A' can't be allocated in segment %d"),
@@ -4640,13 +4639,12 @@ assign_file_positions_for_non_load_secti
BFD_ASSERT (hdr->sh_offset == hdr->bfd_section->filepos);
else if ((hdr->sh_flags & SHF_ALLOC) != 0)
{
- if (hdr->sh_size != 0)
- ((*_bfd_error_handler)
- (_("%B: warning: allocated section `%s' not in segment"),
- abfd,
- (hdr->bfd_section == NULL
- ? "*unknown*"
- : hdr->bfd_section->name)));
+ (*_bfd_error_handler)
+ (_("%B: warning: allocated section `%s' not in segment"),
+ abfd,
+ (hdr->bfd_section == NULL
+ ? "*unknown*"
+ : hdr->bfd_section->name));
/* We don't need to page align empty sections. */
if ((abfd->flags & D_PAGED) != 0 && hdr->sh_size != 0)
off += vma_page_aligned_bias (hdr->sh_addr, off,
@@ -5868,8 +5866,7 @@ copy_elf_program_header (bfd *ibfd, bfd
section = section->next)
{
this_hdr = &(elf_section_data(section)->this_hdr);
- if (this_hdr->sh_size != 0
- && ELF_SECTION_IN_SEGMENT (this_hdr, segment))
+ if (ELF_SECTION_IN_SEGMENT (this_hdr, segment))
{
if (!first_section)
first_section = lowest_section = section;
@@ -5948,8 +5945,7 @@ copy_elf_program_header (bfd *ibfd, bfd
section = section->next)
{
this_hdr = &(elf_section_data(section)->this_hdr);
- if (this_hdr->sh_size != 0
- && ELF_SECTION_IN_SEGMENT (this_hdr, segment))
+ if (ELF_SECTION_IN_SEGMENT (this_hdr, segment))
{
map->sections[isec++] = section->output_section;
if (isec == section_count)
@@ -6026,8 +6022,7 @@ 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 (this_hdr->sh_size != 0
- && ELF_SECTION_IN_SEGMENT (this_hdr, segment))
+ if (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: binutils/readelf.c
===================================================================
RCS file: /cvs/src/src/binutils/readelf.c,v
retrieving revision 1.506
diff -u -p -r1.506 readelf.c
--- binutils/readelf.c 19 Jul 2010 12:46:01 -0000 1.506
+++ binutils/readelf.c 20 Jul 2010 13:53:33 -0000
@@ -3889,8 +3889,8 @@ process_program_headers (FILE * file)
for (j = 1; j < elf_header.e_shnum; j++, section++)
{
- if (ELF_SECTION_SIZE (section, segment) != 0
- && ELF_SECTION_IN_SEGMENT (section, segment))
+ if (!ELF_TBSS_SPECIAL (section, segment)
+ && ELF_SECTION_IN_SEGMENT_STRICT (section, segment))
printf ("%s ", SECTION_NAME (section));
}
Index: ld/testsuite/ld-powerpc/tlsexe.r
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsexe.r,v
retrieving revision 1.25
diff -u -p -r1.25 tlsexe.r
--- ld/testsuite/ld-powerpc/tlsexe.r 2 Oct 2009 15:00:30 -0000 1.25
+++ ld/testsuite/ld-powerpc/tlsexe.r 20 Jul 2010 07:05:25 -0000
@@ -47,7 +47,7 @@ Program Headers:
+0+ +
+01 +\.interp
+02 +\.interp \.hash \.dynsym \.dynstr \.rela\.dyn \.rela\.plt \.text
- +03 +\.tdata \.dynamic \.got \.plt
+ +03 +\.tdata \.dynamic (\.branch_lt |)\.got \.plt
+04 +\.dynamic
+05 +\.tdata \.tbss
Index: ld/testsuite/ld-powerpc/tlsexetoc.r
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsexetoc.r,v
retrieving revision 1.26
diff -u -p -r1.26 tlsexetoc.r
--- ld/testsuite/ld-powerpc/tlsexetoc.r 2 Oct 2009 15:00:30 -0000 1.26
+++ ld/testsuite/ld-powerpc/tlsexetoc.r 20 Jul 2010 07:05:25 -0000
@@ -47,7 +47,7 @@ Program Headers:
+0+ +
+01 +\.interp
+02 +\.interp \.hash \.dynsym \.dynstr \.rela\.dyn \.rela\.plt \.text
- +03 +\.tdata \.dynamic \.got \.plt
+ +03 +\.tdata \.dynamic (\.branch_lt |)\.got \.plt
+04 +\.dynamic
+05 +\.tdata \.tbss
Index: ld/testsuite/ld-powerpc/tlsso.r
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsso.r,v
retrieving revision 1.26
diff -u -p -r1.26 tlsso.r
--- ld/testsuite/ld-powerpc/tlsso.r 2 Oct 2009 15:00:30 -0000 1.26
+++ ld/testsuite/ld-powerpc/tlsso.r 20 Jul 2010 07:05:25 -0000
@@ -40,7 +40,7 @@ Program Headers:
Section to Segment mapping:
+Segment Sections\.\.\.
+0+ +\.hash \.dynsym \.dynstr \.rela\.dyn \.rela\.plt \.text
- +01 +\.tdata \.dynamic \.got \.plt
+ +01 +\.tdata \.dynamic (\.branch_lt |)\.got \.plt
+02 +\.dynamic
+03 +\.tdata \.tbss
Index: ld/testsuite/ld-powerpc/tlstocso.r
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlstocso.r,v
retrieving revision 1.24
diff -u -p -r1.24 tlstocso.r
--- ld/testsuite/ld-powerpc/tlstocso.r 2 Oct 2009 15:00:30 -0000 1.24
+++ ld/testsuite/ld-powerpc/tlstocso.r 20 Jul 2010 07:05:25 -0000
@@ -40,7 +40,7 @@ Program Headers:
Section to Segment mapping:
+Segment Sections\.\.\.
+0+ +\.hash \.dynsym \.dynstr \.rela\.dyn \.rela\.plt \.text
- +01 +\.tdata \.dynamic \.got \.plt
+ +01 +\.tdata \.dynamic (\.branch_lt |)\.got \.plt
+02 +\.dynamic
+03 +\.tdata \.tbss
--
Alan Modra
Australia Development Lab, IBM
next prev parent reply other threads:[~2010-07-20 14:11 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
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 [this message]
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=20100720141031.GI19525@bubble.grove.modra.org \
--to=amodra@gmail.com \
--cc=binutils@sourceware.org \
--cc=hjl.tools@gmail.com \
--cc=schwab@redhat.com \
--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).