citrun

watch C/C++ source code execute
Log | Files | Refs | LICENSE

commit 78ad6ae422cebafc403169a371bb3fbbf83e6d5c
parent a1484816d6ab0e1a014390d804b5c6f69469218d
Author: Kyle Milz <kyle@windows.krwm.net>
Date:   Sun,  1 Jan 2017 20:58:18 -0800

src: add win32 equivalent of __attribute__((constructor))

Diffstat:
Msrc/inst_action.cc | 18++++++++++++++++++
1 file changed, 18 insertions(+), 0 deletions(-)

diff --git a/src/inst_action.cc b/src/inst_action.cc @@ -77,10 +77,28 @@ InstrumentAction::EndSourceFileAction() << " \"" << m_compiler_file_name << "\",\n" << " \"" << getCurrentFile().str() << "\",\n"; preamble << "};\n"; +#ifdef _WIN32 + // + // Cribbed from an answer by Joe: + // http://stackoverflow.com/questions/1113409/attribute-constructor-equivalent-in-vc + // + preamble << "#pragma section(\".CRT$XCU\",read)\n" + << "#define INITIALIZER2_(f,p) \\\n" + << " static void f(void); \\\n" + << " __declspec(allocate(\".CRT$XCU\")) void (*f##_)(void) = f; \\\n" + << " __pragma(comment(linker,\"/include:\" p #f \"_\")) \\\n" + << " static void f(void)\n" + << "#define INITIALIZER(f) INITIALIZER2_(f,\"_\")\n"; + preamble << "INITIALIZER( init)\n" + << "{" + << " citrun_node_add(citrun_major, citrun_minor, &_citrun);\n" + << "}\n"; +#else preamble << "__attribute__((constructor)) static void\n" << "citrun_constructor() {\n" << " citrun_node_add(citrun_major, citrun_minor, &_citrun);\n" << "}\n"; +#endif preamble << "#ifdef __cplusplus\n" << "}\n" << "#endif\n";