Index: pe-dll.c =================================================================== RCS file: /cvs/src/src/ld/pe-dll.c,v retrieving revision 1.23 diff -u -r1.23 pe-dll.c --- pe-dll.c 2001/03/13 06:14:27 1.23 +++ pe-dll.c 2001/04/29 12:18:23 @@ -231,24 +231,77 @@ free (local_copy); } +/* + abfd is a bfd containing n (or NULL) + It can be used for contextual checks. +*/ static int -auto_export (d, n) +auto_export (abfd, d, n) + bfd *abfd; def_file *d; const char *n; { int i; struct exclude_list_struct *ex; + + /* we should not re-export imported stuff */ + if (strncmp (n, "_imp__",6) == 0) + return 0; + for (i = 0; i < d->num_exports; i++) if (strcmp (d->exports[i].name, n) == 0) return 0; if (pe_dll_do_default_excludes) { + /* First of all, make context checks: + Don't export anything from libgcc */ + + if (abfd + && abfd->my_archive) + { + /* Do not specify suffix explicitly, to allow for dllized versions */ + if (strstr(abfd->my_archive->filename,"libgcc.")) return 0; + if (strstr(abfd->my_archive->filename,"libstdc++.")) return 0; + if (strstr(abfd->my_archive->filename,"libmingw32.")) return 0; + } + + { + /* skip .*crt\d\.o */ + char *p; + if (abfd + && (p=strstr(abfd->filename,"crt")) + && (isdigit(p[3]) && p[4]=='.' && p[5]=='o' && p[6]==0)) return 0; + } + +#if 0 + /* Don't export any 'reserved' symbols */ + if (*n && *n=='_' && n[1]=='_') return 0; +#endif + if (strcmp (n, "DllMain@12") == 0) return 0; if (strcmp (n, "DllEntryPoint@0") == 0) return 0; + if (strcmp (n, "DllMainCRTStartup@12") == 0) + return 0; if (strcmp (n, "impure_ptr") == 0) return 0; + + if (strncmp (n, "__rtti_", 7) == 0) + return 0; + if (strncmp (n, "__builtin_", 10) == 0) + return 0; + + /* Don't export symbols for specifying DLL's internal layout */ + + if (strncmp (n, "_head_", 6) == 0) + return 0; + + { + int len = strlen(n); + if (len>6 && strncmp (n + len - 6, "_iname", 7) == 0) + return 0; + } } for (ex = excludes; ex; ex = ex->next) if (strcmp (n, ex->string) == 0) @@ -301,15 +354,30 @@ for (j = 0; j < nsyms; j++) { - /* We should export symbols which are either global or not - anything at all. (.bss data is the latter) */ - if ((symbols[j]->flags & BSF_GLOBAL) - || (symbols[j]->flags == BSF_NO_FLAGS)) + /* We should export symbols which are either global or not + anything at all. (.bss data is the latter) + We should not export undefined symbols + */ + if (symbols[j]->section!=&bfd_und_section + && ((symbols[j]->flags & BSF_GLOBAL) + || (symbols[j]->flags == BFD_FORT_COMM_DEFAULT_VALUE))) { const char *sn = symbols[j]->name; + + /* we should not re-export imported stuff */ + { + char *name = (char *) xmalloc (strlen (sn) + 2 + 6); + sprintf (name, "%s%s", U("_imp_"), sn); + blhe = bfd_link_hash_lookup (info->hash, name, + false, false, false); + free (name); + + if (blhe && blhe->type == bfd_link_hash_defined) continue; + } + if (*sn == '_') sn++; - if (auto_export (pe_def_file, sn)) + if (auto_export (b, pe_def_file, sn)) { def_file_export *p; p=def_file_add_export (pe_def_file, sn, 0, -1); @@ -350,7 +418,7 @@ { char *tmp = xstrdup (pe_def_file->exports[i].name); *(strchr (tmp, '@')) = 0; - if (auto_export (pe_def_file, tmp)) + if (auto_export (NULL, pe_def_file, tmp)) def_file_add_export (pe_def_file, tmp, pe_def_file->exports[i].internal_name, -1); else