diff options
author | Rui Ueyama <ruiu@google.com> | 2014-04-24 20:12:01 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2014-04-24 20:12:01 +0000 |
commit | f550eba39c32b7aa7484869a82b4ba74b8515bf5 (patch) | |
tree | da6840c6c5e04a48f7f7cf9d8d73e1037db02515 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp | |
parent | b83dd55eb6fe366b572c58e805a509bb8c5479fc (diff) | |
download | bcm5719-llvm-f550eba39c32b7aa7484869a82b4ba74b8515bf5.tar.gz bcm5719-llvm-f550eba39c32b7aa7484869a82b4ba74b8515bf5.zip |
[PECOFF] Define implicit symbols for exported ones.
This patch is to fix a compatibility issue with MSVC link.exe as to
use of dllexported symbols inside DLL.
A DLL exports two symbols for a function. One is non-decorated one,
and the other is with __imp_ prefix. The former is a function that
you can directly call, and the latter is a pointer to the function.
These dllexported symbols are created by linker for programs that
link against the DLL. So, I naturally believed that __imp_ symbols
become available when you once create a DLL and link against it, but
they don't exist until then. And that's not true.
MSVC link.exe is smart enough to allow users to use __imp_ symbols
locally. That is, if a symbol is specified with /export option, it
implicitly creates a new symbol with __imp_ prefix as a pointer to
the exported symbol. This feature allows the following program to
be linked and run, although _imp__hello is not defined in this code.
#include <stdio.h>
__declspec(dllexport)
void hello(void) { printf("Hello\n"); }
extern void (*_imp__hello)(void);
int main() {
_imp__hello();
return 0;
}
MSVC link.exe prints out the following warning when linking it.
LNK4217: locally defined symbol _hello imported in function _main
Using __imp_ symbols locally is I think not a good coding style. One
should just take an address using "&" operator rather than appending
__imp_ prefix. However, there are programs in the wild that depends
on this link.exe's behavior, so we need this feature.
llvm-svn: 207141
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
0 files changed, 0 insertions, 0 deletions