I've included some source files from a BSD-licensed library into my program. I didn't notice a function with this signature:
class SomeClass {
...
private:
static void initializeFunc() __attribute__ ((__constructor__));
....
};
From this other stackoverflow question it seems that __constructor__ is supposed to make initializeFunc called whenever the library gets loaded by the running binary. Of course in my case, the source code is compiled into the binary so it's not called as a library.
Now, someone else in my organization noticed from an oprofile that initializeFunc is being called thousands of times, even if SomeClass is never instantiated or called. I don't understand this behavior. Probably I should just remove that attribute and call initializeFunc directly from main. But why in my case isn't it being called exactly once? Can someone help me understand what is going on here?