All of lore.kernel.org
 help / color / mirror / Atom feed
* ld bug causing stupid CTOR count in mini-os
@ 2011-08-17 23:53 Jeremy Fitzhardinge
  2011-08-17 23:57 ` Samuel Thibault
  0 siblings, 1 reply; 2+ messages in thread
From: Jeremy Fitzhardinge @ 2011-08-17 23:53 UTC (permalink / raw)
  To: Samuel Thibault; +Cc: xen-devel

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.

I'm wondering, why not just terminate the loop with the NULL sentinel,
and forget about putting the count there?

    J

diff -r b81c0417b901 extras/mini-os/arch/ia64/minios-ia64.lds
--- a/extras/mini-os/arch/ia64/minios-ia64.lds	Wed Aug 17 16:08:41 2011 -0700
+++ b/extras/mini-os/arch/ia64/minios-ia64.lds	Wed Aug 17 16:34:32 2011 -0700
@@ -55,7 +55,6 @@
   .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 @@
   .dtors : AT(ADDR(.dtors) - (((5<<(61))+0x100000000) - (1 << 20)))
         {
         __DTOR_LIST__ = .;
-        QUAD((__DTOR_END__ - __DTOR_LIST__) / 8 - 2)
         *(.dtors)
         QUAD(0)
         __DTOR_END__ = .;
diff -r b81c0417b901 extras/mini-os/arch/x86/minios-x86_32.lds
--- a/extras/mini-os/arch/x86/minios-x86_32.lds	Wed Aug 17 16:08:41 2011 -0700
+++ b/extras/mini-os/arch/x86/minios-x86_32.lds	Wed Aug 17 16:34:32 2011 -0700
@@ -30,7 +30,6 @@
 
   .ctors : {
         __CTOR_LIST__ = .;
-        LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
         *(.ctors)
 	CONSTRUCTORS
         LONG(0)
@@ -39,7 +38,6 @@
 
   .dtors : {
         __DTOR_LIST__ = .;
-        LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
         *(.dtors)
         LONG(0)
         __DTOR_END__ = .;
diff -r b81c0417b901 extras/mini-os/arch/x86/minios-x86_64.lds
--- a/extras/mini-os/arch/x86/minios-x86_64.lds	Wed Aug 17 16:08:41 2011 -0700
+++ b/extras/mini-os/arch/x86/minios-x86_64.lds	Wed Aug 17 16:34:32 2011 -0700
@@ -30,7 +30,6 @@
 
   .ctors : {
         __CTOR_LIST__ = .;
-        QUAD((__CTOR_END__ - __CTOR_LIST__) / 8 - 2)
         *(.ctors)
 	CONSTRUCTORS
         QUAD(0)
@@ -39,7 +38,6 @@
 
   .dtors : {
         __DTOR_LIST__ = .;
-        QUAD((__DTOR_END__ - __DTOR_LIST__) / 8 - 2)
         *(.dtors)
         QUAD(0)
         __DTOR_END__ = .;
diff -r b81c0417b901 extras/mini-os/main.c
--- a/extras/mini-os/main.c	Wed Aug 17 16:08:41 2011 -0700
+++ b/extras/mini-os/main.c	Wed Aug 17 16:34:32 2011 -0700
@@ -153,7 +153,7 @@
 
     __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 @@
 {
     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();

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: ld bug causing stupid CTOR count in mini-os
  2011-08-17 23:53 ld bug causing stupid CTOR count in mini-os Jeremy Fitzhardinge
@ 2011-08-17 23:57 ` Samuel Thibault
  0 siblings, 0 replies; 2+ messages in thread
From: Samuel Thibault @ 2011-08-17 23:57 UTC (permalink / raw)
  To: Jeremy Fitzhardinge; +Cc: xen-devel

Jeremy Fitzhardinge, le Wed 17 Aug 2011 16:53:06 -0700, a écrit :
> I'm wondering, why not just terminate the loop with the NULL sentinel,
> and forget about putting the count there?

It looks safer than relying on correct size computation indeed.

Samuel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-08-17 23:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-17 23:53 ld bug causing stupid CTOR count in mini-os Jeremy Fitzhardinge
2011-08-17 23:57 ` Samuel Thibault

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.