I am having the same problem, and I tried the answer provided by Suma above. I have no trouble getting the linker to find my overridden EncodePointer/DecodePointer import vectors, but the program consistently crashes at runtime. (Segfault -> bad instruction pointer). I've stepped through the disassembly and it all looks solid to me -- I have no idea what is going on.
Compile this file:
extern "C" {
void * __stdcall imp_DecodePointer(void *x) {return x;}
void * __stdcall imp_EncodePointer(void *x) {return x;}
};
int main( void )
{
return 0;
}
with MSVC 2010:
cl.exe /c main.cpp
link.exe main.obj
I've tried every permutation of /NODEFAULTLIB for kernel32.lib and libcmt.lib. The program crashes consistently on a call to EncodePointer made by the CRT initialization functions. Stack trace:
0034ff30 00b92075 00000000 00b912e8 76f51484 0x31e9
0034ff38 00b912e8 76f51484 00b924e8 00000000 main!_encoded_null+0x8 [f:\dd\vctools\crt_bld\self_x86\crt\src\tidtable.c @ 81]
0034ff40 00b924e8 00000000 00000000 00b91150 main!_init_pointers+0x8 [f:\dd\vctools\crt_bld\self_x86\crt\src\crt0dat.c @ 810]
0034ff4c 00b91150 a4cfec4b 00000000 00000000 main!_mtinit+0xcb [f:\dd\vctools\crt_bld\self_x86\crt\src\tidtable.c @ 256]
0034ff88 76f53677 7efde000 0034ffd4 77479d72 main!__tmainCRTStartup+0x80 [f:\dd\vctools\crt_bld\self_x86\crt\src\crt0.c @ 228]
0034ff94 77479d72 7efde000 5708d4b0 00000000 kernel32!BaseThreadInitThunk+0x12
0034ffd4 77479d45 00b91231 7efde000 00000000 ntdll32!RtlInitializeExceptionChain+0x63
0034ffec 00000000 00b91231 7efde000 00000000 ntdll32!RtlInitializeExceptionChain+0x36
Suma, do you know the reason for this? Thanks!