summaryrefslogtreecommitdiff
path: root/lib/compiler.h
diff options
context:
space:
mode:
authorHelmut Schaa <helmut.schaa@googlemail.com>2013-12-13 14:05:00 +0100
committerBen Pfaff <blp@nicira.com>2013-12-13 09:14:29 -0800
commit6164839f3ee00436b32af3100c903ee152803117 (patch)
tree01484ca8c683feb42599b92342a2ef08cba877cc /lib/compiler.h
parent42efb1dc451ebdd7a37ef27a4df7423df74d423c (diff)
downloadopenvswitch-6164839f3ee00436b32af3100c903ee152803117.tar.gz
compiler: Add OVS_CONSTRUCTOR to mark functions as init functions
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>
Diffstat (limited to 'lib/compiler.h')
-rw-r--r--lib/compiler.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/compiler.h b/lib/compiler.h
index 0dbacbfcc..daca32dd7 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 */