diff options
-rw-r--r-- | ld/ChangeLog | 45 | ||||
-rw-r--r-- | ld/emultempl/alphaelf.em | 13 | ||||
-rw-r--r-- | ld/emultempl/avrelf.em | 2 | ||||
-rw-r--r-- | ld/emultempl/cr16elf.em | 29 | ||||
-rw-r--r-- | ld/emultempl/crxelf.em | 29 | ||||
-rw-r--r-- | ld/emultempl/mmix-elfnmmo.em | 2 | ||||
-rw-r--r-- | ld/emultempl/needrelax.em | 2 | ||||
-rw-r--r-- | ld/emultempl/ppc32elf.em | 4 | ||||
-rw-r--r-- | ld/emultempl/sh64elf.em | 9 | ||||
-rw-r--r-- | ld/emultempl/xtensaelf.em | 20 | ||||
-rw-r--r-- | ld/ld.h | 24 | ||||
-rw-r--r-- | ld/ld.texinfo | 24 | ||||
-rw-r--r-- | ld/ldlang.c | 4 | ||||
-rw-r--r-- | ld/ldmain.c | 5 | ||||
-rw-r--r-- | ld/lexsup.c | 10 |
15 files changed, 115 insertions, 107 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog index cd88318..904262f 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,48 @@ +2009-11-26 Nick Clifton <nickc@redhat.com> + + PR ld/10956 + * ld.h (struct args_type): Rename 'relax' field to + 'disable_target_specific_optimizations' and turn it into a + tri-state variable. + (RELAXATION_DISABLED_BY_DEFAULT): New macro. + (RELAXATION_DISABLED_BY_USER): New macro. + (RELAXATION_ENABLED): New macro. + (DISABLE_RELAXATION): New macro. + (ENABLE_RELAXATION): New macro. + * lexsup (enum option_values): Add OPTION_NO_RELAX. + (struct ld_options): Add --no-relax. + (parse_args): Handle OPTION_NO_RELAX. Use DISABLE_RELAXATION and + ENABLE_RELAXATION macros. + * ldlang.c (lang_relax_sections): Use RELAXATION_ENABLED macro. + (lang_process): Likewise. + * ldmain.c (main): Initialise + disable_target_specific_optimizations field. + (multiple_definition): Use RELAXATION_ENABLED macro. + * ld.texinfo: Document new command line option. + * emultempl/alphaelf.em: Remove --no-relax option. + (before_allocation): Test RELAXATION_DISABLED_BY_USER macro. + Use ENABLE_RELAXATION macro. + * emultempl/avrelf.em: (after_allocation): Test RELAXATION_ENABLED + macro. + * emultempl/cr16elf.em: Remove --no-relax option. + (before_allocation): Test RELAXATION_DISABLED_BY_USER macro. + Use ENABLE_RELAXATION macro. + * emultempl/crxelf.em: Remove --no-relax option. + (before_allocation): Test RELAXATION_DISABLED_BY_USER macro. + Use ENABLE_RELAXATION macro. + * emultempl/mmix-elfnmmo.em: (before_allocation): Use + ENABLE_RELAXATION macro. + * emultempl/needrelax.em: (before_allocation): Use + ENABLE_RELAXATION macro. + * emultempl/ppc32elf.em: (before_allocation): Test + RELAXATION_DISABLED_BY_DEFAULT macro. Use + ENABLE_RELAXATION macro. + * emultempl/sh64elf.em: (before_allocation): Test + RELAXATION_ENABLED macro. Use DISABLE_RELAXATION macro. + * emultempl/xtensaelf.em: Remove --no-relax option. + (before_allocation): Test RELAXATION_ENABLED macro. + Use ENABLE_RELAXATION macro. + 2009-11-25 Kai Tietz <kai.tietz@onevision.com> * scripttempl/pe.sc: (.note.GNU-stack): Mark as discardable. diff --git a/ld/emultempl/alphaelf.em b/ld/emultempl/alphaelf.em index 864e699..7b7c8d7 100644 --- a/ld/emultempl/alphaelf.em +++ b/ld/emultempl/alphaelf.em @@ -30,7 +30,6 @@ fragment <<EOF #include "elf-bfd.h" static bfd_boolean limit_32bit; -static bfd_boolean disable_relaxation; extern bfd_boolean elf64_alpha_use_secureplt; @@ -91,8 +90,8 @@ alpha_before_allocation (void) 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; + if (link_info.optimize && !link_info.relocatable && ! RELAXATION_DISABLED_BY_USER) + ENABLE_RELAXATION; } static void @@ -110,14 +109,12 @@ EOF # PARSE_AND_LIST_PROLOGUE=' #define OPTION_TASO 300 -#define OPTION_NO_RELAX (OPTION_TASO + 1) -#define OPTION_SECUREPLT (OPTION_NO_RELAX + 1) +#define OPTION_SECUREPLT (OPTION_TASO + 1) #define OPTION_NO_SECUREPLT (OPTION_SECUREPLT + 1) ' PARSE_AND_LIST_LONGOPTS=' { "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 }, ' @@ -126,7 +123,6 @@ PARSE_AND_LIST_OPTIONS=' 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\ ")); @@ -136,9 +132,6 @@ PARSE_AND_LIST_ARGS_CASES=' case OPTION_TASO: limit_32bit = 1; break; - case OPTION_NO_RELAX: - disable_relaxation = TRUE; - break; case OPTION_SECUREPLT: elf64_alpha_use_secureplt = TRUE; break; diff --git a/ld/emultempl/avrelf.em b/ld/emultempl/avrelf.em index f0807dd..84f1633 100644 --- a/ld/emultempl/avrelf.em +++ b/ld/emultempl/avrelf.em @@ -146,7 +146,7 @@ avr_elf_create_output_section_statements (void) static void avr_elf_after_allocation (void) { - if (!avr_no_stubs && !command_line.relax) + if (!avr_no_stubs && ! RELAXATION_ENABLED) { /* If relaxing, elf32_avr_size_stubs will be called from elf32_avr_relax_section. */ diff --git a/ld/emultempl/cr16elf.em b/ld/emultempl/cr16elf.em index 83f0783..9850bda 100644 --- a/ld/emultempl/cr16elf.em +++ b/ld/emultempl/cr16elf.em @@ -27,9 +27,6 @@ fragment <<EOF #include "ldctor.h" -/* Flag for the emulation-specific "--no-relax" option. */ -static bfd_boolean disable_relaxation = FALSE; - static void check_sections (bfd *, asection *, void *); @@ -173,34 +170,12 @@ cr16elf_before_allocation (void) specified. This is done here instead of in the before_parse hook because there is a check in main() to prohibit use of --relax and -r together. */ - - if (!disable_relaxation) - command_line.relax = TRUE; + if (RELAXATION_DISABLED_BY_DEFAULT) + ENABLE_RELAXATION; } EOF -# Define some shell vars to insert bits of code into the standard elf -# parse_args and list_options functions. -# -PARSE_AND_LIST_PROLOGUE=' -#define OPTION_NO_RELAX 301 -' - -PARSE_AND_LIST_LONGOPTS=' - { "no-relax", no_argument, NULL, OPTION_NO_RELAX}, -' - -PARSE_AND_LIST_OPTIONS=' - fprintf (file, _(" --no-relax Do not relax branches\n")); -' - -PARSE_AND_LIST_ARGS_CASES=' - case OPTION_NO_RELAX: - disable_relaxation = TRUE; - break; -' - # Put these extra cr16-elf routines in ld_${EMULATION_NAME}_emulation # LDEMUL_AFTER_OPEN=cr16_elf_after_open diff --git a/ld/emultempl/crxelf.em b/ld/emultempl/crxelf.em index a257c06..c6d5a8d 100644 --- a/ld/emultempl/crxelf.em +++ b/ld/emultempl/crxelf.em @@ -27,9 +27,6 @@ fragment <<EOF #include "ldctor.h" -/* Flag for the emulation-specific "--no-relax" option. */ -static bfd_boolean disable_relaxation = FALSE; - static void crxelf_after_parse (void); static void @@ -62,34 +59,12 @@ crxelf_before_allocation (void) specified. This is done here instead of in the before_parse hook because there is a check in main() to prohibit use of --relax and -r together. */ - - if (!disable_relaxation) - command_line.relax = TRUE; + if (RELAXATION_DISABLED_BY_DEFAULT) + ENABLE_RELAXATION; } EOF -# Define some shell vars to insert bits of code into the standard elf -# parse_args and list_options functions. -# -PARSE_AND_LIST_PROLOGUE=' -#define OPTION_NO_RELAX 301 -' - -PARSE_AND_LIST_LONGOPTS=' - { "no-relax", no_argument, NULL, OPTION_NO_RELAX}, -' - -PARSE_AND_LIST_OPTIONS=' - fprintf (file, _(" --no-relax Do not relax branches\n")); -' - -PARSE_AND_LIST_ARGS_CASES=' - case OPTION_NO_RELAX: - disable_relaxation = TRUE; - break; -' - # Put these extra crx-elf routines in ld_${EMULATION_NAME}_emulation # LDEMUL_AFTER_PARSE=crxelf_after_parse diff --git a/ld/emultempl/mmix-elfnmmo.em b/ld/emultempl/mmix-elfnmmo.em index 6a7b295..0059792 100644 --- a/ld/emultempl/mmix-elfnmmo.em +++ b/ld/emultempl/mmix-elfnmmo.em @@ -42,7 +42,7 @@ mmix_before_allocation (void) /* Force -relax on (regardless of whether we're doing a relocatable link). */ - command_line.relax = TRUE; + ENABLE_RELAXATION; if (!_bfd_mmix_before_linker_allocation (link_info.output_bfd, &link_info)) einfo ("%X%P: Internal problems setting up section %s", diff --git a/ld/emultempl/needrelax.em b/ld/emultempl/needrelax.em index 4c475db..7f90224 100644 --- a/ld/emultempl/needrelax.em +++ b/ld/emultempl/needrelax.em @@ -34,6 +34,6 @@ need_relax_${EMULATION_NAME}_before_allocation (void) /* Force -relax on if not doing a relocatable link. */ if (! link_info.relocatable) - command_line.relax = TRUE; + ENABLE_RELAXATION; } EOF diff --git a/ld/emultempl/ppc32elf.em b/ld/emultempl/ppc32elf.em index 3befe75..9ff81f5 100644 --- a/ld/emultempl/ppc32elf.em +++ b/ld/emultempl/ppc32elf.em @@ -121,7 +121,7 @@ ppc_before_allocation (void) /* Turn on relaxation if executable sections have addresses that might make branches overflow. */ - if (!command_line.relax) + if (RELAXATION_DISABLED_BY_DEFAULT) { bfd_vma low = (bfd_vma) -1; bfd_vma high = 0; @@ -148,7 +148,7 @@ ppc_before_allocation (void) high = o->vma + o->rawsize - 1; } if (high > low && high - low > (1 << 25) - 1) - command_line.relax = TRUE; + ENABLE_RELAXATION; } } diff --git a/ld/emultempl/sh64elf.em b/ld/emultempl/sh64elf.em index 0c5dc4e..88035b0 100644 --- a/ld/emultempl/sh64elf.em +++ b/ld/emultempl/sh64elf.em @@ -59,7 +59,7 @@ sh64_elf_${EMULATION_NAME}_before_allocation (void) if (cranges != NULL) { - if (command_line.relax) + if (RELAXATION_ENABLED) { /* FIXME: Look through incoming sections with .cranges descriptors, build up some kind of descriptors that the @@ -82,7 +82,7 @@ sh64_elf_${EMULATION_NAME}_before_allocation (void) } } - command_line.relax = FALSE; + DISABLE_RELAXATION; } /* We wouldn't need to do anything when there's already a .cranges @@ -91,13 +91,14 @@ sh64_elf_${EMULATION_NAME}_before_allocation (void) .cranges section. */ } - if (command_line.relax) + if (RELAXATION_ENABLED) { LANG_FOR_EACH_INPUT_STATEMENT (f) { if (bfd_get_flavour (f->the_bfd) == bfd_target_elf_flavour) { asection *isec; + for (isec = f->the_bfd->sections; isec != NULL; isec = isec->next) @@ -107,7 +108,7 @@ sh64_elf_${EMULATION_NAME}_before_allocation (void) { einfo (_("%P: Sorry, turning off relaxing: SHmedia sections present.\n")); einfo (" %I\n", f); - command_line.relax = FALSE; + DISABLE_RELAXATION; goto done_scanning_shmedia_sections; } } diff --git a/ld/emultempl/xtensaelf.em b/ld/emultempl/xtensaelf.em index acc3290..0ae0d1c 100644 --- a/ld/emultempl/xtensaelf.em +++ b/ld/emultempl/xtensaelf.em @@ -42,9 +42,6 @@ static void xtensa_strip_inconsistent_linkonce_sections (lang_statement_list_type *); -/* Flag for the emulation-specific "--no-relax" option. */ -static bfd_boolean disable_relaxation = FALSE; - /* This number is irrelevant until we turn on use_literal_pages */ static bfd_vma xtensa_page_power = 12; /* 4K pages. */ @@ -527,16 +524,16 @@ elf_xtensa_before_allocation (void) specified. This is done here instead of in the before_parse hook because there is a check in main() to prohibit use of --relax and -r together and that combination should be allowed for Xtensa. */ - - if (!disable_relaxation) - command_line.relax = TRUE; + if (RELAXATION_DISABLED_BY_DEFAULT) + ENABLE_RELAXATION; xtensa_strip_inconsistent_linkonce_sections (stat_ptr); gld${EMULATION_NAME}_before_allocation (); xtensa_wild_group_interleave (stat_ptr->head); - if (command_line.relax) + + if (RELAXATION_ENABLED) xtensa_colocate_output_literals (stat_ptr->head); /* TBD: We need to force the page alignments to here and only do @@ -1983,8 +1980,7 @@ EOF # PARSE_AND_LIST_PROLOGUE=' #define OPTION_OPT_SIZEOPT (300) -#define OPTION_NO_RELAX (OPTION_OPT_SIZEOPT + 1) -#define OPTION_LITERAL_MOVEMENT (OPTION_NO_RELAX + 1) +#define OPTION_LITERAL_MOVEMENT (OPTION_OPT_SIZEOPT + 1) #define OPTION_NO_LITERAL_MOVEMENT (OPTION_LITERAL_MOVEMENT + 1) extern int elf32xtensa_size_opt; extern int elf32xtensa_no_literal_movement; @@ -1992,7 +1988,6 @@ extern int elf32xtensa_no_literal_movement; PARSE_AND_LIST_LONGOPTS=' { "size-opt", no_argument, NULL, OPTION_OPT_SIZEOPT}, - { "no-relax", no_argument, NULL, OPTION_NO_RELAX}, { "literal-movement", no_argument, NULL, OPTION_LITERAL_MOVEMENT}, { "no-literal-movement", no_argument, NULL, OPTION_NO_LITERAL_MOVEMENT}, ' @@ -2001,17 +1996,12 @@ PARSE_AND_LIST_OPTIONS=' fprintf (file, _("\ --size-opt When relaxing longcalls, prefer size\n\ optimization over branch target alignment\n")); - fprintf (file, _("\ - --no-relax Do not relax branches or coalesce literals\n")); ' PARSE_AND_LIST_ARGS_CASES=' case OPTION_OPT_SIZEOPT: elf32xtensa_size_opt = 1; break; - case OPTION_NO_RELAX: - disable_relaxation = TRUE; - break; case OPTION_LITERAL_MOVEMENT: elf32xtensa_no_literal_movement = 0; break; @@ -146,7 +146,29 @@ typedef struct { /* 1 => do not assign addresses to common symbols. */ bfd_boolean inhibit_common_definition; - bfd_boolean relax; + + /* Enable or disable target specific optimizations. + + Not all targets have optimizations to enable. + + Normally these optimizations are disabled by default but some targets + prefer to enable them by default. So this field is a tri-state variable. + The values are: + + zero: Enable the optimizations (either from --relax being specified on + the command line or the backend's before_allocation emulation function. + + positive: The user has requested that these optimizations be disabled. + (Via the --no-relax command line option). + + negative: The optimizations are disabled. (Set when initializing the + args_type structure in ldmain.c:main. */ + signed int disable_target_specific_optimizations; +#define RELAXATION_DISABLED_BY_DEFAULT (command_line.disable_target_specific_optimizations < 0) +#define RELAXATION_DISABLED_BY_USER (command_line.disable_target_specific_optimizations > 0) +#define RELAXATION_ENABLED (command_line.disable_target_specific_optimizations == 0) +#define DISABLE_RELAXATION do { command_line.disable_target_specific_optimizations = 1; } while (0) +#define ENABLE_RELAXATION do { command_line.disable_target_specific_optimizations = 0; } while (0) /* If TRUE, build MIPS embedded PIC relocation tables in the output file. */ diff --git a/ld/ld.texinfo b/ld/ld.texinfo index 8ac4c7d..aa9a223 100644 --- a/ld/ld.texinfo +++ b/ld/ld.texinfo @@ -1563,7 +1563,9 @@ This option is ignored for SVR4 compatibility. @kindex --relax @cindex synthesizing linker @cindex relaxing addressing modes +@cindex --no-relax @item --relax +@itemx --no-relax An option with machine dependent effects. @ifset GENERIC This option is only supported on a few targets. @@ -1584,16 +1586,17 @@ This option is only supported on a few targets. @xref{PowerPC ELF32,,@command{ld} and PowerPC 32-bit ELF Support}. @end ifset -On some platforms, the @samp{--relax} option performs global -optimizations that become possible when the linker resolves addressing -in the program, such as relaxing address modes and synthesizing new -instructions in the output object file. +On some platforms the @samp{--relax} option performs target specific, +global optimizations that become possible when the linker resolves +addressing in the program, such as relaxing address modes, +synthesizing new instructions, selecting shorter version of current +instructions, and combinig constant values. On some platforms these link time global optimizations may make symbolic debugging of the resulting executable impossible. @ifset GENERIC -This is known to be -the case for the Matsushita MN10200 and MN10300 family of processors. +This is known to be the case for the Matsushita MN10200 and MN10300 +family of processors. @end ifset @ifset GENERIC @@ -1601,6 +1604,9 @@ On platforms where this is not supported, @samp{--relax} is accepted, but ignored. @end ifset +On platforms where @samp{--relax} is accepted the option +@samp{--no-relax} can be used to disable the feature. + @cindex retaining specified symbols @cindex stripping all but some symbols @cindex symbols, retaining selectively @@ -7146,12 +7152,6 @@ control the linker: @cindex Xtensa options @table @option -@kindex --no-relax -@item --no-relax -Since the Xtensa version of @code{ld} enables the @option{--relax} option -by default, the @option{--no-relax} option is provided to disable -relaxation. - @item --size-opt When optimizing indirect calls to direct calls, optimize for code size more than performance. With this option, the linker will not insert diff --git a/ld/ldlang.c b/ld/ldlang.c index 2d792f8..019fe0e 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -6212,7 +6212,7 @@ lang_find_relro_sections (void) void lang_relax_sections (bfd_boolean need_layout) { - if (command_line.relax) + if (RELAXATION_ENABLED) { /* We may need more than one relaxation pass. */ int i = link_info.relax_pass; @@ -6364,7 +6364,7 @@ lang_process (void) lang_find_relro_sections (); /* Size up the sections. */ - lang_size_sections (NULL, !command_line.relax); + lang_size_sections (NULL, ! RELAXATION_ENABLED); /* See if anything special should be done now we know how big everything is. This is where relaxation is done. */ diff --git a/ld/ldmain.c b/ld/ldmain.c index 3ba0592..e0917f6 100644 --- a/ld/ldmain.c +++ b/ld/ldmain.c @@ -253,6 +253,7 @@ main (int argc, char **argv) command_line.warn_mismatch = TRUE; command_line.warn_search_mismatch = TRUE; command_line.check_section_addresses = -1; + command_line.disable_target_specific_optimizations = -1; /* We initialize DEMANGLING based on the environment variable COLLECT_NO_DEMANGLE. The gcc collect2 program will demangle the @@ -906,10 +907,10 @@ multiple_definition (struct bfd_link_info *info ATTRIBUTE_UNUSED, if (obfd != NULL) einfo (_("%D: first defined here\n"), obfd, osec, oval); - if (command_line.relax) + if (RELAXATION_ENABLED) { einfo (_("%P: Disabling relaxation: it will not work with multiple definitions\n")); - command_line.relax = 0; + command_line.disable_target_specific_optimizations = -1; } return TRUE; diff --git a/ld/lexsup.c b/ld/lexsup.c index 71b426a..20aef7b 100644 --- a/ld/lexsup.c +++ b/ld/lexsup.c @@ -90,6 +90,7 @@ enum option_values OPTION_NO_WHOLE_ARCHIVE, OPTION_OFORMAT, OPTION_RELAX, + OPTION_NO_RELAX, OPTION_RETAIN_SYMBOLS_FILE, OPTION_RPATH, OPTION_RPATH_LINK, @@ -479,7 +480,9 @@ static const struct ld_option ld_options[] = '\0', NULL, N_("Reduce memory overheads, possibly taking much longer"), TWO_DASHES }, { {"relax", no_argument, NULL, OPTION_RELAX}, - '\0', NULL, N_("Relax branches on certain targets"), TWO_DASHES }, + '\0', NULL, N_("Reduce code size by using target specific optimizations"), TWO_DASHES }, + { {"no-relax", no_argument, NULL, OPTION_NO_RELAX}, + '\0', NULL, N_("Do not use relaxation techniques to reduce code size"), TWO_DASHES }, { {"retain-symbols-file", required_argument, NULL, OPTION_RETAIN_SYMBOLS_FILE}, '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES }, @@ -1132,8 +1135,11 @@ parse_args (unsigned argc, char **argv) command_line.rpath_link = buf; } break; + case OPTION_NO_RELAX: + DISABLE_RELAXATION; + break; case OPTION_RELAX: - command_line.relax = TRUE; + ENABLE_RELAXATION; break; case OPTION_RETAIN_SYMBOLS_FILE: add_keepsyms_file (optarg); |