Back to index

cell-binutils  2.17cvs20070401
Defines | Enumerations | Functions | Variables
dllwrap.c File Reference
#include "bfd.h"
#include "libiberty.h"
#include "bucomm.h"
#include "getopt.h"
#include "dyn-string.h"
#include <time.h>
#include <sys/stat.h>
#include <stdarg.h>

Go to the source code of this file.

Defines

#define WIFEXITED(w)   (((w)&0377) == 0)
#define WIFSIGNALED(w)   (((w)&0377) != 0177 && ((w)&~0377) == 0)
#define WTERMSIG(w)   ((w) & 0177)
#define WEXITSTATUS(w)   (((w) >> 8) & 0377)
#define OPTION_START   149
#define OPTION_QUIET   (OPTION_START + 1)
#define OPTION_VERBOSE   (OPTION_QUIET + 1)
#define OPTION_VERSION   (OPTION_VERBOSE + 1)
#define OPTION_DRY_RUN   (OPTION_VERSION + 1)
#define OPTION_DRIVER_NAME   (OPTION_DRY_RUN + 1)
#define OPTION_DRIVER_FLAGS   (OPTION_DRIVER_NAME + 1)
#define OPTION_DLLTOOL_NAME   (OPTION_DRIVER_FLAGS + 1)
#define OPTION_ENTRY   (OPTION_DLLTOOL_NAME + 1)
#define OPTION_IMAGE_BASE   (OPTION_ENTRY + 1)
#define OPTION_TARGET   (OPTION_IMAGE_BASE + 1)
#define OPTION_MNO_CYGWIN   (OPTION_TARGET + 1)
#define OPTION_NODELETE   (OPTION_MNO_CYGWIN + 1)
#define OPTION_DLLNAME   (OPTION_NODELETE + 1)
#define OPTION_NO_IDATA4   (OPTION_DLLNAME + 1)
#define OPTION_NO_IDATA5   (OPTION_NO_IDATA4 + 1)
#define OPTION_OUTPUT_EXP   (OPTION_NO_IDATA5 + 1)
#define OPTION_OUTPUT_DEF   (OPTION_OUTPUT_EXP + 1)
#define OPTION_EXPORT_ALL_SYMS   (OPTION_OUTPUT_DEF + 1)
#define OPTION_NO_EXPORT_ALL_SYMS   (OPTION_EXPORT_ALL_SYMS + 1)
#define OPTION_EXCLUDE_SYMS   (OPTION_NO_EXPORT_ALL_SYMS + 1)
#define OPTION_NO_DEFAULT_EXCLUDES   (OPTION_EXCLUDE_SYMS + 1)
#define OPTION_OUTPUT_LIB   (OPTION_NO_DEFAULT_EXCLUDES + 1)
#define OPTION_DEF   (OPTION_OUTPUT_LIB + 1)
#define OPTION_ADD_UNDERSCORE   (OPTION_DEF + 1)
#define OPTION_KILLAT   (OPTION_ADD_UNDERSCORE + 1)
#define OPTION_HELP   (OPTION_KILLAT + 1)
#define OPTION_MACHINE   (OPTION_HELP + 1)
#define OPTION_ADD_INDIRECT   (OPTION_MACHINE + 1)
#define OPTION_BASE_FILE   (OPTION_ADD_INDIRECT + 1)
#define OPTION_AS   (OPTION_BASE_FILE + 1)

Enumerations

enum  target_type { UNKNOWN_TARGET, CYGWIN_TARGET, MINGW_TARGET }

Functions

