[Issue 1695] implib produces wrong *.lib files

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Oct 21 03:58:11 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=1695


Denis Shelomovskij <verylonglogin.reg at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |verylonglogin.reg at gmail.com
            Version|2.007                       |unspecified
         Resolution|INVALID                     |
            Summary|Calling some functions out  |implib produces wrong *.lib
                   |of PSAPI.dll corrupts stack |files


--- Comment #2 from Denis Shelomovskij <verylonglogin.reg at gmail.com> 2012-10-21 14:58:05 MSD ---
(In reply to comment #1)
> The problem is declaring Windows API functions as being extern(C). They should
> be extern(Windows). Stack corruption is the result of incorrectly declaring
> what function calling convention to use.

Looks like Walter like spending people time. As "extern(Windows)" and
"extern(C)" functions has different symbol names the fact that the program
links, runs and corrupts the stack just shows that `implib` generates incorrect
*.lib files.


Incorrect behavior example (DLL):

implib /noi /system psapi-from-dll.lib %windir%\system32\psapi.dll

---
pragma(lib, "psapi-from-dll.lib");

extern(C) nothrow extern void EnumProcesses(); // links fine

void main()
{
    auto p = &EnumProcesses;
}
---


More than that 'implib' works incorrect with '.def' files too.
Incorrect behavior example (DEF):

psapi.def (from mingw except library name is "PSAPI" instead of "PSAPI.DLL"
because 'implib' stops on dot with error):
---
LIBRARY PSAPI
EXPORTS
EnumProcesses at 12
---

implib /noi /system psapi-from-def.lib psapi.def

---
pragma(lib, "psapi-from-def.lib");

// Error 42: Symbol Undefined _EnumProcesses
// or _EnumProcesses at 12 for extern(Windows)
extern(C) nothrow extern void EnumProcesses(int, int, int);

void main()
{
    auto p = &EnumProcesses;
}
---

The second issue is because 'implib' ignores '/system' switch for *.def files:

implib /noi psapi-from-def-no-system.lib psapi.def

produces exactly same *.lib file.



The second issue has trivial workaround: one should prefix all symbols in *.def
file with '_' by hands. E.g. such *.def file finally forces 'implib' to produce
a correct *.lib:
---
LIBRARY PSAPI
EXPORTS
_EnumProcesses at 12
---

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list