(patch) dlltool compat implib
Mumit Khan
khan@nanotech.wisc.edu
Mon Jan 3 11:59:00 GMT 2000
Small tweak for dlltool (I've already sent the corresponding patch to
pe-dll):
--compat-implib adds the double underscore __imp_<SYMBOL> to be
backward compatible for those using ancient versions of gcc. And I
mean really ancient! This takes down the size of one of my implibs
from 6.8MB to 5.9MB, a reasonable saving in my book.
1999-12-23 Mumit Khan <khan@xraylith.wisc.edu>
* dlltool.c (create_compat_implib): New variable.
(gen_exp_file): Use.
(make_one_lib_file): Use.
(long_options): Add compat-implib option.
(usage): Handle.
(main): Handle.
Index: dlltool.c
===================================================================
RCS file: /homes/khan/src/CVSROOT/binutils-19990911/binutils/dlltool.c,v
retrieving revision 1.1.1.1
retrieving revision 1.4
diff -u -3 -p -r1.1.1.1 -r1.4
--- dlltool.c 1999/12/23 07:19:35 1.1.1.1
+++ dlltool.c 1999/12/23 20:03:24 1.4
@@ -367,6 +367,10 @@ static boolean do_default_excludes;
/* Default symbols to exclude when exporting all the symbols. */
static const char *default_excludes = "DllMain@12,DllEntryPoint@0,impure_ptr";
+/* True if we should add __imp_<SYMBOL> to import libraries for backward
+ compatibility to old Cygwin releases. */
+static boolean create_compat_implib;
+
static char *def_file;
extern char * program_name;
@@ -1203,7 +1207,9 @@ scan_drectve_symbols (abfd)
inform (_("Sucking in info from %s section in %s\n"),
DRECTVE_SECTION_NAME, bfd_get_filename (abfd));
- /* Search for -export: strings */
+ /* Search for -export: strings. The exported symbols can optionally
+ have type tags (eg., -export:foo,data), so handle those as well.
+ Currently only data tag is supported. */
p = buf;
e = buf + size;
while (p < e)
@@ -1213,25 +1219,36 @@ scan_drectve_symbols (abfd)
{
char * name;
char * c;
+ flagword flags = BSF_FUNCTION;
p += 8;
name = p;
- while (p < e && *p != ' ' && *p != '-')
+ while (p < e && *p != ',' && *p != ' ' && *p != '-')
p++;
c = xmalloc (p - name + 1);
memcpy (c, name, p - name);
c[p - name] = 0;
+ if (p < e && *p == ',') /* found type tag. */
+ {
+ char *tag_start = ++p;
+ while (p < e && *p != ' ' && *p != '-')
+ p++;
+ if (strncmp (tag_start, "data", 4) == 0)
+ flags &= ~BSF_FUNCTION;
+ }
+
/* FIXME: The 5th arg is for the `constant' field.
What should it be? Not that it matters since it's not
currently useful. */
- def_exports (c, 0, -1, 0, 0, 0);
+ def_exports (c, 0, -1, 0, 0, ! (flags & BSF_FUNCTION));
if (add_stdcall_alias && strchr (c, '@'))
{
char *exported_name = xstrdup (c);
char *atsym = strchr (exported_name, '@');
*atsym = '\0';
+ /* Note: stdcall alias symbols can never be data. */
def_exports (exported_name, xstrdup (c), -1, 0, 0, 0);
}
}
@@ -1273,13 +1290,15 @@ scan_filtered_symbols (abfd, minisyms, s
if (bfd_get_symbol_leading_char (abfd) == symbol_name[0])
++symbol_name;
- def_exports (xstrdup (symbol_name) , 0, -1, 0, 0, 0);
+ def_exports (xstrdup (symbol_name) , 0, -1, 0, 0,
+ ! (sym->flags & BSF_FUNCTION));
if (add_stdcall_alias && strchr (symbol_name, '@'))
{
char *exported_name = xstrdup (symbol_name);
char *atsym = strchr (exported_name, '@');
*atsym = '\0';
+ /* Note: stdcall alias symbols can never be data. */
def_exports (exported_name, xstrdup (symbol_name), -1, 0, 0, 0);
}
}
@@ -1857,9 +1876,11 @@ gen_exp_file ()
/* We use a single underscore for MS compatibility, and a
double underscore for backward compatibility with old
cygwin releases. */
- fprintf (f, "\t%s\t__imp_%s\n", ASM_GLOBAL, exp->name);
+ if (create_compat_implib)
+ fprintf (f, "\t%s\t__imp_%s\n", ASM_GLOBAL, exp->name);
fprintf (f, "\t%s\t_imp__%s\n", ASM_GLOBAL, exp->name);
- fprintf (f, "__imp_%s:\n", exp->name);
+ if (create_compat_implib)
+ fprintf (f, "__imp_%s:\n", exp->name);
fprintf (f, "_imp__%s:\n", exp->name);
fprintf (f, "\t%s\t%s\n", ASM_LONG, exp->name);
}
@@ -2126,10 +2147,12 @@ make_one_lib_file (exp, i)
f = fopen (name, FOPEN_WT);
fprintf (f, "\t.text\n");
fprintf (f, "\t%s\t%s%s\n", ASM_GLOBAL, ASM_PREFIX, exp->name);
- fprintf (f, "\t%s\t__imp_%s\n", ASM_GLOBAL, exp->name);
+ if (create_compat_implib)
+ fprintf (f, "\t%s\t__imp_%s\n", ASM_GLOBAL, exp->name);
fprintf (f, "\t%s\t_imp__%s\n", ASM_GLOBAL, exp->name);
- fprintf (f, "%s%s:\n\t%s\t__imp_%s\n", ASM_PREFIX,
- exp->name, ASM_JUMP, exp->name);
+ if (create_compat_implib)
+ fprintf (f, "%s%s:\n\t%s\t__imp_%s\n", ASM_PREFIX,
+ exp->name, ASM_JUMP, exp->name);
fprintf (f, "\t.section\t.idata$7\t%s To force loading of head\n", ASM_C);
fprintf (f, "\t%s\t%s\n", ASM_LONG, head_label);
@@ -2138,7 +2161,8 @@ make_one_lib_file (exp, i)
fprintf (f,"%s Import Address Table\n", ASM_C);
fprintf (f, "\t.section .idata$5\n");
- fprintf (f, "__imp_%s:\n", exp->name);
+ if (create_compat_implib)
+ fprintf (f, "__imp_%s:\n", exp->name);
fprintf (f, "_imp__%s:\n", exp->name);
dump_iat (f, exp);
@@ -2266,11 +2290,14 @@ make_one_lib_file (exp, i)
/* Generate imp symbols with one underscore for Microsoft
compatibility, and with two underscores for backward
compatibility with old versions of cygwin. */
- iname = bfd_make_empty_symbol(abfd);
- iname->name = make_label ("__imp_", exp->name);
- iname->section = secdata[IDATA5].sec;
- iname->flags = BSF_GLOBAL;
- iname->value = 0;
+ if (create_compat_implib)
+ {
+ iname = bfd_make_empty_symbol(abfd);
+ iname->name = make_label ("__imp_", exp->name);
+ iname->section = secdata[IDATA5].sec;
+ iname->flags = BSF_GLOBAL;
+ iname->value = 0;
+ }
iname2 = bfd_make_empty_symbol(abfd);
iname2->name = make_label ("_imp__", exp->name);
@@ -2287,7 +2314,8 @@ make_one_lib_file (exp, i)
iname_pp = ptrs + oidx;
- ptrs[oidx++] = iname;
+ if (create_compat_implib)
+ ptrs[oidx++] = iname;
ptrs[oidx++] = iname2;
iname_lab_pp = ptrs + oidx;
@@ -3103,6 +3131,7 @@ usage (file, status)
fprintf (file, _(" -S --as <name> Use <name> for assembler.\n"));
fprintf (file, _(" -f --as-flags <flags> Pass <flags> to the assembler.\n"));
fprintf (file, _(" -n --no-delete Keep temp files (repeat for extra preservation).\n"));
+ fprintf (file, _(" -C --compat-implib Create backward compatible import library.\n"));
fprintf (file, _(" -v --verbose Be verbose.\n"));
fprintf (file, _(" -V --version Display the program version.\n"));
fprintf (file, _(" -h --help Display this information.\n"));
@@ -3146,6 +3175,7 @@ static const struct option long_options[
{"as", required_argument, NULL, 'S'},
{"as-flags", required_argument, NULL, 'f'},
{"mcore-elf", required_argument, NULL, 'M'},
+ {"compat-implib", no_argument, NULL, 'C'},
{0}
};
@@ -3266,6 +3296,9 @@ main (ac, av)
mcore_elf_linker_flags = optarg;
break;
#endif
+ case 'C':
+ create_compat_implib = 1;
+ break;
default:
usage (stderr, 1);
break;
More information about the Binutils
mailing list