dllimport and __asm__("_alias" )
Danny Smith
dannysmith@clear.net.nz
Sat Feb 3 10:32:00 GMT 2007
Hello,
I would appreciate help with
While working on some dllimport problems with aliased symbols, I ran
across this inconsistency with gcc (all versions)
The use of a literal asmspec to rename a static lib symbol
(say "bar"),
extern void foo (void) __asm__("_bar");
void call_bar(void)
{ foo(); }
does the right thing. The literal is treated as a verbatim asm name,
so explicitly adding the '_' USER_LABEL_PREFIX to "bar" is necesssry:
_call_bar:
pushl %ebp
movl %esp, %ebp
popl %ebp
jmp _bar
However,if we try to alias a dllimport'd symbol,
like so
extern __declspec(dllimport) void foo (void) __asm__("_bar");
void call_bar(void)
{ foo(); }
The literal is not treated as verbatim, but _imp_ prefix as well as
additional USER_LABEL_PREFIX to bar is generated
_call_bar:
pushl %ebp
movl __imp___bar, %ecx <<< 3 underscores betweem imp and bar
movl %esp, %ebp
popl %ebp
jmp *%ecx
The above will lead to link error if the user name for the exported
symbol is "bar".
My feeling is that to avoid confusion, an asmspec'd alias should
really,really always be verbatim, no adding import prefix, stdcall
suffix, nor C++mangling, nothing. That is the way gcc works on other
targets.
That is, to do the right thing, we would need to:
extern __declspec(dllimport) void foo (void) __asm__("__imp__bar");
void call_bar(void)
{ foo(); }
to get
_call_bar:
pushl %ebp
movl __imp__bar, %ecx
movl %esp, %ebp
popl %ebp
jmp *%ecx
Any comments, before I submit the patch to gcc?
Should gcc warn if the asmspec of a dllimport alias lacks the "__imp__".
Danny
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
More information about the Cygwin
mailing list