2004-08-26 Jeff Baker * bfd/elflink.c (_bfd_elf_add_dynamic_entry): Add code to warn if adding a DT_TEXTREL to a shared object and --warn-shared-textrel was specified. * include/bfdlink.h (bfd_link_info): Add boolean warn_shared_textrel. * ld/lexsup.c: Handle --warn-shared-textrel option. Index: elflink.c =================================================================== RCS file: /cvs/src/src/bfd/elflink.c,v retrieving revision 1.98 diff -w -u -1 -0 -p -r1.98 elflink.c --- elflink.c 21 Aug 2004 01:13:22 -0000 1.98 +++ elflink.c 26 Aug 2004 19:05:05 -0000 @@ -2650,20 +2650,25 @@ _bfd_elf_add_dynamic_entry (struct bfd_l const struct elf_backend_data *bed; asection *s; bfd_size_type newsize; bfd_byte *newcontents; Elf_Internal_Dyn dyn; hash_table = elf_hash_table (info); if (! is_elf_hash_table (hash_table)) return FALSE; + if (info->warn_shared_textrel && info->shared && tag == DT_TEXTREL) { + (*_bfd_error_handler) + (_("warning: creating a DT_TEXTREL in a shared object.")); + } + bed = get_elf_backend_data (hash_table->dynobj); s = bfd_get_section_by_name (hash_table->dynobj, ".dynamic"); BFD_ASSERT (s != NULL); newsize = s->size + bed->s->sizeof_dyn; newcontents = bfd_realloc (s->contents, newsize); if (newcontents == NULL) return FALSE; dyn.d_tag = tag; Index: bfdlink.h =================================================================== RCS file: /cvs/src/src/include/bfdlink.h,v retrieving revision 1.45 diff -w -u -1 -0 -p -r1.45 bfdlink.h --- bfdlink.h 13 Aug 2004 03:16:01 -0000 1.45 +++ bfdlink.h 26 Aug 2004 19:05:31 -0000 @@ -390,20 +390,23 @@ struct bfd_link_info unsigned int spare_dynamic_tags; /* May be used to set DT_FLAGS for ELF. */ bfd_vma flags; /* May be used to set DT_FLAGS_1 for ELF. */ bfd_vma flags_1; /* Start and end of RELRO region. */ bfd_vma relro_start, relro_end; + + /* Warn if adding a DT_TEXTREL to a shared object. */ + bfd_boolean warn_shared_textrel; }; /* This structures holds a set of callback functions. These are called by the BFD linker routines. The first argument to each callback function is the bfd_link_info structure being used. Each function returns a boolean value. If the function returns FALSE, then the BFD function which called it will return with a failure indication. */ struct bfd_link_callbacks Index: lexsup.c =================================================================== RCS file: /cvs/src/src/ld/lexsup.c,v retrieving revision 1.76 diff -w -u -1 -0 -p -r1.76 lexsup.c --- lexsup.c 19 Jul 2004 16:40:52 -0000 1.76 +++ lexsup.c 26 Aug 2004 19:05:45 -0000 @@ -139,21 +139,22 @@ enum option_values OPTION_NOSTDLIB, OPTION_NO_OMAGIC, OPTION_STRIP_DISCARDED, OPTION_NO_STRIP_DISCARDED, OPTION_ACCEPT_UNKNOWN_INPUT_ARCH, OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH, OPTION_PIE, OPTION_UNRESOLVED_SYMBOLS, OPTION_WARN_UNRESOLVED_SYMBOLS, OPTION_ERROR_UNRESOLVED_SYMBOLS, - OPTION_REDUCE_MEMORY_OVERHEADS + OPTION_REDUCE_MEMORY_OVERHEADS, + OPTION_WARN_SHARED_TEXTREL }; /* The long options. This structure is used for both the option parsing and the help text. */ struct ld_option { /* The long option information. */ struct option opt; /* The short option with the same meaning ('\0' if none). */ @@ -489,20 +490,23 @@ static const struct ld_option ld_options "\t\t\t\tfollowing dynamic libs"), TWO_DASHES }, { {"no-add-needed", no_argument, NULL, OPTION_NO_ADD_NEEDED}, '\0', NULL, N_("Do not set DT_NEEDED tags for DT_NEEDED entries\n" "\t\t\t\tin following dynamic libs"), TWO_DASHES }, { {"as-needed", no_argument, NULL, OPTION_AS_NEEDED}, '\0', NULL, N_("Only set DT_NEEDED for following dynamic libs if used"), TWO_DASHES }, { {"no-as-needed", no_argument, NULL, OPTION_NO_AS_NEEDED}, '\0', NULL, N_("Always set DT_NEEDED for following dynamic libs"), TWO_DASHES }, + { {"warn-shared-textrel", no_argument, NULL, OPTION_WARN_SHARED_TEXTREL}, + '\0', NULL, N_("Warn if shared object has DT_TEXTREL"), + TWO_DASHES }, { {"wrap", required_argument, NULL, OPTION_WRAP}, '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES }, }; #define OPTION_COUNT ARRAY_SIZE (ld_options) void parse_args (unsigned argc, char **argv) { unsigned i; @@ -1209,20 +1213,23 @@ parse_args (unsigned argc, char **argv) break; case OPTION_NO_ADD_NEEDED: add_needed = FALSE; break; case OPTION_AS_NEEDED: as_needed = TRUE; break; case OPTION_NO_AS_NEEDED: as_needed = FALSE; break; + case OPTION_WARN_SHARED_TEXTREL: + link_info.warn_shared_textrel = TRUE; + break; case OPTION_WRAP: add_wrap (optarg); break; case OPTION_DISCARD_NONE: link_info.discard = discard_none; break; case 'X': link_info.discard = discard_l; break; case 'x':