mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-22 19:09:31 +08:00
ld: Add --warn-textrel and obsolete --warn-shared-textrel
--warn-shared-textrel and -z text apply to both shared object and PIE. Add --warn-textrel and obsolete --warn-shared-textrel. Consolidate --warn-textrel and -z text/notext/textoff implementation. bfd/ PR ld/22909 * elflink.c (bfd_elf_final_link): Use bfd_link_textrel_check. Check bfd_link_dll when issue a DT_TEXTREL warning. * elfxx-x86.c (maybe_set_textrel): Likewise. (_bfd_x86_elf_size_dynamic_sections): Likewise. include/ PR ld/22909 * bfdlink.h (textrel_check_method): New enum. (bfd_link_textrel_check): New. (bfd_link_info): Replace warn_shared_textrel and error_textrel with textrel_check. ld/ PR ld/22909 * NEWS: Mention --warn-textrel. * ld.texi: Update -z text/notext/textoff. Add --warn-textrel. Remove --warn-shared-textrel. * ldlex.h (option_values): Rename OPTION_WARN_SHARED_TEXTREL to OPTION_WARN_TEXTREL. * lexsup.c (ld_options): Add --warn-textrel. Obsolete --warn-shared-textrel. (parse_args): Updated. (elf_shlib_list_options): Check link_info.textrel_check. * emultempl/elf.em: Updated. * testsuite/ld-elf/pr19539.d: Replace -z notext with --warn-textrel. Expect a warning. * testsuite/ld-i386/warn1.d: Update expected warning.
This commit is contained in:
@ -1,3 +1,11 @@
|
|||||||
|
2020-05-27 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
|
PR ld/22909
|
||||||
|
* elflink.c (bfd_elf_final_link): Use bfd_link_textrel_check.
|
||||||
|
Check bfd_link_dll when issue a DT_TEXTREL warning.
|
||||||
|
* elfxx-x86.c (maybe_set_textrel): Likewise.
|
||||||
|
(_bfd_x86_elf_size_dynamic_sections): Likewise.
|
||||||
|
|
||||||
2020-05-26 Nick Clifton <nickc@redhat.com>
|
2020-05-26 Nick Clifton <nickc@redhat.com>
|
||||||
|
|
||||||
* plugin.c (try_load_plugin): Extend error message when a plugin
|
* plugin.c (try_load_plugin): Extend error message when a plugin
|
||||||
|
@ -12896,8 +12896,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
|
|||||||
goto error_return;
|
goto error_return;
|
||||||
|
|
||||||
/* Check for DT_TEXTREL (late, in case the backend removes it). */
|
/* Check for DT_TEXTREL (late, in case the backend removes it). */
|
||||||
if (((info->warn_shared_textrel && bfd_link_pic (info))
|
if (bfd_link_textrel_check (info)
|
||||||
|| info->error_textrel)
|
|
||||||
&& (o = bfd_get_linker_section (dynobj, ".dynamic")) != NULL)
|
&& (o = bfd_get_linker_section (dynobj, ".dynamic")) != NULL)
|
||||||
{
|
{
|
||||||
bfd_byte *dyncon, *dynconend;
|
bfd_byte *dyncon, *dynconend;
|
||||||
@ -12912,12 +12911,15 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
|
|||||||
|
|
||||||
if (dyn.d_tag == DT_TEXTREL)
|
if (dyn.d_tag == DT_TEXTREL)
|
||||||
{
|
{
|
||||||
if (info->error_textrel)
|
if (info->textrel_check == textrel_check_error)
|
||||||
info->callbacks->einfo
|
info->callbacks->einfo
|
||||||
(_("%P%X: read-only segment has dynamic relocations\n"));
|
(_("%P%X: read-only segment has dynamic relocations\n"));
|
||||||
|
else if (bfd_link_dll (info))
|
||||||
|
info->callbacks->einfo
|
||||||
|
(_("%P: warning: creating DT_TEXTREL in a shared object\n"));
|
||||||
else
|
else
|
||||||
info->callbacks->einfo
|
info->callbacks->einfo
|
||||||
(_("%P: warning: creating a DT_TEXTREL in a shared object\n"));
|
(_("%P: warning: creating DT_TEXTREL in a PIE\n"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -575,8 +575,7 @@ maybe_set_textrel (struct elf_link_hash_entry *h, void *inf)
|
|||||||
"in read-only section `%pA'\n"),
|
"in read-only section `%pA'\n"),
|
||||||
sec->owner, h->root.root.string, sec);
|
sec->owner, h->root.root.string, sec);
|
||||||
|
|
||||||
if ((info->warn_shared_textrel && bfd_link_pic (info))
|
if (bfd_link_textrel_check (info))
|
||||||
|| info->error_textrel)
|
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
info->callbacks->einfo (_("%P: %pB: warning: relocation against `%s' "
|
info->callbacks->einfo (_("%P: %pB: warning: relocation against `%s' "
|
||||||
"in read-only section `%pA'\n"),
|
"in read-only section `%pA'\n"),
|
||||||
@ -1117,8 +1116,7 @@ _bfd_x86_elf_size_dynamic_sections (bfd *output_bfd,
|
|||||||
&& (info->flags & DF_TEXTREL) == 0)
|
&& (info->flags & DF_TEXTREL) == 0)
|
||||||
{
|
{
|
||||||
info->flags |= DF_TEXTREL;
|
info->flags |= DF_TEXTREL;
|
||||||
if ((info->warn_shared_textrel && bfd_link_pic (info))
|
if (bfd_link_textrel_check (info))
|
||||||
|| info->error_textrel)
|
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
info->callbacks->einfo
|
info->callbacks->einfo
|
||||||
(_("%P: %pB: warning: relocation "
|
(_("%P: %pB: warning: relocation "
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
2020-05-27 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
|
PR ld/22909
|
||||||
|
* bfdlink.h (textrel_check_method): New enum.
|
||||||
|
(bfd_link_textrel_check): New.
|
||||||
|
(bfd_link_info): Replace warn_shared_textrel and error_textrel
|
||||||
|
with textrel_check.
|
||||||
|
|
||||||
2020-05-25 H.J. Lu <hongjiu.lu@intel.com>
|
2020-05-25 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
* elf/common.h: Update comments for ET_EXEC and ET_DYN.
|
* elf/common.h: Update comments for ET_EXEC and ET_DYN.
|
||||||
|
@ -273,6 +273,18 @@ enum report_method
|
|||||||
RM_DIAGNOSE,
|
RM_DIAGNOSE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* How to handle DT_TEXTREL. */
|
||||||
|
|
||||||
|
enum textrel_check_method
|
||||||
|
{
|
||||||
|
textrel_check_none,
|
||||||
|
textrel_check_warning,
|
||||||
|
textrel_check_error
|
||||||
|
};
|
||||||
|
|
||||||
|
#define bfd_link_textrel_check(info) \
|
||||||
|
(info->textrel_check != textrel_check_none)
|
||||||
|
|
||||||
typedef enum {with_flags, without_flags} flag_type;
|
typedef enum {with_flags, without_flags} flag_type;
|
||||||
|
|
||||||
/* A section flag list. */
|
/* A section flag list. */
|
||||||
@ -410,11 +422,8 @@ struct bfd_link_info
|
|||||||
should be created. 1 for DWARF2 tables, 2 for compact tables. */
|
should be created. 1 for DWARF2 tables, 2 for compact tables. */
|
||||||
unsigned int eh_frame_hdr_type: 2;
|
unsigned int eh_frame_hdr_type: 2;
|
||||||
|
|
||||||
/* TRUE if we should warn when adding a DT_TEXTREL to a shared object. */
|
/* What to do with DT_TEXTREL in output. */
|
||||||
unsigned int warn_shared_textrel: 1;
|
ENUM_BITFIELD (textrel_check_method) textrel_check: 2;
|
||||||
|
|
||||||
/* TRUE if we should error when adding a DT_TEXTREL. */
|
|
||||||
unsigned int error_textrel: 1;
|
|
||||||
|
|
||||||
/* TRUE if .hash section should be created. */
|
/* TRUE if .hash section should be created. */
|
||||||
unsigned int emit_hash: 1;
|
unsigned int emit_hash: 1;
|
||||||
|
17
ld/ChangeLog
17
ld/ChangeLog
@ -1,3 +1,20 @@
|
|||||||
|
2020-05-27 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
|
PR ld/22909
|
||||||
|
* NEWS: Mention --warn-textrel.
|
||||||
|
* ld.texi: Update -z text/notext/textoff. Add --warn-textrel.
|
||||||
|
Remove --warn-shared-textrel.
|
||||||
|
* ldlex.h (option_values): Rename OPTION_WARN_SHARED_TEXTREL to
|
||||||
|
OPTION_WARN_TEXTREL.
|
||||||
|
* lexsup.c (ld_options): Add --warn-textrel. Obsolete
|
||||||
|
--warn-shared-textrel.
|
||||||
|
(parse_args): Updated.
|
||||||
|
(elf_shlib_list_options): Check link_info.textrel_check.
|
||||||
|
* emultempl/elf.em: Updated.
|
||||||
|
* testsuite/ld-elf/pr19539.d: Replace -z notext with
|
||||||
|
--warn-textrel. Expect a warning.
|
||||||
|
* testsuite/ld-i386/warn1.d: Update expected warning.
|
||||||
|
|
||||||
2020-05-26 H.J. Lu <hongjiu.lu@intel.com>
|
2020-05-26 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
* testsuite/ld-ifunc/ifunc-23a-x86.d: Skip *-*-lynxos *-*-nto*.
|
* testsuite/ld-ifunc/ifunc-23a-x86.d: Skip *-*-lynxos *-*-nto*.
|
||||||
|
3
ld/NEWS
3
ld/NEWS
@ -1,5 +1,8 @@
|
|||||||
-*- text -*-
|
-*- text -*-
|
||||||
|
|
||||||
|
* Add a command-line option for ELF linker, --warn-textrel, to warn that
|
||||||
|
DT_TEXTREL is set in a position-independent executable or shared object.
|
||||||
|
|
||||||
* Add command-line options --enable-non-contiguous-regions and
|
* Add command-line options --enable-non-contiguous-regions and
|
||||||
--enable-non-contiguous-regions-warnings.
|
--enable-non-contiguous-regions-warnings.
|
||||||
|
|
||||||
|
@ -803,11 +803,11 @@ fragment <<EOF
|
|||||||
else if (strcmp (optarg, "nocommon") == 0)
|
else if (strcmp (optarg, "nocommon") == 0)
|
||||||
link_info.elf_stt_common = no_elf_stt_common;
|
link_info.elf_stt_common = no_elf_stt_common;
|
||||||
else if (strcmp (optarg, "text") == 0)
|
else if (strcmp (optarg, "text") == 0)
|
||||||
link_info.error_textrel = TRUE;
|
link_info.textrel_check = textrel_check_error;
|
||||||
else if (strcmp (optarg, "notext") == 0)
|
else if (strcmp (optarg, "notext") == 0)
|
||||||
link_info.error_textrel = FALSE;
|
link_info.textrel_check = textrel_check_none;
|
||||||
else if (strcmp (optarg, "textoff") == 0)
|
else if (strcmp (optarg, "textoff") == 0)
|
||||||
link_info.error_textrel = FALSE;
|
link_info.textrel_check = textrel_check_none;
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
13
ld/ld.texi
13
ld/ld.texi
@ -1358,9 +1358,9 @@ Specifying zero will override any default non-zero sized
|
|||||||
@item text
|
@item text
|
||||||
@itemx notext
|
@itemx notext
|
||||||
@itemx textoff
|
@itemx textoff
|
||||||
Report an error if DT_TEXTREL is set, i.e., if the binary has dynamic
|
Report an error if DT_TEXTREL is set, i.e., if the position-independent
|
||||||
relocations in read-only sections. Don't report an error if
|
or shared object has dynamic relocations in read-only sections. Don't
|
||||||
@samp{notext} or @samp{textoff}.
|
report an error if @samp{notext} or @samp{textoff}.
|
||||||
|
|
||||||
@item undefs
|
@item undefs
|
||||||
Do not report unresolved symbol references from regular object files,
|
Do not report unresolved symbol references from regular object files,
|
||||||
@ -2404,9 +2404,10 @@ The address will only be changed if it not explicitly specified; that
|
|||||||
is, if the @code{SECTIONS} command does not specify a start address for
|
is, if the @code{SECTIONS} command does not specify a start address for
|
||||||
the section (@pxref{SECTIONS}).
|
the section (@pxref{SECTIONS}).
|
||||||
|
|
||||||
@kindex --warn-shared-textrel
|
@kindex --warn-textrel
|
||||||
@item --warn-shared-textrel
|
@item --warn-textrel
|
||||||
Warn if the linker adds a DT_TEXTREL to a shared object.
|
Warn if the linker adds DT_TEXTREL to a position-independent executable
|
||||||
|
or shared object.
|
||||||
|
|
||||||
@kindex --warn-alternate-em
|
@kindex --warn-alternate-em
|
||||||
@item --warn-alternate-em
|
@item --warn-alternate-em
|
||||||
|
@ -130,7 +130,7 @@ enum option_values
|
|||||||
OPTION_UNRESOLVED_SYMBOLS,
|
OPTION_UNRESOLVED_SYMBOLS,
|
||||||
OPTION_WARN_UNRESOLVED_SYMBOLS,
|
OPTION_WARN_UNRESOLVED_SYMBOLS,
|
||||||
OPTION_ERROR_UNRESOLVED_SYMBOLS,
|
OPTION_ERROR_UNRESOLVED_SYMBOLS,
|
||||||
OPTION_WARN_SHARED_TEXTREL,
|
OPTION_WARN_TEXTREL,
|
||||||
OPTION_WARN_ALTERNATE_EM,
|
OPTION_WARN_ALTERNATE_EM,
|
||||||
OPTION_REDUCE_MEMORY_OVERHEADS,
|
OPTION_REDUCE_MEMORY_OVERHEADS,
|
||||||
#ifdef ENABLE_PLUGINS
|
#ifdef ENABLE_PLUGINS
|
||||||
|
30
ld/lexsup.c
30
ld/lexsup.c
@ -516,9 +516,11 @@ static const struct ld_option ld_options[] =
|
|||||||
{ {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN},
|
{ {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN},
|
||||||
'\0', NULL, N_("Warn if start of section changes due to alignment"),
|
'\0', NULL, N_("Warn if start of section changes due to alignment"),
|
||||||
TWO_DASHES },
|
TWO_DASHES },
|
||||||
{ {"warn-shared-textrel", no_argument, NULL, OPTION_WARN_SHARED_TEXTREL},
|
{ {"warn-textrel", no_argument, NULL, OPTION_WARN_TEXTREL},
|
||||||
'\0', NULL, N_("Warn if shared object has DT_TEXTREL"),
|
'\0', NULL, N_("Warn if outpout has DT_TEXTREL"),
|
||||||
TWO_DASHES },
|
TWO_DASHES },
|
||||||
|
{ {"warn-shared-textrel", no_argument, NULL, OPTION_WARN_TEXTREL},
|
||||||
|
'\0', NULL, NULL, NO_HELP },
|
||||||
{ {"warn-alternate-em", no_argument, NULL, OPTION_WARN_ALTERNATE_EM},
|
{ {"warn-alternate-em", no_argument, NULL, OPTION_WARN_ALTERNATE_EM},
|
||||||
'\0', NULL, N_("Warn if an object has alternate ELF machine code"),
|
'\0', NULL, N_("Warn if an object has alternate ELF machine code"),
|
||||||
TWO_DASHES },
|
TWO_DASHES },
|
||||||
@ -1438,8 +1440,8 @@ parse_args (unsigned argc, char **argv)
|
|||||||
case OPTION_WARN_SECTION_ALIGN:
|
case OPTION_WARN_SECTION_ALIGN:
|
||||||
config.warn_section_align = TRUE;
|
config.warn_section_align = TRUE;
|
||||||
break;
|
break;
|
||||||
case OPTION_WARN_SHARED_TEXTREL:
|
case OPTION_WARN_TEXTREL:
|
||||||
link_info.warn_shared_textrel = TRUE;
|
link_info.textrel_check = textrel_check_warning;
|
||||||
break;
|
break;
|
||||||
case OPTION_WARN_ALTERNATE_EM:
|
case OPTION_WARN_ALTERNATE_EM:
|
||||||
link_info.warn_alternate_em = TRUE;
|
link_info.warn_alternate_em = TRUE;
|
||||||
@ -1846,12 +1848,26 @@ elf_shlib_list_options (FILE *file)
|
|||||||
-z nocommon Generate common symbols with STT_OBJECT type\n"));
|
-z nocommon Generate common symbols with STT_OBJECT type\n"));
|
||||||
fprintf (file, _("\
|
fprintf (file, _("\
|
||||||
-z stack-size=SIZE Set size of stack segment\n"));
|
-z stack-size=SIZE Set size of stack segment\n"));
|
||||||
|
if (link_info.textrel_check == textrel_check_error)
|
||||||
fprintf (file, _("\
|
fprintf (file, _("\
|
||||||
-z text Treat DT_TEXTREL in shared object as error\n"));
|
-z text Treat DT_TEXTREL in output as error (default)\n"));
|
||||||
|
else
|
||||||
fprintf (file, _("\
|
fprintf (file, _("\
|
||||||
-z notext Don't treat DT_TEXTREL in shared object as error\n"));
|
-z text Treat DT_TEXTREL in output as error\n"));
|
||||||
|
if (link_info.textrel_check == textrel_check_none)
|
||||||
|
{
|
||||||
fprintf (file, _("\
|
fprintf (file, _("\
|
||||||
-z textoff Don't treat DT_TEXTREL in shared object as error\n"));
|
-z notext Don't treat DT_TEXTREL in output as error (default)\n"));
|
||||||
|
fprintf (file, _("\
|
||||||
|
-z textoff Don't treat DT_TEXTREL in output as error (default)\n"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf (file, _("\
|
||||||
|
-z notext Don't treat DT_TEXTREL in output as error\n"));
|
||||||
|
fprintf (file, _("\
|
||||||
|
-z textoff Don't treat DT_TEXTREL in output as error\n"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#source: start.s
|
#source: start.s
|
||||||
#source: pr19539.s
|
#source: pr19539.s
|
||||||
#ld: -pie -T pr19539.t -z notext
|
#ld: -pie -T pr19539.t --warn-textrel
|
||||||
#readelf : --dyn-syms --wide
|
#readelf : --dyn-syms --wide
|
||||||
|
#warning: .*: creating DT_TEXTREL in a PIE
|
||||||
#target: *-*-linux* *-*-gnu* *-*-solaris* arm*-*-uclinuxfdpiceabi
|
#target: *-*-linux* *-*-gnu* *-*-solaris* arm*-*-uclinuxfdpiceabi
|
||||||
#xfail: cris*-*-* ![check_pie_support]
|
#xfail: cris*-*-* ![check_pie_support]
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#name: --warn-shared-textrel --fatal-warnings
|
#name: --warn-shared-textrel --fatal-warnings
|
||||||
#as: --32
|
#as: --32
|
||||||
#ld: -shared -melf_i386 --warn-shared-textrel --fatal-warnings
|
#ld: -shared -melf_i386 --warn-shared-textrel --fatal-warnings
|
||||||
#error: .*warning: creating a DT_TEXTREL in a shared object
|
#error: .*warning: creating DT_TEXTREL in a shared object
|
||||||
|
Reference in New Issue
Block a user