X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=ld%2Femultempl%2Felf32.em;h=67e0d250b22a9f162155934c4bf017071451766d;hb=95500e1ca45a2d6bdd31f084a1946c4f777fa89a;hp=e03da1b6159cb44fde71e4f2943c5fc224e547fa;hpb=6d02a66752fabe76bdec0b36f34be7f3c25ac993;p=binutils-gdb.git diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em index e03da1b6159..67e0d250b22 100644 --- a/ld/emultempl/elf32.em +++ b/ld/emultempl/elf32.em @@ -3,11 +3,16 @@ # This file is now misnamed, because it supports both 32 bit and 64 bit # ELF emulations. test -z "${ELFSIZE}" && ELFSIZE=32 +if [ -z "$MACHINE" ]; then + OUTPUT_ARCH=${ARCH} +else + OUTPUT_ARCH=${ARCH}:${MACHINE} +fi cat >e${EMULATION_NAME}.c < ELF support by Ian Lance Taylor @@ -32,6 +37,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "bfd.h" #include "sysdep.h" +#include "libiberty.h" #include @@ -77,7 +83,7 @@ if test -n "$EXTRA_EM_FILE" ; then . ${srcdir}/emultempl/${EXTRA_EM_FILE}.em fi -# Functions in this file can be overriden by setting the LDEMUL_* shell +# Functions in this file can be overridden by setting the LDEMUL_* shell # variables. If the name of the overriding function is the same as is # defined in this file, then don't output this file's version. # If a different overriding name is given then output the standard function @@ -89,7 +95,15 @@ cat >>e${EMULATION_NAME}.c <arch; + ldfile_output_machine = arch->mach; + ldfile_output_machine_name = arch->printable_name; + } + else + ldfile_output_architecture = bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`; config.dynamic_link = ${DYNAMIC_LINK-true}; config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo true ; else echo false ; fi`; } @@ -123,14 +137,14 @@ static boolean global_vercheck_failed; This is called via lang_for_each_input_file. GLOBAL_VERCHECK_NEEDED is the list of objects needed by the object - which we ar checking. This sets GLOBAL_VERCHECK_FAILED if we find + which we are checking. This sets GLOBAL_VERCHECK_FAILED if we find a conflicting version. */ static void gld${EMULATION_NAME}_vercheck (s) lang_input_statement_type *s; { - const char *soname, *f; + const char *soname; struct bfd_link_needed_list *l; if (global_vercheck_failed) @@ -141,19 +155,13 @@ gld${EMULATION_NAME}_vercheck (s) soname = bfd_elf_get_dt_soname (s->the_bfd); if (soname == NULL) - soname = bfd_get_filename (s->the_bfd); - - f = strrchr (soname, '/'); - if (f != NULL) - ++f; - else - f = soname; + soname = basename (bfd_get_filename (s->the_bfd)); for (l = global_vercheck_needed; l != NULL; l = l->next) { const char *suffix; - if (strcmp (f, l->name) == 0) + if (strcmp (soname, l->name) == 0) { /* Probably can't happen, but it's an easy check. */ continue; @@ -168,7 +176,7 @@ gld${EMULATION_NAME}_vercheck (s) suffix += sizeof ".so." - 1; - if (strncmp (f, l->name, suffix - l->name) == 0) + if (strncmp (soname, l->name, suffix - l->name) == 0) { /* Here we know that S is a dynamic object FOO.SO.VER1, and the object we are considering needs a dynamic object @@ -192,7 +200,6 @@ gld${EMULATION_NAME}_stat_needed (s) struct stat st; const char *suffix; const char *soname; - const char *f; if (global_found) return; @@ -216,7 +223,7 @@ gld${EMULATION_NAME}_stat_needed (s) different versions of the same shared library. For example, there may be a problem if -lc picks up libc.so.6 but some other shared library has a DT_NEEDED entry of libc.so.5. This is a - hueristic test, and it will only work if the name looks like + heuristic test, and it will only work if the name looks like NAME.so.VERSION. FIXME: Depending on file names is error-prone. If we really want to issue warnings about mixing version numbers of shared libraries, we need to find a better way. */ @@ -230,17 +237,12 @@ gld${EMULATION_NAME}_stat_needed (s) soname = bfd_elf_get_dt_soname (s->the_bfd); if (soname == NULL) - soname = s->filename; + soname = basename (s->filename); - f = strrchr (soname, '/'); - if (f != NULL) - ++f; - else - f = soname; - - if (strncmp (f, global_needed->name, suffix - global_needed->name) == 0) + if (strncmp (soname, global_needed->name, + suffix - global_needed->name) == 0) einfo ("%P: warning: %s, needed by %B, may conflict with %s\n", - global_needed->name, global_needed->by, f); + global_needed->name, global_needed->by, soname); } @@ -340,11 +342,7 @@ cat >>e${EMULATION_NAME}.c <filename, '/'); - if (soname) - soname++; - else - soname = abfd->filename; + soname = basename (abfd->filename); if (trace_file_tries) info_msg (_("found %s at %s\n"), soname, name); @@ -362,6 +360,9 @@ cat >>e${EMULATION_NAME}.c <filename); + /* Tell the ELF backend that the output file needs a DT_NEEDED entry for this file if it is used to resolve the reference in a regular object. */ @@ -386,6 +387,9 @@ gld${EMULATION_NAME}_search_needed (path, name, force) const char *s; size_t len; + if (name[0] == '/') + return gld${EMULATION_NAME}_try_needed (name, force); + if (path == NULL || *path == '\0') return false; len = strlen (name); @@ -425,11 +429,13 @@ EOF if [ "x${host}" = "x${target}" ] ; then case " ${EMULATION_LIBPATH} " in *" ${EMULATION_NAME} "*) -cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <filename != NULL - && strcmp (s->filename, global_needed->name) == 0) + if (s->filename != NULL) { - global_found = true; - return; + const char *f; + + if (strcmp (s->filename, global_needed->name) == 0) + { + global_found = true; + return; + } + + if (s->search_dirs_flag) + { + f = strrchr (s->filename, '/'); + if (f != NULL + && strcmp (f + 1, global_needed->name) == 0) + { + global_found = true; + return; + } + } } if (s->the_bfd != NULL) @@ -542,21 +565,6 @@ gld${EMULATION_NAME}_check_needed (s) return; } } - - if (s->search_dirs_flag - && s->filename != NULL - && strchr (global_needed->name, '/') == NULL) - { - const char *f; - - f = strrchr (s->filename, '/'); - if (f != NULL - && strcmp (f + 1, global_needed->name) == 0) - { - global_found = true; - return; - } - } } EOF @@ -695,10 +703,15 @@ EOF if [ "x${host}" = "x${target}" ] ; then case " ${EMULATION_LIBPATH} " in *" ${EMULATION_NAME} "*) -cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <name, force)) break; EOF + # Linux + ;; + esac ;; esac fi @@ -792,6 +805,18 @@ gld${EMULATION_NAME}_find_statement_assignment (s) EOF if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then + if test x"${ELF_INTERPRETER_NAME+set}" = xset; then + ELF_INTERPRETER_SET_DEFAULT=" + if (sinterp != NULL) + { + sinterp->contents = ${ELF_INTERPRETER_NAME}; + sinterp->_raw_size = strlen (sinterp->contents) + 1; + } + +" + else + ELF_INTERPRETER_SET_DEFAULT= + fi cat >>e${EMULATION_NAME}.c <the_bfd, bfd_object) && (entry->the_bfd->flags & DYNAMIC) != 0) { - char *needed_name; - ASSERT (entry->is_archive && entry->search_dirs_flag); /* Rather than duplicating the logic above. Just use the - filename we recorded earlier. - - First strip off everything before the last '/'. */ - filename = strrchr (entry->filename, '/'); - filename++; + filename we recorded earlier. */ - needed_name = (char *) xmalloc (strlen (filename) + 1); - strcpy (needed_name, filename); - bfd_elf_set_dt_needed_name (entry->the_bfd, needed_name); + filename = xstrdup (basename (entry->filename)); + bfd_elf_set_dt_needed_name (entry->the_bfd, filename); } return true; @@ -988,6 +1006,35 @@ EOF if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then cat >>e${EMULATION_NAME}.c <next) + { + lookup = &u->output_section_statement; + if (lookup == os) + break; + if (lookup->bfd_section != NULL) + s = lookup->bfd_section; + } + + if (u == NULL) + return NULL; + + return s; +} + + /* Place an orphan section. We use this to put random SHF_ALLOC sections in the right segment. */ @@ -1021,7 +1068,7 @@ gld${EMULATION_NAME}_place_orphan (file, s) secname = bfd_get_section_name (s->owner, s); - if (! config.unique_orphan_sections) + if (! config.unique_orphan_sections && ! unique_section_p (secname)) { /* Look through the script to see where to place this section. */ os = lang_output_section_find (secname); @@ -1066,7 +1113,7 @@ gld${EMULATION_NAME}_place_orphan (file, s) if ((s->flags & SEC_ALLOC) == 0) ; else if ((s->flags & SEC_LOAD) != 0 - && strncmp (secname, ".note", 4) == 0 + && strncmp (secname, ".note", 5) == 0 && HAVE_SECTION (hold_interp, ".interp")) place = &hold_interp; else if ((s->flags & SEC_HAS_CONTENTS) == 0 @@ -1093,7 +1140,7 @@ gld${EMULATION_NAME}_place_orphan (file, s) /* 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 allocateable characteristics. */ + loadable or allocatable characteristics. */ outsecname = secname; if (bfd_get_section_by_name (output_bfd, outsecname) != NULL) { @@ -1174,12 +1221,16 @@ gld${EMULATION_NAME}_place_orphan (file, s) if (place != NULL) { - asection *snew, **pps; + asection *snew, **pps, *bfd_section; snew = os->bfd_section; + bfd_section = place->os->bfd_section; + if (place->section == NULL && bfd_section == NULL) + bfd_section = output_prev_sec_find (place->os); + if (place->section != NULL - || (place->os->bfd_section != NULL - && place->os->bfd_section != snew)) + || (bfd_section != NULL + && bfd_section != snew)) { /* Shuffle the section to make the output file look neater. This is really only cosmetic. */ @@ -1188,15 +1239,15 @@ gld${EMULATION_NAME}_place_orphan (file, s) #if 0 /* Finding the end of the list is a little tricky. We make a wild stab at it by comparing section flags. */ - flagword first_flags = place->os->bfd_section->flags; - for (pps = &place->os->bfd_section->next; + flagword first_flags = bfd_section->flags; + for (pps = &bfd_section->next; *pps != NULL && (*pps)->flags == first_flags; pps = &(*pps)->next) ; place->section = pps; #else /* Put orphans after the first section on the list. */ - place->section = &place->os->bfd_section->next; + place->section = &bfd_section->next; #endif } @@ -1325,6 +1376,7 @@ cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <