Distilled example case:
template<class T> class Test {
static __declspec(allocate(".xyz")) int snafu;
};
template<class T> int Test<T>::snafu = 42;
Everything in ".xyz" section is actually used - indirectly. Is there any way to prevent the linker from removing "snafu"? Did i miss something?
Note 1: I auto generate bullshit access functions for them and prevent linkers eagerness that way - so, no standing problem. My question is towards: is there something i have missed and i can just tell it (VS toolchain via source code) to not mess with certain globals? Not expecting there to be, but it does not hurt to ask.
Note 2: The whole point of doing what the example code is related to is to see where i can get with it - so, sidestepping the problem as shown is completely nonsensical. Please do not.
edit update:
Blaming linker was premature - this case has more todo with funky template behavior. Short: if you instantiate a template then its static variables are only instantiated when you have reachable references to it. Instantiation won't happen even when the constructor of the variable has visible side effects elsewhere.