compiler: Add OVS_CONSTRUCTOR to mark functions as init functions
authorHelmut Schaa <helmut.schaa@googlemail.com>
Fri, 13 Dec 2013 13:05:00 +0000 (14:05 +0100)
committerBen Pfaff <blp@nicira.com>
Fri, 13 Dec 2013 17:14:29 +0000 (09:14 -0800)
Functions marked with OVS_CONSTRUCTOR are called unconditionally
before main.

Tested with GCC. Untested with MSVC.

Signed-off-by: Helmut Schaa <helmut.schaa@googlemail.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
lib/compiler.h

index 0dbacbf..daca32d 100644 (file)
 #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 */