diff options
Diffstat (limited to 'contrib/binutils/ld/emultempl/elf32.em')
-rw-r--r-- | contrib/binutils/ld/emultempl/elf32.em | 154 |
1 files changed, 89 insertions, 65 deletions
diff --git a/contrib/binutils/ld/emultempl/elf32.em b/contrib/binutils/ld/emultempl/elf32.em index c4debe2..2913ecf 100644 --- a/contrib/binutils/ld/emultempl/elf32.em +++ b/contrib/binutils/ld/emultempl/elf32.em @@ -7,7 +7,8 @@ cat >e${EMULATION_NAME}.c <<EOF /* This file is is generated by a shell script. DO NOT EDIT! */ /* ${ELFSIZE} bit ELF emulation code for ${EMULATION_NAME} - Copyright (C) 1991, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc. + Copyright (C) 1991, 93, 94, 95, 96, 97, 98, 1999 + Free Software Foundation, Inc. Written by Steve Chamberlain <sac@cygnus.com> ELF support by Ian Lance Taylor <ian@cygnus.com> @@ -73,10 +74,12 @@ gld${EMULATION_NAME}_before_parse() { 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`; } /* Try to open a dynamic archive. This is where we know that ELF - dynamic libraries have an extension of .so. */ + dynamic libraries have an extension of .so (or .sl on oddball systems + like hpux). */ static boolean gld${EMULATION_NAME}_open_dynamic_archive (arch, search, entry) @@ -92,13 +95,27 @@ gld${EMULATION_NAME}_open_dynamic_archive (arch, search, entry) filename = entry->filename; + /* This allocates a few bytes too many when EXTRA_SHLIB_EXTENSION + is defined, but it does not seem worth the headache to optimize + away those two bytes of space. */ string = (char *) xmalloc (strlen (search->name) + strlen (filename) + strlen (arch) +#ifdef EXTRA_SHLIB_EXTENSION + + strlen (EXTRA_SHLIB_EXTENSION) +#endif + sizeof "/lib.so"); sprintf (string, "%s/lib%s%s.so", search->name, filename, arch); +#ifdef EXTRA_SHLIB_EXTENSION + /* 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); +#endif + if (! ldfile_try_open_bfd (string, entry)) { free (string); @@ -126,10 +143,16 @@ gld${EMULATION_NAME}_open_dynamic_archive (arch, search, entry) char *needed_name; ASSERT (entry->is_archive && entry->search_dirs_flag); - needed_name = (char *) xmalloc (strlen (filename) - + strlen (arch) - + sizeof "lib.so"); - sprintf (needed_name, "lib%s%s.so", filename, arch); + + /* 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++; + + needed_name = (char *) xmalloc (strlen (filename) + 1); + strcpy (needed_name, filename); bfd_elf_set_dt_needed_name (entry->the_bfd, needed_name); } @@ -138,7 +161,8 @@ gld${EMULATION_NAME}_open_dynamic_archive (arch, search, entry) EOF if [ "x${host}" = "x${target}" ] ; then - if [ "x${DEFAULT_EMULATION}" = "x${EMULATION_NAME}" ] ; then + case " ${EMULATION_LIBPATH} " in + *" ${EMULATION_NAME} "*) cat >>e${EMULATION_NAME}.c <<EOF /* For a native linker, check the file /etc/ld.so.conf for directories @@ -223,7 +247,8 @@ gld${EMULATION_NAME}_check_ld_so_conf (name, force) } EOF - fi + ;; + esac fi cat >>e${EMULATION_NAME}.c <<EOF @@ -308,13 +333,15 @@ gld${EMULATION_NAME}_after_open () } EOF if [ "x${host}" = "x${target}" ] ; then - if [ "x${DEFAULT_EMULATION}" = "x${EMULATION_NAME}" ] ; then + case " ${EMULATION_LIBPATH} " in + *" ${EMULATION_NAME} "*) cat >>e${EMULATION_NAME}.c <<EOF lib_path = (const char *) getenv ("LD_LIBRARY_PATH"); if (gld${EMULATION_NAME}_search_needed (lib_path, l->name, force)) break; EOF - fi + ;; + esac fi cat >>e${EMULATION_NAME}.c <<EOF len = strlen (l->name); @@ -334,12 +361,14 @@ cat >>e${EMULATION_NAME}.c <<EOF break; EOF if [ "x${host}" = "x${target}" ] ; then - if [ "x${DEFAULT_EMULATION}" = "x${EMULATION_NAME}" ] ; then + case " ${EMULATION_LIBPATH} " in + *" ${EMULATION_NAME} "*) cat >>e${EMULATION_NAME}.c <<EOF if (gld${EMULATION_NAME}_check_ld_so_conf (l->name, force)) break; EOF - fi + ;; + esac fi cat >>e${EMULATION_NAME}.c <<EOF } @@ -761,37 +790,6 @@ gld${EMULATION_NAME}_before_allocation () s->_raw_size = 0; } } - -#if defined (TARGET_IS_elf32bmip) || defined (TARGET_IS_elf32lmip) - /* For MIPS ELF the .reginfo section requires special handling. - Each input section is 24 bytes, and the final output section must - also be 24 bytes. We handle this by clobbering all but the first - input section size to 0. The .reginfo section is handled - specially by the backend code anyhow. */ - { - boolean found = false; - LANG_FOR_EACH_INPUT_STATEMENT (is) - { - asection *s; - - if (is->just_syms_flag) - continue; - - s = bfd_get_section_by_name (is->the_bfd, ".reginfo"); - if (s == NULL) - continue; - - if (! found) - { - found = true; - continue; - } - - s->_raw_size = 0; - s->_cooked_size = 0; - } - } -#endif } /* This is called by the before_allocation routine via @@ -925,7 +923,9 @@ gld${EMULATION_NAME}_place_orphan (file, s) stored right after the program headers where the OS can read it in the first page. */ place = NULL; - if ((s->flags & SEC_LOAD) != 0 + if (s->flags & SEC_EXCLUDE) + return false; + else if ((s->flags & SEC_LOAD) != 0 && strncmp (secname, ".note", 4) == 0 && hold_interp != NULL) place = hold_interp; @@ -1024,7 +1024,8 @@ gld${EMULATION_NAME}_place_orphan (file, s) wild_doit (&os->children, s, os, file); lang_leave_output_section_statement - ((bfd_vma) 0, "*default*", (struct lang_output_section_phdr_list *) NULL); + ((bfd_vma) 0, "*default*", (struct lang_output_section_phdr_list *) NULL, + "*default*"); stat_ptr = &add; if (*ps == '\0' && config.build_constructors) @@ -1090,30 +1091,31 @@ then # Scripts compiled in. # sed commands to quote an ld script as a C string. -sc='s/["\\]/\\&/g -s/$/\\n\\/ -1s/^/"/ -$s/$/n"/ -' +sc="-f stringify.sed" cat >>e${EMULATION_NAME}.c <<EOF { *isfile = 0; if (link_info.relocateable == true && config.build_constructors == true) - return `sed "$sc" ldscripts/${EMULATION_NAME}.xu`; - else if (link_info.relocateable == true) - return `sed "$sc" ldscripts/${EMULATION_NAME}.xr`; - else if (!config.text_read_only) - return `sed "$sc" ldscripts/${EMULATION_NAME}.xbn`; - else if (!config.magic_demand_paged) - return `sed "$sc" ldscripts/${EMULATION_NAME}.xn`; - else if (link_info.shared) - return `sed "$sc" ldscripts/${EMULATION_NAME}.xs`; - else - return `sed "$sc" ldscripts/${EMULATION_NAME}.x`; -} + return EOF +sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c +echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c +echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c +echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c + +if test -n "$GENERATE_SHLIB_SCRIPT" ; then +echo ' ; else if (link_info.shared) return' >> e${EMULATION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c +fi + +echo ' ; else return' >> e${EMULATION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c +echo '; }' >> e${EMULATION_NAME}.c else # Scripts read from the filesystem. @@ -1139,6 +1141,22 @@ EOF fi +if test -n "$PARSE_AND_LIST_ARGS" ; then +cat >>e${EMULATION_NAME}.c <<EOF +static int gld_${EMULATION_NAME}_parse_args PARAMS ((int, char **)); +static void gld_${EMULATION_NAME}_list_options PARAMS ((FILE * file)); + + $PARSE_AND_LIST_ARGS +EOF +else + +cat >>e${EMULATION_NAME}.c <<EOF +#define gld_${EMULATION_NAME}_parse_args NULL +#define gld_${EMULATION_NAME}_list_options NULL +EOF + +fi + cat >>e${EMULATION_NAME}.c <<EOF struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = @@ -1155,9 +1173,15 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = gld${EMULATION_NAME}_get_script, "${EMULATION_NAME}", "${OUTPUT_FORMAT}", - NULL, - NULL, + NULL, /* finish */ + NULL, /* create output section statements */ gld${EMULATION_NAME}_open_dynamic_archive, - gld${EMULATION_NAME}_place_orphan + gld${EMULATION_NAME}_place_orphan, + NULL, /* set_symbols */ + gld_${EMULATION_NAME}_parse_args, + NULL, /* unrecognized_file */ + gld_${EMULATION_NAME}_list_options, + NULL, /* recognized_file */ + NULL /* find_potential_libraries */ }; EOF |