static int run (const char *, char *)
static char * mybasename (const char *)
static int strhash (const char *)
static void usage (FILE *, int)
static void display (static char *look_for_prog(const char const char *, va_list)
static void inform VPARAMS ((const char *message,...))
static void warn VPARAMS ((const char *format,...))
static char * look_for_prog (const char *prog_name, const char *prefix, int end_prefix)
static char * deduce_name (const char *name)
static void delete_temp_files (void)
static void cleanup_and_exit (int status)
int main (int, char **)

Variables

static char * driver_name = NULL
static char * cygwin_driver_flags = "-Wl,--dll -nostartfiles"
static char * mingw32_driver_flags = "-mdll"
static char * generic_driver_flags = "-Wl,--dll"
static char * entry_point
static char * dlltool_name = NULL
static char * target = TARGET
static target_type which_target = UNKNOWN_TARGET
static int dontdeltemps = 0
static int dry_run = 0
static char * prog_name
static int verbose = 0
static char * dll_file_name
static char * dll_name
static char * base_file_name
static char * exp_file_name
static char * def_file_name
static int delete_base_file = 1
static int delete_exp_file = 1
static int delete_def_file = 1
static struct option []

Define Documentation

#define OPTION_ADD_INDIRECT   (OPTION_MACHINE + 1)

Definition at line 552 of file dllwrap.c.

#define OPTION_ADD_UNDERSCORE   (OPTION_DEF + 1)

Definition at line 548 of file dllwrap.c.

#define OPTION_AS   (OPTION_BASE_FILE + 1)

Definition at line 554 of file dllwrap.c.

Definition at line 553 of file dllwrap.c.

#define OPTION_DEF   (OPTION_OUTPUT_LIB + 1)

Definition at line 547 of file dllwrap.c.

#define OPTION_DLLNAME   (OPTION_NODELETE + 1)

Definition at line 537 of file dllwrap.c.

Definition at line 529 of file dllwrap.c.

Definition at line 528 of file dllwrap.c.

#define OPTION_DRIVER_NAME   (OPTION_DRY_RUN + 1)

Definition at line 527 of file dllwrap.c.

#define OPTION_DRY_RUN   (OPTION_VERSION + 1)

Definition at line 526 of file dllwrap.c.

#define OPTION_ENTRY   (OPTION_DLLTOOL_NAME + 1)

Definition at line 530 of file dllwrap.c.

Definition at line 544 of file dllwrap.c.

Definition at line 542 of file dllwrap.c.

#define OPTION_HELP   (OPTION_KILLAT + 1)

Definition at line 550 of file dllwrap.c.

#define OPTION_IMAGE_BASE   (OPTION_ENTRY + 1)

Definition at line 531 of file dllwrap.c.

Definition at line 549 of file dllwrap.c.

#define OPTION_MACHINE   (OPTION_HELP + 1)

Definition at line 551 of file dllwrap.c.

#define OPTION_MNO_CYGWIN   (OPTION_TARGET + 1)

Definition at line 533 of file dllwrap.c.

Definition at line 545 of file dllwrap.c.

Definition at line 543 of file dllwrap.c.

#define OPTION_NO_IDATA4   (OPTION_DLLNAME + 1)

Definition at line 538 of file dllwrap.c.

#define OPTION_NO_IDATA5   (OPTION_NO_IDATA4 + 1)

Definition at line 539 of file dllwrap.c.

#define OPTION_NODELETE   (OPTION_MNO_CYGWIN + 1)

Definition at line 536 of file dllwrap.c.

Definition at line 541 of file dllwrap.c.

#define OPTION_OUTPUT_EXP   (OPTION_NO_IDATA5 + 1)

Definition at line 540 of file dllwrap.c.

Definition at line 546 of file dllwrap.c.

#define OPTION_QUIET   (OPTION_START + 1)

Definition at line 521 of file dllwrap.c.

#define OPTION_START   149

Definition at line 518 of file dllwrap.c.

#define OPTION_TARGET   (OPTION_IMAGE_BASE + 1)

Definition at line 532 of file dllwrap.c.

#define OPTION_VERBOSE   (OPTION_QUIET + 1)

Definition at line 522 of file dllwrap.c.

#define OPTION_VERSION   (OPTION_VERBOSE + 1)

Definition at line 523 of file dllwrap.c.

#define WEXITSTATUS (   w)    (((w) >> 8) & 0377)

Definition at line 58 of file dllwrap.c.

#define WIFEXITED (   w)    (((w)&0377) == 0)

Definition at line 49 of file dllwrap.c.

#define WIFSIGNALED (   w)    (((w)&0377) != 0177 && ((w)&~0377) == 0)

Definition at line 52 of file dllwrap.c.

#define WTERMSIG (   w)    ((w) & 0177)

Definition at line 55 of file dllwrap.c.


Enumeration Type Documentation

Enumerator:
UNKNOWN_TARGET 
CYGWIN_TARGET 
MINGW_TARGET 

Definition at line 88 of file dllwrap.c.


Function Documentation

static void cleanup_and_exit ( int  status) [static]

Definition at line 339 of file dllwrap.c.

{
  delete_temp_files ();
  exit (status);
}

Here is the call graph for this function:

static char* deduce_name ( const char *  name) [static]

Definition at line 243 of file dllwrap.c.

{
  char *cmd;
  const char *dash;
  const char *slash;
  const char *cp;

  dash = NULL;
  slash = NULL;
  for (cp = prog_name; *cp != '\0'; ++cp)
    {
      if (*cp == '-')
       dash = cp;

      if (
#if defined(__DJGPP__) || defined (__CYGWIN__) || defined(__WIN32__)
         *cp == ':' || *cp == '\\' ||
#endif
         *cp == '/')
       {
         slash = cp;
         dash = NULL;
       }
    }

  cmd = NULL;

  if (dash != NULL)
    /* First, try looking for a prefixed NAME in the
       PROG_NAME directory, with the same prefix as PROG_NAME.  */
    cmd = look_for_prog (name, prog_name, dash - prog_name + 1);

  if (slash != NULL && cmd == NULL)
    /* Next, try looking for a NAME in the same directory as
       that of this program.  */
    cmd = look_for_prog (name, prog_name, slash - prog_name + 1);

  if (cmd == NULL)
    /* Just return NAME as is.  */
    cmd = xstrdup (name);

  return cmd;
}

Here is the call graph for this function:

static void delete_temp_files ( void  ) [static]

Definition at line 288 of file dllwrap.c.

{
  if (delete_base_file && base_file_name)
    {
      if (verbose)
       {
         if (dontdeltemps)
           warn (_("Keeping temporary base file %s"), base_file_name);
         else
           warn (_("Deleting temporary base file %s"), base_file_name);
       }
      if (! dontdeltemps)
       {
         unlink (base_file_name);
         free (base_file_name);
       }
    }

  if (delete_exp_file && exp_file_name)
    {
      if (verbose)
       {
         if (dontdeltemps)
           warn (_("Keeping temporary exp file %s"), exp_file_name);
         else
           warn (_("Deleting temporary exp file %s"), exp_file_name);
       }
      if (! dontdeltemps)
       {
         unlink (exp_file_name);
         free (exp_file_name);
       }
    }
  if (delete_def_file && def_file_name)
    {
      if (verbose)
       {
         if (dontdeltemps)
           warn (_("Keeping temporary def file %s"), def_file_name);
         else
           warn (_("Deleting temporary def file %s"), def_file_name);
       }
      if (! dontdeltemps)
       {
         unlink (def_file_name);
         free (def_file_name);
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void display ( static char *look_for_prog (const char  const char *,
va_list   
) [static]

Definition at line 117 of file dllwrap.c.

{
  if (prog_name != NULL)
    fprintf (stderr, "%s: ", prog_name);

  vfprintf (stderr, message, args);
  fputc ('\n', stderr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* look_for_prog ( const char *  prog_name,
const char *  prefix,
int  end_prefix 
) [static]

Definition at line 177 of file dllwrap.c.

{
  struct stat s;
  char *cmd;

  cmd = xmalloc (strlen (prefix)
               + strlen (prog_name)
#ifdef HAVE_EXECUTABLE_SUFFIX
               + strlen (EXECUTABLE_SUFFIX)
#endif
               + 10);
  strcpy (cmd, prefix);

  sprintf (cmd + end_prefix, "%s", prog_name);

  if (strchr (cmd, '/') != NULL)
    {
      int found;

      found = (stat (cmd, &s) == 0
#ifdef HAVE_EXECUTABLE_SUFFIX
              || stat (strcat (cmd, EXECUTABLE_SUFFIX), &s) == 0
#endif
              );

      if (! found)
       {
         /* xgettext:c-format */
         inform (_("Tried file: %s"), cmd);
         free (cmd);
         return NULL;
       }
    }

  /* xgettext:c-format */
  inform (_("Using file: %s"), cmd);

  return cmd;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)
static char * mybasename ( const char *  name) [static]

Definition at line 432 of file dllwrap.c.

{
  const char *base = name;

  while (*name)
    {
      if (*name == '/' || *name == '\\')
       {
         base = name + 1;
       }
      ++name;
    }
  return (char *) base;
}
static int run ( const char *  what,
char *  args 
) [static]

Definition at line 346 of file dllwrap.c.

{
  char *s;
  int pid, wait_status, retcode;
  int i;
  const char **argv;
  char *errmsg_fmt, *errmsg_arg;
  char *temp_base = choose_temp_base ();
  int in_quote;
  char sep;

  if (verbose || dry_run)
    fprintf (stderr, "%s %s\n", what, args);

  /* Count the args */
  i = 0;
  for (s = args; *s; s++)
    if (*s == ' ')
      i++;
  i++;
  argv = alloca (sizeof (char *) * (i + 3));
  i = 0;
  argv[i++] = what;
  s = args;
  while (1)
    {
      while (*s == ' ' && *s != 0)
       s++;
      if (*s == 0)
       break;
      in_quote = (*s == '\'' || *s == '"');
      sep = (in_quote) ? *s++ : ' ';
      argv[i++] = s;
      while (*s != sep && *s != 0)
       s++;
      if (*s == 0)
       break;
      *s++ = 0;
      if (in_quote)
       s++;
    }
  argv[i++] = NULL;

  if (dry_run)
    return 0;

  pid = pexecute (argv[0], (char * const *) argv, prog_name, temp_base,
                &errmsg_fmt, &errmsg_arg, PEXECUTE_ONE | PEXECUTE_SEARCH);

  if (pid == -1)
    {
      int errno_val = errno;

      fprintf (stderr, "%s: ", prog_name);
      fprintf (stderr, errmsg_fmt, errmsg_arg);
      fprintf (stderr, ": %s\n", strerror (errno_val));
      return 1;
    }

  retcode = 0;
  pid = pwait (pid, &wait_status, 0);
  if (pid == -1)
    {
      warn ("wait: %s", strerror (errno));
      retcode = 1;
    }
  else if (WIFSIGNALED (wait_status))
    {
      warn (_("subprocess got fatal signal %d"), WTERMSIG (wait_status));
      retcode = 1;
    }
  else if (WIFEXITED (wait_status))
    {
      if (WEXITSTATUS (wait_status) != 0)
       {
         warn (_("%s exited with status %d"), what, WEXITSTATUS (wait_status));
         retcode = 1;
       }
    }
  else
    retcode = 1;

  return retcode;
}

Here is the call graph for this function:

static int strhash ( const char *  str) [static]

Definition at line 448 of file dllwrap.c.

{
  const unsigned char *s;
  unsigned long hash;
  unsigned int c;
  unsigned int len;

  hash = 0;
  len = 0;
  s = (const unsigned char *) str;
  while ((c = *s++) != '\0')
    {
      hash += c + (c << 17);
      hash ^= hash >> 2;
      ++len;
    }
  hash += len + (len << 17);
  hash ^= hash >> 2;

  return hash;
}
static void usage ( FILE *  file,
int  status 
) [static]

Definition at line 473 of file dllwrap.c.

{
  fprintf (file, _("Usage %s <option(s)> <object-file(s)>\n"), prog_name);
  fprintf (file, _("  Generic options:\n"));
  fprintf (file, _("   @<file>                Read options from <file>\n"));    
  fprintf (file, _("   --quiet, -q            Work quietly\n"));
  fprintf (file, _("   --verbose, -v          Verbose\n"));
  fprintf (file, _("   --version              Print dllwrap version\n"));
  fprintf (file, _("   --implib <outname>     Synonym for --output-lib\n"));
  fprintf (file, _("  Options for %s:\n"), prog_name);
  fprintf (file, _("   --driver-name <driver> Defaults to \"gcc\"\n"));
  fprintf (file, _("   --driver-flags <flags> Override default ld flags\n"));
  fprintf (file, _("   --dlltool-name <dlltool> Defaults to \"dlltool\"\n"));
  fprintf (file, _("   --entry <entry>        Specify alternate DLL entry point\n"));
  fprintf (file, _("   --image-base <base>    Specify image base address\n"));
  fprintf (file, _("   --target <machine>     i386-cygwin32 or i386-mingw32\n"));
  fprintf (file, _("   --dry-run              Show what needs to be run\n"));
  fprintf (file, _("   --mno-cygwin           Create Mingw DLL\n"));
  fprintf (file, _("  Options passed to DLLTOOL:\n"));
  fprintf (file, _("   --machine <machine>\n"));
  fprintf (file, _("   --output-exp <outname> Generate export file.\n"));
  fprintf (file, _("   --output-lib <outname> Generate input library.\n"));
  fprintf (file, _("   --add-indirect         Add dll indirects to export file.\n"));
  fprintf (file, _("   --dllname <name>       Name of input dll to put into output lib.\n"));
  fprintf (file, _("   --def <deffile>        Name input .def file\n"));
  fprintf (file, _("   --output-def <deffile> Name output .def file\n"));
  fprintf (file, _("   --export-all-symbols     Export all symbols to .def\n"));
  fprintf (file, _("   --no-export-all-symbols  Only export .drectve symbols\n"));
  fprintf (file, _("   --exclude-symbols <list> Exclude <list> from .def\n"));
  fprintf (file, _("   --no-default-excludes    Zap default exclude symbols\n"));
  fprintf (file, _("   --base-file <basefile> Read linker generated base file\n"));
  fprintf (file, _("   --no-idata4           Don't generate idata$4 section\n"));
  fprintf (file, _("   --no-idata5           Don't generate idata$5 section\n"));
  fprintf (file, _("   -U                     Add underscores to .lib\n"));
  fprintf (file, _("   -k                     Kill @<n> from exported names\n"));
  fprintf (file, _("   --add-stdcall-alias    Add aliases without @<n>\n"));
  fprintf (file, _("   --as <name>            Use <name> for assembler\n"));
  fprintf (file, _("   --nodelete             Keep temp files.\n"));
  fprintf (file, _("  Rest are passed unmodified to the language driver\n"));
  fprintf (file, "\n\n");
  if (REPORT_BUGS_TO[0] && status == 0)
    fprintf (file, _("Report bugs to %s\n"), REPORT_BUGS_TO);
  exit (status);
}

Here is the call graph for this function:

static void inform VPARAMS ( (const char *message,...)  ) [static]

Definition at line 147 of file dllwrap.c.

{
  VA_OPEN (args, message);
  VA_FIXEDARG (args, const char *, message);

  if (!verbose)
    return;

  display (message, args);

  VA_CLOSE (args);
}

Here is the call graph for this function:

static void warn VPARAMS ( (const char *format,...)  ) [static]

Definition at line 161 of file dllwrap.c.

{
  VA_OPEN (args, format);
  VA_FIXEDARG (args, const char *, format);

  display (format, args);

  VA_CLOSE (args);
}

Here is the call graph for this function:


Variable Documentation

char* base_file_name [static]

Definition at line 106 of file dllwrap.c.

char* cygwin_driver_flags = "-Wl,--dll -nostartfiles" [static]

Definition at line 77 of file dllwrap.c.

char* def_file_name [static]

Definition at line 108 of file dllwrap.c.

int delete_base_file = 1 [static]

Definition at line 109 of file dllwrap.c.

int delete_def_file = 1 [static]

Definition at line 111 of file dllwrap.c.

int delete_exp_file = 1 [static]

Definition at line 110 of file dllwrap.c.

char* dll_file_name [static]

Definition at line 104 of file dllwrap.c.

char* dll_name [static]

Definition at line 105 of file dllwrap.c.

char* dlltool_name = NULL [static]

Definition at line 84 of file dllwrap.c.

int dontdeltemps = 0 [static]

Definition at line 97 of file dllwrap.c.

char* driver_name = NULL [static]

Definition at line 76 of file dllwrap.c.

int dry_run = 0 [static]

Definition at line 98 of file dllwrap.c.

char* entry_point [static]

Definition at line 82 of file dllwrap.c.

char* exp_file_name [static]

Definition at line 107 of file dllwrap.c.

char* generic_driver_flags = "-Wl,--dll" [static]

Definition at line 80 of file dllwrap.c.

char* mingw32_driver_flags = "-mdll" [static]

Definition at line 79 of file dllwrap.c.

struct option[] [static]

Definition at line 556 of file dllwrap.c.

char* prog_name [static]

Definition at line 100 of file dllwrap.c.

char* target = TARGET [static]

Definition at line 86 of file dllwrap.c.

int verbose = 0 [static]

Definition at line 102 of file dllwrap.c.

Definition at line 95 of file dllwrap.c.