Skip to contentSkip to conversation

qemu/linux-user main.c

Qemu-devel Thiemo Seufer 3 participants 5 messages Mar 19, 2007

lore
Share & tools
lore
#1 lore raw
Quoted 10 lines · Thiemo Seufer

CVSROOT: /sources/qemu
Module name: qemu
Changes by: Thiemo Seufer <ths> 07/03/19 12:16:29

Modified files:
linux-user : main.c

Log message:
Support -cpu selection for mips usermode emulation. Fix segfault when dispaying the -cpu list help.

Could you tell more about the segfault ?
exit is used at many other places without any problem and furthermore I did not experiment any crash while testing the PowerPC target with the initial patch, so ? (I'd really like to understand...)

Signature · 2 lines
J. Mayer <[email protected]>
Never organized
#2 lore raw
Quoted 5 lines · J. Mayer
Quoted 4 lines · Thiemo Seufer

CVSROOT: /sources/qemu
Module name: qemu
Changes by: Thiemo Seufer <ths> 07/03/19 12:16:29

Quoted 8 lines
Quoted 6 lines

Modified files:
linux-user : main.c

Log message:
Support -cpu selection for mips usermode emulation. Fix segfault when dispaying the -cpu list help.

Could you tell more about the segfault ?

It segfaulted for me (on ppc/linux) after printing the help list.

Quoted 3 lines

exit is used at many other places without any problem and furthermore I did not experiment any crash while testing the PowerPC target with the initial patch, so ? (I'd really like to understand...)

I didn't really debug it, but I noticed the other branch in the conditional uses _exit() instead of exit(). With that change, the segfault disappeared. I figure we have an atexit/on_exit call somwhere which tries to use data which isn't initialized at that point.

Thiemo

#3 lore raw
Quoted 17 lines · On Monday 19 March 2007 21:13:12 Thiemo Seufer wrote:
Quoted 5 lines · J. Mayer
Quoted 4 lines · Thiemo Seufer

CVSROOT: /sources/qemu
Module name: qemu
Changes by: Thiemo Seufer <ths> 07/03/19 12:16:29

Quoted 8 lines
Quoted 6 lines

Modified files:
linux-user : main.c

Log message:
Support -cpu selection for mips usermode emulation. Fix segfault when dispaying the -cpu list help.

Could you tell more about the segfault ?

It segfaulted for me (on ppc/linux) after printing the help list.

Quoted 8 lines
Quoted 3 lines

exit is used at many other places without any problem and furthermore I did not experiment any crash while testing the PowerPC target with the initial patch, so ? (I'd really like to understand...)

I didn't really debug it, but I noticed the other branch in the conditional uses _exit() instead of exit(). With that change, the segfault disappeared. I figure we have an atexit/on_exit call somwhere which tries to use data which isn't initialized at that point.

Maybe that's related to the problem i've got (in
http://lists.gnu.org/archive/html/qemu-devel/2007-03/msg00110.html ). There is some piece of code in main.c which mess around libc initialization & exit and were making my qemu-i386 segfault really early. It seems it was designed to avoid a bug in some versions of glibc.
I attach the simple patch I've made to avoid that.
It may need adjustements since I don't know enough about libc internals on initialization to be sure that's the correct fix - I would be deeply interested in some input/comments on this problem.

Pierre Palatin

main.c +1 -1
Index: linux-user/main.c
===================================================================
@@ -44,7 +44,7 @@
 
 /* for recent libc, we add these dummy symbols which are not declared
    when generating a linked object (bug in ld ?) */
-#if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined(CONFIG_STATIC)
+#if (__GLIBC__ == 2 && __GLIBC_MINOR__ == 3) && !defined(CONFIG_STATIC)
 long __preinit_array_start[0];
 long __preinit_array_end[0];
 long __init_array_start[0];
#4 lore raw
Quoted 45 lines · Pierre Palatin
Quoted 17 lines · On Monday 19 March 2007 21:13:12 Thiemo Seufer wrote:
Quoted 5 lines · J. Mayer
Quoted 4 lines · Thiemo Seufer

CVSROOT: /sources/qemu
Module name: qemu
Changes by: Thiemo Seufer <ths> 07/03/19 12:16:29

Quoted 8 lines
Quoted 6 lines

Modified files:
linux-user : main.c

Log message:
Support -cpu selection for mips usermode emulation. Fix segfault when dispaying the -cpu list help.

Could you tell more about the segfault ?

It segfaulted for me (on ppc/linux) after printing the help list.

Quoted 8 lines
Quoted 3 lines

exit is used at many other places without any problem and furthermore I did not experiment any crash while testing the PowerPC target with the initial patch, so ? (I'd really like to understand...)

I didn't really debug it, but I noticed the other branch in the conditional uses _exit() instead of exit(). With that change, the segfault disappeared. I figure we have an atexit/on_exit call somwhere which tries to use data which isn't initialized at that point.

Maybe that's related to the problem i've got (in
http://lists.gnu.org/archive/html/qemu-devel/2007-03/msg00110.html ).

There is some piece of code in main.c which mess around libc initialization & exit and were making my qemu-i386 segfault really early. It seems it was designed to avoid a bug in some versions of glibc.
I attach the simple patch I've made to avoid that.
It may need adjustements since I don't know enough about libc internals on initialization to be sure that's the correct fix - I would be deeply interested in some input/comments on this problem.

Pierre Palatin

Index: linux-user/main.c
===================================================================

main.c line 50

Quoted 8 lines
main.c +1 -1
@@ -44,7 +44,7 @@
 
 /* for recent libc, we add these dummy symbols which are not declared
    when generating a linked object (bug in ld ?) */
-#if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined(CONFIG_STATIC)
+#if (__GLIBC__ == 2 && __GLIBC_MINOR__ == 3) && !defined(CONFIG_STATIC)
 long __preinit_array_start[0];
 long __preinit_array_end[0];
 long __init_array_start[0];

binutils' ld had a bug a while ago, this looks like a workaround for it (which means the check for glibc is wrong, and there's no easy way to do it right).

Commenting out that code made no difference to me.

Thiemo