From: Nick Clifton Date: Thu, 26 Nov 2009 13:45:25 +0000 (+0000) Subject: PR ld/10956 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=28d5f6774058f4c7d5141b1dda8b76ee81f8cf4f;p=binutils-gdb.git 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. --- diff --git a/ld/ChangeLog b/ld/ChangeLog index cd88318c5d9..904262fb9f5 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,48 @@ +2009-11-26 Nick Clifton + + 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 * scripttempl/pe.sc: (.note.GNU-stack): Mark as discardable. diff --git a/ld/emultempl/alphaelf.em b/ld/emultempl/alphaelf.em index 864e6998acb..7b7c8d70723 100644 --- a/ld/emultempl/alphaelf.em +++ b/ld/emultempl/alphaelf.em @@ -30,7 +30,6 @@ fragment <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 0c5dc4e9ed0..88035b0dc51 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 acc32909824..0ae0d1c0d70 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; diff --git a/ld/ld.h b/ld/ld.h index 10d2b338273..aa0979d6f27 100644 --- a/ld/ld.h +++ b/ld/ld.h @@ -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 8ac4c7d7d1f..aa9a2239d09 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 2d792f88c72..019fe0ef48f 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 3ba0592b78f..e0917f66858 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 71b426a59f9..20aef7b8cee 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);