Shared Library Module Support
Subsystems (2)
v2 cover Shared Library Module Support
This series implements feature of shared object building as described in:
http://wiki.qemu.org/Features/Modules
It's achieved in three steps, with extra bonus to change curl and qed to a shared library module in the end (only to demonstrate the usage, no "make install" support of .so files yet).
v2: <inline below>
1. Allow per object cflags and libs:
[01/06] make.rule: fix $(obj) to a real relative path
Slightly changed, added $(obj-base) to work with module dependency
variable expansion.
[02/06] rule.mak: allow per object cflags and libs2. Rules for building .so:
[03/06] Makefile: introduce common-obj-m and block-obj-m for DSO
[Richard] Change some rule generation and don't use "ln -r" to for intermediate object.
3. Code to load module. All .so files are scanned and loaded when program starts:
[04/06] module: implement module loading function
[mjt] Don't load all .so unconditionally, subsystem call module_load for specific type.
[Lluís] Used configure time prefix as the module base directory.
4. curl and qed adoption:
[05/06] curl: build as shared library
[06/06] qed: build as shared library
Added to demostrate how to write multi-file module.
Fam Zheng (6):
make.rule: fix $(obj) to a real relative path rule.mak: allow per object cflags and libs
Makefile: introduce common-obj-m and block-obj-m for DSO
module: implement module loading function
curl: build as shared library
qed: build as shared library
Makefile | 32 ++++++++++++++++++++++++++++--- Makefile.objs | 14 +++++++++++++- Makefile.target | 3 ++- block.c | 1 + block/Makefile.objs | 7 ++++--- bsd-user/main.c | 3 +++ configure | 28 +++++++++++++++------------ include/qemu/module.h | 9 +++++++++ linux-user/main.c | 3 +++ qemu-img.c | 1 + rules.mak | 25 +++++++++++++++++++------ scripts/create_config | 4 ++++ ui/console.c | 1 + util/Makefile.objs | 2 ++ util/module.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ vl.c | 2 ++ 16 files changed, 161 insertions(+), 26 deletions(-)
Signature · 1 line
1.8.3.1
RFC PATCH v2 1/6 make.rule: fix $(obj) to a real relative path
Makefile.target includes rule.mak and unnested common-obj-y, then prefix them with '../', this will ignore object specific QEMU_CFLAGS in subdir Makefile.objs:
$(obj)/curl.o: QEMU_CFLAGS += $(CURL_CFLAGS)
Because $(obj) here is './block', instead of '../block'. This doesn't hurt compiling because we basically build all .o from top Makefile, before entering Makefile.target, but it will affact arriving per-object libs support.
The starting point of $(obj) is fixed in $(obj-base) before including ./Makefile.objs, to get consistency with nested Makefile rules in target rule and variable definition.
--- Makefile.target | 3 ++- rules.mak | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-)
Makefile.target +2 -1
@@ -144,12 +144,13 @@ endif # CONFIG_SOFTMMU %/translate.o: QEMU_CFLAGS += $(TRANSLATE_OPT_CFLAGS) nested-vars += obj-y +obj-base := .. # This resolves all nested paths, so it must come last include $(SRC_PATH)/Makefile.objs all-obj-y = $(obj-y) -all-obj-y += $(addprefix ../, $(common-obj-y)) +all-obj-y += $(addprefix $(obj)/, $(common-obj-y)) ifndef CONFIG_HAIKU LIBS+=-lm
rules.mak +4 -3
@@ -103,7 +103,7 @@ clean: clean-timestamp # magic to descend into other directories -obj := . +obj = $(obj-base) old-nested-dirs := define push-var
@@ -119,9 +119,10 @@ endef define unnest-dir $(foreach var,$(nested-vars),$(call push-var,$(var),$1/)) -$(eval obj := $(obj)/$1) +$(eval old-obj := $(obj)) +$(eval obj := $(if $(obj),$(obj)/$1,$1)) $(eval include $(SRC_PATH)/$1/Makefile.objs) -$(eval obj := $(patsubst %/$1,%,$(obj))) +$(eval obj := $(old-obj)) $(foreach var,$(nested-vars),$(call pop-var,$(var),$1/)) endef
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [RFC PATCH v2 1/6] make.rule: fix $(obj) to a real relative path
Fam Zheng writes:
[...]
Quoted 4 lines
Because $(obj) here is './block', instead of '../block'. This doesn't hurt compiling because we basically build all .o from top
Makefile, before entering Makefile.target, but it will affact arriving per-object libs support.
I'm curious. What's the reason to not use recursive make in QEMU?
Thanks,
Lluis
Re: [Qemu-devel] [RFC PATCH v2 1/6] make.rule: fix $(obj) to a real relative path
Quoted 9 lines · Lluís Vilanova
Fam Zheng writes:
[...]Quoted 4 lines
Because $(obj) here is './block', instead of '../block'. This doesn't hurt compiling because we basically build all .o from top
Makefile, before entering Makefile.target, but it will affact arriving per-object libs support.I'm curious. What's the reason to not use recursive make in QEMU?
I don't know the answer, Paolo?
Fam
Re: [Qemu-devel] [RFC PATCH v2 1/6] make.rule: fix $(obj) to a real relative path
Il 09/09/2013 03:34, Fam Zheng ha scritto:
Quoted 11 lines · Lluís Vilanova
Quoted 9 lines
Fam Zheng writes:
[...]Quoted 4 lines
Because $(obj) here is './block', instead of '../block'. This doesn't hurt compiling because we basically build all .o from top
Makefile, before entering Makefile.target, but it will affact arriving per-object libs support.I'm curious. What's the reason to not use recursive make in QEMU?
I don't know the answer, Paolo?
It predates my involvement by a long time, so I don't know.
But my guess is that whenever directories are not present in the build tree (e.g. i386-softmmu/hw) we have to create the Makefile in the configure script. Thus a heavily declarative Makefile style works better.
Paolo
Re: [Qemu-devel] [RFC PATCH v2 1/6] make.rule: fix $(obj) to a real relative path
In reply to Lluís VilanovaQuoted 8 lines · Lluís Vilanova
Fam Zheng writes:
[...]Quoted 4 lines
Because $(obj) here is './block', instead of '../block'. This doesn't hurt compiling because we basically build all .o from top
Makefile, before entering Makefile.target, but it will affact arriving per-object libs support.I'm curious. What's the reason to not use recursive make in QEMU?
The classic paper is "Recursive make considered harmful":
http://aegis.sourceforge.net/auug97.pdf
-- PMM
RFC PATCH v2 2/6 rule.mak: allow per object cflags and libs
In reply to Fam ZhengAdds extract-libs in LINK to expand any "per object libs", the syntax to define such a libs options is like:
$(obj)/curl.o-libs = $(CURL_LIBS)
in block/Makefile.objs.
Similarly,
$(obj)foo.o-cflags = $(FOO_CFLAGS)
is also supported.
--- rules.mak | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
rules.mak +5 -3
@@ -17,15 +17,17 @@ QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d # Same as -I$(SRC_PATH) -I., but for the nested source/object directories QEMU_INCLUDES += -I$(<D) -I$(@D) +extract-libs = $(strip $(foreach o,$1,$($(obj-base)$o-libs))) + %.o: %.c - $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CC $(TARGET_DIR)$@") + $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $<," CC $(TARGET_DIR)$@") %.o: %.rc $(call quiet-command,$(WINDRES) -I. -o $@ $<," RC $(TARGET_DIR)$@") ifeq ($(LIBTOOL),) LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \ $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \ - $(LIBS)," LINK $(TARGET_DIR)$@") + $(call extract-libs,$^) $(LIBS)," LINK $(TARGET_DIR)$@") else LIBTOOL += $(if $(V),,--quiet) %.lo: %.c
@@ -41,7 +43,7 @@ LINK = $(call quiet-command,\ $(sort $(filter %.o, $1)) $(filter-out %.o, $1) \ $(if $(filter %.lo %.la,$^),$(version-lobj-y),$(version-obj-y)) \ $(if $(filter %.lo %.la,$^),$(LIBTOOLFLAGS)) \ - $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", " LINK ")"$(TARGET_DIR)$@") + $(call extract-libs,$^) $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", " LINK ")"$(TARGET_DIR)$@") endif %.asm: %.S
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [RFC PATCH v2 2/6] rule.mak: allow per object cflags and libs
Quoted 5 lines · Fam Zheng
Adds extract-libs in LINK to expand any "per object libs", the syntax to define such a libs options is like:
$(obj)/curl.o-libs = $(CURL_LIBS)
Quoted 7 lines
in
block/Makefile.objs.Similarly,
$(obj)foo.o-cflags = $(FOO_CFLAGS)is also supported.
Please note the UNsimilarity of -libs and -cflags -- one is with slash and another is without. Is it just the patch comment?
Thanks,
/mjt
Re: [Qemu-devel] [RFC PATCH v2 2/6] rule.mak: allow per object cflags and libs
Quoted 10 lines · Michael Tokarev
Quoted 9 lines · Fam Zheng
Adds extract-libs in LINK to expand any "per object libs", the syntax to define such a libs options is like:
$(obj)/curl.o-libs = $(CURL_LIBS)in
block/Makefile.objs.Similarly,
Quoted 8 lines
Quoted 3 lines
$(obj)foo.o-cflags = $(FOO_CFLAGS)is also supported.
Please note the UNsimilarity of -libs and -cflags -- one is with slash and another is without. Is it just the patch comment?
It's a typo in the commit message. I will fix it.
Thanks,
Fam
RFC PATCH v2 3/6 Makefile: introduce common-obj-m and block-obj-m for DSO
In reply to Fam ZhengAdd necessary rules and flags for shared object generation. $(common-obj-m) will include $(block-obj-m), like $(common-obj-y) does for $(block-obj-y). The new rules introduced here are:
0) For all %.so compiling:
QEMU_CFLAGS += -shared -fPIC
1) %.o in $(common-obj-m) is compiled to %.o, with "QEMU_CFLAGS += -shared -fPIC". Then linked to %.so.
2) %.mo in $(common-obj-m) is the placeholder for %.so for pattern matching in Makefile. It's linked to "-shared" with all its dependencies (multiple *.o) as input. Which means the list of depended objects must be ruled out in each sub-Makefile.objs with an variable:
$(obj)/foo.mo-obj := $(addprefix $(obj)/,bar.o baz.o qux.o)
Notice that $(obj)/ is required for both target and dependency in the rule. DSO suffix (.so) is configure variable (.dll for Windows).
--- Makefile | 32 +++++++++++++++++++++++++++++--- Makefile.objs | 14 +++++++++++++- configure | 3 +++ rules.mak | 10 ++++++++++ 4 files changed, 55 insertions(+), 4 deletions(-)
Makefile +29 -3
@@ -56,7 +56,7 @@ Makefile: ; configure: ; .PHONY: all clean cscope distclean dvi html info install install-doc \ - pdf recurse-all speed test dist + pdf recurse-all speed test dist modules $(call set-vpath, $(SRC_PATH))
@@ -121,7 +121,30 @@ ifeq ($(CONFIG_SMARTCARD_NSS),y) include $(SRC_PATH)/libcacard/Makefile endif -all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all +all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all modules + +mod-obj-m = $(patsubst %.o,%$(DSOSUF),$(filter %.o,$(common-obj-m))) \ + $(patsubst %.mo,%$(DSOSUF),$(filter %.mo,$(common-obj-m))) + +# Generate rules for single file modules (%.so: %.o). +$(foreach o,$(filter %.o,$(common-obj-m)),$(eval \ + $(patsubst %.o,%.so,$o): $o )) + +# For multi file modules, dependencies should be listed explicitly in +# Makefile.objs as +# $(obj)/foo.mo-obj := $(obj)/bar.o $(obj)/biz.o +$(foreach o,$(filter %.mo,$(mod-obj-m)),$(eval \ + $o: $($o-obj))) + +%.mo: + $(if $(BUILD_DYNAMIC), \ + $(call quiet-command,$(CC) $(sort $^) -shared -o $@," LD[M] $(TARGET_DIR)$@"), \ + $(call quiet-command,$(AR) rcs $@ $(sort $^)," AR $(TARGET_DIR)$@")) + + +modules: $(mod-obj-m) +modules: BUILD_DYNAMIC = 1 +modules: QEMU_CFLAGS += -shared -fPIC config-host.h: config-host.h-timestamp config-host.h-timestamp: config-host.mak
@@ -155,7 +178,7 @@ subdir-dtc:dtc/libfdt dtc/tests dtc/%: mkdir -p $@ -$(SUBDIR_RULES): libqemuutil.a libqemustub.a $(common-obj-y) +$(SUBDIR_RULES): libqemuutil.a libqemustub.a $(common-obj-y) $(common-obj-m) ROMSUBDIR_RULES=$(patsubst %,romsubdir-%, $(ROMS)) romsubdir-%:
@@ -235,6 +258,9 @@ clean: rm -f qemu-options.def find . -name '*.[oda]' -type f -exec rm -f {} + find . -name '*.l[oa]' -type f -exec rm -f {} + + find . -name '*'$(DSOSUF) -type f -exec rm -f {} + + find . -name '*.mo' -type f -exec rm -f {} + + rm -f $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~ rm -Rf .libs rm -f qemu-img-cmds.h
Makefile.objs +13 -1
@@ -19,6 +19,8 @@ block-obj-y += qemu-coroutine.o qemu-coroutine-lock.o qemu-coroutine-io.o block-obj-y += qemu-coroutine-sleep.o block-obj-y += coroutine-$(CONFIG_COROUTINE_BACKEND).o +block-obj-m = block/ + ifeq ($(CONFIG_VIRTIO)$(CONFIG_VIRTFS)$(CONFIG_PCI),yyy) # Lots of the fsdev/9pcode is pulled in by vl.c via qemu_fsdev_add. # only pull in the actual virtio-9p device if we also enabled virtio.
@@ -83,6 +85,9 @@ common-obj-$(CONFIG_SMARTCARD_NSS) += $(libcacard-y) common-obj-y += qmp-marshal.o common-obj-y += qmp.o hmp.o + +common-obj-m = $(block-obj-m) + endif ######################################################################
@@ -121,5 +126,12 @@ nested-vars += \ util-obj-y \ qga-obj-y \ block-obj-y \ - common-obj-y + block-obj-m \ + common-obj-y \ + common-obj-m + dummy := $(call unnest-vars) + +# static linked mods are expanded to .o list +dummy := $(call expand-mod-obj,common-obj-y) +dummy := $(call expand-mod-obj,block-obj-y)
configure +3 -0
@@ -190,6 +190,7 @@ mingw32="no" gcov="no" gcov_tool="gcov" EXESUF="" +DSOSUF=".so" prefix="/usr/local" mandir="\${prefix}/share/man" datadir="\${prefix}/share"
@@ -584,6 +585,7 @@ fi if test "$mingw32" = "yes" ; then EXESUF=".exe" + DSOSUF=".dll" QEMU_CFLAGS="-DWIN32_LEAN_AND_MEAN -DWINVER=0x501 $QEMU_CFLAGS" # enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later) QEMU_CFLAGS="-D__USE_MINGW_ANSI_STDIO=1 $QEMU_CFLAGS"
@@ -4175,6 +4177,7 @@ echo "LIBTOOLFLAGS=$LIBTOOLFLAGS" >> $config_host_mak echo "LIBS+=$LIBS" >> $config_host_mak echo "LIBS_TOOLS+=$libs_tools" >> $config_host_mak echo "EXESUF=$EXESUF" >> $config_host_mak +echo "DSOSUF=$DSOSUF" >> $config_host_mak echo "LIBS_QGA+=$libs_qga" >> $config_host_mak echo "POD2MAN=$POD2MAN" >> $config_host_mak echo "TRANSLATE_OPT_CFLAGS=$TRANSLATE_OPT_CFLAGS" >> $config_host_mak
rules.mak +10 -0
@@ -58,6 +58,10 @@ endif %.o: %.dtrace $(call quiet-command,dtrace -o $@ -G -s $<, " GEN $(TARGET_DIR)$@") +%$(DSOSUF): QEMU_CLFAGS += -shared -fPIC +%$(DSOSUF): %.o + $(call quiet-command,$(LD) $< -o $@ -shared," LD[M] $(TARGET_DIR)$@") + %$(EXESUF): %.o $(call LINK,$^)
@@ -145,3 +149,9 @@ $(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var)))))) $(foreach var,$(nested-vars), $(eval \ -include $(addsuffix *.d, $(sort $(dir $($(var))))))) endef + +define expand-mod-obj +$(eval pref = $(if $(obj-base),$(obj-base)/,)) +$(eval t = $(foreach o,$($1),$(if $($(pref)$o-obj),$($(pref)$o-obj),$o))) +$(eval $1 = $t) +endef
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [RFC PATCH v2 3/6] Makefile: introduce common-obj-m and block-obj-m for DSO
Il 06/09/2013 09:28, Fam Zheng ha scritto:
Quoted 16 lines
Add necessary rules and flags for shared object generation. $(common-obj-m) will include $(block-obj-m), like $(common-obj-y) does for $(block-obj-y). The new rules introduced here are:
0) For all %.so compiling:
QEMU_CFLAGS += -shared -fPIC1) %.o in $(common-obj-m) is compiled to %.o, with "
QEMU_CFLAGS+= -shared -fPIC". Then linked to %.so.2) %.mo in $(common-obj-m) is the placeholder for %.so for pattern matching in
Makefile. It's linked to "-shared" with all its dependencies (multiple *.o) as input. Which means the list of depended objects must be ruled out in each sub-Makefile.objs with an variable:
Quoted 4 lines
$(obj)/foo.mo-obj := $(addprefix $(obj)/,bar.o baz.o qux.o)Notice that $(obj)/ is required for both target and dependency in the rule. DSO suffix (.so) is configure variable (.dll for Windows).
Some kinks to iron, but this is really well-architected. You took all the best parts of mjt's patches and fixed almost all the ugly ones. Kudos!
Quoted 22 lines
Signed-off-by Fam Zheng <[email protected]>--- Makefile | 32 +++++++++++++++++++++++++++++--- Makefile.objs | 14 +++++++++++++- configure | 3 +++ rules.mak | 10 ++++++++++ 4 files changed, 55 insertions(+), 4 deletions(-)Makefile +1
-1@@ -56,7 +56,7 @@ Makefile: ; configure: ; .PHONY: all clean cscope distclean dvi html info install install-doc \ - pdf recurse-all speed test dist + pdf recurse-all speed test dist modules $(call set-vpath, $(SRC_PATH))
Makefile ifeq ($(CONFIG_SMARTCARD_NSS),y) · line 127
Quoted 8 lines
Makefile +4
-1@@ -121,7 +121,30 @@ ifeq ($(CONFIG_SMARTCARD_NSS),y) include $(SRC_PATH)/libcacard/Makefile endif -all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all +all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all modules + +mod-obj-m = $(patsubst %.o,%$(DSOSUF),$(filter %.o,$(common-obj-m))) \ + $(patsubst %.mo,%$(DSOSUF),$(filter %.mo,$(common-obj-m)))
Why common-obj-m only, what about block-obj-m?
Perhaps adding to mod-obj-m (better name: modules-m) can be done in unnest-vars?
Makefile ifeq ($(CONFIG_SMARTCARD_NSS),y) · line 131
Quoted 3 lines
Makefile +3
-0+# Generate rules for single file modules (%.so: %.o). +$(foreach o,$(filter %.o,$(common-obj-m)),$(eval \ + $(patsubst %.o,%.so,$o): $o ))
If you subst %.o to %.mo, you can use the same set of rules for both cases.
Makefile ifeq ($(CONFIG_SMARTCARD_NSS),y) · line 135
Quoted 3 lines
Makefile +3
-0+# For multi file modules, dependencies should be listed explicitly in +# Makefile.objs as +# $(obj)/foo.mo-obj := $(obj)/bar.o $(obj)/biz.o
Why not
$(obj)/foo.mo: $(obj)/bar.o $(obj)/biz.o
?
Makefile ifeq ($(CONFIG_SMARTCARD_NSS),y) · line 142
Quoted 7 lines
Makefile +7
-0+$(foreach o,$(filter %.mo,$(mod-obj-m)),$(eval \ + $o: $($o-obj))) + +%.mo: + $(if $(BUILD_DYNAMIC), \ + $(call quiet-command,$(CC) $(sort $^) -shared -o $@," LD[M] $(TARGET_DIR)$@"), \ + $(call quiet-command,$(AR) rcs $@ $(sort $^)," AR $(TARGET_DIR)$@"))
I think we can always build modules dynamically. If the module/no-module configure option decides whether an object moves between *-obj-y and *-obj-m, statically-linked modules will just go on the linker command line with no need for $(AR) or --whole-archive/--no-whole-archive.
I'm missing where is the .so built (or I guess it can just be hard-linked?) from the .mo file.
IIRC -shared is not portable to Darwin. Darwin has separate file formats for dynamic libraries (.dylib) and loadable modules (.so), so it needs "-bundle" instad. All this screams "just use libtool"...
Makefile ifeq ($(CONFIG_SMARTCARD_NSS),y) · line 147
Quoted 5 lines
Makefile +5
-0+ + +modules: $(mod-obj-m) +modules: BUILD_DYNAMIC = 1 +modules: QEMU_CFLAGS += -shared -fPIC
-shared is not needed here, only -fPIC. Again, libtool would abstract this nicely. But it's fine if you prefer to have v3 still without libtool and only working on ELF systems.
In fact, you probably don't need a special modules target. You can just add $(mod-obj-m) to "all".
Quoted 92 lines
Makefile +4
-1config-host.h: config-host.h-timestamp config-host.h-timestamp: config-host.mak@@ -155,7 +178,7 @@ subdir-dtc:dtc/libfdt dtc/tests dtc/%: mkdir -p $@ -$(SUBDIR_RULES): libqemuutil.a libqemustub.a $(common-obj-y) +$(SUBDIR_RULES): libqemuutil.a libqemustub.a $(common-obj-y) $(common-obj-m) ROMSUBDIR_RULES=$(patsubst %,romsubdir-%, $(ROMS)) romsubdir-%:@@ -235,6 +258,9 @@ clean: rm -f qemu-options.def find . -name '*.[oda]' -type f -exec rm -f {} + find . -name '*.l[oa]' -type f -exec rm -f {} + + find . -name '*'$(DSOSUF) -type f -exec rm -f {} + + find . -name '*.mo' -type f -exec rm -f {} + + rm -f $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~ rm -Rf .libs rm -f qemu-img-cmds.hMakefile.objs +13
-1@@ -19,6 +19,8 @@ block-obj-y += qemu-coroutine.o qemu-coroutine-lock.o qemu-coroutine-io.o block-obj-y += qemu-coroutine-sleep.o block-obj-y += coroutine-$(CONFIG_COROUTINE_BACKEND).o +block-obj-m = block/ + ifeq ($(CONFIG_VIRTIO)$(CONFIG_VIRTFS)$(CONFIG_PCI),yyy) # Lots of the fsdev/9pcode is pulled in by vl.c via qemu_fsdev_add. # only pull in the actual virtio-9p device if we also enabled virtio.@@ -83,6 +85,9 @@ common-obj-$(CONFIG_SMARTCARD_NSS) += $(libcacard-y) common-obj-y += qmp-marshal.o common-obj-y += qmp.o hmp.o + +common-obj-m = $(block-obj-m) + endif ######################################################################@@ -121,5 +126,12 @@ nested-vars += \ util-obj-y \ qga-obj-y \ block-obj-y \ - common-obj-y + block-obj-m \ + common-obj-y \ + common-obj-m + dummy := $(call unnest-vars) + +# static linked mods are expanded to .o list +dummy := $(call expand-mod-obj,common-obj-y) +dummy := $(call expand-mod-obj,block-obj-y)configure +3
-0@@ -190,6 +190,7 @@ mingw32="no" gcov="no" gcov_tool="gcov" EXESUF="" +DSOSUF=".so" prefix="/usr/local" mandir="\${prefix}/share/man" datadir="\${prefix}/share"@@ -584,6 +585,7 @@ fi if test "$mingw32" = "yes" ; then EXESUF=".exe" + DSOSUF=".dll" QEMU_CFLAGS="-DWIN32_LEAN_AND_MEAN -DWINVER=0x501 $QEMU_CFLAGS" # enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later) QEMU_CFLAGS="-D__USE_MINGW_ANSI_STDIO=1 $QEMU_CFLAGS"@@ -4175,6 +4177,7 @@ echo "LIBTOOLFLAGS=$LIBTOOLFLAGS" >> $config_host_mak echo "LIBS+=$LIBS" >> $config_host_mak echo "LIBS_TOOLS+=$libs_tools" >> $config_host_mak echo "EXESUF=$EXESUF" >> $config_host_mak +echo "DSOSUF=$DSOSUF" >> $config_host_mak echo "LIBS_QGA+=$libs_qga" >> $config_host_mak echo "POD2MAN=$POD2MAN" >> $config_host_mak echo "TRANSLATE_OPT_CFLAGS=$TRANSLATE_OPT_CFLAGS" >> $config_host_makrules.mak +0
-0
rules.mak endif · line 64
Quoted 7 lines
rules.mak +4
-0@@ -58,6 +58,10 @@ endif %.o: %.dtrace $(call quiet-command,dtrace -o $@ -G -s $<, " GEN $(TARGET_DIR)$@") +%$(DSOSUF): QEMU_CLFAGS += -shared -fPIC +%$(DSOSUF): %.o + $(call quiet-command,$(LD) $< -o $@ -shared," LD[M] $(TARGET_DIR)$@") +
As mentioned above, I think these four lines are not needed and you can always go through the "modules" or $(mod-obj-m) targets. In fact, CLFAGS sounds dubious. :)
Paolo
Quoted 14 lines
rules.mak +6
-0%$(EXESUF): %.o $(call LINK,$^)@@ -145,3 +149,9 @@ $(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var)))))) $(foreach var,$(nested-vars), $(eval \ -include $(addsuffix *.d, $(sort $(dir $($(var))))))) endef + +define expand-mod-obj +$(eval pref = $(if $(obj-base),$(obj-base)/,)) +$(eval t = $(foreach o,$($1),$(if $($(pref)$o-obj),$($(pref)$o-obj),$o))) +$(eval $1 = $t) +endef
Re: [Qemu-devel] [RFC PATCH v2 3/6] Makefile: introduce common-obj-m and block-obj-m for DSO
Quoted 50 lines · Paolo Bonzini
Il 06/09/2013 09:28, Fam Zheng ha scritto:
Quoted 16 lines
Add necessary rules and flags for shared object generation. $(common-obj-m) will include $(block-obj-m), like $(common-obj-y) does for $(block-obj-y). The new rules introduced here are:
0) For all %.so compiling:
QEMU_CFLAGS += -shared -fPIC1) %.o in $(common-obj-m) is compiled to %.o, with "
QEMU_CFLAGS+= -shared -fPIC". Then linked to %.so.2) %.mo in $(common-obj-m) is the placeholder for %.so for pattern matching in
Makefile. It's linked to "-shared" with all its dependencies (multiple *.o) as input. Which means the list of depended objects must be ruled out in each sub-Makefile.objs with an variable:Quoted 4 lines
$(obj)/foo.mo-obj := $(addprefix $(obj)/,bar.o baz.o qux.o)Notice that $(obj)/ is required for both target and dependency in the rule. DSO suffix (.so) is configure variable (.dll for Windows).
Some kinks to iron, but this is really well-architected. You took all the best parts of mjt's patches and fixed almost all the ugly ones. Kudos!
Quoted 25 lines
Signed-off-by Fam Zheng <[email protected]>--- Makefile | 32 +++++++++++++++++++++++++++++--- Makefile.objs | 14 +++++++++++++- configure | 3 +++ rules.mak | 10 ++++++++++ 4 files changed, 55 insertions(+), 4 deletions(-)Makefile +1
-1@@ -56,7 +56,7 @@ Makefile: ; configure: ; .PHONY: all clean cscope distclean dvi html info install install-doc \ - pdf recurse-all speed test dist + pdf recurse-all speed test dist modules $(call set-vpath, $(SRC_PATH))@@ -121,7 +121,30 @@ ifeq ($(CONFIG_SMARTCARD_NSS),y) include $(SRC_PATH)/libcacard/Makefile endif
Quoted 9 lines
Makefile ifeq ($(CONFIG_SMARTCARD_NSS),y) · line 127
Quoted 5 lines
Makefile +4
-1-all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all +all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all modules + +mod-obj-m = $(patsubst %.o,%$(DSOSUF),$(filter %.o,$(common-obj-m))) \ + $(patsubst %.mo,%$(DSOSUF),$(filter %.mo,$(common-obj-m)))Why common-obj-m only, what about block-obj-m?
Because common-obj-m = $(block-obj-m), in Makefile.objs below.
Quoted 2 lines
Perhaps adding to mod-obj-m (better name: modules-m) can be done in unnest-vars?
It looks more straightforward for me to do here, and it's used very locally.
Quoted 13 lines
Makefile ifeq ($(CONFIG_SMARTCARD_NSS),y) · line 131
Quoted 4 lines
Makefile +3
-0+# Generate rules for single file modules (%.so: %.o). +$(foreach o,$(filter %.o,$(common-obj-m)),$(eval \ + $(patsubst %.o,%.so,$o): $o ))If you subst %.o to %.mo, you can use the same set of rules for both cases.
Makefile ifeq ($(CONFIG_SMARTCARD_NSS),y) · line 135
Quoted 3 lines
Makefile +3
-0+# For multi file modules, dependencies should be listed explicitly in +# Makefile.objs as +# $(obj)/foo.mo-obj := $(obj)/bar.o $(obj)/biz.oWhy not
Quoted 4 lines
$(obj)/foo.mo: $(obj)/bar.o $(obj)/biz.o
?
Because I don't know how to expand foo.mo to bar.o and biz.o: I expand "foo.mo" to "bar.o biz.o" in the link command line, to skip creating to foo.mo, or libfoo.a, if it's to be linked static:
block-obj-y += foo.mo
That's for avoiding ar and ln -r.
Quoted 5 lines
Quoted 5 lines
Makefile +5
-0+$(foreach o,$(filter %.mo,$(mod-obj-m)),$(eval \ + $o: $($o-obj))) + +%.mo: + $(if $(BUILD_DYNAMIC), \
Quoted 9 lines
Makefile ifeq ($(CONFIG_SMARTCARD_NSS),y) · line 142
Quoted 2 lines
Makefile +2
-0+ $(call quiet-command,$(CC) $(sort $^) -shared -o $@," LD[M] $(TARGET_DIR)$@"), \ + $(call quiet-command,$(AR) rcs $@ $(sort $^)," AR $(TARGET_DIR)$@"))I think we can always build modules dynamically. If the module/no-module configure option decides whether an object moves between *-obj-y and *-obj-m, statically-linked modules will just go on the linker command line with no need for $(AR) or --whole-archive/--no-whole-archive.
I don't understand, do you mean a "cc -shared" output can be statically linked into a executable?
Quoted 141 lines
I'm missing where is the .so built (or I guess it can just be hard-linked?) from the .mo file.
IIRC -shared is not portable to Darwin. Darwin has separate file formats for dynamic libraries (.dylib) and loadable modules (.so), so it needs "-bundle" instad. All this screams "just use libtool"...
Makefile ifeq ($(CONFIG_SMARTCARD_NSS),y) · line 147
Quoted 5 lines
Makefile +5
-0+ + +modules: $(mod-obj-m) +modules: BUILD_DYNAMIC = 1 +modules: QEMU_CFLAGS += -shared -fPIC-shared is not needed here, only -fPIC. Again, libtool would abstract this nicely. But it's fine if you prefer to have v3 still without libtool and only working on ELF systems.
In fact, you probably don't need a special modules target. You can just add $(mod-obj-m) to "all".
Quoted 92 lines
Makefile +4
-1config-host.h: config-host.h-timestamp config-host.h-timestamp: config-host.mak@@ -155,7 +178,7 @@ subdir-dtc:dtc/libfdt dtc/tests dtc/%: mkdir -p $@ -$(SUBDIR_RULES): libqemuutil.a libqemustub.a $(common-obj-y) +$(SUBDIR_RULES): libqemuutil.a libqemustub.a $(common-obj-y) $(common-obj-m) ROMSUBDIR_RULES=$(patsubst %,romsubdir-%, $(ROMS)) romsubdir-%:@@ -235,6 +258,9 @@ clean: rm -f qemu-options.def find . -name '*.[oda]' -type f -exec rm -f {} + find . -name '*.l[oa]' -type f -exec rm -f {} + + find . -name '*'$(DSOSUF) -type f -exec rm -f {} + + find . -name '*.mo' -type f -exec rm -f {} + + rm -f $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~ rm -Rf .libs rm -f qemu-img-cmds.hMakefile.objs +13
-1@@ -19,6 +19,8 @@ block-obj-y += qemu-coroutine.o qemu-coroutine-lock.o qemu-coroutine-io.o block-obj-y += qemu-coroutine-sleep.o block-obj-y += coroutine-$(CONFIG_COROUTINE_BACKEND).o +block-obj-m = block/ + ifeq ($(CONFIG_VIRTIO)$(CONFIG_VIRTFS)$(CONFIG_PCI),yyy) # Lots of the fsdev/9pcode is pulled in by vl.c via qemu_fsdev_add. # only pull in the actual virtio-9p device if we also enabled virtio.@@ -83,6 +85,9 @@ common-obj-$(CONFIG_SMARTCARD_NSS) += $(libcacard-y) common-obj-y += qmp-marshal.o common-obj-y += qmp.o hmp.o + +common-obj-m = $(block-obj-m) + endif ######################################################################@@ -121,5 +126,12 @@ nested-vars += \ util-obj-y \ qga-obj-y \ block-obj-y \ - common-obj-y + block-obj-m \ + common-obj-y \ + common-obj-m + dummy := $(call unnest-vars) + +# static linked mods are expanded to .o list +dummy := $(call expand-mod-obj,common-obj-y) +dummy := $(call expand-mod-obj,block-obj-y)configure +3
-0@@ -190,6 +190,7 @@ mingw32="no" gcov="no" gcov_tool="gcov" EXESUF="" +DSOSUF=".so" prefix="/usr/local" mandir="\${prefix}/share/man" datadir="\${prefix}/share"@@ -584,6 +585,7 @@ fi if test "$mingw32" = "yes" ; then EXESUF=".exe" + DSOSUF=".dll" QEMU_CFLAGS="-DWIN32_LEAN_AND_MEAN -DWINVER=0x501 $QEMU_CFLAGS" # enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later) QEMU_CFLAGS="-D__USE_MINGW_ANSI_STDIO=1 $QEMU_CFLAGS"@@ -4175,6 +4177,7 @@ echo "LIBTOOLFLAGS=$LIBTOOLFLAGS" >> $config_host_mak echo "LIBS+=$LIBS" >> $config_host_mak echo "LIBS_TOOLS+=$libs_tools" >> $config_host_mak echo "EXESUF=$EXESUF" >> $config_host_mak +echo "DSOSUF=$DSOSUF" >> $config_host_mak echo "LIBS_QGA+=$libs_qga" >> $config_host_mak echo "POD2MAN=$POD2MAN" >> $config_host_mak echo "TRANSLATE_OPT_CFLAGS=$TRANSLATE_OPT_CFLAGS" >> $config_host_makrules.mak +0
-0rules.mak endif · line 64
Quoted 7 lines
rules.mak +4
-0@@ -58,6 +58,10 @@ endif %.o: %.dtrace $(call quiet-command,dtrace -o $@ -G -s $<, " GEN $(TARGET_DIR)$@") +%$(DSOSUF): QEMU_CLFAGS += -shared -fPIC +%$(DSOSUF): %.o + $(call quiet-command,$(LD) $< -o $@ -shared," LD[M] $(TARGET_DIR)$@") +As mentioned above, I think these four lines are not needed and you can always go through the "modules" or $(mod-obj-m) targets. In fact, CLFAGS sounds dubious. :)
Paolo
Quoted 14 lines
rules.mak +6
-0%$(EXESUF): %.o $(call LINK,$^)@@ -145,3 +149,9 @@ $(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var)))))) $(foreach var,$(nested-vars), $(eval \ -include $(addsuffix *.d, $(sort $(dir $($(var))))))) endef + +define expand-mod-obj +$(eval pref = $(if $(obj-base),$(obj-base)/,)) +$(eval t = $(foreach o,$($1),$(if $($(pref)$o-obj),$($(pref)$o-obj),$o))) +$(eval $1 = $t) +endef
Re: [Qemu-devel] [RFC PATCH v2 3/6] Makefile: introduce common-obj-m and block-obj-m for DSO
Il 06/09/2013 13:47, Fam Zheng ha scritto:
Quoted 60 lines · Paolo Bonzini
Quoted 50 lines
Il 06/09/2013 09:28, Fam Zheng ha scritto:
Quoted 16 lines
Add necessary rules and flags for shared object generation. $(common-obj-m) will include $(block-obj-m), like $(common-obj-y) does for $(block-obj-y). The new rules introduced here are:
0) For all %.so compiling:
QEMU_CFLAGS += -shared -fPIC1) %.o in $(common-obj-m) is compiled to %.o, with "
QEMU_CFLAGS+= -shared -fPIC". Then linked to %.so.2) %.mo in $(common-obj-m) is the placeholder for %.so for pattern matching in
Makefile. It's linked to "-shared" with all its dependencies (multiple *.o) as input. Which means the list of depended objects must be ruled out in each sub-Makefile.objs with an variable:Quoted 4 lines
$(obj)/foo.mo-obj := $(addprefix $(obj)/,bar.o baz.o qux.o)Notice that $(obj)/ is required for both target and dependency in the rule. DSO suffix (.so) is configure variable (.dll for Windows).
Some kinks to iron, but this is really well-architected. You took all the best parts of mjt's patches and fixed almost all the ugly ones. Kudos!
Quoted 25 lines
Signed-off-by Fam Zheng <[email protected]>--- Makefile | 32 +++++++++++++++++++++++++++++--- Makefile.objs | 14 +++++++++++++- configure | 3 +++ rules.mak | 10 ++++++++++ 4 files changed, 55 insertions(+), 4 deletions(-)Makefile +1
-1@@ -56,7 +56,7 @@ Makefile: ; configure: ; .PHONY: all clean cscope distclean dvi html info install install-doc \ - pdf recurse-all speed test dist + pdf recurse-all speed test dist modules $(call set-vpath, $(SRC_PATH))@@ -121,7 +121,30 @@ ifeq ($(CONFIG_SMARTCARD_NSS),y) include $(SRC_PATH)/libcacard/Makefile endifQuoted 9 lines
Makefile ifeq ($(CONFIG_SMARTCARD_NSS),y) · line 127
Quoted 5 lines
Makefile +4
-1-all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all +all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all modules + +mod-obj-m = $(patsubst %.o,%$(DSOSUF),$(filter %.o,$(common-obj-m))) \ + $(patsubst %.mo,%$(DSOSUF),$(filter %.mo,$(common-obj-m)))Why common-obj-m only, what about block-obj-m?
Quoted 6 lines
Because common-obj-m = $(block-obj-m), in Makefile.objs below.
Quoted 2 lines
Perhaps adding to mod-obj-m (better name: modules-m) can be done in unnest-vars?
It looks more straightforward for me to do here, and it's used very locally.
But it doesn't scale too well, does it? There's no particular reason why all -m variables would be included in common-obj-m. In fact, block- obj-y/block-obj-m are the only remaining case of one variable including another. In another review I even proposed eliminating this exception.
Quoted 16 lines
Quoted 12 lines
Makefile ifeq ($(CONFIG_SMARTCARD_NSS),y) · line 131
Quoted 3 lines
Makefile +3
-0+# Generate rules for single file modules (%.so: %.o). +$(foreach o,$(filter %.o,$(common-obj-m)),$(eval \ + $(patsubst %.o,%.so,$o): $o ))If you subst %.o to %.mo, you can use the same set of rules for both cases.
Makefile ifeq ($(CONFIG_SMARTCARD_NSS),y) · line 135
Quoted 3 lines
Makefile +3
-0+# For multi file modules, dependencies should be listed explicitly in +# Makefile.objs as +# $(obj)/foo.mo-obj := $(obj)/bar.o $(obj)/biz.oWhy not
Quoted 4 lines
$(obj)/foo.mo: $(obj)/bar.o $(obj)/biz.o
?
Quoted 7 lines
Because I don't know how to expand foo.mo to bar.o and biz.o: I expand "foo.mo" to "bar.o biz.o" in the link command line, to skip creating to foo.mo, or libfoo.a, if it's to be linked static:
block-obj-y += foo.moThat's for avoiding ar and ln -r.
Ah, I see now. See below for an idea (if it works).
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
Makefile +5
-0+$(foreach o,$(filter %.mo,$(mod-obj-m)),$(eval \ + $o: $($o-obj))) + +%.mo: + $(if $(BUILD_DYNAMIC), \Quoted 9 lines
Makefile ifeq ($(CONFIG_SMARTCARD_NSS),y) · line 142
Quoted 2 lines
Makefile +2
-0+ $(call quiet-command,$(CC) $(sort $^) -shared -o $@," LD[M] $(TARGET_DIR)$@"), \ + $(call quiet-command,$(AR) rcs $@ $(sort $^)," AR $(TARGET_DIR)$@"))I think we can always build modules dynamically. If the module/no-module configure option decides whether an object moves between *-obj-y and *-obj-m, statically-linked modules will just go on the linker command line with no need for $(AR) or --whole-archive/--no-whole-archive.
Quoted 2 lines
I don't understand, do you mean a "cc -shared" output can be statically linked into a executable?
So if I understand correctly the .mo file is never used for a statically-linked module? So the "ar" doesn't matter as things stand
Perhaps you could just use .mo file as a placeholder that holds the module's list of dependencies, no matter if it is shared or static:
%.mo:
$(call quiet-command,echo $(sort $^) > $@," GEN $(TARGET_DIR_$@"))
In the LINK rule include the list from all .mo files:
$(sort $(filter %.o, $1)) \ $(shell cat $(filter %.mo,$^)) \ $(filter-out %.o %.mo,$^))
And the rule for shared objects would be simply:
%.$(DSOSUF): QEMU_LDFLAGS += -shared
%.$(DSOSUF): %.mo
$(call LINK,$^)
This would remove the need for the $i-obj variables.
Paolo
Re: [Qemu-devel] [RFC PATCH v2 3/6] Makefile: introduce common-obj-m and block-obj-m for DSO
Quoted 131 lines · Paolo Bonzini
Il 06/09/2013 13:47, Fam Zheng ha scritto:
Quoted 60 lines · Paolo Bonzini
Quoted 50 lines
Il 06/09/2013 09:28, Fam Zheng ha scritto:
Quoted 16 lines
Add necessary rules and flags for shared object generation. $(common-obj-m) will include $(block-obj-m), like $(common-obj-y) does for $(block-obj-y). The new rules introduced here are:
0) For all %.so compiling:
QEMU_CFLAGS += -shared -fPIC1) %.o in $(common-obj-m) is compiled to %.o, with "
QEMU_CFLAGS+= -shared -fPIC". Then linked to %.so.2) %.mo in $(common-obj-m) is the placeholder for %.so for pattern matching in
Makefile. It's linked to "-shared" with all its dependencies (multiple *.o) as input. Which means the list of depended objects must be ruled out in each sub-Makefile.objs with an variable:Quoted 4 lines
$(obj)/foo.mo-obj := $(addprefix $(obj)/,bar.o baz.o qux.o)Notice that $(obj)/ is required for both target and dependency in the rule. DSO suffix (.so) is configure variable (.dll for Windows).
Some kinks to iron, but this is really well-architected. You took all the best parts of mjt's patches and fixed almost all the ugly ones. Kudos!
Quoted 25 lines
Signed-off-by Fam Zheng <[email protected]>--- Makefile | 32 +++++++++++++++++++++++++++++--- Makefile.objs | 14 +++++++++++++- configure | 3 +++ rules.mak | 10 ++++++++++ 4 files changed, 55 insertions(+), 4 deletions(-)Makefile +1
-1@@ -56,7 +56,7 @@ Makefile: ; configure: ; .PHONY: all clean cscope distclean dvi html info install install-doc \ - pdf recurse-all speed test dist + pdf recurse-all speed test dist modules $(call set-vpath, $(SRC_PATH))@@ -121,7 +121,30 @@ ifeq ($(CONFIG_SMARTCARD_NSS),y) include $(SRC_PATH)/libcacard/Makefile endifQuoted 9 lines
Makefile ifeq ($(CONFIG_SMARTCARD_NSS),y) · line 127
Quoted 5 lines
Makefile +4
-1-all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all +all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all modules + +mod-obj-m = $(patsubst %.o,%$(DSOSUF),$(filter %.o,$(common-obj-m))) \ + $(patsubst %.mo,%$(DSOSUF),$(filter %.mo,$(common-obj-m)))Why common-obj-m only, what about block-obj-m?
Quoted 6 lines
Because common-obj-m = $(block-obj-m), in Makefile.objs below.
Quoted 2 lines
Perhaps adding to mod-obj-m (better name: modules-m) can be done in unnest-vars?
It looks more straightforward for me to do here, and it's used very locally.
But it doesn't scale too well, does it? There's no particular reason why all -m variables would be included in common-obj-m. In fact, block- obj-y/block-obj-m are the only remaining case of one variable including another. In another review I even proposed eliminating this exception.
Quoted 16 lines
Quoted 12 lines
Makefile ifeq ($(CONFIG_SMARTCARD_NSS),y) · line 131
Quoted 3 lines
Makefile +3
-0+# Generate rules for single file modules (%.so: %.o). +$(foreach o,$(filter %.o,$(common-obj-m)),$(eval \ + $(patsubst %.o,%.so,$o): $o ))If you subst %.o to %.mo, you can use the same set of rules for both cases.
Makefile ifeq ($(CONFIG_SMARTCARD_NSS),y) · line 135
Quoted 3 lines
Makefile +3
-0+# For multi file modules, dependencies should be listed explicitly in +# Makefile.objs as +# $(obj)/foo.mo-obj := $(obj)/bar.o $(obj)/biz.oWhy not
Quoted 4 lines
$(obj)/foo.mo: $(obj)/bar.o $(obj)/biz.o
?
Quoted 7 lines
Because I don't know how to expand foo.mo to bar.o and biz.o: I expand "foo.mo" to "bar.o biz.o" in the link command line, to skip creating to foo.mo, or libfoo.a, if it's to be linked static:
block-obj-y += foo.moThat's for avoiding ar and ln -r.
Ah, I see now. See below for an idea (if it works).
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
Makefile +5
-0+$(foreach o,$(filter %.mo,$(mod-obj-m)),$(eval \ + $o: $($o-obj))) + +%.mo: + $(if $(BUILD_DYNAMIC), \Quoted 9 lines
Makefile ifeq ($(CONFIG_SMARTCARD_NSS),y) · line 142
Quoted 2 lines
Makefile +2
-0+ $(call quiet-command,$(CC) $(sort $^) -shared -o $@," LD[M] $(TARGET_DIR)$@"), \ + $(call quiet-command,$(AR) rcs $@ $(sort $^)," AR $(TARGET_DIR)$@"))I think we can always build modules dynamically. If the module/no-module configure option decides whether an object moves between *-obj-y and *-obj-m, statically-linked modules will just go on the linker command line with no need for $(AR) or --whole-archive/--no-whole-archive.
Quoted 2 lines
I don't understand, do you mean a "cc -shared" output can be statically linked into a executable?
So if I understand correctly the .mo file is never used for a statically-linked module? So the "ar" doesn't matter as things stand
Perhaps you could just use .mo file as a placeholder that holds the module's list of dependencies, no matter if it is shared or static:
%.mo:
$(call quiet-command,echo $(sort $^) > $@," GEN $(TARGET_DIR_$@"))In the LINK rule include the list from all .mo files:
$(sort $(filter %.o, $1)) \ $(shell cat $(filter %.mo,$^)) \ $(filter-out %.o %.mo,$^))
Quoted 8 lines
And the rule for shared objects would be simply:
%.$(DSOSUF):
QEMU_LDFLAGS+= -shared
%.$(DSOSUF): %.mo$(call LINK,$^)This would remove the need for the $i-obj variables.
Actually I would like a try to keep $i-{obj,cflags,libs}:
foo-obj := bar.o biz.o
foo-libs := $(FOO_LIBS)
foo-cflags := $(FOO_CFLAGS)getting rid of all the $(obj)/'s and expand them in the toplevel unnest magic (because we know foo.mo is contained in local $(block-obj-y) so it's all trackable).
If this idea can't work out, I'll use your suggested way.
Thanks,
Fam
Re: [Qemu-devel] [RFC PATCH v2 3/6] Makefile: introduce common-obj-m and block-obj-m for DSO
Il 09/09/2013 04:26, Fam Zheng ha scritto:
Quoted 11 lines
Actually I would like a try to keep $i-{obj,cflags,libs}:
foo-obj := bar.o biz.o foo-libs := $(FOO_LIBS) foo-cflags := $(FOO_CFLAGS)getting rid of all the $(obj)/'s and expand them in the toplevel unnest magic (because we know foo.mo is contained in local $(block-obj-y) so it's all trackable).
If this idea can't work out, I'll use your suggested way.
Yes, either way works (i.e. as long as it's consistent).
Paolo
RFC PATCH v2 4/6 module: implement module loading function
In reply to Fam ZhengAdded three types of modules:
typedef enum {
MODULE_LOAD_BLOCK = 0,
MODULE_LOAD_UI,
MODULE_LOAD_NET,
MODULE_LOAD_MAX,
} module_load_type;and their loading function:
void module_load(module_load_type).
which loads all ".so" files in a subdir under "${PREFIX}/qemu/", e.g. "/usr/lib/qemu/block". Modules of each type should be loaded before respective subsystem initialization code.
Requires gmodule-2.0 from glib.
--- block.c | 1 + bsd-user/main.c | 3 +++ configure | 20 +++++++++++--------- include/qemu/module.h | 9 +++++++++ linux-user/main.c | 3 +++ qemu-img.c | 1 + scripts/create_config | 4 ++++ ui/console.c | 1 + util/Makefile.objs | 2 ++ util/module.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ vl.c | 2 ++ 11 files changed, 89 insertions(+), 9 deletions(-)
block.c +1 -0
@@ -4009,6 +4009,7 @@ BlockDriverAIOCB *bdrv_aio_discard(BlockDriverState *bs,void bdrv_init (void ) { +module_load (MODULE_LOAD_BLOCK );module_call_init (MODULE_INIT_BLOCK ); }
bsd-user/main.c +3 -0
@@ -33,6 +33,7 @@#include "tcg.h" #include "qemu/timer.h" #include "qemu/envlist.h" +#include "qemu/module.h" int singlestep;#if defined(CONFIG_USE_GUEST_BASE )
@@ -749,6 +750,8 @@ int main(int argc, char **argv)if (argc <=1 )usage (); +module_load (MODULE_LOAD_UI ); +module_load (MODULE_LOAD_NET );module_call_init (MODULE_INIT_QOM );if ((envlist =envlist_create ()) ==NULL ) {
configure +11 -9
@@ -2249,15 +2249,17 @@ if test "$mingw32" = yes; then else glib_req_ver=2.12 fi -if $pkg_config --atleast-version=$glib_req_ver gthread-2.0 > /dev/null 2>&1 -then - glib_cflags=`$pkg_config --cflags gthread-2.0 2>/dev/null` - glib_libs=`$pkg_config --libs gthread-2.0 2>/dev/null` - LIBS="$glib_libs $LIBS" - libs_qga="$glib_libs $libs_qga" -else - error_exit "glib-$glib_req_ver required to compile QEMU" -fi +for i in gthread-2.0 gmodule-2.0; do + if $pkg_config --atleast-version=$glib_req_ver $i > /dev/null 2>&1 + then + glib_cflags=`$pkg_config --cflags $i 2>/dev/null` + glib_libs=`$pkg_config --libs $i 2>/dev/null` + LIBS="$glib_libs $LIBS" + libs_qga="$glib_libs $libs_qga" + else + error_exit "glib-$glib_req_ver required to compile QEMU" + fi +done ########################################## # pixman support probe
include/qemu/module.h +9 -0
@@ -37,4 +37,13 @@ void register_module_init(void (*fn)(void), module_init_type type);void module_call_init (module_init_type type); +typedef enum { +MODULE_LOAD_BLOCK =0 , +MODULE_LOAD_UI , +MODULE_LOAD_NET , +MODULE_LOAD_MAX , +}module_load_type ; + +void module_load (module_load_type type); +#endif
linux-user/main.c +3 -0
@@ -34,6 +34,7 @@#include "qemu/timer.h" #include "qemu/envlist.h" #include "elf.h" +#include <qemu/module.h> char *exec_path;
@@ -3547,6 +3548,8 @@ int main(int argc, char **argv, char **envp)int i;int ret; +module_load (MODULE_LOAD_UI ); +module_load (MODULE_LOAD_NET );module_call_init (MODULE_INIT_QOM );qemu_cache_utils_init (envp);
qemu-img.c +1 -0
@@ -34,6 +34,7 @@#include <getopt.h> #include <stdio.h> #include <stdarg.h> +#include "qemu/module.h" #ifdef _WIN32#include <windows.h>
scripts/create_config +4 -0
@@ -25,6 +25,7 @@ case $line in prefix=*) # save for the next definitions prefix=${line#*=} + echo "#define CONFIG_PREFIX \"$prefix\"" ;; CONFIG_AUDIO_DRIVERS=*) drivers=${line#*=}
@@ -104,6 +105,9 @@ case $line in value=${line#*=} echo "#define $name $value" ;; + DSOSUF=*) + echo "#define HOST_DSOSUF \"${line#*=}\"" + ;; esac done # read
ui/console.c +1 -0
@@ -27,6 +27,7 @@#include "qemu/timer.h" #include "qmp-commands.h" #include "sysemu/char.h" +#include "qemu/module.h" //#define DEBUG_CONSOLE #define DEFAULT_BACKSCROLL 512
util/Makefile.objs +2 -0
@@ -11,3 +11,5 @@ util-obj-y += iov.o aes.o qemu-config.o qemu-sockets.o uri.o notify.o util-obj-y += qemu-option.o qemu-progress.o util-obj-y += hexdump.o util-obj-y += crc32c.o + +$(obj)/module.o-libs := -lglib
util/module.c +52 -0
61 lines not on this page · raw message
vl.c +2 -0
@@ -2940,6 +2940,8 @@ int main(int argc, char **argv, char **envp)#endif } +module_load (MODULE_LOAD_UI ); +module_load (MODULE_LOAD_NET );module_call_init (MODULE_INIT_QOM );qemu_add_opts (&qemu_drive_opts);
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [RFC PATCH v2 4/6] module: implement module loading function
Il 06/09/2013 09:28, Fam Zheng ha scritto:
Quoted 176 lines
Added three types of modules:
typedef enum { MODULE_LOAD_BLOCK = 0, MODULE_LOAD_UI, MODULE_LOAD_NET, MODULE_LOAD_MAX, } module_load_type;and their loading function:
void
module_load(module_load_type).which loads all ".so" files in a subdir under "${PREFIX}/qemu/", e.g. "
/usr/lib/qemu/block". Modules of each type should be loaded before respective subsystem initialization code.Requires gmodule-2.0 from glib.
Signed-off-by Fam Zheng <[email protected]>--- block.c | 1 + bsd-user/main.c | 3 +++ configure | 20 +++++++++++--------- include/qemu/module.h | 9 +++++++++ linux-user/main.c | 3 +++ qemu-img.c | 1 + scripts/create_config | 4 ++++ ui/console.c | 1 + util/Makefile.objs | 2 ++ util/module.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ vl.c | 2 ++ 11 files changed, 89 insertions(+), 9 deletions(-)block.c +1
-0@@ -4009,6 +4009,7 @@ BlockDriverAIOCB *bdrv_aio_discard(BlockDriverState *bs,void bdrv_init (void ) { +module_load (MODULE_LOAD_BLOCK );module_call_init (MODULE_INIT_BLOCK ); }bsd-user/main.c +3
-0@@ -33,6 +33,7 @@#include "tcg.h" #include "qemu/timer.h" #include "qemu/envlist.h" +#include "qemu/module.h" int singlestep;#if defined(CONFIG_USE_GUEST_BASE )@@ -749,6 +750,8 @@ int main(int argc, char **argv)if (argc <=1 )usage (); +module_load (MODULE_LOAD_UI ); +module_load (MODULE_LOAD_NET );module_call_init (MODULE_INIT_QOM );if ((envlist =envlist_create ()) ==NULL ) {configure +11
-9@@ -2249,15 +2249,17 @@ if test "$mingw32" = yes; then else glib_req_ver=2.12 fi -if $pkg_config --atleast-version=$glib_req_ver gthread-2.0 > /dev/null 2>&1 -then - glib_cflags=`$pkg_config --cflags gthread-2.0 2>/dev/null` - glib_libs=`$pkg_config --libs gthread-2.0 2>/dev/null` - LIBS="$glib_libs $LIBS" - libs_qga="$glib_libs $libs_qga" -else - error_exit "glib-$glib_req_ver required to compile QEMU" -fi +for i in gthread-2.0 gmodule-2.0; do + if $pkg_config --atleast-version=$glib_req_ver $i > /dev/null 2>&1 + then + glib_cflags=`$pkg_config --cflags $i 2>/dev/null` + glib_libs=`$pkg_config --libs $i 2>/dev/null` + LIBS="$glib_libs $LIBS" + libs_qga="$glib_libs $libs_qga" + else + error_exit "glib-$glib_req_ver required to compile QEMU" + fi +done ########################################## # pixman support probeinclude/qemu/module.h +9
-0@@ -37,4 +37,13 @@ void register_module_init(void (*fn)(void), module_init_type type);void module_call_init (module_init_type type); +typedef enum { +MODULE_LOAD_BLOCK =0 , +MODULE_LOAD_UI , +MODULE_LOAD_NET , +MODULE_LOAD_MAX , +}module_load_type ; + +void module_load (module_load_type type); +#endif linux-user/main.c +3
-0@@ -34,6 +34,7 @@#include "qemu/timer.h" #include "qemu/envlist.h" #include "elf.h" +#include <qemu/module.h> char *exec_path;@@ -3547,6 +3548,8 @@ int main(int argc, char **argv, char **envp)int i;int ret; +module_load (MODULE_LOAD_UI ); +module_load (MODULE_LOAD_NET );module_call_init (MODULE_INIT_QOM );qemu_cache_utils_init (envp);qemu-img.c +1
-0@@ -34,6 +34,7 @@#include <getopt.h> #include <stdio.h> #include <stdarg.h> +#include "qemu/module.h" #ifdef _WIN32#include <windows.h> scripts/create_config +4
-0@@ -25,6 +25,7 @@ case $line in prefix=*) # save for the next definitions prefix=${line#*=} + echo "#define CONFIG_PREFIX \"$prefix\"" ;; CONFIG_AUDIO_DRIVERS=*) drivers=${line#*=}@@ -104,6 +105,9 @@ case $line in value=${line#*=} echo "#define $name $value" ;; + DSOSUF=*) + echo "#define HOST_DSOSUF \"${line#*=}\"" + ;; esac done # readui/console.c +0
-0
ui/console.c line 30
Quoted 4 lines
ui/console.c +1
-0@@ -27,6 +27,7 @@#include "qemu/timer.h" #include "qmp-commands.h" #include "sysemu/char.h" +#include "qemu/module.h"
Why?
Quoted 60 lines
ui/console.c +0
-0//#define DEBUG_CONSOLE #define DEFAULT_BACKSCROLL 512util/Makefile.objs +2
-0@@ -11,3 +11,5 @@ util-obj-y += iov.o aes.o qemu-config.o qemu-sockets.o uri.o notify.o util-obj-y += qemu-option.o qemu-progress.o util-obj-y += hexdump.o util-obj-y += crc32c.o + +$(obj)/module.o-libs := -lglibutil/module.c +32
-0@@ -13,6 +13,8 @@* GNU GPL, version 2 or (at your option) any later version. */ +#include <gmodule.h> +#include <dirent.h> #include "qemu-common.h" #include "qemu/queue.h" #include "qemu/module.h" @@ -79,3 +81,53 @@ void module_call_init(module_init_type type) e->init (); } } + +void module_load (module_load_type type) +{ +const char *path; +const char *dsosuf =HOST_DSOSUF ; +char fname[1024 ]; +int suf_len =strlen (dsosuf); +DIR *dp; +struct dirent *ep =NULL ; +GModule *g_module; + +if (!g_module_supported ()) { +return ; + } + +switch (type) { +case MODULE_LOAD_BLOCK : + path =CONFIG_PREFIX "/qemu/block/" ; +break ; +case MODULE_LOAD_UI : + path =CONFIG_PREFIX "/qemu/ui/" ; +break ; +case MODULE_LOAD_NET : + path =CONFIG_PREFIX "/qemu/net/" ; +break ; +default : +return ; + } + + dp =opendir (path);
util/module.c void module_call_init(module_init_type type) · line 123
Quoted 10 lines
util/module.c +10
-0+if (!dp) { +fprintf (stderr,"Failed to open dir %s\n" , path); +return ; + } +for (ep =readdir (dp); ep; ep =readdir (dp)) { +int len =strlen (ep->d_name); +if (len > suf_len && + !strcmp (&ep->d_name[len - suf_len], dsosuf)) { +pstrcpy (fname,sizeof (fname), path); +pstrcat (fname,sizeof (fname), ep->d_name);
Please use g_strdup_printf instead.
util/module.c void module_call_init(module_init_type type) · line 124
Quoted 1 line
util/module.c +1
-0+ g_module =g_module_open (fname,G_MODULE_BIND_LAZY );
Why G_MODULE_BIND_LAZY? Performance, I guess?
Having G_MODULE_BIND_LOCAL is probably a good idea too.
Paolo
Quoted 23 lines
util/module.c +9
-0+if (!g_module) { +fprintf (stderr,"Failed to open module file %s\n" , +g_module_error ()); +continue ; + } +printf ("Loaded module %s\n" , fname); + } + } +}vl.c +2
-0@@ -2940,6 +2940,8 @@ int main(int argc, char **argv, char **envp)#endif } +module_load (MODULE_LOAD_UI ); +module_load (MODULE_LOAD_NET );module_call_init (MODULE_INIT_QOM );qemu_add_opts (&qemu_drive_opts);
RFC PATCH v2 5/6 curl: build as shared library
In reply to Fam ZhengCurl block driver is built as shared object module when enabled. We have per object cflags and libs support now, move CURL_CFLAGS and CURL_LIBS from global option variables to a per object basis.
"make install" is not installing it yet, manually copy it to ${prefix}/qemu/block/curl.so to make it loaded.
--- block/Makefile.objs | 3 ++- configure | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-)
block/Makefile.objs +2 -1
@@ -23,4 +23,5 @@ common-obj-y += commit.o common-obj-y += mirror.o common-obj-y += backup.o -$(obj)/curl.o: QEMU_CFLAGS+=$(CURL_CFLAGS) +$(obj)/curl.o-cflags := $(CURL_CFLAGS) +$(obj)/curl.o-libs := $(CURL_LIBS)
configure +2 -3
@@ -2210,8 +2210,6 @@ EOF curl_libs=`$curlconfig --libs 2>/dev/null` if compile_prog "$curl_cflags" "$curl_libs" ; then curl=yes - libs_tools="$curl_libs $libs_tools" - libs_softmmu="$curl_libs $libs_softmmu" else if test "$curl" = "yes" ; then feature_not_found "curl"
@@ -3889,8 +3887,9 @@ if test "$bswap_h" = "yes" ; then echo "CONFIG_MACHINE_BSWAP_H=y" >> $config_host_mak fi if test "$curl" = "yes" ; then - echo "CONFIG_CURL=y" >> $config_host_mak + echo "CONFIG_CURL=m" >> $config_host_mak echo "CURL_CFLAGS=$curl_cflags" >> $config_host_mak + echo "CURL_LIBS=$curl_libs" >> $config_host_mak fi if test "$brlapi" = "yes" ; then echo "CONFIG_BRLAPI=y" >> $config_host_mak
Signature · 1 line
1.8.3.1
RFC PATCH v2 6/6 qed: build as shared library
In reply to Fam ZhengAnother example of DSO build but with multiple files in a module.
--- block/Makefile.objs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
block/Makefile.objs +2 -2
@@ -1,7 +1,6 @@ block-obj-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o -block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o -block-obj-y += qed-check.o +block-obj-m += qed.mo block-obj-y += vhdx.o block-obj-y += parallels.o blkdebug.o blkverify.o block-obj-y += snapshot.o qapi.o
@@ -25,3 +24,4 @@ common-obj-y += backup.o $(obj)/curl.o-cflags := $(CURL_CFLAGS) $(obj)/curl.o-libs := $(CURL_LIBS) +$(obj)/qed.mo-obj := $(addprefix $(obj)/,qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o qed-check.o)
Signature · 1 line
1.8.3.1