On 11 March 2018 at 06:58, Eva Chen <debby83...@gmail.com> wrote:
> Hello,
> I am working on compiling QEMU 2.10.2 to a static library.
> Everything works fine in compiling QEMU to an execution
> file(qemu-system-aarch64), but after I link all .o and .a file to create a
> QEMU library and write a c file to call qemu_main() in qemu/util/vl.c(I
> have changed the name "main()" into "qemu_main()"), then it shows this
> error message.

This isn't really supported, so you're kind of on your
own here, but I have a few debugging suggestions below:

> util/qemu-thread-posix.c: 64: qemu_mutex_lock: Assertion
> 'mutex->initialized' failed.
> Abort (core dumped)
> The information of gdb's backtrace is shown as bellow
> (gdb) bt
> *#o Ox00007ffff05b31f7 in raise () at /usr/lib64/libc.so.6
> #1 0x00007ffff05b48e8 in abort () at /usr/lib64/libc.s0.6
> #2 0x00007ffff05ac266 in assert fail base () at /usr/lib64/libc.so.6
> #3 0x00007ffff05ac312 in 0 at /usr/lib64/libc.so.6
> #4 0x00000000005c47e3 in qemu_mutex_lock (mutex=mutex@entry=0xd84be0 
> <rcu_registry lock>) at
> util/qemu-thread-posix.c:64
> #5 0x00000000005d5b46 in rcu_register_thread() at util/rcu.c:290
> #6 0x00007ffff5a790de in rcu_init_complete () at util/rcu.c:318,
> #7 Ox00007ffff7dea503 in _dl_init_internal () at /lib64/ld.linux-x86-64.50.2
> #8 0x00007ffff7ddclaa in _dl_start_user () at /lib64/ld.linux - x86-64.so.2
> #9 0x0000000000000014 in ()*
> I found out that it aborted before conducted to the main function in QEMU

This happens before main because this backtrace is from rcu_init()
in util/rcu.c, which is marked as __attribute__((__constructor__)),
so it is called before main().

(As an aside, you'll probably find your backtraces are more
helpful and debugging is easier if you configure QEMU with
--enable-debug, which will mean we compile with debug rather
than optimization. When you've got it working you can make the
final build a non-debug one.)

> Also,  I use si and n in gdb to see what happened in this QEMU library
> it showed  that the address and content of *rcu_registry_lock* would change
> when it executed qemu_thread_create() in util/rcu.c:315
> $ qemu_thread_create(&thread, "cal_rcu", call_rcu_thread, NULL,
> This change caused the failure of assert(mutex->initialized) in
> qemu_mutex_lock (which called by rcu_register_thread() in call_rcu_thread())

That's odd, because mutex->initialized is supposed to be
set by qemu_mutex_init() and then not written until something
calls qemu_mutex_destroy(). If I were you I'd try using debugger
watchpoints to find out where the code is that's overwriting

-- PMM

Reply via email to