This is the mail archive of the binutils@sources.redhat.com 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: Fix relro when COMMONPAGESIZE < MAXPAGESIZE


On Thu, Sep 09, 2004 at 02:35:17PM +0200, Andreas Schwab wrote:
> 2004-09-09  Andreas Schwab  <schwab@suse.de>
> 
> 	* ldexp.c (fold_binary) [DATA_SEGMENT_ALIGN]: Adjust data segment
> 	base so that relro end is suitably aligned.
> 
> --- ld/ldexp.c	02 Sep 2004 15:29:34 +0200	1.33
> +++ ld/ldexp.c	09 Sep 2004 14:00:15 +0200	
> @@ -425,12 +425,9 @@ fold_binary (etree_type *tree,
>  		    {
>  		      /* Attempt to align DATA_SEGMENT_RELRO_END at
>  			 a common page boundary.  */
> -		      bfd_vma relro;
> -
> -		      result.value += dot & (maxpage - 1);
> -		      relro = exp_data_seg.relro_end - exp_data_seg.base;
> -		      result.value += -relro & (other.value - 1);
> -		      exp_data_seg.base = result.value;
> +		      exp_data_seg.base += (-exp_data_seg.relro_end
> +					    & (other.value - 1));
> +		      result.value = exp_data_seg.base;
>  		    }
>  		  else if (exp_data_seg.phase != exp_dataseg_adjust)
>  		    {

I have tried your patch now (sorry it took so long).
Unfortunately it doesn't work.

On x86-64:

char bar[3096] __attribute__((aligned (32))) = { 1 };
const char baz[2048] = { 1, 2 };
int foo (void)
{
}

gcc -O2 -fpic -o test1.o test1.c  -c
gcc -shared -o test1.so test1.o  -Wl,-z,relro -B../ld/tmpdir/ld/

With older binutils, I get:
  [14] .eh_frame         PROGBITS        0000000000000f78 000f78 000034 00   A  0   0  8
  [15] .ctors            PROGBITS        0000000000100e28 100e28 000010 00  WA  0   0  8
  [16] .dtors            PROGBITS        0000000000100e38 100e38 000010 00  WA  0   0  8
  [17] .jcr              PROGBITS        0000000000100e48 100e48 000008 00  WA  0   0  8
  [18] .dynamic          DYNAMIC         0000000000100e50 100e50 000180 10  WA  3   0  8
  [19] .got              PROGBITS        0000000000100fd0 100fd0 000018 08  WA  0   0  8
  [20] .got.plt          PROGBITS        0000000000100fe8 100fe8 000020 08  WA  0   0  8
  [21] .data             PROGBITS        0000000000101020 101020 000c38 00  WA  0   0 32
(end of PT_GNU_RELRO, which is .got.plt+24, is aligned to 4K and
for all sections (sh_addr & 0xfffff) == (sh_offset & 0xfffff).

Current CVS binutils (that includes your 2004-09-07 patch):
  [14] .eh_frame         PROGBITS        0000000000000f78 000f78 000034 00   A  0   0  8
  [15] .ctors            PROGBITS        0000000000101dd0 001dd0 000010 00  WA  0   0  8
  [16] .dtors            PROGBITS        0000000000101de0 001de0 000010 00  WA  0   0  8
  [17] .jcr              PROGBITS        0000000000101df0 001df0 000008 00  WA  0   0  8
  [18] .dynamic          DYNAMIC         0000000000101df8 001df8 000180 10  WA  3   0  8
  [19] .got              PROGBITS        0000000000101f78 001f78 000018 08  WA  0   0  8
  [20] .got.plt          PROGBITS        0000000000101f90 001f90 000020 08  WA  0   0  8
  [21] .data             PROGBITS        0000000000101fc0 001fc0 000c38 00  WA  0   0 32
Here, .got.plt+24 is not 4K aligned (so relro is useless) and also
(sh_addr & 0xfffff) != (sh_offset & 0xfffff) for sections in read-write
segment, which means x86-64 ELF ABI is violated; particularly you can use
such binaries solely on machines with at most 4K page size (sure, all
currently are using such page size), but MAXPAGESIZE is 1MB on x86-64 so
that bigger page sizes could be used in the future (otherwise I don't
understand why MAXPAGESIZE 4K was not used).

Current CVS binutils + your 2004-09-09 patch is better, but only partially:
  [14] .eh_frame         PROGBITS        0000000000000f78 000f78 000034 00   A  0   0  8
  [15] .ctors            PROGBITS        0000000000101e28 001e28 000010 00  WA  0   0  8
  [16] .dtors            PROGBITS        0000000000101e38 001e38 000010 00  WA  0   0  8
  [17] .jcr              PROGBITS        0000000000101e48 001e48 000008 00  WA  0   0  8
  [18] .dynamic          DYNAMIC         0000000000101e50 001e50 000180 10  WA  3   0  8
  [19] .got              PROGBITS        0000000000101fd0 001fd0 000018 08  WA  0   0  8
  [20] .got.plt          PROGBITS        0000000000101fe8 001fe8 000020 08  WA  0   0  8
  [21] .data             PROGBITS        0000000000102020 002020 000c38 00  WA  0   0 32
.got.plt+24 is 4K aligned again, so relro works again, but the other
constraint is violated.  If you think 1MB page size is excessive and
you think it is possible to change the ABI, it should change MAXPAGESIZE
to 4K rather than changing the relro mechanism.

	Jakub


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