Functions marked with OVS_CONSTRUCTOR are called unconditionally
before main.

Tested with GCC. Untested with MSVC.

Signed-off-by: Helmut Schaa <[email protected]>
---
 lib/compiler.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/lib/compiler.h b/lib/compiler.h
index 0dbacbf..daca32d 100644
--- a/lib/compiler.h
+++ b/lib/compiler.h
@@ -179,4 +179,17 @@
 #define OVS_PACKED(DECL) __pragma(pack(push, 1)) DECL __pragma(pack(pop))
 #endif
 
+#ifdef _MSC_VER
+#define CCALL __cdecl
+#pragma section(".CRT$XCU",read)
+#define OVS_CONSTRUCTOR(f) \
+    static void __cdecl f(void); \
+    __declspec(allocate(".CRT$XCU")) void (__cdecl*f##_)(void) = f; \
+    static void __cdecl f(void)
+#else
+#define OVS_CONSTRUCTOR(f) \
+    static void f(void) __attribute__((constructor)); \
+    static void f(void)
+#endif
+
 #endif /* compiler.h */
-- 
1.8.1.4

_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

Reply via email to