[PATCH] Put .gnu.linkonce.d.rel.ro.* sections into .data.rel.ro output section

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Put .gnu.linkonce.d.rel.ro.* sections into .data.rel.ro output section

Jakub Jelinek
Hi!

As GCC keeps using .gnu.linkonce.*.* section names even when using COMDAT
and it probably will not change overnight, I think we need to help
it in the linker script to allow more accurate -z relro on C++ code.

I'll post a separate GCC patch to emit those sections soon (though, it
will be backwards compatible with older linkers, as worst case
the relro sections will end up in .data as they did before).

Ok to commit?

2005-12-14  Jakub Jelinek  <[hidden email]>

        * scripttempl/elf.sc: Put .gnu.linkonce.d.rel.ro.* sections into
        .data.rel.ro output section.  Fix a pasto for -z nocombreloc
        .rela.data.rel.ro section content.

--- ld/scripttempl/elf.sc.jj 2005-12-14 13:50:35.000000000 +0100
+++ ld/scripttempl/elf.sc 2005-12-14 13:56:15.000000000 +0100
@@ -117,7 +117,7 @@ if test -z "$GOT"; then
 fi
 DYNAMIC=".dynamic      ${RELOCATING-0} : { *(.dynamic) }"
 RODATA=".rodata       ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
-DATARELRO=".data.rel.ro : { *(.data.rel.ro.local) *(.data.rel.ro*) }"
+DATARELRO=".data.rel.ro : { *(.data.rel.ro.local) *(.gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro*) *(.gnu.linkonce.d.rel.ro.*) }"
 STACKNOTE="/DISCARD/ : { *(.note.GNU-stack) }"
 if test -z "${NO_SMALL_DATA}"; then
   SBSS=".sbss         ${RELOCATING-0} :
@@ -282,8 +282,8 @@ eval $COMBRELOCCAT <<EOF
   .rel.rodata   ${RELOCATING-0} : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) }
   .rela.rodata  ${RELOCATING-0} : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) }
   ${OTHER_READONLY_RELOC_SECTIONS}
-  .rel.data.rel.ro ${RELOCATING-0} : { *(.rel.data.rel.ro${RELOCATING+*}) }
-  .rela.data.rel.ro ${RELOCATING-0} : { *(.rel.data.rel.ro${RELOCATING+*}) }
+  .rel.data.rel.ro ${RELOCATING-0} : { *(.rel.data.rel.ro${RELOCATING+* .rel.gnu.linkonce.d.rel.ro.*}) }
+  .rela.data.rel.ro ${RELOCATING-0} : { *(.rela.data.rel.ro${RELOCATING+* .rela.gnu.linkonce.d.rel.ro.*}) }
   .rel.data     ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
   .rela.data    ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
   .rel.tdata ${RELOCATING-0} : { *(.rel.tdata${RELOCATING+ .rel.tdata.* .rel.gnu.linkonce.td.*}) }

        Jakub
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Put .gnu.linkonce.d.rel.ro.* sections into .data.rel.ro output section

Alan Modra
On Wed, Dec 14, 2005 at 03:09:50PM +0100, Jakub Jelinek wrote:
> --- ld/scripttempl/elf.sc.jj 2005-12-14 13:50:35.000000000 +0100
> +++ ld/scripttempl/elf.sc 2005-12-14 13:56:15.000000000 +0100
> @@ -117,7 +117,7 @@ if test -z "$GOT"; then
>  fi
>  DYNAMIC=".dynamic      ${RELOCATING-0} : { *(.dynamic) }"
>  RODATA=".rodata       ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
> -DATARELRO=".data.rel.ro : { *(.data.rel.ro.local) *(.data.rel.ro*) }"
> +DATARELRO=".data.rel.ro : { *(.data.rel.ro.local) *(.gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro*) *(.gnu.linkonce.d.rel.ro.*) }"

Is there any good reason why all the .data.rel.ro.local input sections
must be first?  I suspect it might be better to keep the ordering as
given in input files, for data locality.  ie. use

DATARELRO=".data.rel.ro : { *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) }"

Otherwise the patch is OK.

--
Alan Modra
IBM OzLabs - Linux Technology Centre
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Put .gnu.linkonce.d.rel.ro.* sections into .data.rel.ro output section

Jakub Jelinek
On Thu, Dec 15, 2005 at 01:03:29AM +1030, Alan Modra wrote:

> On Wed, Dec 14, 2005 at 03:09:50PM +0100, Jakub Jelinek wrote:
> > --- ld/scripttempl/elf.sc.jj 2005-12-14 13:50:35.000000000 +0100
> > +++ ld/scripttempl/elf.sc 2005-12-14 13:56:15.000000000 +0100
> > @@ -117,7 +117,7 @@ if test -z "$GOT"; then
> >  fi
> >  DYNAMIC=".dynamic      ${RELOCATING-0} : { *(.dynamic) }"
> >  RODATA=".rodata       ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
> > -DATARELRO=".data.rel.ro : { *(.data.rel.ro.local) *(.data.rel.ro*) }"
> > +DATARELRO=".data.rel.ro : { *(.data.rel.ro.local) *(.gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro*) *(.gnu.linkonce.d.rel.ro.*) }"
>
> Is there any good reason why all the .data.rel.ro.local input sections
> must be first?  I suspect it might be better to keep the ordering as
> given in input files, for data locality.  ie. use
>
> DATARELRO=".data.rel.ro : { *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) }"

Yes.  .data.rel.ro.local* sections contain only relative relocations, while
other .data.rel.ro* sections contain also other relocations.
When prelinking relative relocations don't need any runtime adjustements,
while the others do.  So if you have say 16KB of .data.rel.ro.local*
sections and 32KB of .data.rel.ro*, the first 16KB don't need to be COWed,
only the rest.

Guess *(.data.rel.ro.local) should be *(.data.rel.ro.local*) though.

        Jakub
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Put .gnu.linkonce.d.rel.ro.* sections into .data.rel.ro output section

Alan Modra
On Wed, Dec 14, 2005 at 03:42:00PM +0100, Jakub Jelinek wrote:

> On Thu, Dec 15, 2005 at 01:03:29AM +1030, Alan Modra wrote:
> > Is there any good reason why all the .data.rel.ro.local input sections
> > must be first?  I suspect it might be better to keep the ordering as
> > given in input files, for data locality.  ie. use
> >
> > DATARELRO=".data.rel.ro : { *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) }"
>
> Yes.  .data.rel.ro.local* sections contain only relative relocations, while
> other .data.rel.ro* sections contain also other relocations.
> When prelinking relative relocations don't need any runtime adjustements,
> while the others do.  So if you have say 16KB of .data.rel.ro.local*
> sections and 32KB of .data.rel.ro*, the first 16KB don't need to be COWed,
> only the rest.

Oh, OK.

> Guess *(.data.rel.ro.local) should be *(.data.rel.ro.local*) though.

Yes.  Hmm, let's have just the sorting you need:

DATARELRO=".data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) }"

And if there is some further reason why you need full sorting, just
commit your patch and ignore me.  :)

--
Alan Modra
IBM OzLabs - Linux Technology Centre
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Put .gnu.linkonce.d.rel.ro.* sections into .data.rel.ro output section

Jakub Jelinek
On Thu, Dec 15, 2005 at 01:36:15AM +1030, Alan Modra wrote:
> Yes.  Hmm, let's have just the sorting you need:
>
> DATARELRO=".data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) }"

Good idea, committed that way.  Thanks.

        Jakub