[lld] r290986 - ELF: Round p_memsz of the PT_GNU_RELRO program header up to the page size.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 5 13:51:11 PST 2017


It looks like bfd and gold can both start their relro in the middle of a
page, but it will extend to the start of the page following the relro
region. It seems to be in fact the end address that is rounded down, not
the size.

Peter

On Thu, Jan 5, 2017 at 1:37 PM, Rafael Avila de Espindola <
rafael.espindola at gmail.com> wrote:

>
> Both bfd and gold seem to have the same bug. Would you mind reporting
> this bug to them?
>
> Thanks,
> Rafael
>
> Peter Collingbourne via llvm-commits <llvm-commits at lists.llvm.org>
> writes:
>
> > Author: pcc
> > Date: Wed Jan  4 12:56:15 2017
> > New Revision: 290986
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=290986&view=rev
> > Log:
> > ELF: Round p_memsz of the PT_GNU_RELRO program header up to the page
> size.
> >
> > The glibc dynamic loader rounds the size down, so without this the loader
> > will fail to change the memory protection for the last page.
> >
> > Differential Revision: https://reviews.llvm.org/D28267
> >
> > Modified:
> >     lld/trunk/ELF/Writer.cpp
> >     lld/trunk/test/ELF/basic-mips.s
> >     lld/trunk/test/ELF/basic-ppc.s
> >
> > Modified: lld/trunk/ELF/Writer.cpp
> > URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.
> cpp?rev=290986&r1=290985&r2=290986&view=diff
> > ============================================================
> ==================
> > --- lld/trunk/ELF/Writer.cpp (original)
> > +++ lld/trunk/ELF/Writer.cpp Wed Jan  4 12:56:15 2017
> > @@ -1444,8 +1444,13 @@ template <class ELFT> void Writer<ELFT>:
> >      }
> >      if (P.p_type == PT_LOAD)
> >        P.p_align = Config->MaxPageSize;
> > -    else if (P.p_type == PT_GNU_RELRO)
> > +    else if (P.p_type == PT_GNU_RELRO) {
> >        P.p_align = 1;
> > +      // The glibc dynamic loader rounds the size down, so we need to
> round up
> > +      // to protect the last page. This is a no-op on FreeBSD which
> always
> > +      // rounds up.
> > +      P.p_memsz = alignTo(P.p_memsz, Config->MaxPageSize);
> > +    }
> >
> >      // The TLS pointer goes after PT_TLS. At least glibc will align it,
> >      // so round up the size to make sure the offsets are correct.
> >
> > Modified: lld/trunk/test/ELF/basic-mips.s
> > URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/
> basic-mips.s?rev=290986&r1=290985&r2=290986&view=diff
> > ============================================================
> ==================
> > --- lld/trunk/test/ELF/basic-mips.s (original)
> > +++ lld/trunk/test/ELF/basic-mips.s Wed Jan  4 12:56:15 2017
> > @@ -297,7 +297,7 @@ __start:
> >  # CHECK-NEXT:     VirtualAddress: 0x30000
> >  # CHECK-NEXT:     PhysicalAddress: 0x30000
> >  # CHECK-NEXT:     FileSize: 8
> > -# CHECK-NEXT:     MemSize: 8
> > +# CHECK-NEXT:     MemSize: 65536
> >  # CHECK-NEXT:     Flags [ (0x4)
> >  # CHECK-NEXT:       PF_R (0x4)
> >  # CHECK-NEXT:     ]
> >
> > Modified: lld/trunk/test/ELF/basic-ppc.s
> > URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/
> basic-ppc.s?rev=290986&r1=290985&r2=290986&view=diff
> > ============================================================
> ==================
> > --- lld/trunk/test/ELF/basic-ppc.s (original)
> > +++ lld/trunk/test/ELF/basic-ppc.s Wed Jan  4 12:56:15 2017
> > @@ -295,7 +295,7 @@
> >  // CHECK-NEXT:     VirtualAddress: 0x2000
> >  // CHECK-NEXT:     PhysicalAddress: 0x2000
> >  // CHECK-NEXT:     FileSize: 48
> > -// CHECK-NEXT:     MemSize: 48
> > +// CHECK-NEXT:     MemSize: 4096
> >  // CHECK-NEXT:     Flags [ (0x4)
> >  // CHECK-NEXT:       PF_R (0x4)
> >  // CHECK-NEXT:     ]
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>



-- 
-- 
Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170105/c818f1fc/attachment.html>


More information about the llvm-commits mailing list