This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
PATCH mingw32 PE dlltool: No ASM underscore for symbols beginningwith ?
- From: "Aaron W. LaFramboise" <aaron98wiridge9 at aaronwl dot com>
- To: binutils at sources dot redhat dot com
- Date: Sun, 27 Jun 2004 19:49:26 -0500
- Subject: PATCH mingw32 PE dlltool: No ASM underscore for symbols beginningwith ?
MS LINK and LIB do not generate a leading underscore for symbols that
begin with ? in .def files. The following patch matches this behavior.
These symbols are MSVC C++ mangled names. Without this patch, an
import library from a DLL with MSVC C++ exports will be incorrect,
causing link failures when linking MSVC C++ code.
(FYI, I have not yet been notified by the FSF of acceptance of my
copyright assignment forms. I'm not sure whether or not this patch is
considered trivial. With any luck, they'll get around to processing me
Monday.)
2004-06-27 Aaron W. LaFramboise <aaron98wiridge9@aaronwl.com>
* binutils/dlltool.c (asm_prefix): Add parameter: name.
No underscore for symbols beginning with ?.
(ASM_PREFIX): Add parameter: NAME.
(gen_exp_file): Use new parameter.
(make_label): Same.
(make_imp_label): Same.
(make_one_lib_file): Same.
Index: src/binutils/dlltool.c
===================================================================
RCS file: /cvs/src/src/binutils/dlltool.c,v
retrieving revision 1.49
diff -c -3 -p -r1.49 dlltool.c
*** src/binutils/dlltool.c 15 Jun 2004 01:19:13 -0000 1.49
--- src/binutils/dlltool.c 28 Jun 2004 00:36:54 -0000
*************** static struct string_list *excludes;
*** 664,670 ****
static const char *rvaafter (int);
static const char *rvabefore (int);
! static const char *asm_prefix (int);
static void process_def_file (const char *);
static void new_directive (char *);
static void append_import (const char *, const char *, int);
--- 664,670 ----
static const char *rvaafter (int);
static const char *rvabefore (int);
! static const char *asm_prefix (int, const char *);
static void process_def_file (const char *);
static void new_directive (char *);
static void append_import (const char *, const char *, int);
*************** rvabefore (int machine)
*** 795,801 ****
}
static const char *
! asm_prefix (int machine)
{
switch (machine)
{
--- 795,801 ----
}
static const char *
! asm_prefix (int machine, const char *name)
{
switch (machine)
{
*************** asm_prefix (int machine)
*** 810,816 ****
case MARM_EPOC:
break;
case M386:
! return "_";
default:
/* xgettext:c-format */
fatal (_("Internal error: Unknown machine type: %d"), machine
);
--- 810,820 ----
case MARM_EPOC:
break;
case M386:
! /* Symbol names starting with ? do not have a leading
underscore. */
! if (name && *name == '?')
! break;
! else
! return "_";
default:
/* xgettext:c-format */
fatal (_("Internal error: Unknown machine type: %d"), machine
);
*************** asm_prefix (int machine)
*** 819,844 ****
return "";
}
! #define ASM_BYTE mtable[machine].how_byte
! #define ASM_SHORT mtable[machine].how_short
! #define ASM_LONG mtable[machine].how_long
! #define ASM_TEXT mtable[machine].how_asciz
! #define ASM_C mtable[machine].how_comment
! #define ASM_JUMP mtable[machine].how_jump
! #define ASM_GLOBAL mtable[machine].how_global
! #define ASM_SPACE mtable[machine].how_space
! #define ASM_ALIGN_SHORT mtable[machine].how_align_short
! #define ASM_RVA_BEFORE rvabefore(machine)
! #define ASM_RVA_AFTER rvaafter(machine)
! #define ASM_PREFIX asm_prefix(machine)
! #define ASM_ALIGN_LONG mtable[machine].how_align_long
! #define HOW_BFD_READ_TARGET 0 /* always default*/
! #define HOW_BFD_WRITE_TARGET mtable[machine].how_bfd_target
! #define HOW_BFD_ARCH mtable[machine].how_bfd_arch
! #define HOW_JTAB mtable[machine].how_jtab
! #define HOW_JTAB_SIZE mtable[machine].how_jtab_size
! #define HOW_JTAB_ROFF mtable[machine].how_jtab_roff
! #define ASM_SWITCHES mtable[machine].how_default_as_switches
static char **oav;
--- 823,848 ----
return "";
}
! #define ASM_BYTE mtable[machine].how_byte
! #define ASM_SHORT mtable[machine].how_short
! #define ASM_LONG mtable[machine].how_long
! #define ASM_TEXT mtable[machine].how_asciz
! #define ASM_C mtable[machine].how_comment
! #define ASM_JUMP mtable[machine].how_jump
! #define ASM_GLOBAL mtable[machine].how_global
! #define ASM_SPACE mtable[machine].how_space
! #define ASM_ALIGN_SHORT mtable[machine].
how_align_short
! #define ASM_RVA_BEFORE rvabefore(machine)
! #define ASM_RVA_AFTER rvaafter(machine)
! #define ASM_PREFIX(NAME) asm_prefix(machine, (NAME))
! #define ASM_ALIGN_LONG mtable[machine].how_align_long
! #define HOW_BFD_READ_TARGET 0 /* always default*/
! #define HOW_BFD_WRITE_TARGET mtable[machine].how_bfd_target
! #define HOW_BFD_ARCH mtable[machine].how_bfd_arch
! #define HOW_JTAB mtable[machine].how_jtab
! #define HOW_JTAB_SIZE mtable[machine].how_jtab_size
! #define HOW_JTAB_ROFF mtable[machine].how_jtab_roff
! #define ASM_SWITCHES mtable[machine].
how_default_as_switches
static char **oav;
*************** gen_exp_file (void)
*** 1816,1822 ****
exp->internal_name, ASM_RVA_AFTER, ASM_C,
exp->ordinal);
else
fprintf (f, "\t%s%s%s%s\t%s %d\n", ASM_RVA_BEFORE,
! ASM_PREFIX,
exp->internal_name, ASM_RVA_AFTER, ASM_C,
exp->ordinal);
}
else
--- 1820,1826 ----
exp->internal_name, ASM_RVA_AFTER, ASM_C,
exp->ordinal);
else
fprintf (f, "\t%s%s%s%s\t%s %d\n", ASM_RVA_BEFORE,
! ASM_PREFIX(exp->internal_name),
exp->internal_name, ASM_RVA_AFTER, ASM_C,
exp->ordinal);
}
else
*************** ID2: .short 2
*** 2150,2159 ****
static char *
make_label (const char *prefix, const char *name)
{
! int len = strlen (ASM_PREFIX) + strlen (prefix) + strlen (name);
char *copy = xmalloc (len +1 );
! strcpy (copy, ASM_PREFIX);
strcat (copy, prefix);
strcat (copy, name);
return copy;
--- 2154,2163 ----
static char *
make_label (const char *prefix, const char *name)
{
! int len = strlen (ASM_PREFIX(name)) + strlen (prefix) + strlen (
name);
char *copy = xmalloc (len +1 );
! strcpy (copy, ASM_PREFIX(name));
strcat (copy, prefix);
strcat (copy, name);
return copy;
*************** make_imp_label (const char *prefix, cons
*** 2174,2183 ****
}
else
{
! len = strlen (ASM_PREFIX) + strlen (prefix) + strlen (name);
copy = xmalloc (len + 1);
strcpy (copy, prefix);
! strcat (copy, ASM_PREFIX);
strcat (copy, name);
}
return copy;
--- 2178,2187 ----
}
else
{
! len = strlen (ASM_PREFIX(name)) + strlen (prefix) + strlen (
name);
copy = xmalloc (len + 1);
strcpy (copy, prefix);
! strcat (copy, ASM_PREFIX(name));
strcat (copy, name);
}
return copy;
*************** make_one_lib_file (export_type *exp, int
*** 2197,2208 ****
sprintf (name, "%ss%05d.s", prefix, 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
);
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);
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);
--- 2201,2212 ----
sprintf (name, "%ss%05d.s", prefix, 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),
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);
if (create_compat_implib)
! fprintf (f, "%s%s:\n\t%s\t__imp_%s\n", ASM_PREFIX(exp->name),
exp->name, ASM_JUMP, exp->name);
fprintf (f, "\t.section\t.idata$7\t%s To force loading of
head\n", ASM_C);