Skip to contentSkip to conversation

Compiling Qemu to dynamic library

Qemu-devel Halsey Pian 2 participants 2 messages Jan 8, 2015

lore
Share & tools
lore
#0 lore raw

Hi All,

During building this so library, I found that there are many functions with same name in stubs and other source file, for example,

There are two implement functions with same name slirp_pollfds_fill in slirp.c and main-loop.c.

./stubs/slirp.c:void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)

./main-loop.c: slirp_pollfds_fill(gpollfds, &timeout);

Do you know when qemustub should be used? libqemustub.a is only used for qemu-img, qemu-nbd, qemu-io, but not for qemu-system-x86_64(and other platform binary)?

Thanks!

Best Regards

Halsey Pian

From: Halsey Pian [mailto:[email protected]]
Sent: 2015年1月7日 16:37
To: [email protected]
Subject: [Qemu-devel] [Makefile] Compiling Qemu to dynamic library

Dear All,

Recently, I would try to compile qemu to a so in order to call qemu internal functions in my program, I’m trying to do this by steps,

1. Add rules in qemu-2.1.2/ rules.mak

%.so:

$(call quiet-command,rm -f $@ && $(LINKPROG) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) -fPIC -shared -DBUILD_DSO $(CFLAGS)
$($@-cflags) $(LDFLAGS) $(LIBS) -o $@ $^," GEN $(TARGET_DIR)$@")

2. Add target in qemu-2.1.2/Makefile

qemu-kvm-obj = vl.o blockdev.o migration.o migration-unix.o qtest.o migration-fd.o ioport.o savevm.o cpus.o

qemu-kvm-obj += net/net.o net/queue.o

qemu-kvm-obj += ui/console.o

qemu-kvm-obj += qom/object.o

qemu-kvm-obj += hw/usb/bus.o

qemu-kvm-obj += pixman/pixman/pixman-bits-image.o pixman/pixman/pixman-utils.o

qemu-kvm-obj += qapi/qapi-visit-core.o

libqemu.so : $(block-obj-y) $(util-obj-y) qemu-img.o vmstate.o qemu-file.o $(qemu-kvm-obj) vl.o qapi-event.o migration.o blockdev.
o migration-unix.o qtest.o migration-fd.o

as you know, the main entrance for final binary qemu-system-x86_64 is located in vl.c, I just want it and qemu-img.o to be included in the so library, so it seems that there are many dependent objects above should have to be included, that would be suffering problem to be fixed below during doing this,

There are many platform dependent source code i.e. cpus.c memory.c, how to compile them into so for specific platform? Is there some guidance for building qemu to so? could you give help on this?

Thanks a lot!

Best Regards

Halsey Pian

#1 lore raw
Quoted 7 lines · Halsey Pian

./stubs/slirp.c:void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)

./main-loop.c: slirp_pollfds_fill(gpollfds, &timeout);

Do you know when qemustub should be used? libqemustub.a is only used for qemu-img, qemu-nbd, qemu-io, but not for qemu-system-x86_64(and other platform binary)?

No, the stub library is always linked. We rely on the linker's behaviour of only pulling a .o file out of the .a archive if it is needed to satisfy a symbol dependency not provided by one of the other .o files in the link. So if the program we're building provides an implementation of the function (in this example, if the binary links main-loop.c) then we will use that. If the program being built doesn't provide an implementation then we'll use the stub implementation.

-- PMM