]> xenbits.xensource.com Git - people/liuw/mini-os.git/commitdiff
stubdom: support constructors and destructors
authorKeir Fraser <keir.fraser@citrix.com>
Thu, 22 May 2008 14:09:08 +0000 (15:09 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Thu, 22 May 2008 14:09:08 +0000 (15:09 +0100)
Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
arch/ia64/minios-ia64.lds
arch/x86/minios-x86_32.lds
arch/x86/minios-x86_64.lds
main.c

index 0b38a34e8e979acbccdfcce87668a0f3cb743871..3122648969cc016c35c86bfb72299c9b50e2c017 100644 (file)
@@ -52,6 +52,23 @@ SECTIONS
   .fini_array     : { *(.fini_array) }
   PROVIDE (__fini_array_end = .);
 
+  .ctors : {
+        __CTOR_LIST__ = .;
+        LONG((__CTOR_END__ - __CTOR_LIST__) / 8 - 2)
+        *(SORT_BY_NAME(.ctors))
+       SORT_BY_NAME(CONSTRUCTORS)
+        LONG(0)
+        __CTOR_END__ = .;
+        }
+
+  .dtors : {
+        __DTOR_LIST__ = .;
+        LONG((__DTOR_END__ - __DTOR_LIST__) / 8 - 2)
+        *(SORT_BY_NAME(.dtors))
+        LONG(0)
+        __DTOR_END__ = .;
+        }
+
   .IA_64.unwind_info : AT(ADDR(.IA_64.unwind_info) - (((5<<(61))+0x100000000) - (1 << 20)))
   { *(.IA_64.unwind_info) }
 
index 9bd0b77691ed0e417eb7e011f8d2602e2c4980a5..40a92ee4e65a185d1b4bec7bc0a4a1ecb38234d3 100644 (file)
@@ -28,9 +28,25 @@ SECTIONS
   .fini_array     : { *(.fini_array) }
   PROVIDE (__fini_array_end = .);
 
+  .ctors : {
+        __CTOR_LIST__ = .;
+        LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
+        *(SORT_BY_NAME(.ctors))
+       SORT_BY_NAME(CONSTRUCTORS)
+        LONG(0)
+        __CTOR_END__ = .;
+        }
+
+  .dtors : {
+        __DTOR_LIST__ = .;
+        LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
+        *(SORT_BY_NAME(.dtors))
+        LONG(0)
+        __DTOR_END__ = .;
+        }
+
   .data : {                    /* Data */
        *(.data)
-       CONSTRUCTORS
        }
 
   _edata = .;                  /* End of data section */
index 361b264c5eedecf10d4878847cf46b5280a359e0..d53d639f2f35baaf85014d0eeec68c00340304ec 100644 (file)
@@ -28,9 +28,25 @@ SECTIONS
   .fini_array     : { *(.fini_array) }
   PROVIDE (__fini_array_end = .);
 
+  .ctors : {
+        __CTOR_LIST__ = .;
+        LONG((__CTOR_END__ - __CTOR_LIST__) / 8 - 2)
+        *(SORT_BY_NAME(.ctors))
+       SORT_BY_NAME(CONSTRUCTORS)
+        LONG(0)
+        __CTOR_END__ = .;
+        }
+
+  .dtors : {
+        __DTOR_LIST__ = .;
+        LONG((__DTOR_END__ - __DTOR_LIST__) / 8 - 2)
+        *(SORT_BY_NAME(.dtors))
+        LONG(0)
+        __DTOR_END__ = .;
+        }
+
   .data : {                    /* Data */
        *(.data)
-       CONSTRUCTORS
        }
 
   _edata = .;                  /* End of data section */
diff --git a/main.c b/main.c
index 6e67b01138458ac655a4bc81c150a09c255fd0d2..1851469c3ec459f94c4c499f42b3d3bafccdb5f5 100644 (file)
--- a/main.c
+++ b/main.c
@@ -19,6 +19,8 @@
 extern int main(int argc, char *argv[], char *envp[]);
 extern void __libc_init_array(void);
 extern void __libc_fini_array(void);
+extern unsigned long __CTOR_LIST__[];
+extern unsigned long __DTOR_LIST__[];
 
 struct thread *main_thread;
 
@@ -147,6 +149,8 @@ static void call_main(void *p)
 
     __libc_init_array();
     environ = envp;
+    for (i = 1; i <= __CTOR_LIST__[0]; i++)
+        ((void((*)(void)))__CTOR_LIST__[i]) ();
     tzset();
 
     exit(main(argc, argv, envp));
@@ -154,6 +158,10 @@ static void call_main(void *p)
 
 void _exit(int ret)
 {
+    int i;
+
+    for (i = 1; i <= __DTOR_LIST__[0]; i++)
+        ((void((*)(void)))__DTOR_LIST__[i]) ();
     close_all_files();
     __libc_fini_array();
     printk("main returned %d\n", ret);