* emultempl/hppaelf.em (build_section_lists): New function.
[deliverable/binutils-gdb.git] / ld / emultempl / sunos.em
index 590736243ce2cfe668366c8915211be8328ef023..17cd40787ce5f9fb3e7233957bfb6c648e895997 100644 (file)
@@ -1,10 +1,16 @@
 # This shell script emits a C file. -*- C -*-
 # It does some substitutions.
+if [ -z "$MACHINE" ]; then 
+  OUTPUT_ARCH=${ARCH}
+else
+  OUTPUT_ARCH=${ARCH}:${MACHINE}
+fi
 cat >e${EMULATION_NAME}.c <<EOF
 /* This file is is generated by a shell script.  DO NOT EDIT! */
 
 /* SunOS emulation code for ${EMULATION_NAME}
-   Copyright (C) 1991, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
+   Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
+   Free Software Foundation, Inc.
    Written by Steve Chamberlain <sac@cygnus.com>
    SunOS shared library support by Ian Lance Taylor <ian@cygnus.com>
 
@@ -26,22 +32,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #define TARGET_IS_${EMULATION_NAME}
 
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
 #include "bfd.h"
 #include "sysdep.h"
 #include "bfdlink.h"
 #include "libiberty.h"
+#include "safe-ctype.h"
 
 #include "ld.h"
 #include "ldmain.h"
-#include "ldemul.h"
-#include "ldfile.h"
 #include "ldmisc.h"
 #include "ldexp.h"
 #include "ldlang.h"
+#include "ldfile.h"
+#include "ldemul.h"
 
 #ifdef HAVE_DIRENT_H
 # include <dirent.h>
@@ -86,8 +89,17 @@ static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
 static void
 gld${EMULATION_NAME}_before_parse()
 {
-  ldfile_output_architecture = bfd_arch_${ARCH};
+  const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}");
+  if (arch)
+    {
+      ldfile_output_architecture = arch->arch;
+      ldfile_output_machine = arch->mach;
+      ldfile_output_machine_name = arch->printable_name;
+    }
+  else
+    ldfile_output_architecture = bfd_arch_${ARCH};
   config.dynamic_link = true;
+  config.has_shared = true;
 }
 
 /* This is called after the command line arguments have been parsed,
@@ -100,7 +112,8 @@ gld${EMULATION_NAME}_set_symbols ()
 {
 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
   const char *env;
 
@@ -125,7 +138,8 @@ cat >>e${EMULATION_NAME}.c <<EOF
        }
     }
 EOF
-  fi
+  ;;
+  esac
 fi
 cat >>e${EMULATION_NAME}.c <<EOF
 }
@@ -152,7 +166,7 @@ gld${EMULATION_NAME}_find_so (inp)
      lang_input_statement_type *inp;
 {
   search_dirs_type *search;
-  char *found;
+  char *found = NULL;
   char *alc;
   struct stat st;
 
@@ -196,7 +210,7 @@ gld${EMULATION_NAME}_find_so (inp)
      found, add it to the list of input files.  */
   alc = (char *) xmalloc (strlen (inp->filename) + 1);
   strcpy (alc, inp->filename);
-  strstr (alc + strlen (search->name), ".so.")[2] = 'a';
+  strstr (alc + strlen (search->name), ".so")[2] = 'a';
   if (stat (alc, &st) != 0)
     free (alc);
   else
@@ -233,6 +247,10 @@ gld${EMULATION_NAME}_search_dir (dirname, filename, found_static)
   int max_maj, max_min;
   DIR *dir;
   struct dirent *entry;
+  unsigned int dirnamelen;
+  char *full_path;
+  int statval;
+  struct stat st;
 
   *found_static = false;
 
@@ -265,6 +283,7 @@ gld${EMULATION_NAME}_search_dir (dirname, filename, found_static)
   dir = opendir (dirname);
   if (dir == NULL)
     return NULL;
+  dirnamelen = strlen (dirname);
   
   while ((entry = readdir (dir)) != NULL)
     {
@@ -282,12 +301,22 @@ gld${EMULATION_NAME}_search_dir (dirname, filename, found_static)
          continue;
        }
 
-      if (strncmp (entry->d_name + 3 + len, ".so.", 4) != 0
-         || ! isdigit (entry->d_name[7 + len]))
+      /* We accept libfoo.so without a version number, even though the
+         native linker does not.  This is more convenient for packages
+         which just generate .so files for shared libraries, as on ELF
+         systems.  */
+      if (strncmp (entry->d_name + 3 + len, ".so", 3) != 0)
+       continue;
+      if (entry->d_name[6 + len] == '\0')
+       ;
+      else if (entry->d_name[6 + len] == '.'
+              && ISDIGIT (entry->d_name[7 + len]))
+       ;
+      else
        continue;
 
-      for (s = entry->d_name + 7 + len; *s != '\0'; s++)
-       if (*s != '.' && ! isdigit (*s))
+      for (s = entry->d_name + 6 + len; *s != '\0'; s++)
+       if (*s != '.' && ! ISDIGIT (*s))
          break;
       if (*s != '\0')
        continue;
@@ -303,6 +332,14 @@ gld${EMULATION_NAME}_search_dir (dirname, filename, found_static)
          || (force_min != -1 && force_min != found_min))
        continue;
 
+      /* Make sure the file really exists (ignore broken symlinks).  */
+      full_path = xmalloc (dirnamelen + 1 + strlen (entry->d_name) + 1);
+      sprintf (full_path, "%s/%s", dirname, entry->d_name);
+      statval = stat (full_path, &st);
+      free (full_path);
+      if (statval != 0)
+       continue;
+
       /* We've found a match for the name we are searching for.  See
         if this is the version we should use.  If the major and minor
         versions match, we use the last entry in alphabetical order;
@@ -441,7 +478,8 @@ 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
       {
        const char *lib_path;
@@ -451,7 +489,8 @@ cat >>e${EMULATION_NAME}.c <<EOF
          continue;
       }
 EOF
-  fi
+  ;;
+  esac
 fi
 cat >>e${EMULATION_NAME}.c <<EOF
       if (command_line.rpath != NULL)
@@ -944,28 +983,25 @@ 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
-    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
+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.
@@ -1005,10 +1041,15 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
   gld${EMULATION_NAME}_get_script,
   "${EMULATION_NAME}",
   "${OUTPUT_FORMAT}",
-  NULL, /* finish */
+  NULL,        /* finish */
   gld${EMULATION_NAME}_create_output_section_statements,
-  NULL, /* open_dynamic_library */
-  NULL, /* place_orphan */
-  gld${EMULATION_NAME}_set_symbols
+  NULL,        /* open dynamic archive */
+  NULL,        /* place orphan */
+  gld${EMULATION_NAME}_set_symbols,
+  NULL,        /* parse args */
+  NULL,        /* unrecognized file */
+  NULL,        /* list options */
+  NULL,        /* recognized file */
+  NULL         /* find_potential_libraries */
 };
 EOF
This page took 0.025498 seconds and 4 git commands to generate.