I`m trying to build a shared object with MinGW (DLL in this case) which contains a bunch of functions that i want to access through a linker generated list by using:
attribute((section("my_custom_section"))).
I also want to have my export table free of anything but the two linker generated symbols (__start_my_custom_section, __stop_my_custom_section).
I tried to give different attributes to the variables inside the custom section, including "used". When I inspect the dll with Dependency walker, i get nothing. I also tried to put
__declspec(dllexport) extern fp_t __start_my_custom_section; inside the header file.
I actually tried everything I could find (visibility, gc-off, etc..) but nothing seems to work.
//header.h
typedef void (* fp_t)(void);
#define ADD_FUNC(name) \
void function_##name(void); \
__attribute__((section("custom_section"))) \
fp_t function_##name##_data = function_##name \
void function_##name(void)
//source1.c
ADD_FUNC(foo)
{
//do stuff;
}
//source2.c
ADD_FUNC(bar)
{
//do stuff;
}
The main problem is that i need to do this inside the header without involving any extra source.
This works as long as there is a variable initialized with __start/__stop, but obviously i cannot put a variable inside the header since a conflict will arise.
Another solution would be to link a extra source file that contains these variables, but i would like to avoid that.
Basically i'm asking if there is a way to force the custom linker generated symbols inside the dll export table, without involving DEF files, or any other extra files, only by using a single header file that I include in [1..n] C files containing functions that get a pointer added inside the custom section.