This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Exclude zero size section for RELRO segment match


On Fri, Feb 16, 2018 at 04:13:04AM -0800, H.J. Lu wrote:
> On Fri, Feb 16, 2018 at 4:08 AM, Alan Modra <amodra@gmail.com> wrote:
> > On Thu, Feb 15, 2018 at 03:58:16AM -0800, H.J. Lu wrote:
> >> When seaching a LOAD segment which overlaps with the RELRO segment, we
> >> need to check the size of the last non-zero size section in the LOAD
> >> segment.
> >
> > Why?  Do you have a case where the current algorithm goes wrong?
> >
> 
> Yes, apply this patch and I get assert in
> assign_file_positions_for_non_load_sections
> on x86-64:

On looking at the tbss1 fail, I see a PT_LOAD with a single
zero length .eh_frame section.  So we have a degenerate PT_LOAD.
I think the following simpler patch is sufficient.

Your testsuite change is OK, but please check a large set of targets
before committing in case some targets won't support -z separate-code.

	PR 22845
	* elf.c (assign_file_positions_for_non_load_sections): Ignore
	degenerate zero size PT_LOAD segments when finding one overlapping
	the PT_GNU_RELRO segment.

diff --git a/bfd/elf.c b/bfd/elf.c
index 397fa62..b069b59 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -5897,6 +5897,7 @@ assign_file_positions_for_non_load_sections (bfd *abfd,
 		   lm = lm->next, lp++)
 		{
 		  if (lp->p_type == PT_LOAD
+		      && lp->p_memsz != 0
 		      && lm->count != 0
 		      && lm->sections[lm->count - 1]->vma >= start
 		      && lm->sections[0]->vma < end)

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]