Index: src/bfd/pe-x86_64.c =================================================================== --- src.orig/bfd/pe-x86_64.c 2010-04-17 16:30:01.126279000 +0200 +++ src/bfd/pe-x86_64.c 2010-04-22 08:20:25.604257600 +0200 @@ -28,7 +28,11 @@ #define COFF_WITH_PE #define COFF_WITH_pex64 #define PCRELOFFSET TRUE +#if defined (USE_MINGW64_LEADING_UNDERSCORES) #define TARGET_UNDERSCORE '_' +#else +#define TARGET_UNDERSCORE 0 +#endif #define COFF_LONG_SECTION_NAMES #define COFF_SUPPORT_GNU_LINKONCE #define COFF_LONG_FILENAMES Index: src/bfd/pei-x86_64.c =================================================================== --- src.orig/bfd/pei-x86_64.c 2010-04-17 16:30:01.129279000 +0200 +++ src/bfd/pei-x86_64.c 2010-04-22 08:20:25.610257600 +0200 @@ -29,7 +29,11 @@ #define COFF_WITH_PE #define COFF_WITH_pex64 #define PCRELOFFSET TRUE +#if defined (USE_MINGW64_LEADING_UNDERSCORES) #define TARGET_UNDERSCORE '_' +#else +#define TARGET_UNDERSCORE 0 +#endif /* Long section names not allowed in executable images, only object files. */ #define COFF_LONG_SECTION_NAMES 0 #define COFF_SUPPORT_GNU_LINKONCE Index: src/bfd/config.bfd =================================================================== --- src.orig/bfd/config.bfd 2010-04-17 16:30:01.121279000 +0200 +++ src/bfd/config.bfd 2010-04-17 16:30:14.389279200 +0200 @@ -639,7 +639,7 @@ case "${targ}" in targ_defvec=x86_64pe_vec targ_selvecs="x86_64pe_vec x86_64pei_vec bfd_elf64_x86_64_vec bfd_elf64_l1om_vec" want64=true - targ_underscore=yes + targ_underscore=no ;; #endif i[3-7]86-*-lynxos*) Index: src/binutils/dlltool.c =================================================================== --- src.orig/binutils/dlltool.c 2010-04-17 16:30:01.133279000 +0200 +++ src/binutils/dlltool.c 2010-04-22 08:20:25.617257600 +0200 @@ -4143,6 +4143,16 @@ main (int ac, char **av) /* Check if we generated PE+. */ create_for_pep = strcmp (mname, "i386:x86-64") == 0; + { + /* Check the default underscore */ + int u = leading_underscore; /* Underscoring mode. -1 for use default. */ + if (u == -1) + bfd_get_target_info (mtable[machine].how_bfd_target, NULL, + NULL, &u, NULL); + if (u != -1) + leading_underscore = (u != 0 ? TRUE : FALSE); + } + if (!dll_name && exp_name) { /* If we are inferring dll_name from exp_name, Index: src/bfd/coffcode.h =================================================================== --- src.orig/bfd/coffcode.h 2010-04-17 16:30:01.117279000 +0200 +++ src/bfd/coffcode.h 2010-04-17 17:02:06.752279200 +0200 @@ -2648,7 +2648,7 @@ coff_write_relocs (bfd * abfd, int first entries know which symbol index they point to. So we have to look up the output symbol here. */ - if (q->sym_ptr_ptr[0]->the_bfd != abfd) + if (q->sym_ptr_ptr[0] != NULL && q->sym_ptr_ptr[0]->the_bfd != abfd) { int j; const char *sname = q->sym_ptr_ptr[0]->name; @@ -2677,7 +2677,7 @@ coff_write_relocs (bfd * abfd, int first n.r_symndx = q->addend; else #endif - if (q->sym_ptr_ptr) + if (q->sym_ptr_ptr && q->sym_ptr_ptr[0] != NULL) { #ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q, s)) Index: src/ld/pe-dll.c =================================================================== --- src.orig/ld/pe-dll.c 2010-04-05 10:57:35.000000000 +0200 +++ src/ld/pe-dll.c 2010-04-18 12:53:58.338184400 +0200 @@ -385,7 +385,7 @@ static const autofilter_entry_type autof { STRING_COMMA_LEN ("__rtti_") }, { STRING_COMMA_LEN ("__builtin_") }, /* Don't re-export auto-imported symbols. */ - { STRING_COMMA_LEN ("_nm_") }, + { STRING_COMMA_LEN ("__nm_") }, /* Don't export symbols specifying internal DLL layout. */ { STRING_COMMA_LEN ("_head_") }, { STRING_COMMA_LEN ("_IMPORT_DESCRIPTOR_") }, @@ -2135,11 +2135,11 @@ make_one (def_file_export *exp, bfd *par /* Symbol to reference ord/name of imported data symbol, used to implement auto-import. */ if (exp->flag_data) - quick_symbol (abfd, U ("_nm_"), U (""), exp->internal_name, id6, + quick_symbol (abfd, "__nm_", U (""), exp->internal_name, id6, BSF_GLOBAL,0); } if (pe_dll_compat_implib) - quick_symbol (abfd, U ("__imp_"), exp->internal_name, "", id5, + quick_symbol (abfd, "___imp_", exp->internal_name, "", id5, BSF_GLOBAL, 0); if (include_jmp_stub) @@ -2286,7 +2286,7 @@ make_singleton_name_imp (const char *imp symptr = 0; symtab = xmalloc (3 * sizeof (asymbol *)); id5 = quick_section (abfd, ".idata$5", SEC_HAS_CONTENTS, 2); - quick_symbol (abfd, U ("_imp_"), import, "", id5, BSF_GLOBAL, 0); + quick_symbol (abfd, "__imp_", import, "", id5, BSF_GLOBAL, 0); /* We need space for the real thunk and for the null terminator. */ bfd_set_section_size (abfd, id5, PE_IDATA5_SIZE * 2); @@ -2327,8 +2327,8 @@ make_singleton_name_thunk (const char *i symptr = 0; symtab = xmalloc (3 * sizeof (asymbol *)); id4 = quick_section (abfd, ".idata$4", SEC_HAS_CONTENTS, 2); - quick_symbol (abfd, U ("_nm_thnk_"), import, "", id4, BSF_GLOBAL, 0); - quick_symbol (abfd, U ("_nm_"), import, "", UNDSEC, BSF_GLOBAL, 0); + quick_symbol (abfd, "__nm_thnk_", import, "", id4, BSF_GLOBAL, 0); + quick_symbol (abfd, "__nm_", import, "", UNDSEC, BSF_GLOBAL, 0); /* We need space for the real thunk and for the null terminator. */ bfd_set_section_size (abfd, id4, PE_IDATA4_SIZE * 2); @@ -2420,12 +2420,12 @@ make_import_fixup_entry (const char *nam symtab = xmalloc (6 * sizeof (asymbol *)); id2 = quick_section (abfd, ".idata$2", SEC_HAS_CONTENTS, 2); - quick_symbol (abfd, U ("_nm_thnk_"), name, "", UNDSEC, BSF_GLOBAL, 0); + quick_symbol (abfd, "__nm_thnk_", name, "", UNDSEC, BSF_GLOBAL, 0); quick_symbol (abfd, U (""), symname, "_iname", UNDSEC, BSF_GLOBAL, 0); /* For relocator v2 we have to use the .idata$5 element and not fixup_name. */ if (link_info.pei386_runtime_pseudo_reloc == 2) - quick_symbol (abfd, U ("_imp_"), name, "", UNDSEC, BSF_GLOBAL, 0); + quick_symbol (abfd, "__imp_", name, "", UNDSEC, BSF_GLOBAL, 0); else quick_symbol (abfd, "", fixup_name, "", UNDSEC, BSF_GLOBAL, 0); @@ -2495,7 +2495,7 @@ make_runtime_pseudo_reloc (const char *n size += 12; runtime_pseudp_reloc_v2_init = 1; } - quick_symbol (abfd, U ("_imp_"), name, "", UNDSEC, BSF_GLOBAL, 0); + quick_symbol (abfd, "__imp_", name, "", UNDSEC, BSF_GLOBAL, 0); bfd_set_section_size (abfd, rt_rel, size); rt_rel_d = xmalloc (size); @@ -2588,10 +2588,10 @@ pe_create_import_fixup (arelent *rel, as bfd *b; int need_import_table = 1; - sprintf (buf, U ("_imp_%s"), name); + sprintf (buf, "__imp_%s", name); name_imp_sym = bfd_link_hash_lookup (link_info.hash, buf, 0, 0, 1); - sprintf (buf, U ("_nm_thnk_%s"), name); + sprintf (buf, "__nm_thnk_%s", name); name_thunk_sym = bfd_link_hash_lookup (link_info.hash, buf, 0, 0, 1); @@ -2803,8 +2803,9 @@ pe_undef_alias_cdecl_match (struct bfd_l sl = strlen (string); if (h->type == bfd_link_hash_undefined - && ((*hs == '@' && *string == '_' - && strncmp (hs + 1, string + 1, sl - 1) == 0) + && ((*hs == '@' && (!pe_details->underscored || *string == '_') + && strncmp (hs + 1, string + (pe_details->underscored != 0), + sl - (pe_details->underscored != 0)) == 0) || strncmp (hs, string, sl) == 0) && h->root.string[sl] == '@') { @@ -3149,7 +3150,7 @@ pe_implied_import_dll (const char *filen /* Skip unwanted symbols, which are exported in buggy auto-import releases. */ - if (! CONST_STRNEQ (erva + name_rva, "_nm_")) + if (! CONST_STRNEQ (erva + name_rva, "__nm_")) { /* is_data is true if the address is in the data, rdata or bss segment. */ Index: src/bfd/config.in =================================================================== --- src.orig/bfd/config.in 2010-04-17 16:28:39.000000000 +0200 +++ src/bfd/config.in 2010-04-22 08:20:25.570257600 +0200 @@ -297,6 +297,9 @@ /* Use b modifier when opening binary files? */ #undef USE_BINARY_FOPEN +/* Define if we should use leading underscore on 64 bit mingw targets */ +#undef USE_MINGW64_LEADING_UNDERSCORES + /* Use mmap if it's available? */ #undef USE_MMAP Index: src/bfd/configure =================================================================== --- src.orig/bfd/configure 2010-04-17 16:28:39.000000000 +0200 +++ src/bfd/configure 2010-04-22 08:20:25.588257600 +0200 @@ -785,6 +785,7 @@ enable_64_bit_bfd enable_targets with_mmap enable_secureplt +enable_leading_mingw64_underscores with_separate_debug_dir enable_elf_stt_common with_pkgversion @@ -1435,6 +1436,8 @@ Optional Features: --enable-64-bit-bfd 64-bit support (on hosts with narrower word sizes) --enable-targets alternative target configurations --enable-secureplt Default to creating read-only plt entries + --enable-leading-mingw64-underscores + Enable leading underscores on 64 bit mingw targets --enable-elf-stt-common Allow the generation of ELF symbols with the STT_COMMON type --enable-werror treat compile warnings as errors --enable-build-warnings enable build-time compiler warnings @@ -11402,7 +11405,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11405 "configure" +#line 11408 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -11508,7 +11511,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11511 "configure" +#line 11514 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -12049,6 +12052,17 @@ $as_echo "#define USE_SECUREPLT 1" >>con fi +# Check whether --enable-leading-mingw64-underscores was given. +if test "${enable_leading_mingw64_underscores+set}" = set; then : + enableval=$enable_leading_mingw64_underscores; +fi + +if test x"$enable_leading_mingw64_underscores" = xyes ; then : + +$as_echo "#define USE_MINGW64_LEADING_UNDERSCORES 1" >>confdefs.h + +fi + DEBUGDIR=${libdir}/debug # Check whether --with-separate-debug-dir was given. Index: src/bfd/configure.in =================================================================== --- src.orig/bfd/configure.in 2010-04-17 16:28:39.000000000 +0200 +++ src/bfd/configure.in 2010-04-22 08:20:25.600257600 +0200 @@ -75,6 +75,14 @@ if test $use_secureplt = true; then [Define if we should default to creating read-only plt entries]) fi +AC_ARG_ENABLE(leading-mingw64-underscores, + AS_HELP_STRING([--enable-leading-mingw64-underscores], + [Enable leading underscores on 64 bit mingw targets]), + [],[]) +AS_IF([ test x"$enable_leading_mingw64_underscores" = xyes ], + [AC_DEFINE(USE_MINGW64_LEADING_UNDERSCORES, 1, + [Define if we should use leading underscore on 64 bit mingw targets])]) + DEBUGDIR=${libdir}/debug AC_ARG_WITH(separate-debug-dir, AS_HELP_STRING([--with-separate-debug-dir=DIR], Index: src/binutils/testsuite/binutils-all/dlltool.exp =================================================================== --- src.orig/binutils/testsuite/binutils-all/dlltool.exp 2010-03-31 18:24:03.000000000 +0200 +++ src/binutils/testsuite/binutils-all/dlltool.exp 2010-04-25 11:24:40.781403600 +0200 @@ -14,13 +14,14 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. -if {![istarget "i*86-*-*"] && ![istarget "x86_64-*-mingw*"] } { +if {![istarget "i*86-*-*"] && ![istarget "x86_64-*-mingw*"] && ![istarget "arm-*-pe*]} { return } if {![istarget "i*86-*-*pe*"] \ && ![istarget "i*86-*-cygwin*"] \ && ![istarget "i*86-*-mingw32*"] \ + && ![istarget "arm-*-pe*"] \ && ![istarget "x86_64-*-mingw*"] } { set target_xfail "yes" } else { @@ -35,8 +36,8 @@ if {[which $DLLTOOL] == 0} then { return } -verbose "$DLLTOOL -d $srcdir/$subdir/fastcall.def" 1 -catch "exec $DLLTOOL -d $srcdir/$subdir/fastcall.def" err +verbose "$DLLTOOL --leading-underscore -d $srcdir/$subdir/fastcall.def" 1 +catch "exec $DLLTOOL --leading-underscore -d $srcdir/$subdir/fastcall.def" err if ![string match "" $err] then { send_log "$err\n" @@ -50,8 +51,8 @@ if { "$target_xfail" == "yes" } { setup_xfail *-* } -verbose "$DLLTOOL -p prefix -l tmpdir/libalias.a -d $srcdir/$subdir/alias.def $dlltool_gas_flag" 1 -catch "exec $DLLTOOL -p prefix -l tmpdir/libalias.a -d $srcdir/$subdir/alias.def $dlltool_gas_flag" err +verbose "$DLLTOOL -p prefix --leading-underscore -l tmpdir/libalias.a -d $srcdir/$subdir/alias.def $dlltool_gas_flag" 1 +catch "exec $DLLTOOL -p prefix --leading-underscore -l tmpdir/libalias.a -d $srcdir/$subdir/alias.def $dlltool_gas_flag" err if ![string match "" $err] then { send_log "$err\n" @@ -80,8 +81,8 @@ if [regexp $want $got] then { fail "dlltool -p (import name)" } -verbose "$DLLTOOL -p prefix -l tmpdir/libalias2.a -d $srcdir/$subdir/alias-2.def $dlltool_gas_flag" 1 -catch "exec $DLLTOOL -p prefix -l tmpdir/libalias2.a -d $srcdir/$subdir/alias-2.def $dlltool_gas_flag" err +verbose "$DLLTOOL -p prefix --leading-underscore -l tmpdir/libalias2.a -d $srcdir/$subdir/alias-2.def $dlltool_gas_flag" 1 +catch "exec $DLLTOOL -p prefix --leading-underscore -l tmpdir/libalias2.a -d $srcdir/$subdir/alias-2.def $dlltool_gas_flag" err if ![string match "" $err] then { send_log "$err\n"