Bug 30421 - Symbols in import lib are influenced by .def file
Summary: Symbols in import lib are influenced by .def file
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.39
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-05-04 19:52 UTC by Luca Bacci
Modified: 2023-12-08 11:26 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
draft patch (2.43 KB, patch)
2023-05-12 18:59 UTC, Luca Bacci
Details | Diff
draft patch rev2 (2.57 KB, patch)
2023-05-13 10:56 UTC, Luca Bacci
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Luca Bacci 2023-05-04 19:52:07 UTC
Hello!

I'm experiencing an issue when building a shared library / DLL for the x86 architecture using gcc. All public functions use the __stdcall calling convention and are exported using a .def file so to have undecorated names in the resulting DLL. That is helpful for users that want to use GetProcAddress().

However gcc generates an import lib with undecorated names also in the symbols table. That causes linking errors, because the compiler can only know about decorated symbols.

The error doesn't happen when building with other compilers like clang or msvc. The resulting import libraries always have decorated symbols.

See also the relevant discussion at https://sourceforge.net/p/mingw-w64/mailman/message/37839853/

Thank you very much!
Luca Bacci
Comment 1 Luca Bacci 2023-05-04 20:00:30 UTC
As linked in the discussion, there's a sample repo at https://github.com/lb90/my-shared-lib

Another report of the issue is at https://github.com/KhronosGroup/OpenCL-ICD-Loader/issues/191

Thanks,
Luca
Comment 2 Luca Bacci 2023-05-12 18:59:41 UTC
Created attachment 14877 [details]
draft patch
Comment 3 Luca Bacci 2023-05-13 10:56:06 UTC
Created attachment 14878 [details]
draft patch rev2
Comment 4 LIU Hao 2023-05-14 08:50:38 UTC
From binutils/MAINTAINERS: 


```
The home page for binutils is:

  http://www.gnu.org/software/binutils/binutils.html

and patches should be sent to:

  binutils@sourceware.org
```
Comment 5 Luca Bacci 2023-05-15 14:18:40 UTC
Ah, true! I have now sent an email: https://sourceware.org/pipermail/binutils/2023-May/127440.html
Comment 6 Sourceware Commits 2023-05-17 12:39:22 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=80d4e113d7b9af8a5a36e5ea4399bca86050784f

commit 80d4e113d7b9af8a5a36e5ea4399bca86050784f
Author: Luca Bacci <luca.bacci@outlook.com>
Date:   Wed May 17 13:38:14 2023 +0100

    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.
Comment 7 Luca Bacci 2023-12-08 11:26:49 UTC
Fixed with commit 80d4e113