X-Git-Url: https://oss.titaniummirror.com/gitweb?p=msp430-binutils.git;a=blobdiff_plain;f=ld%2Femultempl%2Felf32.em;fp=ld%2Femultempl%2Felf32.em;h=9518714e163b1476b5cad9592148a537c2ea977a;hp=d60d4ddeec7e0d3bfe6a36900e49ac1b987f8002;hb=d5da4f291af551c0b8b79e1d4a9b173d60e5c10e;hpb=7b5ea4fcdf2819e070665ab5610f8b48e3867c10 diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em index d60d4dd..9518714 100644 --- a/ld/emultempl/elf32.em +++ b/ld/emultempl/elf32.em @@ -13,7 +13,8 @@ fragment < ELF support by Ian Lance Taylor @@ -62,9 +63,9 @@ fragment <as_needed) - class = DYN_AS_NEEDED; + link_class = DYN_AS_NEEDED; /* Tell the ELF linker that we don't want the output file to have a DT_NEEDED entry for any dynamic library in DT_NEEDED tags from this file at all. */ if (!entry->add_needed) - class |= DYN_NO_ADD_NEEDED; + link_class |= DYN_NO_ADD_NEEDED; if (entry->just_syms_flag && (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) != 0) einfo (_("%P%F: --just-symbols may not be used on DSO: %B\n"), entry->the_bfd); - if (!class + if (!link_class || (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) == 0) return FALSE; - bfd_elf_set_dyn_lib_class (entry->the_bfd, class); + bfd_elf_set_dyn_lib_class (entry->the_bfd, + (enum dynamic_lib_link_class) link_class); /* Continue on with normal load_symbols processing. */ return FALSE; @@ -305,9 +307,9 @@ gld${EMULATION_NAME}_try_needed (struct dt_needed *needed, bfd *abfd; const char *name = needed->name; const char *soname; - int class; + int link_class; - abfd = bfd_openr (name, bfd_get_target (output_bfd)); + abfd = bfd_openr (name, bfd_get_target (link_info.output_bfd)); if (abfd == NULL) return FALSE; if (! bfd_check_format (abfd, bfd_object)) @@ -322,7 +324,7 @@ gld${EMULATION_NAME}_try_needed (struct dt_needed *needed, } /* For DT_NEEDED, they have to match. */ - if (abfd->xvec != output_bfd->xvec) + if (abfd->xvec != link_info.output_bfd->xvec) { bfd_close (abfd); return FALSE; @@ -418,16 +420,16 @@ fragment <by != NULL && (bfd_elf_get_dyn_lib_class (needed->by) & DYN_NO_ADD_NEEDED) != 0) - class |= DYN_NO_NEEDED | DYN_NO_ADD_NEEDED; + link_class |= DYN_NO_NEEDED | DYN_NO_ADD_NEEDED; - bfd_elf_set_dyn_lib_class (abfd, class); + bfd_elf_set_dyn_lib_class (abfd, (enum dynamic_lib_link_class) link_class); /* Add this file into the symbol table. */ if (! bfd_link_add_symbols (abfd, &link_info)) @@ -556,7 +558,7 @@ gld${EMULATION_NAME}_check_ld_elf_hints (const char *name, int force) FILE *f; char *tmppath; - tmppath = concat (ld_sysroot, _PATH_ELF_HINTS, NULL); + tmppath = concat (ld_sysroot, _PATH_ELF_HINTS, (const char *) NULL); f = fopen (tmppath, FOPEN_RB); free (tmppath); if (f != NULL) @@ -776,11 +778,13 @@ gld${EMULATION_NAME}_check_ld_so_conf (const char *name, int force) info.path = NULL; info.len = info.alloc = 0; - tmppath = concat (ld_sysroot, "${prefix}/etc/ld.so.conf", NULL); + tmppath = concat (ld_sysroot, "${prefix}/etc/ld.so.conf", + (const char *) NULL); if (!gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath)) { free (tmppath); - tmppath = concat (ld_sysroot, "/etc/ld.so.conf", NULL); + tmppath = concat (ld_sysroot, "/etc/ld.so.conf", + (const char *) NULL); gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath); } free (tmppath); @@ -927,7 +931,7 @@ static bfd_boolean gld${EMULATION_NAME}_write_build_id_section (bfd *abfd) { const struct elf_backend_data *bed = get_elf_backend_data (abfd); - struct build_id_info *info = + struct build_id_info *info = (struct build_id_info *) elf_tdata (abfd)->after_write_object_contents_info; asection *asec; Elf_Internal_Shdr *i_shdr; @@ -936,23 +940,24 @@ gld${EMULATION_NAME}_write_build_id_section (bfd *abfd) Elf_External_Note *e_note; asec = info->sec; - if (asec->output_section == NULL) + if (bfd_is_abs_section (asec->output_section)) { - einfo (_("%P: .note.gnu.build-id section missing")); - return FALSE; + einfo (_("%P: warning: .note.gnu.build-id section discarded," + " --build-id ignored.\n")); + return TRUE; } i_shdr = &elf_section_data (asec->output_section)->this_hdr; if (i_shdr->contents == NULL) { if (asec->contents == NULL) - asec->contents = xmalloc (asec->size); + asec->contents = (unsigned char *) xmalloc (asec->size); contents = asec->contents; } else contents = i_shdr->contents + asec->output_offset; - e_note = (void *) contents; + e_note = (Elf_External_Note *) contents; size = offsetof (Elf_External_Note, name[sizeof "GNU"]); size = (size + 3) & -(bfd_size_type) 4; id_bits = contents + size; @@ -1046,37 +1051,49 @@ gld${EMULATION_NAME}_after_open (void) abfd = link_info.input_bfds; - size = gld${EMULATION_NAME}_id_note_section_size (abfd, &link_info); - if (size == 0) + if (abfd == NULL) { - einfo ("%P: warning: unrecognized --build-id style ignored.\n"); + /* PR 10555: If there are no input files do not + try to create a .note.gnu-build-id section. */ free (link_info.emit_note_gnu_build_id); link_info.emit_note_gnu_build_id = NULL; } else { - s = bfd_make_section_with_flags (abfd, ".note.gnu.build-id", - SEC_ALLOC | SEC_LOAD - | SEC_IN_MEMORY | SEC_LINKER_CREATED - | SEC_READONLY | SEC_DATA); - if (s != NULL && bfd_set_section_alignment (abfd, s, 2)) + size = gld${EMULATION_NAME}_id_note_section_size (abfd, &link_info); + if (size == 0) { - struct elf_obj_tdata *t = elf_tdata (output_bfd); - struct build_id_info *b = xmalloc (sizeof *b); - b->style = link_info.emit_note_gnu_build_id; - b->sec = s; - elf_section_type (s) = SHT_NOTE; - s->size = size; - t->after_write_object_contents - = &gld${EMULATION_NAME}_write_build_id_section; - t->after_write_object_contents_info = b; + einfo ("%P: warning: unrecognized --build-id style ignored.\n"); + free (link_info.emit_note_gnu_build_id); + link_info.emit_note_gnu_build_id = NULL; } else { - einfo ("%P: warning: Cannot create .note.gnu.build-id section," - " --build-id ignored.\n"); - free (link_info.emit_note_gnu_build_id); - link_info.emit_note_gnu_build_id = NULL; + s = bfd_make_section_with_flags (abfd, ".note.gnu.build-id", + SEC_ALLOC | SEC_LOAD + | SEC_IN_MEMORY | SEC_LINKER_CREATED + | SEC_READONLY | SEC_DATA); + if (s != NULL && bfd_set_section_alignment (abfd, s, 2)) + { + struct elf_obj_tdata *t = elf_tdata (link_info.output_bfd); + struct build_id_info *b = + (struct build_id_info *) xmalloc (sizeof *b); + + b->style = link_info.emit_note_gnu_build_id; + b->sec = s; + elf_section_type (s) = SHT_NOTE; + s->size = size; + t->after_write_object_contents + = &gld${EMULATION_NAME}_write_build_id_section; + t->after_write_object_contents_info = b; + } + else + { + einfo ("%P: warning: Cannot create .note.gnu.build-id section," + " --build-id ignored.\n"); + free (link_info.emit_note_gnu_build_id); + link_info.emit_note_gnu_build_id = NULL; + } } } } @@ -1124,7 +1141,7 @@ gld${EMULATION_NAME}_after_open (void) loop. */ if (!link_info.executable) return; - needed = bfd_elf_get_needed_list (output_bfd, &link_info); + needed = bfd_elf_get_needed_list (link_info.output_bfd, &link_info); for (l = needed; l != NULL; l = l->next) { struct bfd_link_needed_list *ll; @@ -1228,7 +1245,7 @@ fi if [ "x${USE_LIBPATH}" = xyes ] ; then fragment <next) { char *tmpname = gld${EMULATION_NAME}_add_sysroot (rp->name); @@ -1319,7 +1336,8 @@ gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp) will do no harm. */ if (strcmp (exp->assign.dst, ".") != 0) { - if (!bfd_elf_record_link_assignment (output_bfd, &link_info, + if (!bfd_elf_record_link_assignment (link_info.output_bfd, + &link_info, exp->assign.dst, provide, exp->assign.hidden)) einfo ("%P%F: failed to record assignment to %s: %E\n", @@ -1388,7 +1406,7 @@ gld${EMULATION_NAME}_before_allocation (void) asection *sinterp; if (link_info.hash->type == bfd_link_elf_hash_table) - _bfd_elf_tls_setup (output_bfd, &link_info); + _bfd_elf_tls_setup (link_info.output_bfd, &link_info); /* If we are going to make any variable assignments, we need to let the ELF backend know about them in case the variables are @@ -1401,7 +1419,7 @@ gld${EMULATION_NAME}_before_allocation (void) if (rpath == NULL) rpath = (const char *) getenv ("LD_RUN_PATH"); if (! (bfd_elf_size_dynamic_sections - (output_bfd, command_line.soname, rpath, + (link_info.output_bfd, command_line.soname, rpath, command_line.filter_shlib, (const char * const *) command_line.auxiliary_filters, &link_info, &sinterp, lang_elf_version_info))) @@ -1437,7 +1455,7 @@ ${ELF_INTERPRETER_SET_DEFAULT} continue; sz = s->size; - msg = xmalloc ((size_t) (sz + 1)); + msg = (char *) xmalloc ((size_t) (sz + 1)); if (! bfd_get_section_contents (is->the_bfd, s, msg, (file_ptr) 0, sz)) einfo ("%F%B: Can't read contents of section .gnu.warning: %E\n", @@ -1469,7 +1487,7 @@ ${ELF_INTERPRETER_SET_DEFAULT} before_allocation_default (); - if (!bfd_elf_size_dynsym_hash_dynstr (output_bfd, &link_info)) + if (!bfd_elf_size_dynsym_hash_dynstr (link_info.output_bfd, &link_info)) einfo ("%P%F: failed to set dynamic section sizes: %E\n"); } @@ -1512,8 +1530,9 @@ gld${EMULATION_NAME}_open_dynamic_archive /* Try the .so extension first. If that fails build a new filename using EXTRA_SHLIB_EXTENSION. */ if (! ldfile_try_open_bfd (string, entry)) - sprintf (string, "%s/lib%s%s%s", search->name, - filename, arch, EXTRA_SHLIB_EXTENSION); + { + sprintf (string, "%s/lib%s%s%s", search->name, + filename, arch, EXTRA_SHLIB_EXTENSION); #endif if (! ldfile_try_open_bfd (string, entry)) @@ -1521,6 +1540,9 @@ gld${EMULATION_NAME}_open_dynamic_archive free (string); return FALSE; } +#ifdef EXTRA_SHLIB_EXTENSION + } +#endif entry->filename = string; @@ -1575,7 +1597,7 @@ output_rel_find (asection *sec, int isdyn) lookup != NULL; lookup = lookup->next) { - if (lookup->constraint != -1 + if (lookup->constraint >= 0 && CONST_STRNEQ (lookup->name, ".rel")) { int lookrela = lookup->name[4] == 'a'; @@ -1626,8 +1648,10 @@ output_rel_find (asection *sec, int isdyn) /* Place an orphan section. We use this to put random SHF_ALLOC sections in the right segment. */ -static bfd_boolean -gld${EMULATION_NAME}_place_orphan (asection *s) +static lang_output_section_statement_type * +gld${EMULATION_NAME}_place_orphan (asection *s, + const char *secname, + int constraint) { static struct orphan_save hold[] = { @@ -1651,7 +1675,10 @@ gld${EMULATION_NAME}_place_orphan (asection *s) 0, 0, 0, 0 }, { ".sdata", SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_SMALL_DATA, - 0, 0, 0, 0 } + 0, 0, 0, 0 }, + { 0, + SEC_HAS_CONTENTS, + 0, 0, 0, 0 }, }; enum orphan_save_index { @@ -1661,19 +1688,17 @@ gld${EMULATION_NAME}_place_orphan (asection *s) orphan_bss, orphan_rel, orphan_interp, - orphan_sdata + orphan_sdata, + orphan_nonalloc }; static int orphan_init_done = 0; struct orphan_save *place; - const char *secname; lang_output_section_statement_type *after; lang_output_section_statement_type *os; int isdyn = 0; int iself = s->owner->xvec->flavour == bfd_target_elf_flavour; unsigned int sh_type = iself ? elf_section_type (s) : SHT_NULL; - secname = bfd_get_section_name (s->owner, s); - if (! link_info.relocatable && link_info.combreloc && (s->flags & SEC_ALLOC)) @@ -1699,33 +1724,39 @@ gld${EMULATION_NAME}_place_orphan (asection *s) } } - if (isdyn || (!config.unique_orphan_sections && !unique_section_p (s))) - { - /* Look through the script to see where to place this section. */ - os = lang_output_section_find (secname); - - if (os != NULL - && (os->bfd_section == NULL - || os->bfd_section->flags == 0 - || (_bfd_elf_match_sections_by_type (output_bfd, - os->bfd_section, - s->owner, s) - && ((s->flags ^ os->bfd_section->flags) - & (SEC_LOAD | SEC_ALLOC)) == 0))) - { - /* We already have an output section statement with this - name, and its bfd section, if any, has compatible flags. - If the section already exists but does not have any flags - set, then it has been created by the linker, probably as a - result of a --section-start command line switch. */ - lang_add_section (&os->children, s, os); - return TRUE; - } - } + /* Look through the script to see where to place this section. */ + if (constraint == 0) + for (os = lang_output_section_find (secname); + os != NULL; + os = next_matching_output_section_statement (os, 0)) + { + /* If we don't match an existing output section, tell + lang_insert_orphan to create a new output section. */ + constraint = SPECIAL; + + if (os->bfd_section != NULL + && (os->bfd_section->flags == 0 + || (_bfd_elf_match_sections_by_type (link_info.output_bfd, + os->bfd_section, + s->owner, s) + && ((s->flags ^ os->bfd_section->flags) + & (SEC_LOAD | SEC_ALLOC)) == 0))) + { + /* We already have an output section statement with this + name, and its bfd section has compatible flags. + If the section already exists but does not have any flags + set, then it has been created by the linker, probably as a + result of a --section-start command line switch. */ + lang_add_section (&os->children, s, os); + return os; + } + } if (!orphan_init_done) { + lang_output_section_statement_type *lookup; struct orphan_save *ho; + for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho) if (ho->name != NULL) { @@ -1733,6 +1764,16 @@ gld${EMULATION_NAME}_place_orphan (asection *s) if (ho->os != NULL && ho->os->flags == 0) ho->os->flags = ho->flags; } + lookup = hold[orphan_bss].os; + if (lookup == NULL) + lookup = &lang_output_section_statement.head->output_section_statement; + for (; lookup != NULL; lookup = lookup->next) + if ((lookup->bfd_section != NULL + && (lookup->bfd_section->flags & SEC_DEBUGGING) != 0) + || strcmp (lookup->name, ".comment") == 0) + break; + hold[orphan_nonalloc].os = lookup ? lookup->prev : NULL; + hold[orphan_nonalloc].name = ".comment"; orphan_init_done = 1; } @@ -1740,12 +1781,12 @@ gld${EMULATION_NAME}_place_orphan (asection *s) sections into the .text section to get them out of the way. */ if (link_info.executable && ! link_info.relocatable - && CONST_STRNEQ (secname, ".gnu.warning.") + && CONST_STRNEQ (s->name, ".gnu.warning.") && hold[orphan_text].os != NULL) { - lang_add_section (&hold[orphan_text].os->children, s, - hold[orphan_text].os); - return TRUE; + os = hold[orphan_text].os; + lang_add_section (&os->children, s, os); + return os; } /* Decide which segment the section should go in based on the @@ -1755,7 +1796,9 @@ gld${EMULATION_NAME}_place_orphan (asection *s) in the first page. */ place = NULL; - if ((s->flags & SEC_ALLOC) == 0) + if ((s->flags & (SEC_ALLOC | SEC_DEBUGGING)) == 0) + place = &hold[orphan_nonalloc]; + else if ((s->flags & SEC_ALLOC) == 0) ; else if ((s->flags & SEC_LOAD) != 0 && ((iself && sh_type == SHT_NOTE) @@ -1795,34 +1838,20 @@ gld${EMULATION_NAME}_place_orphan (asection *s) after = &lang_output_section_statement.head->output_section_statement; } - /* Choose a unique name for the section. This will be needed if the - same section name appears in the input file with different - loadable or allocatable characteristics. */ - if (bfd_get_section_by_name (output_bfd, secname) != NULL) - { - static int count = 1; - secname = bfd_get_unique_section_name (output_bfd, secname, &count); - if (secname == NULL) - einfo ("%F%P: place_orphan failed: %E\n"); - } - - lang_insert_orphan (s, secname, after, place, NULL, NULL); - - return TRUE; + return lang_insert_orphan (s, secname, constraint, after, place, NULL, NULL); } EOF fi -if test x"$LDEMUL_FINISH" != xgld"$EMULATION_NAME"_finish; then +if test x"$LDEMUL_AFTER_ALLOCATION" != xgld"$EMULATION_NAME"_after_allocation; then fragment <> e${EMULATION_NAME}.c echo ' && link_info.relro' >> e${EMULATION_NAME}.c -echo ' && (link_info.flags & DT_BIND_NOW)) return' >> e${EMULATION_NAME}.c +echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xdw >> e${EMULATION_NAME}.c echo ' ; else if (link_info.pie && link_info.combreloc) return' >> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c @@ -1873,7 +1902,7 @@ if test -n "$GENERATE_SHLIB_SCRIPT" ; then if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then echo ' ; else if (link_info.shared && link_info.combreloc' >> e${EMULATION_NAME}.c echo ' && link_info.relro' >> e${EMULATION_NAME}.c -echo ' && (link_info.flags & DT_BIND_NOW)) return' >> e${EMULATION_NAME}.c +echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xsw >> e${EMULATION_NAME}.c echo ' ; else if (link_info.shared && link_info.combreloc) return' >> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c @@ -1883,7 +1912,7 @@ sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c fi if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then echo ' ; else if (link_info.combreloc && link_info.relro' >> e${EMULATION_NAME}.c -echo ' && (link_info.flags & DT_BIND_NOW)) return' >> e${EMULATION_NAME}.c +echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xw >> e${EMULATION_NAME}.c echo ' ; else if (link_info.combreloc) return' >> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xc >> e${EMULATION_NAME}.c @@ -1917,7 +1946,7 @@ if test -n "$GENERATE_PIE_SCRIPT" ; then if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then fragment <