gcov: Call constructors during initialization
authorFrediano Ziglio <frediano.ziglio@citrix.com>
Thu, 14 Feb 2013 12:37:13 +0000 (12:37 +0000)
committerKeir <keir.xen@gmail.com>
Thu, 21 Feb 2013 16:15:33 +0000 (16:15 +0000)
This allow modules to set initializer functions.
This is used by Gcc instrumentation code for profiling arcs and test
coverage.

xen/arch/arm/setup.c
xen/arch/arm/xen.lds.S
xen/arch/x86/setup.c
xen/arch/x86/xen.lds.S
xen/common/lib.c
xen/include/xen/lib.h

index 43a69eb72a0a742f1928c3fd6bd811f689aa6eaf..e07c1cb532f18e3dfd011dd8cd688eeb850b5fb0 100644 (file)
@@ -442,6 +442,8 @@ void __init start_xen(unsigned long boot_phys_offset,
        scrub_heap_pages();
     */
 
+    init_constructors();
+
     console_endboot();
 
     /* Hide UART from DOM0 if we're using it */
index 410d7dbcf3d4886be4cc21437e2bc575cdd38aaf..50e0c4b2c869b5100ceec970ec41314a7055dbf6 100644 (file)
@@ -84,6 +84,13 @@ SECTIONS
        *(.init.data)
        *(.init.data.rel)
        *(.init.data.rel.*)
+
+       . = ALIGN(4);
+       __CTOR_LIST__ = .;
+       LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
+       *(.ctors)
+       LONG(0)
+       __CTOR_END__ = .;
   } :text
   . = ALIGN(32);
   .init.setup : {
index 55666c7627aa9dca5c633f0741d3a6c2a88218b0..43301a53602177d3f2a8643fc1af3560e79a2653 100644 (file)
@@ -1378,6 +1378,8 @@ void __init __start_xen(unsigned long mbi_p)
 
     init_trace_bufs();
 
+    init_constructors();
+
     console_endboot();
 
     /* Hide UART from DOM0 if we're using it */
index d324afdd6713be2438f30069358e09db78a2e22d..55703896e35007ddc1653cceae99fab45b7592a4 100644 (file)
@@ -108,6 +108,13 @@ SECTIONS
        __trampoline_seg_start = .;
        *(.trampoline_seg)
        __trampoline_seg_stop = .;
+
+       . = ALIGN(8);
+       __CTOR_LIST__ = .;
+       QUAD((__CTOR_END__ - __CTOR_LIST__) / 8 - 2)
+       *(.ctors)
+       QUAD(0)
+       __CTOR_END__ = .;
   } :text
   . = ALIGN(32);
   .init.setup : {
index 018345ebbdeeeb9eec1f7a093d74687f41240e08..e0c65cfec3d6b72842abc6c451bf59b6c3029418 100644 (file)
@@ -2,6 +2,7 @@
 #include <xen/ctype.h>
 #include <xen/lib.h>
 #include <xen/types.h>
+#include <xen/init.h>
 #include <asm/byteorder.h>
 
 /* for ctype.h */
@@ -478,6 +479,19 @@ unsigned long long parse_size_and_unit(const char *s, const char **ps)
     return ret;
 }
 
+extern const struct
+{
+    unsigned long count;
+    void (*funcs[1])(void);
+} __CTOR_LIST__;
+
+void __init init_constructors(void)
+{
+    unsigned long n;
+    for ( n = 0; n < __CTOR_LIST__.count; ++n )
+        __CTOR_LIST__.funcs[n]();
+}
+
 /*
  * Local variables:
  * mode: C
index 31e111744669c9790d16cc53b4e7873e2cafe049..74b34eb9321a8efadb2c7b6392c5d22e9408a5eb 100644 (file)
@@ -127,4 +127,6 @@ extern void add_taint(unsigned);
 struct cpu_user_regs;
 void dump_execstate(struct cpu_user_regs *);
 
+void init_constructors(void);
+
 #endif /* __LIB_H__ */