2002-03-07 H.J. Lu (hjl@gnu.org)
[deliverable/binutils-gdb.git] / ld / pe-dll.c
index 2f326481170d5b07fd865a115a9a63cf9081179c..7fe46cb828b5d8a26c5369ea97ac0753f12b89c9 100644 (file)
@@ -1,5 +1,5 @@
 /* Routines to help build PEI-format DLLs (Win32 etc)
-   Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+   Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
    Written by DJ Delorie <dj@cygnus.com>
 
    This file is part of GLD, the Gnu Linker.
@@ -23,9 +23,9 @@
 #include "sysdep.h"
 #include "bfdlink.h"
 #include "libiberty.h"
+#include "safe-ctype.h"
 
 #include <time.h>
-#include <ctype.h>
 
 #include "ld.h"
 #include "ldexp.h"
@@ -239,6 +239,11 @@ static autofilter_entry_type autofilter_objlist[] =
   { "crt0.o", 6 },
   { "crt1.o", 6 },
   { "crt2.o", 6 },
+  { "dllcrt1.o", 9 },
+  { "dllcrt2.o", 9 },
+  { "gcrt0.o", 7 },
+  { "gcrt1.o", 7 },
+  { "gcrt2.o", 7 },  
   { NULL, 0 }
 };
 
@@ -281,14 +286,16 @@ static void generate_reloc PARAMS ((bfd *, struct bfd_link_info *));
 static void quoteput PARAMS ((char *, FILE *, int));
 static asection *quick_section PARAMS ((bfd *, const char *, int, int));
 static void quick_symbol
-  PARAMS ((bfd *, char *, char *, char *, asection *, int, int));
+  PARAMS ((bfd *, const char *, const char *, const char *,
+          asection *, int, int));
 static void quick_reloc PARAMS ((bfd *, int, int, int));
 static bfd *make_head PARAMS ((bfd *));
 static bfd *make_tail PARAMS ((bfd *));
 static bfd *make_one PARAMS ((def_file_export *, bfd *));
-static bfd *make_singleton_name_thunk PARAMS ((char *, bfd *));
+static bfd *make_singleton_name_thunk PARAMS ((const char *, bfd *));
 static char *make_import_fixup_mark PARAMS ((arelent *));
-static bfd *make_import_fixup_entry PARAMS ((char *, char *, char *, bfd *));
+static bfd *make_import_fixup_entry
+  PARAMS ((const char *, const char *, const char *, bfd *));
 static unsigned int pe_get16 PARAMS ((bfd *, int));
 static unsigned int pe_get32 PARAMS ((bfd *, int));
 static unsigned int pe_as32 PARAMS ((void *));
@@ -414,7 +421,7 @@ auto_export (abfd, d, n)
 
   if (pe_dll_do_default_excludes)
     {
-      char * p;
+      const char * p;
       int    len;
 
       if (pe_dll_extra_pe_debug)
@@ -436,16 +443,16 @@ auto_export (abfd, d, n)
        }
 
       /* Next, exclude symbols from certain startup objects.  */
-      afptr = autofilter_objlist;
 
-      while (afptr->name)
+      if (abfd && (p = lbasename (abfd->filename)))
        {
-         if (abfd && 
-             (p = strstr (abfd->filename, afptr->name)) &&
-             (*(p + afptr->len - 1) == 0))
-           return 0;
-
-         afptr ++;
+          afptr = autofilter_objlist;
+          while (afptr->name)
+           {
+             if ( strcmp (p, afptr->name) == 0 )
+               return 0;
+             afptr++;
+           }
        }
 
       /* Don't try to blindly exclude all symbols
@@ -988,7 +995,7 @@ static struct sec *current_sec;
 void
 pe_walk_relocs_of_symbol (info, name, cb)
      struct bfd_link_info *info;
-     CONST char *name;
+     const char *name;
      int (*cb) (arelent *, asection *);
 {
   bfd *b;
@@ -1252,7 +1259,7 @@ quoteput (s, f, needs_quotes)
     if (*cp == '\''
        || *cp == '"'
        || *cp == '\\'
-       || isspace ((unsigned char) *cp)
+       || ISSPACE (*cp)
        || *cp == ','
        || *cp == ';')
       needs_quotes = 1;
@@ -1474,9 +1481,9 @@ quick_section (abfd, name, flags, align)
 static void
 quick_symbol (abfd, n1, n2, n3, sec, flags, addr)
      bfd *abfd;
-     char *n1;
-     char *n2;
-     char *n3;
+     const char *n1;
+     const char *n2;
+     const char *n3;
      asection *sec;
      int flags;
      int addr;
@@ -1893,7 +1900,7 @@ make_one (exp, parent)
 
 static bfd *
 make_singleton_name_thunk (import, parent)
-     char *import;
+     const char *import;
      bfd *parent;
 {
   /* Name thunks go to idata$4.  */
@@ -1941,7 +1948,7 @@ make_import_fixup_mark (rel)
   /* We convert reloc to symbol, for later reference.  */
   static int counter;
   static char *fixup_name = NULL;
-  static unsigned int buffer_len = 0;
+  static size_t buffer_len = 0;
   
   struct symbol_cache_entry *sym = *rel->sym_ptr_ptr;
   
@@ -1989,9 +1996,9 @@ make_import_fixup_mark (rel)
 
 static bfd *
 make_import_fixup_entry (name, fixup_name, dll_symname,parent)
