1306 – extern (Windows) should work like extern (C) for variables

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1306 - extern (Windows) should work like extern (C) for variables
Summary: extern (Windows) should work like extern (C) for variables
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: Walter Bright
URL:
Keywords: link-failure
Depends on:
Blocks:
Reported: 2007年07月02日 03:21 UTC by torhu
Modified: 2014年02月16日 15:22 UTC (History)
0 users

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description torhu 2007年07月02日 03:21:51 UTC
In some cases, extern (Windows) causes '@0' to get added to the end of symbols that represent variables. This causes linking errors. I wasn't able to create a simple test case, but the problem should be clear.
Scenario:
I have a few hundred function pointers in a C library. To link with those, I have to use extern (C). But to actually call the functions, I need the function pointers to have type extern (Windows). Since extern (Windows) changes the mangling of the pointers, I can't link both link with the C library, and call the functions successfully. So I'm stuck, and probably need some ugly workaround.
I compiled 'int __stdcall x;' with msvc 6, which it accepted with a warning. Looking at the object file, the symbol was not affected by __stdcall. So DMD's behavior is probably wrong.
Comment 1 Brad Roberts 2007年07月02日 10:33:19 UTC
Please include a set of reproduction steps, including source code.
Comment 2 torhu 2007年07月02日 11:41:02 UTC
I nailed, it's another problem with the export keyword.
stdcall.d:
---
export extern (Windows) void (*funcptr)(int);
void main()
{
 funcptr(5);
}
---
Just to show how funcptr gets mangled:
c:\prog\test\D>dmd stdcall
c:\prog\dmd\bin\..\..\dm\bin\link.exe stdcall,,,user32+kernel32/noi;
OPTLINK (R) for Win32 Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved
c:\prog\dmd\bin\..\lib\phobos.lib(dmain2)
 Error 42: Symbol Undefined _funcptr@0
--- errorlevel 1
funcptr is mangled as _funcptr@0, which I believe is a stdcall function of zero arguments. This is clearly wrong, and won't link with the corresponding C definition of the function pointer.
Comment 3 Walter Bright 2007年07月30日 15:48:53 UTC
Fixed DMD 1.019 and 2.003


AltStyle によって変換されたページ (->オリジナル) /