diff options
author | Alan Modra <amodra@gmail.com> | 2018-04-14 16:23:56 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2018-04-14 17:56:40 +0930 |
commit | 702d167134149f420ea3bcbc194d63a2653a0c27 (patch) | |
tree | 3039514093375d874d15ac74aed9cfc5d1a0ecfb | |
parent | 03aa968462e0345b2d846ca240b8c723d713761a (diff) | |
download | gdb-702d167134149f420ea3bcbc194d63a2653a0c27.zip gdb-702d167134149f420ea3bcbc194d63a2653a0c27.tar.gz gdb-702d167134149f420ea3bcbc194d63a2653a0c27.tar.bz2 |
powerpc common-page-size
max-page-size only matters for demand paged executables or shared
libraries, and the ideal size is the largest value used by your
operating system. Values larger than necessary just waste file space
and memory. common-page-size also affects file and memory size,
trading a possible small increase in file size for a decrease in
memory size when the operating system is using a common-page-size
page. With a powerpc max-page-size of 64k and common-page-size of 4k
many executables will use no more memory pages when the system page
size is 4k than an executable linked with -z max-page-size=0x1000,
yet will still run on a system using 64k pages. However, when running
on a system using 64k pages relro protection will not be completely
effective.
Due to the relro problem, powerpc binutils has been using a default
common-page-size of 64k since 2014-12-18 (git commit 04c6a44c7),
leading to complaints about increased file and memory sizes. People
not using relro do have a valid reason to complain..
So this patch introduces an extra back-end value to use as the default
for common-page-size when generating relro executables, and enables
the support for powerpc. Non relro executables will now be generated
with a default common-page-size of 4k.
bfd/
* elf-bfd.h (struct elf_backend_data): Add relropagesize.
* elfxx-target.h (ELF_RELROPAGESIZE): Provide default and
sanity test.
(elfNN_bed): Init relropagesize.
* bfd.c (bfd_emul_get_commonpagesize): Add boolean param to
select relropagesize.
* elf32-ppc.c (ELF_COMMONPAGESIZE): Define as 0x1000.
(ELF_RELROPAGESIZE): Define as ELF_MAXPAGESIZE.
(ELF_MINPAGESIZE): Don't define.
* elf64-ppc.c (ELF_COMMONPAGESIZE): Define as 0x1000.
(ELF_RELROPAGESIZE): Define as ELF_MAXPAGESIZE.
* bfd-in2.h: Regenerate.
ld/
* ldmain.c (main): Move config.maxpagesize and
config.commonpagesize initialization to..
* ldemul.c (after_parse_default): ..here.
* testsuite/ld-powerpc/ppc476-shared.d: Pass -z common-page-size.
* testsuite/ld-powerpc/ppc476-shared2.d: Likewise.
-rw-r--r-- | bfd/ChangeLog | 15 | ||||
-rw-r--r-- | bfd/bfd-in2.h | 2 | ||||
-rw-r--r-- | bfd/bfd.c | 13 | ||||
-rw-r--r-- | bfd/elf-bfd.h | 3 | ||||
-rw-r--r-- | bfd/elf32-ppc.c | 4 | ||||
-rw-r--r-- | bfd/elf64-ppc.c | 3 | ||||
-rw-r--r-- | bfd/elfxx-target.h | 11 | ||||
-rw-r--r-- | ld/ChangeLog | 8 | ||||
-rw-r--r-- | ld/ldemul.c | 5 | ||||
-rw-r--r-- | ld/ldmain.c | 2 | ||||
-rw-r--r-- | ld/testsuite/ld-powerpc/ppc476-shared.d | 2 | ||||
-rw-r--r-- | ld/testsuite/ld-powerpc/ppc476-shared2.d | 2 |
12 files changed, 59 insertions, 11 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index c34cff6..c8ee895 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,5 +1,20 @@ 2018-04-14 Alan Modra <amodra@gmail.com> + * elf-bfd.h (struct elf_backend_data): Add relropagesize. + * elfxx-target.h (ELF_RELROPAGESIZE): Provide default and + sanity test. + (elfNN_bed): Init relropagesize. + * bfd.c (bfd_emul_get_commonpagesize): Add boolean param to + select relropagesize. + * elf32-ppc.c (ELF_COMMONPAGESIZE): Define as 0x1000. + (ELF_RELROPAGESIZE): Define as ELF_MAXPAGESIZE. + (ELF_MINPAGESIZE): Don't define. + * elf64-ppc.c (ELF_COMMONPAGESIZE): Define as 0x1000. + (ELF_RELROPAGESIZE): Define as ELF_MAXPAGESIZE. + * bfd-in2.h: Regenerate. + +2018-04-14 Alan Modra <amodra@gmail.com> + * elf32-ppc.c (ELF_MAXPAGESIZE, ELF_COMMONPAGESIZE): Don't depend on __QNXTARGET__ define. diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 3f5d38b..fc07ded 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -7251,7 +7251,7 @@ bfd_vma bfd_emul_get_maxpagesize (const char *); void bfd_emul_set_maxpagesize (const char *, bfd_vma); -bfd_vma bfd_emul_get_commonpagesize (const char *); +bfd_vma bfd_emul_get_commonpagesize (const char *, bfd_boolean); void bfd_emul_set_commonpagesize (const char *, bfd_vma); @@ -2137,7 +2137,7 @@ FUNCTION bfd_emul_get_commonpagesize SYNOPSIS - bfd_vma bfd_emul_get_commonpagesize (const char *); + bfd_vma bfd_emul_get_commonpagesize (const char *, bfd_boolean); DESCRIPTION Returns the common page size, in bytes, as determined by @@ -2148,15 +2148,22 @@ RETURNS */ bfd_vma -bfd_emul_get_commonpagesize (const char *emul) +bfd_emul_get_commonpagesize (const char *emul, bfd_boolean relro) { const bfd_target *target; target = bfd_find_target (emul, NULL); if (target != NULL && target->flavour == bfd_target_elf_flavour) - return xvec_get_elf_backend_data (target)->commonpagesize; + { + const struct elf_backend_data *bed; + bed = xvec_get_elf_backend_data (target); + if (relro) + return bed->relropagesize; + else + return bed->commonpagesize; + } return 0; } diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index afd6982..9c900b7 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -864,6 +864,9 @@ struct elf_backend_data /* The common page size for this backend. */ bfd_vma commonpagesize; + /* The value of commonpagesize to use when -z relro for this backend. */ + bfd_vma relropagesize; + /* The BFD flags applied to sections created for dynamic linking. */ flagword dynamic_sec_flags; diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c index 8629380..0438af4 100644 --- a/bfd/elf32-ppc.c +++ b/bfd/elf32-ppc.c @@ -11390,8 +11390,8 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd, #define ELF_TARGET_ID PPC32_ELF_DATA #define ELF_MACHINE_CODE EM_PPC #define ELF_MAXPAGESIZE 0x10000 -#define ELF_COMMONPAGESIZE 0x10000 -#define ELF_MINPAGESIZE 0x1000 +#define ELF_COMMONPAGESIZE 0x1000 +#define ELF_RELROPAGESIZE ELF_MAXPAGESIZE #define elf_info_to_howto ppc_elf_info_to_howto #ifdef EM_CYGNUS_POWERPC diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c index 59c2922..971adc4 100644 --- a/bfd/elf64-ppc.c +++ b/bfd/elf64-ppc.c @@ -64,7 +64,8 @@ static bfd_vma opd_entry_value #define ELF_TARGET_ID PPC64_ELF_DATA #define ELF_MACHINE_CODE EM_PPC64 #define ELF_MAXPAGESIZE 0x10000 -#define ELF_COMMONPAGESIZE 0x10000 +#define ELF_COMMONPAGESIZE 0x1000 +#define ELF_RELROPAGESIZE ELF_MAXPAGESIZE #define elf_info_to_howto ppc64_elf_info_to_howto #define elf_backend_want_got_sym 0 diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h index ccab02d..89efed3 100644 --- a/bfd/elfxx-target.h +++ b/bfd/elfxx-target.h @@ -367,6 +367,10 @@ #define ELF_COMMONPAGESIZE ELF_MAXPAGESIZE #endif +#ifndef ELF_RELROPAGESIZE +#define ELF_RELROPAGESIZE ELF_COMMONPAGESIZE +#endif + #ifndef ELF_MINPAGESIZE #define ELF_MINPAGESIZE ELF_COMMONPAGESIZE #endif @@ -374,9 +378,15 @@ #if ELF_COMMONPAGESIZE > ELF_MAXPAGESIZE # error ELF_COMMONPAGESIZE > ELF_MAXPAGESIZE #endif +#if ELF_RELROPAGESIZE > ELF_MAXPAGESIZE +# error ELF_RELROPAGESIZE > ELF_MAXPAGESIZE +#endif #if ELF_MINPAGESIZE > ELF_COMMONPAGESIZE # error ELF_MINPAGESIZE > ELF_COMMONPAGESIZE #endif +#if ELF_MINPAGESIZE > ELF_RELROPAGESIZE +# error ELF_MINPAGESIZE > ELF_RELROPAGESIZE +#endif #ifndef ELF_DYNAMIC_SEC_FLAGS /* Note that we set the SEC_IN_MEMORY flag for these sections. */ @@ -757,6 +767,7 @@ static struct elf_backend_data elfNN_bed = ELF_MAXPAGESIZE, /* maxpagesize */ ELF_MINPAGESIZE, /* minpagesize */ ELF_COMMONPAGESIZE, /* commonpagesize */ + ELF_RELROPAGESIZE, /* commonpagesize to use with -z relro */ ELF_DYNAMIC_SEC_FLAGS, /* dynamic_sec_flags */ elf_backend_arch_data, elf_info_to_howto, diff --git a/ld/ChangeLog b/ld/ChangeLog index 9d5bc2d..d7f3e18 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,5 +1,13 @@ 2018-04-14 Alan Modra <amodra@gmail.com> + * ldmain.c (main): Move config.maxpagesize and + config.commonpagesize initialization to.. + * ldemul.c (after_parse_default): ..here. + * testsuite/ld-powerpc/ppc476-shared.d: Pass -z common-page-size. + * testsuite/ld-powerpc/ppc476-shared2.d: Likewise. + +2018-04-14 Alan Modra <amodra@gmail.com> + * emulparams/elf32ppcwindiss.sh: Rewrite to use elf32ppc.sh. * emulparams/ppclynx.sh: Likewise. diff --git a/ld/ldemul.c b/ld/ldemul.c index 6e5b0de..cd6743d 100644 --- a/ld/ldemul.c +++ b/ld/ldemul.c @@ -225,6 +225,11 @@ after_parse_default (void) if (!is_vma) ldlang_add_undef (entry_symbol.name, entry_from_cmdline); } + if (config.maxpagesize == 0) + config.maxpagesize = bfd_emul_get_maxpagesize (default_target); + if (config.commonpagesize == 0) + config.commonpagesize = bfd_emul_get_commonpagesize (default_target, + link_info.relro); } void diff --git a/ld/ldmain.c b/ld/ldmain.c index 6527613..43602fe 100644 --- a/ld/ldmain.c +++ b/ld/ldmain.c @@ -305,8 +305,6 @@ main (int argc, char **argv) emulation = get_emulation (argc, argv); ldemul_choose_mode (emulation); default_target = ldemul_choose_target (argc, argv); - config.maxpagesize = bfd_emul_get_maxpagesize (default_target); - config.commonpagesize = bfd_emul_get_commonpagesize (default_target); lang_init (); ldexp_init (); ldemul_before_parse (); diff --git a/ld/testsuite/ld-powerpc/ppc476-shared.d b/ld/testsuite/ld-powerpc/ppc476-shared.d index 72f8a3d..7953cb4 100644 --- a/ld/testsuite/ld-powerpc/ppc476-shared.d +++ b/ld/testsuite/ld-powerpc/ppc476-shared.d @@ -1,6 +1,6 @@ #source: ppc476-shared.s #as: -a32 -#ld: -melf32ppc -q -shared --ppc476-workaround -T ppc476-shared.lnk +#ld: -melf32ppc -q -shared -z common-page-size=0x10000 --ppc476-workaround -T ppc476-shared.lnk #objdump: -dr #target: powerpc*-*-* diff --git a/ld/testsuite/ld-powerpc/ppc476-shared2.d b/ld/testsuite/ld-powerpc/ppc476-shared2.d index 5bf0a03..26a5c41 100644 --- a/ld/testsuite/ld-powerpc/ppc476-shared2.d +++ b/ld/testsuite/ld-powerpc/ppc476-shared2.d @@ -1,6 +1,6 @@ #source: ppc476-shared.s #as: -a32 -#ld: -melf32ppc -shared --ppc476-workaround -T ppc476-shared.lnk +#ld: -melf32ppc -shared -z common-page-size=0x10000 --ppc476-workaround -T ppc476-shared.lnk #objdump: -R #target: powerpc*-*-* |