-     char *name;
-     char *fixup_name;
-     char *dll_symname;
+     const char *name;
+     const char *fixup_name;
+     const char *dll_symname;
      bfd *parent;
 {
   asection *id3;
@@ -2046,7 +2053,7 @@ pe_create_import_fixup (rel)
   char buf[300];
   struct symbol_cache_entry *sym = *rel->sym_ptr_ptr;
   struct bfd_link_hash_entry *name_thunk_sym;
-  CONST char *name = sym->name;
+  const char *name = sym->name;
   char *fixup_name = make_import_fixup_mark (rel);
 
   sprintf (buf, U ("_nm_thnk_%s"), name);
@@ -2063,9 +2070,10 @@ pe_create_import_fixup (rel)
     }
 
   {
-    extern char * pe_data_import_dll;  /* Defined in emultempl/pe.em.  */
-    
-    bfd *b = make_import_fixup_entry (name, fixup_name, pe_data_import_dll,
+    extern char * pe_data_import_dll;
+    char * dll_symname = pe_data_import_dll ? pe_data_import_dll : "unknown";
+
+    bfd *b = make_import_fixup_entry (name, fixup_name, dll_symname,
                                      output_bfd);
     add_bfd_to_link (b, b->filename, &link_info);
   }
@@ -2086,7 +2094,7 @@ pe_dll_generate_implib (def, impfilename)
   dll_filename = (def->name) ? def->name : dll_name;
   dll_symname = xstrdup (dll_filename);
   for (i = 0; dll_symname[i]; i++)
-    if (!isalnum ((unsigned char) dll_symname[i]))
+    if (!ISALNUM (dll_symname[i]))
       dll_symname[i] = '_';
 
   unlink (impfilename);
@@ -2149,7 +2157,7 @@ pe_dll_generate_implib (def, impfilename)
 static void
 add_bfd_to_link (abfd, name, link_info)
      bfd *abfd;
-     CONST char *name;
+     const char *name;
      struct bfd_link_info *link_info;
 {
   lang_input_statement_type *fake_file;
@@ -2183,7 +2191,7 @@ pe_process_import_defs (output_bfd, link_info)
       dll_filename = module->name;
       dll_symname = xstrdup (module->name);
       for (i = 0; dll_symname[i]; i++)
-       if (!isalnum (dll_symname[i]))
+       if (!ISALNUM (dll_symname[i]))
          dll_symname[i] = '_';
 
       do_this_dll = 0;
@@ -2250,8 +2258,8 @@ pe_get16 (abfd, where)
 {
   unsigned char b[2];
 
-  bfd_seek (abfd, where, SEEK_SET);
-  bfd_read (b, 1, 2, abfd);
+  bfd_seek (abfd, (file_ptr) where, SEEK_SET);
+  bfd_bread (b, (bfd_size_type) 2, abfd);
   return b[0] + (b[1] << 8);
 }
 
@@ -2262,8 +2270,8 @@ pe_get32 (abfd, where)
 {
   unsigned char b[4];
 
-  bfd_seek (abfd, where, SEEK_SET);
-  bfd_read (b, 1, 4, abfd);
+  bfd_seek (abfd, (file_ptr) where, SEEK_SET);
+  bfd_bread (b, (bfd_size_type) 4, abfd);
   return b[0] + (b[1] << 8) + (b[2] << 16) + (b[3] << 24);
 }
 
@@ -2343,8 +2351,8 @@ pe_implied_import_dll (filename)
       unsigned long vsize = pe_get32 (dll, secptr1 + 16);
       unsigned long fptr = pe_get32 (dll, secptr1 + 20);
 
-      bfd_seek (dll, secptr1, SEEK_SET);
-      bfd_read (sname, 1, 8, dll);
+      bfd_seek (dll, (file_ptr) secptr1, SEEK_SET);
+      bfd_bread (sname, (bfd_size_type) 8, dll);
 
       if (vaddr <= export_rva && vaddr + vsize > export_rva)
        {
@@ -2356,8 +2364,8 @@ pe_implied_import_dll (filename)
     }
 
   expdata = (unsigned char *) xmalloc (export_size);
-  bfd_seek (dll, expptr, SEEK_SET);
-  bfd_read (expdata, 1, export_size, dll);
+  bfd_seek (dll, (file_ptr) expptr, SEEK_SET);
+  bfd_bread (expdata, (bfd_size_type) export_size, dll);
   erva = expdata - export_rva;
 
   if (pe_def_file == 0)
@@ -2429,7 +2437,7 @@ pe_dll_fill_sections (abfd, info)
       /* Do the assignments again.  */
       lang_do_assignments (stat_ptr->head,
                           abs_output_section,
-                          (fill_type) 0, (bfd_vma) 0);
+                          (fill_type *) 0, (bfd_vma) 0);
     }
 
   fill_edata (abfd, info);
@@ -2463,7 +2471,7 @@ pe_exe_fill_sections (abfd, info)
       /* Do the assignments again.  */
       lang_do_assignments (stat_ptr->head,
                           abs_output_section,
-                          (fill_type) 0, (bfd_vma) 0);
+                          (fill_type *) 0, (bfd_vma) 0);
     }
   reloc_s->contents = reloc_d;
 }
This page took 0.027084 seconds and 4 git commands to generate.