2

For reference, I'm looking for something that behaves similarly to this:

--wrap=symbol Use a wrapper function for symbol. Any undefined reference to symbol will be resolved to "__wrap_symbol". Any undefined reference to "__real_symbol" will be resolved to symbol.

Does such a thing exist for link.exe? I didn't see anything stick out on the MSDN linker page.

EDIT: My dev environment doesn't support DLLs, so a DLL only solution won't help here.

lhumongous
  • 1,064
  • 12
  • 27
  • 1
    As far as I know it doesn't. This thread contains some discussions on a similar topic that might be of help: http://stackoverflow.com/questions/1316018/globally-override-malloc-in-visual-c – Laserallan May 17 '12 at 16:50
  • Thanks for the link. A combination of /nodefaultlib, defining my own symbols, and linking to crt directly might do the trick. I'll have to mess around with this. – lhumongous May 18 '12 at 17:05

1 Answers1

1

Tricky but possible for DLL's. Your DLL should implement wrap_symbol and link with a .DEF file which renames it to symbol. You can call the original function from within your DLL as just symbol(), as the renaming of wrap_symbol happens later.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • I should clarify that this is for console development. We don't use DLLs since they negatively affect our load times and performance (we lose /ltcg support). – lhumongous May 18 '12 at 17:11
  • Oh, the `/LTCG` part is even more important than you probably realized. Your libs don't contain the assembly for `symbol`, but its (preprocessed) code. BTW, seems GCC has an open issue on `-flto --wrap` for similar reasons. – MSalters May 18 '12 at 18:10