win32_before_main update to holding the symbol with linker include option replacing dllexport
parent
0b6adfde1e
commit
9ddc06fc0a
|
@ -23,8 +23,11 @@ anything.
|
|||
|
||||
However, in this example I show how we can still make it work. We have to
|
||||
make sure the linker won't eliminate the global variable that we are trying to
|
||||
place into the ".CRT$XCU" section. I achieve this by marking it as an export
|
||||
symbol. Export symbols can't be eliminated even if they aren't used locally.
|
||||
place into the ".CRT$XCU" section. We can tell the linker to keep a symbol with
|
||||
/include:<symbol-name> and we can add this command to the linker via a pragma
|
||||
comment:
|
||||
|
||||
__pragma(comment(linker,"/include:<symbol-name>"))
|
||||
|
||||
From what I've seen in testing, this works as desired, even with the /GL option.
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ static void run_before_main_func(void);
|
|||
|
||||
// set the before-main execution function pointer
|
||||
__declspec(allocate(".CRT$XCU"))
|
||||
__declspec(dllexport)
|
||||
__pragma(comment(linker,"/include:run_before_main_ptr"))
|
||||
void (*run_before_main_ptr)(void) = run_before_main_func;
|
||||
|
||||
// define the "before main" function
|
||||
|
@ -29,7 +29,7 @@ int main(){
|
|||
|
||||
#define BEFORE_MAIN(n) static void n(void); \
|
||||
__declspec(allocate(".CRT$XCU")) \
|
||||
__declspec(dllexport) \
|
||||
__pragma(comment(linker,"/include:" #n "__")) \
|
||||
void (*n##__)(void) = n; \
|
||||
static void n(void)
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
|
||||
#define BEFORE_MAIN(n) static void n(void); \
|
||||
__declspec(allocate(".CRT$XCU")) \
|
||||
__declspec(dllexport) \
|
||||
__pragma(comment(linker,"/include:" #n "__")) \
|
||||
void (*n##__)(void) = n; \
|
||||
static void n(void)
|
||||
|
||||
|
|
Loading…
Reference in New Issue