+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.
#include "elf-bfd.h"
static bfd_boolean limit_32bit;
-static bfd_boolean disable_relaxation;
extern bfd_boolean elf64_alpha_use_secureplt;
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
#
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 },
'
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\
"));
case OPTION_TASO:
limit_32bit = 1;
break;
- case OPTION_NO_RELAX:
- disable_relaxation = TRUE;
- break;
case OPTION_SECUREPLT:
elf64_alpha_use_secureplt = TRUE;
break;
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. */
#include "ldctor.h"
-/* Flag for the emulation-specific "--no-relax" option. */
-static bfd_boolean disable_relaxation = FALSE;
-
static void check_sections (bfd *, asection *, 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
#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
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
/* 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",
/* Force -relax on if not doing a relocatable link. */
if (! link_info.relocatable)
- command_line.relax = TRUE;
+ ENABLE_RELAXATION;
}
EOF
/* 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;
high = o->vma + o->rawsize - 1;
}
if (high > low && high - low > (1 << 25) - 1)
- command_line.relax = TRUE;
+ ENABLE_RELAXATION;
}
}
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
}
}
- command_line.relax = FALSE;
+ DISABLE_RELAXATION;
}
/* We wouldn't need to do anything when there's already a .cranges
.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)
{
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;
}
}
(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. */
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
#
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;
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},
'
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;
/* 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. */
@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.
@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
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
@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
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;
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. */
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
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;
OPTION_NO_WHOLE_ARCHIVE,
OPTION_OFORMAT,
OPTION_RELAX,
+ OPTION_NO_RELAX,
OPTION_RETAIN_SYMBOLS_FILE,
OPTION_RPATH,
OPTION_RPATH_LINK,
'\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 },
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);