mold icon indicating copy to clipboard operation
mold copied to clipboard

-Wl,-z,common-page-size issue

Open marxin opened this issue 3 years ago • 1 comments

Also taken from binutils test-suite:

mbind2a.s:

/* Place bss_in_mbind0 in .mbind.bss section with sh_info == 0.  */
	.globl bss_in_mbind0
	.section .mbind.bss,"adw",%nobits,0
	.type bss_in_mbind0, %object
	.size bss_in_mbind0, 1
bss_in_mbind0:
	.zero 1

/* Place data_in_mbind3 in .mbind.data section with sh_info == 3.  */
	.globl data_in_mbind3
	.section .mbind.data,"adw",%progbits,0x3
	.type data_in_mbind3, %object
	.size data_in_mbind3, 1
data_in_mbind3:
	.byte 0

mbind2b.c:

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

extern char bss_in_mbind0;
extern char data_in_mbind3;

int
main (void)
{
  if (((intptr_t) &bss_in_mbind0 & (0x4000 - 1)) != 0)
    abort ();
  if (((intptr_t) &data_in_mbind3 & (0x4000 - 1)) != 0)
    abort ();
  printf ("PASS\n");
  return 0;
}
$ gcc-12 -B ~/Programming/mold/objdir /home/marxin/Programming/binutils/ld/testsuite/ld-elf/mbind2a.s /home/marxin/Programming/binutils/ld/testsuite/ld-elf/mbind2b.c -Wl,-z,noexecstack -Wl,-z,common-page-size=0x4000 -g && ./a.out
Aborted (core dumped)

marxin avatar Oct 25 '22 06:10 marxin

We ignore -z common-page-size and respect only -z max-page-size. It looks like the difference of common-page-size and max-page-size is that RELRO segments are not guaranteed to be read-only if the common-page-size is smaller than the actual page size, while max-page-size doesn't have such drawback. However, it also looks like a change is recently made to GNU ld so that RELRO is now aligned to max-page-size instead of common-page-size to ensure it's readable at runtime.

So common-page-size doesn't seems to mean anything now.

rui314 avatar Oct 25 '22 07:10 rui314