1

I have a C++ test project with a bunch of stub functions that have the same implementation. Those stubs are meant to be 'replaced' during runtime using Windows Detours. The issue is that, in release mode, the compiler make all of those stubs to point to the same implementation. To illustrate this, consider this code:

#include <iostream>
using namespace std;

void A() { cout << "stub" << endl; }
void B() { cout << "stub" << endl; }

void main()
{
    cout << &A << ", " << &B << endl;
}

In debug mode, the pointer values will be different. In release mode, they are the same. I tried the pragma optimize directive (I am using the Microsoft compiler) but it didn't fix the issue. As a result, my Windows Detours hook intercept all the calls to the identical stubs.

How can I fix this? Thanks.

Ville Krumlinde
  • 7,021
  • 1
  • 33
  • 41

1 Answers1

1

Try using preprocessor macros to make your stub functions unique so the optimizer won't merge them into one.

__FILE__, __LINE__, and __FUNCTION__ usage in C++

Something like this:

void A() { cout << __FUNCTION__ << endl; }
void B() { cout << __FUNCTION__ << endl; }
Community
  • 1
  • 1
Ville Krumlinde
  • 7,021
  • 1
  • 33
  • 41