From 8d6d53d42725d34e9f3aa51442a0741b98163fa2 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Sun, 29 May 2005 23:16:09 +0000 Subject: [PATCH] * emulparams/elf64alpha.sh (PLT): New. (TEXT_PLT): New. * emultempl/alphaelf.em (disable_relaxation): New. (limit_32bit): Rename from elf64alpha_32bit; update all users. (elf64_alpha_use_secureplt): Declare. (bfd_elf64_alpha_vec, bfd_elf64_alpha_freebsd_vec): Declare. (alpha_after_open): New. (alpha_before_allocation): New. (OPTION_NO_RELAX, OPTION_SECUREPLT, OPTION_NO_SECUREPLT): New. (PARSE_AND_LIST_LONGOPTS): Include them. (PARSE_AND_LIST_OPTIONS): Likewise. (PARSE_AND_LIST_ARGS_CASES): Likewise. (LDEMUL_AFTER_OPEN, LDEMUL_BEFORE_ALLOCATION): New. * scripttempl/elf.sc (TEXT_PLT): New. (PLT): Use it. --- ld/ChangeLog | 18 ++++++++ ld/emulparams/elf64alpha.sh | 8 +++- ld/emultempl/alphaelf.em | 90 +++++++++++++++++++++++++++++++++---- ld/scripttempl/elf.sc | 3 +- 4 files changed, 108 insertions(+), 11 deletions(-) diff --git a/ld/ChangeLog b/ld/ChangeLog index 0c1185c03ee..32362d50625 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,21 @@ +2005-05-29 Richard Henderson + + * emulparams/elf64alpha.sh (PLT): New. + (TEXT_PLT): New. + * emultempl/alphaelf.em (disable_relaxation): New. + (limit_32bit): Rename from elf64alpha_32bit; update all users. + (elf64_alpha_use_secureplt): Declare. + (bfd_elf64_alpha_vec, bfd_elf64_alpha_freebsd_vec): Declare. + (alpha_after_open): New. + (alpha_before_allocation): New. + (OPTION_NO_RELAX, OPTION_SECUREPLT, OPTION_NO_SECUREPLT): New. + (PARSE_AND_LIST_LONGOPTS): Include them. + (PARSE_AND_LIST_OPTIONS): Likewise. + (PARSE_AND_LIST_ARGS_CASES): Likewise. + (LDEMUL_AFTER_OPEN, LDEMUL_BEFORE_ALLOCATION): New. + * scripttempl/elf.sc (TEXT_PLT): New. + (PLT): Use it. + 2005-05-27 Andreas Schwab * configure.host (HOSTING_LIBS): Add libunwind.a if it exists. diff --git a/ld/emulparams/elf64alpha.sh b/ld/emulparams/elf64alpha.sh index 093c8dfd8e1..47a0bb009c7 100644 --- a/ld/emulparams/elf64alpha.sh +++ b/ld/emulparams/elf64alpha.sh @@ -12,7 +12,13 @@ ARCH=alpha MACHINE= GENERATE_SHLIB_SCRIPT=yes GENERATE_PIE_SCRIPT=yes -DATA_PLT= + +# Yes, we want duplicate .plt sections. The linker chooses the +# appropriate one magically in alpha_after_open. +PLT=".plt ${RELOCATING-0} : SPECIAL { *(.plt) }" +DATA_PLT=yes +TEXT_PLT=yes + # Note that the number is always big-endian, thus we have to # reverse the digit string. NOP=0x0000fe2f1f04ff47 # unop; nop diff --git a/ld/emultempl/alphaelf.em b/ld/emultempl/alphaelf.em index eeac7587a02..62eca180769 100644 --- a/ld/emultempl/alphaelf.em +++ b/ld/emultempl/alphaelf.em @@ -1,5 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2003, 2004 Free Software Foundation, Inc. +# Copyright 2003, 2004, 2005 Free Software Foundation, Inc. # # This file is part of GLD, the Gnu Linker. # @@ -27,15 +27,54 @@ cat >>e${EMULATION_NAME}.c <creator == &bfd_elf64_alpha_vec + || link_info.hash->creator == &bfd_elf64_alpha_freebsd_vec) + { + unsigned int num_plt; + lang_output_section_statement_type *os; + lang_output_section_statement_type *plt_os[2]; + + num_plt = 0; + for (os = &lang_output_section_statement.head->output_section_statement; + os != NULL; + os = os->next) + { + if (os->constraint == SPECIAL && strcmp (os->name, ".plt") == 0) + { + if (num_plt < 2) + plt_os[num_plt] = os; + ++num_plt; + } + } + + if (num_plt == 2) + { + plt_os[0]->constraint = elf64_alpha_use_secureplt ? 0 : -1; + plt_os[1]->constraint = elf64_alpha_use_secureplt ? -1 : 0; + } + } + + gld${EMULATION_NAME}_after_open (); +} + static void alpha_after_parse (void) { - if (elf64alpha_32bit && !link_info.shared && !link_info.relocatable) + if (limit_32bit && !link_info.shared && !link_info.relocatable) lang_section_start (".interp", exp_binop ('+', exp_intop (ALPHA_TEXT_START_32BIT), @@ -43,10 +82,21 @@ alpha_after_parse (void) NULL); } +static void +alpha_before_allocation (void) +{ + /* Call main function; we're just extending it. */ + gld${EMULATION_NAME}_before_allocation (); + + /* Add -relax if -O, not -r, and not explicitly disabled. */ + if (link_info.optimize && !link_info.relocatable && !disable_relaxation) + command_line.relax = TRUE; +} + static void alpha_finish (void) { - if (elf64alpha_32bit) + if (limit_32bit) elf_elfheader (output_bfd)->e_flags |= EF_ALPHA_32BIT; gld${EMULATION_NAME}_finish (); @@ -57,25 +107,47 @@ EOF # parse_args and list_options functions. # PARSE_AND_LIST_PROLOGUE=' -#define OPTION_TASO 300 +#define OPTION_TASO 300 +#define OPTION_NO_RELAX (OPTION_TASO + 1) +#define OPTION_SECUREPLT (OPTION_NO_RELAX + 1) +#define OPTION_NO_SECUREPLT (OPTION_SECUREPLT + 1) ' PARSE_AND_LIST_LONGOPTS=' - {"taso", no_argument, NULL, OPTION_TASO}, + { "taso", no_argument, NULL, OPTION_TASO }, + { "no-relax", no_argument, NULL, OPTION_NO_RELAX }, + { "secureplt", no_argument, NULL, OPTION_SECUREPLT }, + { "no-secureplt", no_argument, NULL, OPTION_NO_SECUREPLT }, ' PARSE_AND_LIST_OPTIONS=' - fprintf (file, _(" -taso\t\t\tLoad executable in the lower 31-bit addressable\n")); - fprintf (file, _("\t\t\t virtual address range\n")); + fprintf (file, _("\ + --taso Load executable in the lower 31-bit addressable\n\ + virtual address range.\n\ + --no-relax Do not relax call and gp sequences.\n\ + --secureplt Force PLT in text segment.\n\ + --no-secureplt Force PLT in data segment.\n\ +")); ' PARSE_AND_LIST_ARGS_CASES=' case OPTION_TASO: - elf64alpha_32bit = 1; + limit_32bit = 1; + break; + case OPTION_NO_RELAX: + disable_relaxation = TRUE; + break; + case OPTION_SECUREPLT: + elf64_alpha_use_secureplt = TRUE; + break; + case OPTION_NO_SECUREPLT: + elf64_alpha_use_secureplt = FALSE; break; ' # Put these extra alpha routines in ld_${EMULATION_NAME}_emulation # +LDEMUL_AFTER_OPEN=alpha_after_open LDEMUL_AFTER_PARSE=alpha_after_parse +LDEMUL_BEFORE_ALLOCATION=alpha_before_allocation LDEMUL_FINISH=alpha_finish diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc index 3e0f0b05dd8..e7702a31e5d 100644 --- a/ld/scripttempl/elf.sc +++ b/ld/scripttempl/elf.sc @@ -104,6 +104,7 @@ INTERP=".interp ${RELOCATING-0} : { *(.interp) }" if test -z "$PLT"; then PLT=".plt ${RELOCATING-0} : { *(.plt) }" fi +test -n "${DATA_PLT-${BSS_PLT-text}}" && TEXT_PLT=yes if test -z "$GOT"; then if test -z "$SEPARATE_GOTPLT"; then GOT=".got ${RELOCATING-0} : { *(.got.plt) *(.got) }" @@ -302,7 +303,7 @@ cat <