]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/mini-os.git/commitdiff
mini-os: work around ld bug causing stupid CTOR count
authorJeremy Fitzhardinge <jeremy@goop.org>
Fri, 19 Aug 2011 08:57:42 +0000 (09:57 +0100)
committerJeremy Fitzhardinge <jeremy@goop.org>
Fri, 19 Aug 2011 08:57:42 +0000 (09:57 +0100)
I'm seeing pvgrub crashing when running CTORs.  It appears its because
the magic in the linker script is generating junk.  If I get ld to
output a map, I see:

.ctors          0x0000000000097000       0x18
                0x0000000000097000                __CTOR_LIST__ = .
                0x0000000000097000        0x4 LONG 0x25c04
                (((__CTOR_END__ - __CTOR_LIST__) / 0x4) - 0x2)
 *(.ctors)
 .ctors         0x0000000000097004       0x10
                /home/jeremy/hg/xen/unstable/stubdom/mini-os-x86_32-grub/mini-os.o
                0x0000000000097014        0x4 LONG 0x0
                0x0000000000097018                __CTOR_END__ = .

In other words, somehow ((0x97018-0x97000) / 4) - 2 = 0x25c04

The specific crash is that the ctor loop tries to call the NULL
sentinel.  I'm seeing the same with the DTOR list.

Avoid this by terminating the loop with the NULL sentinel, and get rid
of the CTOR count entirely.

From: Jeremy Fitzhardinge <jeremy@goop.org>
Signed-off-by: Keir Fraser <keir@xen.org>
arch/ia64/minios-ia64.lds
arch/x86/minios-x86_32.lds
arch/x86/minios-x86_64.lds
main.c

index 8b54c0f3946a5c88c7d4465336aca71a5d0dd83b..2866a4a644add41f77de3aedf542e51952f8cf33 100644 (file)
@@ -55,7 +55,6 @@ SECTIONS
   .ctors : AT(ADDR(.ctors) - (((5<<(61))+0x100000000) - (1 << 20)))
        {
         __CTOR_LIST__ = .;
-        QUAD((__CTOR_END__ - __CTOR_LIST__) / 8 - 2)
         *(.ctors)
        CONSTRUCTORS
         QUAD(0)
@@ -65,7 +64,6 @@ SECTIONS
   .dtors : AT(ADDR(.dtors) - (((5<<(61))+0x100000000) - (1 << 20)))
         {
         __DTOR_LIST__ = .;
-        QUAD((__DTOR_END__ - __DTOR_LIST__) / 8 - 2)
         *(.dtors)
         QUAD(0)
         __DTOR_END__ = .;
index 13796db768ea4c1d0ec6d1342fdc307603d4cb43..f5cabb6a11d9278984ebc2e722cdf38a1a8b4558 100644 (file)
@@ -30,7 +30,6 @@ SECTIONS
 
   .ctors : {
         __CTOR_LIST__ = .;
-        LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
         *(.ctors)
        CONSTRUCTORS
         LONG(0)
@@ -39,7 +38,6 @@ SECTIONS
 
   .dtors : {
         __DTOR_LIST__ = .;
-        LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
         *(.dtors)
         LONG(0)
         __DTOR_END__ = .;
index 6a5c0bb2f965582343b7c1e5be9c797310c1729e..3da0a9f130db75693144a25ee53ad1c9098aaee4 100644 (file)
@@ -30,7 +30,6 @@ SECTIONS
 
   .ctors : {
         __CTOR_LIST__ = .;
-        QUAD((__CTOR_END__ - __CTOR_LIST__) / 8 - 2)
         *(.ctors)
        CONSTRUCTORS
         QUAD(0)
@@ -39,7 +38,6 @@ SECTIONS
 
   .dtors : {
         __DTOR_LIST__ = .;
-        QUAD((__DTOR_END__ - __DTOR_LIST__) / 8 - 2)
         *(.dtors)
         QUAD(0)
         __DTOR_END__ = .;
diff --git a/main.c b/main.c
index 6b53df5e63fc2356d2f92a30aec6d4e7851f2cec..b95b889e1623a1ce14d966ece86ed6a0961f50b4 100644 (file)
--- a/main.c
+++ b/main.c
@@ -153,7 +153,7 @@ static void call_main(void *p)
 
     __libc_init_array();
     environ = envp;
-    for (i = 1; i <= __CTOR_LIST__[0]; i++)
+    for (i = 0; __CTOR_LIST__[i] != 0; i++)
         ((void((*)(void)))__CTOR_LIST__[i]) ();
     tzset();
 
@@ -164,7 +164,7 @@ void _exit(int ret)
 {
     int i;
 
-    for (i = 1; i <= __DTOR_LIST__[0]; i++)
+    for (i = 0; __DTOR_LIST__[i] != 0; i++)
         ((void((*)(void)))__DTOR_LIST__[i]) ();
     close_all_files();
     __libc_fini_array();