diff options
author | Luca Bacci <luca.bacci@outlook.com> | 2023-05-17 13:38:14 +0100 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2023-05-17 13:38:14 +0100 |
commit | 80d4e113d7b9af8a5a36e5ea4399bca86050784f (patch) | |
tree | a471fa8b0176805e795dd73a3a97b5af94630482 /ld | |
parent | 80b6c32f233ed28607643c4e4e4e2ee3399fdfd7 (diff) | |
download | binutils-80d4e113d7b9af8a5a36e5ea4399bca86050784f.zip binutils-80d4e113d7b9af8a5a36e5ea4399bca86050784f.tar.gz binutils-80d4e113d7b9af8a5a36e5ea4399bca86050784f.tar.bz2 |
Decorated symbols in import libs (BUG 30421)
PR 30421
* cofflink.c (_decoration_hash_newfunc): New function. (_bfd_coff_link_hash_table_init): Call it.
* libcoff-in.h (struct coff_link_hash_table): Add decoration_hash field. (struct decoration_hash_entry): Declare. (_decoration_hash_newfunc): Prototype.
* libcoff.h: Regenerate.
* emultempl/pe.em (set_decoration): New function. (pe_fixup_stdcalls): Call the new function.
* emultempl/pep.em (set_decoration): New function. (pep_fixup_stdcalls): Call the new function.
* pe-dll.c (make_one): Check for decoated symbols.
Diffstat (limited to 'ld')
-rw-r--r-- | ld/ChangeLog | 9 | ||||
-rw-r--r-- | ld/emultempl/pe.em | 29 | ||||
-rw-r--r-- | ld/emultempl/pep.em | 25 | ||||
-rw-r--r-- | ld/pe-dll.c | 39 |
4 files changed, 94 insertions, 8 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog index ae1b34a..1acef2a 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,12 @@ +2023-05-17 Luca Bacci <luca.bacci@outlook.com> + + PR 30421 + * emultempl/pe.em (set_decoration): New function. + (pe_fixup_stdcalls): Call the new function. + * emultempl/pep.em (set_decoration): New function. + (pep_fixup_stdcalls): Call the new function. + * pe-dll.c (make_one): Check for decoated symbols. + 2023-05-16 Nick Clifton <nickc@redhat.com> PR 30359 diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em index 38cb611..7d956bf 100644 --- a/ld/emultempl/pe.em +++ b/ld/emultempl/pe.em @@ -1189,6 +1189,30 @@ change_undef (struct bfd_link_hash_entry * undef, } static void +set_decoration (const char *undecorated_name, + struct bfd_link_hash_entry * decoration) +{ + static bool gave_warning_message = false; + struct decoration_hash_entry *entry; + + if (is_underscoring () && undecorated_name[0] == '_') + undecorated_name++; + + entry = (struct decoration_hash_entry *) + bfd_hash_lookup (&(coff_hash_table (&link_info)->decoration_hash), + undecorated_name, true /* create */, false /* copy */); + + if (entry->decorated_link != NULL && !gave_warning_message) + { + einfo (_("%P: warning: overwriting decorated name %s with %s\n"), + entry->decorated_link->root.string, undecorated_name); + gave_warning_message = true; + } + + entry->decorated_link = decoration; +} + +static void pe_fixup_stdcalls (void) { struct bfd_link_hash_entry *undef, *sym; @@ -1231,7 +1255,10 @@ pe_fixup_stdcalls (void) bfd_link_hash_traverse (link_info.hash, pe_undef_cdecl_match, (char *) name); if (pe_undef_found_sym) - change_undef (undef, pe_undef_found_sym); + { + change_undef (undef, pe_undef_found_sym); + set_decoration (undef->root.string, pe_undef_found_sym); + } } } } diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em index 32883b2..99e7195 100644 --- a/ld/emultempl/pep.em +++ b/ld/emultempl/pep.em @@ -1120,6 +1120,30 @@ pep_undef_cdecl_match (struct bfd_link_hash_entry *h, void *inf) } static void +set_decoration (const char *undecorated_name, + struct bfd_link_hash_entry * decoration) +{ + static bool gave_warning_message = false; + struct decoration_hash_entry *entry; + + if (is_underscoring () && undecorated_name[0] == '_') + undecorated_name++; + + entry = (struct decoration_hash_entry *) + bfd_hash_lookup (&(coff_hash_table (&link_info)->decoration_hash), + undecorated_name, true /* create */, false /* copy */); + + if (entry->decorated_link != NULL && !gave_warning_message) + { + einfo (_("%P: warning: overwriting decorated name %s with %s\n"), + entry->decorated_link->root.string, undecorated_name); + gave_warning_message = true; + } + + entry->decorated_link = decoration; +} + +static void pep_fixup_stdcalls (void) { static int gave_warning_message = 0; @@ -1180,6 +1204,7 @@ pep_fixup_stdcalls (void) undef->type = bfd_link_hash_defined; undef->u.def.value = sym->u.def.value; undef->u.def.section = sym->u.def.section; + set_decoration (undef->root.string, sym); if (pep_enable_stdcall_fixup == -1) { diff --git a/ld/pe-dll.c b/ld/pe-dll.c index 8d74dba..e45ae10 100644 --- a/ld/pe-dll.c +++ b/ld/pe-dll.c @@ -2321,6 +2321,31 @@ make_one (def_file_export *exp, bfd *parent, bool include_jmp_stub) bfd *abfd; const unsigned char *jmp_bytes = NULL; int jmp_byte_count = 0; + const char *internal_name = exp->internal_name; + + if (!exp->flag_noname) + { + /* Check for a decorated symbol name */ + struct decoration_hash_entry *entry; + + entry = (struct decoration_hash_entry *) + bfd_hash_lookup (&(coff_hash_table (&link_info)->decoration_hash), + internal_name, false, false); + if (entry) + { + if (entry->decorated_link) + { + internal_name = entry->decorated_link->root.string; + + if (pe_details->underscored && internal_name[0] == '_') + internal_name++; + } + else + { + einfo (_("%P: error: NULL decorated name for %s\n"), internal_name); + } + } + } /* Include the jump stub section only if it is needed. A jump stub is needed if the symbol being imported <sym> is a function @@ -2382,13 +2407,13 @@ make_one (def_file_export *exp, bfd *parent, bool include_jmp_stub) id4 = quick_section (abfd, ".idata$4", SEC_HAS_CONTENTS, 2); id6 = quick_section (abfd, ".idata$6", SEC_HAS_CONTENTS, 2); - if (*exp->internal_name == '@') + if (*internal_name == '@') { quick_symbol (abfd, U ("_head_"), dll_symname, "", UNDSEC, BSF_GLOBAL, 0); if (include_jmp_stub) - quick_symbol (abfd, "", exp->internal_name, "", tx, BSF_GLOBAL, 0); - quick_symbol (abfd, "__imp_", exp->internal_name, "", id5, + quick_symbol (abfd, "", internal_name, "", tx, BSF_GLOBAL, 0); + quick_symbol (abfd, "__imp_", internal_name, "", id5, BSF_GLOBAL, 0); /* Fastcall applies only to functions, so no need for auto-import symbol. */ @@ -2398,18 +2423,18 @@ make_one (def_file_export *exp, bfd *parent, bool include_jmp_stub) quick_symbol (abfd, U ("_head_"), dll_symname, "", UNDSEC, BSF_GLOBAL, 0); if (include_jmp_stub) - quick_symbol (abfd, U (""), exp->internal_name, "", tx, + quick_symbol (abfd, U (""), internal_name, "", tx, BSF_GLOBAL, 0); - quick_symbol (abfd, "__imp_", U (""), exp->internal_name, id5, + quick_symbol (abfd, "__imp_", U (""), internal_name, id5, BSF_GLOBAL, 0); /* Symbol to reference ord/name of imported data symbol, used to implement auto-import. */ if (exp->flag_data) - quick_symbol (abfd, "__nm_", U (""), exp->internal_name, id6, + quick_symbol (abfd, "__nm_", U (""), internal_name, id6, BSF_GLOBAL,0); } if (pe_dll_compat_implib) - quick_symbol (abfd, "___imp_", exp->internal_name, "", id5, + quick_symbol (abfd, "___imp_", internal_name, "", id5, BSF_GLOBAL, 0); if (include_jmp_stub) |