From: H.J. Lu Date: Wed, 27 May 2020 11:53:54 +0000 (-0700) Subject: ld: Add --warn-textrel and obsolete --warn-shared-textrel X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a6dbf402de65fe66f4ec99b56527dfd00d077cb6;p=binutils-gdb.git 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. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index f165b00515e..0fe164458ed 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,11 @@ +2020-05-27 H.J. Lu + + 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 * plugin.c (try_load_plugin): Extend error message when a plugin diff --git a/bfd/elflink.c b/bfd/elflink.c index c157aea90dc..f87927f0bd8 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -12896,8 +12896,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) goto error_return; /* Check for DT_TEXTREL (late, in case the backend removes it). */ - if (((info->warn_shared_textrel && bfd_link_pic (info)) - || info->error_textrel) + if (bfd_link_textrel_check (info) && (o = bfd_get_linker_section (dynobj, ".dynamic")) != NULL) { 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 (info->error_textrel) + if (info->textrel_check == textrel_check_error) info->callbacks->einfo (_("%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 info->callbacks->einfo - (_("%P: warning: creating a DT_TEXTREL in a shared object\n")); + (_("%P: warning: creating DT_TEXTREL in a PIE\n")); break; } } diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c index 9679dca981e..6cc47afd7ea 100644 --- a/bfd/elfxx-x86.c +++ b/bfd/elfxx-x86.c @@ -575,8 +575,7 @@ maybe_set_textrel (struct elf_link_hash_entry *h, void *inf) "in read-only section `%pA'\n"), sec->owner, h->root.root.string, sec); - if ((info->warn_shared_textrel && bfd_link_pic (info)) - || info->error_textrel) + if (bfd_link_textrel_check (info)) /* xgettext:c-format */ info->callbacks->einfo (_("%P: %pB: warning: relocation against `%s' " "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; - if ((info->warn_shared_textrel && bfd_link_pic (info)) - || info->error_textrel) + if (bfd_link_textrel_check (info)) /* xgettext:c-format */ info->callbacks->einfo (_("%P: %pB: warning: relocation " diff --git a/include/ChangeLog b/include/ChangeLog index 53f50e513f4..7d114012b13 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,11 @@ +2020-05-27 H.J. Lu + + 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 * elf/common.h: Update comments for ET_EXEC and ET_DYN. diff --git a/include/bfdlink.h b/include/bfdlink.h index ec97679e6f1..34a0d2ec4ef 100644 --- a/include/bfdlink.h +++ b/include/bfdlink.h @@ -273,6 +273,18 @@ enum report_method 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; /* A section flag list. */ @@ -410,11 +422,8 @@ struct bfd_link_info should be created. 1 for DWARF2 tables, 2 for compact tables. */ unsigned int eh_frame_hdr_type: 2; - /* TRUE if we should warn when adding a DT_TEXTREL to a shared object. */ - unsigned int warn_shared_textrel: 1; - - /* TRUE if we should error when adding a DT_TEXTREL. */ - unsigned int error_textrel: 1; + /* What to do with DT_TEXTREL in output. */ + ENUM_BITFIELD (textrel_check_method) textrel_check: 2; /* TRUE if .hash section should be created. */ unsigned int emit_hash: 1; diff --git a/ld/ChangeLog b/ld/ChangeLog index f0d6c269d57..3fd9b7457ee 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,20 @@ +2020-05-27 H.J. Lu + + 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 * testsuite/ld-ifunc/ifunc-23a-x86.d: Skip *-*-lynxos *-*-nto*. diff --git a/ld/NEWS b/ld/NEWS index 9f5bbe51cf6..0aaa13d4874 100644 --- a/ld/NEWS +++ b/ld/NEWS @@ -1,5 +1,8 @@ -*- 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 --enable-non-contiguous-regions-warnings. diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em index 4fd6fdffe75..c4979eb9538 100644 --- a/ld/emultempl/elf.em +++ b/ld/emultempl/elf.em @@ -803,11 +803,11 @@ fragment <