[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: windows static archive, missing symbols
From: |
Brian Dessent |
Subject: |
Re: windows static archive, missing symbols |
Date: |
Sat, 20 Jan 2007 08:30:17 -0800 |
Howard Chu wrote:
> That's false. It's just an address relocation, performed by the runtime
> linker. Writing code that requires XXX_STATIC macros is nothing but
> ignorant, and hasn't been necessary for at least 5 years.
You know I did actually test this before posting. Go on, do a hello
world that calls a dllimported function. Here is the testcase I used:
#include <stdio.h>
void foo(void);
int main()
{
puts("main");
foo();
}
Without any __declspec on the declaration to foo, the disassembly in the
debugger is:
6 {
0x401050 <main>: push %ebp
0x401051 <main+1>: mov $0x10,%eax
0x401056 <main+6>: mov %esp,%ebp
0x401058 <main+8>: sub $0x8,%esp
0x40105b <main+11>: and $0xfffffff0,%esp
0x40105e <main+14>: call 0x401090 <_alloca>
0x401063 <main+19>: call 0x401120 <__main>
7 puts("main");
0x401068 <main+24>: movl $0x402000,(%esp)
0x40106f <main+31>: call 0x401130 <puts>
8 foo();
0x401074 <main+36>: call 0x401080 <foo>
9 }
0x401079 <main+41>: leave
0x40107a <main+42>: ret
And note that 0x401080 <foo> is the import stub that calls __imp_foo:
0x401080 <foo>: jmp *0x404098
Now, add the __declspec(dllimport) and recompile. This is what you get
now:
6 {
0x401050 <main>: push %ebp
0x401051 <main+1>: mov $0x10,%eax
0x401056 <main+6>: mov %esp,%ebp
0x401058 <main+8>: sub $0x8,%esp
0x40105b <main+11>: and $0xfffffff0,%esp
0x40105e <main+14>: call 0x401090 <_alloca>
0x401063 <main+19>: call 0x401120 <__main>
7 puts("main");
0x401068 <main+24>: movl $0x402000,(%esp)
0x40106f <main+31>: call 0x401130 <puts>
8 foo();
0x401074 <main+36>: call *0x404098
9 }
0x40107a <main+42>: leave
0x40107b <main+43>: ret
Note that here you get a direct call to the .idata location of the
imported address (__imp_foo aka 0x0404098) without the extra call.
So, no, it is not the same to omit dllimport, there is a (small) speed
penalty. And there was recently a patch posted and applied to binutils
that will eliminate these stubs if they are not necessary so once you
upgrade your binutils there will be a size penalty to not using
dllimport also.
Brian
- windows static archive, missing symbols, Bob Rossi, 2007/01/19
- Re: windows static archive, missing symbols, Howard Chu, 2007/01/19
- Re: windows static archive, missing symbols, Bob Rossi, 2007/01/20
- Re: windows static archive, missing symbols, Bob Rossi, 2007/01/20
- Re: windows static archive, missing symbols, Howard Chu, 2007/01/20
- Re: windows static archive, missing symbols, Brian Dessent, 2007/01/20
- Re: windows static archive, missing symbols, Howard Chu, 2007/01/20
- Re: windows static archive, missing symbols,
Brian Dessent <=
Re: windows static archive, missing symbols, Brian Dessent, 2007/01/19