This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PATCH: PR binutils/3281: objcopy changes PT_GNU_RELRO when there is PT_TLS
On Fri, Oct 27, 2006 at 02:35:56PM +0930, Alan Modra wrote:
> On Mon, Oct 23, 2006 at 10:55:59PM -0700, H. J. Lu wrote:
> > + if (p->p_type == PT_GNU_RELRO)
> > + {
> > + /* When we get here, we are copying executable
> > + or shared library. But we need to use the same
> > + linker logic. */
> > + Elf_Internal_Phdr *lp;
> > +
> > + for (lp = phdrs; lp < phdrs + count; ++lp)
> > + {
> > + if (lp->p_type == PT_LOAD
> > + && lp->p_paddr == p->p_paddr)
> > + break;
> > + }
> > +
> > + if (lp < phdrs + count)
> > + {
> > + p->p_filesz += p->p_vaddr - lp->p_vaddr;
> > + p->p_vaddr = lp->p_vaddr;
> > + p->p_offset = lp->p_offset;
> > + p->p_memsz = p->p_filesz;
> > + p->p_align = 1;
> > + }
> > + else
> > + abort ();
> > + }
>
> I don't think this is going to work in all cases. objcopy can do some
> really nasty things as far as GNU_RELRO segment is concerned, deleting
> sections, adding sections, changing section lmas. I think instead
> you should set the GNU_RELRO segment info from the section map, and
> try to get the section map correct in rewrite_elf_program_header. I
> noticed at least one problem with rewrite_elf_program_header "Step
> Three": It should not be allowed to split a GNU_RELRO segment into
> two due to gaps.
>
My patch works with deleted sections, which won't reach "Step Three".
I am not sure if we should keep GNU_RELRO segment when we add section
or change section lmas.
> > +lang_size_relro_sections (void)
>
> Should probably be called lang_find_relro_sections. You aren't doing
> any sizing here.
I will change it.
H.J.