Index: src/ld/emultempl/pe.em =================================================================== --- src.orig/ld/emultempl/pe.em 2010-05-10 17:58:08.464711000 +0200 +++ src/ld/emultempl/pe.em 2010-05-10 17:58:44.766374500 +0200 @@ -145,6 +145,17 @@ static void gld_${EMULATION_NAME}_before_parse (void) { + int u; + /* Now we check target's default for getting proper symbol_char. */ + u = pe_leading_underscore; + if (u == -1 + && !bfd_get_target_info ("${OUTPUT_FORMAT}", NULL, NULL, &u, NULL)) + bfd_get_target_info ("${RELOCATEABLE_OUTPUT_FORMAT}", NULL, NULL, &u, NULL); + + if (u == -1) + abort (); + pe_leading_underscore = u; + ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`); output_filename = "${EXECUTABLE_NAME:-a.exe}"; #ifdef DLL_SUPPORT @@ -463,7 +474,17 @@ static void set_pe_name (char *name, long val) { - int i; + int i, u; + + /* Now we check target's default for getting proper symbol_char. */ + u = pe_leading_underscore; + if (u == -1 + && !bfd_get_target_info ("${OUTPUT_FORMAT}", NULL, NULL, &u, NULL)) + bfd_get_target_info ("${RELOCATEABLE_OUTPUT_FORMAT}", NULL, NULL, &u, NULL); + + if (u == -1) + abort (); + pe_leading_underscore = u; /* Find the name and set it. */ for (i = 0; init[i].ptr; i++) @@ -530,15 +551,13 @@ /* Now we check target's default for getting proper symbol_char. */ u = pe_leading_underscore; - if (u == -1 && !bfd_get_target_info ("${OUTPUT_FORMAT}", NULL, NULL, &u, NULL)) + if (u == -1 + && !bfd_get_target_info ("${OUTPUT_FORMAT}", NULL, NULL, &u, NULL)) bfd_get_target_info ("${RELOCATEABLE_OUTPUT_FORMAT}", NULL, NULL, &u, NULL); - if (u == 0) - initial_symbol_char = ""; - else if (u != -1) - initial_symbol_char = "_"; - else + if (u == -1) abort (); + initial_symbol_char = (u == 1 ? "_" : ""); pe_leading_underscore = u; if (*initial_symbol_char != '\0') @@ -896,7 +915,16 @@ { /* Run through and invent symbols for all the names and insert the defaults. */ - int j; + int j, u; + /* Now we check target's default for getting proper symbol_char. */ + u = pe_leading_underscore; + if (u == -1 + && !bfd_get_target_info ("${OUTPUT_FORMAT}", NULL, NULL, &u, NULL)) + bfd_get_target_info ("${RELOCATEABLE_OUTPUT_FORMAT}", NULL, NULL, &u, NULL); + + if (u == -1) + abort (); + pe_leading_underscore = u; if (!init[IMAGEBASEOFF].inited) { Index: src/ld/emultempl/pep.em =================================================================== --- src.orig/ld/emultempl/pep.em 2010-05-10 17:58:08.464711000 +0200 +++ src/ld/emultempl/pep.em 2010-05-10 17:58:44.766374500 +0200 @@ -118,6 +118,17 @@ static void gld_${EMULATION_NAME}_before_parse (void) { + int u; + /* Now we check target's default for getting proper symbol_char. */ + u = pep_leading_underscore; + if (u == -1 + && !bfd_get_target_info ("${OUTPUT_FORMAT}", NULL, NULL, &u, NULL)) + bfd_get_target_info ("${RELOCATEABLE_OUTPUT_FORMAT}", NULL, NULL, &u, NULL); + + if (u == -1) + abort (); + pep_leading_underscore = u; + ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`); output_filename = "${EXECUTABLE_NAME:-a.exe}"; #ifdef DLL_SUPPORT @@ -286,16 +297,16 @@ #define GET_INIT_SYMBOL_NAME(IDX) \ (init[(IDX)].symbol \ - + ((init[(IDX)].is_c_symbol == FALSE || pep_leading_underscore != 0) ? 0 : 1)) + + ((init[(IDX)].is_c_symbol == FALSE || pep_leading_underscore == 1) ? 0 : 1)) /* Decorates the C visible symbol by underscore, if target requires. */ #define U(CSTR) \ - (pep_leading_underscore == 0 ? CSTR : "_" CSTR) + (pep_leading_underscore != 1 ? CSTR : "_" CSTR) /* Get size of constant string for a possible underscore prefixed C visible symbol. */ #define U_SIZE(CSTR) \ - (sizeof (CSTR) + pep_leading_underscore == 0 ? 0 : 1) + (sizeof (CSTR) + pep_leading_underscore == 1 ? 0 : 1) #define D(field,symbol,def,usc) {&pep.field,sizeof(pep.field), def, symbol,0, usc} @@ -400,7 +411,17 @@ static void set_pep_name (char *name, bfd_vma val) { - int i; + int i, u; + + /* Now we check target's default for getting proper symbol_char. */ + u = pep_leading_underscore; + if (u == -1 + && !bfd_get_target_info ("${OUTPUT_FORMAT}", NULL, NULL, &u, NULL)) + bfd_get_target_info ("${RELOCATEABLE_OUTPUT_FORMAT}", NULL, NULL, &u, NULL); + + if (u == -1) + abort (); + pep_leading_underscore = u; /* Find the name and set it. */ for (i = 0; init[i].ptr; i++) @@ -462,15 +483,13 @@ /* Now we check target's default for getting proper symbol_char. */ u = pep_leading_underscore; - if (u == -1 && !bfd_get_target_info ("${OUTPUT_FORMAT}", NULL, NULL, &u, NULL)) + if (u == -1 + && !bfd_get_target_info ("${OUTPUT_FORMAT}", NULL, NULL, &u, NULL)) bfd_get_target_info ("${RELOCATEABLE_OUTPUT_FORMAT}", NULL, NULL, &u, NULL); - if (u == 0) - initial_symbol_char = ""; - else if (u != -1) - initial_symbol_char = "_"; - else + if (u == -1) abort (); + initial_symbol_char = (u == 1 ? "_" : ""); pep_leading_underscore = u; if (*initial_symbol_char != '\0') @@ -821,7 +840,16 @@ { /* Run through and invent symbols for all the names and insert the defaults. */ - int j; + int j, u; + /* Now we check target's default for getting proper symbol_char. */ + u = pep_leading_underscore; + if (u == -1 + && !bfd_get_target_info ("${OUTPUT_FORMAT}", NULL, NULL, &u, NULL)) + bfd_get_target_info ("${RELOCATEABLE_OUTPUT_FORMAT}", NULL, NULL, &u, NULL); + + if (u == -1) + abort (); + pep_leading_underscore = u; if (!init[IMAGEBASEOFF].inited) {