* [Qemu-devel] [RFC PATCH v2 0/6] Shared Library Module Support
@ 2013-09-06 7:28 Fam Zheng
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 1/6] make.rule: fix $(obj) to a real relative path Fam Zheng
` (5 more replies)
0 siblings, 6 replies; 19+ messages in thread
From: Fam Zheng @ 2013-09-06 7:28 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, famz, mjt, stefanha, pbonzini, vilanova, rth
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 libs
2. 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(-)
--
1.8.3.1
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Qemu-devel] [RFC PATCH v2 1/6] make.rule: fix $(obj) to a real relative path
2013-09-06 7:28 [Qemu-devel] [RFC PATCH v2 0/6] Shared Library Module Support Fam Zheng
@ 2013-09-06 7:28 ` Fam Zheng
2013-09-06 17:19 ` Lluís Vilanova
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 2/6] rule.mak: allow per object cflags and libs Fam Zheng
` (4 subsequent siblings)
5 siblings, 1 reply; 19+ messages in thread
From: Fam Zheng @ 2013-09-06 7:28 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, famz, mjt, stefanha, pbonzini, vilanova, rth
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.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
Makefile.target | 3 ++-
rules.mak | 7 ++++---
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/Makefile.target b/Makefile.target
index 9a49852..0ab60bd 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -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
diff --git a/rules.mak b/rules.mak
index 4499745..eef1b71 100644
--- a/rules.mak
+++ b/rules.mak
@@ -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
--
1.8.3.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [Qemu-devel] [RFC PATCH v2 2/6] rule.mak: allow per object cflags and libs
2013-09-06 7:28 [Qemu-devel] [RFC PATCH v2 0/6] Shared Library Module Support Fam Zheng
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 1/6] make.rule: fix $(obj) to a real relative path Fam Zheng
@ 2013-09-06 7:28 ` Fam Zheng
2013-09-06 10:42 ` Michael Tokarev
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 3/6] Makefile: introduce common-obj-m and block-obj-m for DSO Fam Zheng
` (3 subsequent siblings)
5 siblings, 1 reply; 19+ messages in thread
From: Fam Zheng @ 2013-09-06 7:28 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, famz, mjt, stefanha, pbonzini, vilanova, rth
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,
$(obj)foo.o-cflags = $(FOO_CFLAGS)
is also supported.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
rules.mak | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/rules.mak b/rules.mak
index eef1b71..e581d55 100644
--- a/rules.mak
+++ b/rules.mak
@@ -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
--
1.8.3.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [Qemu-devel] [RFC PATCH v2 3/6] Makefile: introduce common-obj-m and block-obj-m for DSO
2013-09-06 7:28 [Qemu-devel] [RFC PATCH v2 0/6] Shared Library Module Support Fam Zheng
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 1/6] make.rule: fix $(obj) to a real relative path Fam Zheng
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 2/6] rule.mak: allow per object cflags and libs Fam Zheng
@ 2013-09-06 7:28 ` Fam Zheng
2013-09-06 10:09 ` Paolo Bonzini
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 4/6] module: implement module loading function Fam Zheng
` (2 subsequent siblings)
5 siblings, 1 reply; 19+ messages in thread
From: Fam Zheng @ 2013-09-06 7:28 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, famz, mjt, stefanha, pbonzini, vilanova, rth
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 -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).
Signed-off-by: Fam Zheng <famz@redhat.com>
---
Makefile | 32 +++++++++++++++++++++++++++++---
Makefile.objs | 14 +++++++++++++-
configure | 3 +++
rules.mak | 10 ++++++++++
4 files changed, 55 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
index 806946e..cf47ea9 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/Makefile.objs b/Makefile.objs
index f46a4cd..8984a20 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -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)
diff --git a/configure b/configure
index af6b048..75abb87 100755
--- a/configure
+++ b/configure
@@ -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
diff --git a/rules.mak b/rules.mak
index e581d55..0a39499 100644
--- a/rules.mak
+++ b/rules.mak
@@ -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
--
1.8.3.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [Qemu-devel] [RFC PATCH v2 4/6] module: implement module loading function
2013-09-06 7:28 [Qemu-devel] [RFC PATCH v2 0/6] Shared Library Module Support Fam Zheng
` (2 preceding siblings ...)
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 3/6] Makefile: introduce common-obj-m and block-obj-m for DSO Fam Zheng
@ 2013-09-06 7:28 ` Fam Zheng
2013-09-06 9:47 ` Paolo Bonzini
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 5/6] curl: build as shared library Fam Zheng
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 6/6] qed: " Fam Zheng
5 siblings, 1 reply; 19+ messages in thread
From: Fam Zheng @ 2013-09-06 7:28 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, famz, mjt, stefanha, pbonzini, vilanova, rth
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 <famz@redhat.com>
---
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(-)
diff --git a/block.c b/block.c
index a387c1a..49ab0ce 100644
--- a/block.c
+++ b/block.c
@@ -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);
}
diff --git a/bsd-user/main.c b/bsd-user/main.c
index f9246aa..6cb9e35 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -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) {
diff --git a/configure b/configure
index 75abb87..7fec1c7 100755
--- a/configure
+++ b/configure
@@ -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
diff --git a/include/qemu/module.h b/include/qemu/module.h
index c4ccd57..f00bc25 100644
--- a/include/qemu/module.h
+++ b/include/qemu/module.h
@@ -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
diff --git a/linux-user/main.c b/linux-user/main.c
index 03859bc..9cbac14 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -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);
diff --git a/qemu-img.c b/qemu-img.c
index b9a848d..063e6bf 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -34,6 +34,7 @@
#include <getopt.h>
#include <stdio.h>
#include <stdarg.h>
+#include "qemu/module.h"
#ifdef _WIN32
#include <windows.h>
diff --git a/scripts/create_config b/scripts/create_config
index b1adbf5..7a54f2d 100755
--- a/scripts/create_config
+++ b/scripts/create_config
@@ -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
diff --git a/ui/console.c b/ui/console.c
index aad4fc9..ad90950 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -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
diff --git a/util/Makefile.objs b/util/Makefile.objs
index dc72ab0..33e56b0 100644
--- a/util/Makefile.objs
+++ b/util/Makefile.objs
@@ -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
diff --git a/util/module.c b/util/module.c
index 7acc33d..7254b1a 100644
--- a/util/module.c
+++ b/util/module.c
@@ -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);
+ 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);
+ g_module = g_module_open(fname, G_MODULE_BIND_LAZY);
+ if (!g_module) {
+ fprintf(stderr, "Failed to open module file %s\n",
+ g_module_error());
+ continue;
+ }
+ printf("Loaded module %s\n", fname);
+ }
+ }
+}
diff --git a/vl.c b/vl.c
index dfbc071..716c2db 100644
--- a/vl.c
+++ b/vl.c
@@ -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);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [Qemu-devel] [RFC PATCH v2 5/6] curl: build as shared library
2013-09-06 7:28 [Qemu-devel] [RFC PATCH v2 0/6] Shared Library Module Support Fam Zheng
` (3 preceding siblings ...)
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 4/6] module: implement module loading function Fam Zheng
@ 2013-09-06 7:28 ` Fam Zheng
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 6/6] qed: " Fam Zheng
5 siblings, 0 replies; 19+ messages in thread
From: Fam Zheng @ 2013-09-06 7:28 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, famz, mjt, stefanha, pbonzini, vilanova, rth
Curl 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.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
block/Makefile.objs | 3 ++-
configure | 5 ++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/block/Makefile.objs b/block/Makefile.objs
index 4cf9aa4..b1e1520 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -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)
diff --git a/configure b/configure
index 7fec1c7..4adc267 100755
--- a/configure
+++ b/configure
@@ -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
--
1.8.3.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [Qemu-devel] [RFC PATCH v2 6/6] qed: build as shared library
2013-09-06 7:28 [Qemu-devel] [RFC PATCH v2 0/6] Shared Library Module Support Fam Zheng
` (4 preceding siblings ...)
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 5/6] curl: build as shared library Fam Zheng
@ 2013-09-06 7:28 ` Fam Zheng
5 siblings, 0 replies; 19+ messages in thread
From: Fam Zheng @ 2013-09-06 7:28 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, famz, mjt, stefanha, pbonzini, vilanova, rth
Another example of DSO build but with multiple files in a module.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
block/Makefile.objs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/block/Makefile.objs b/block/Makefile.objs
index b1e1520..4cb2ab9 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -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)
--
1.8.3.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [Qemu-devel] [RFC PATCH v2 4/6] module: implement module loading function
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 4/6] module: implement module loading function Fam Zheng
@ 2013-09-06 9:47 ` Paolo Bonzini
0 siblings, 0 replies; 19+ messages in thread
From: Paolo Bonzini @ 2013-09-06 9:47 UTC (permalink / raw)
To: Fam Zheng; +Cc: peter.maydell, mjt, qemu-devel, stefanha, vilanova, rth
Il 06/09/2013 09:28, Fam Zheng ha scritto:
> 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 <famz@redhat.com>
> ---
> 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(-)
>
> diff --git a/block.c b/block.c
> index a387c1a..49ab0ce 100644
> --- a/block.c
> +++ b/block.c
> @@ -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);
> }
>
> diff --git a/bsd-user/main.c b/bsd-user/main.c
> index f9246aa..6cb9e35 100644
> --- a/bsd-user/main.c
> +++ b/bsd-user/main.c
> @@ -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) {
> diff --git a/configure b/configure
> index 75abb87..7fec1c7 100755
> --- a/configure
> +++ b/configure
> @@ -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
> diff --git a/include/qemu/module.h b/include/qemu/module.h
> index c4ccd57..f00bc25 100644
> --- a/include/qemu/module.h
> +++ b/include/qemu/module.h
> @@ -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
> diff --git a/linux-user/main.c b/linux-user/main.c
> index 03859bc..9cbac14 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -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);
> diff --git a/qemu-img.c b/qemu-img.c
> index b9a848d..063e6bf 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -34,6 +34,7 @@
> #include <getopt.h>
> #include <stdio.h>
> #include <stdarg.h>
> +#include "qemu/module.h"
>
> #ifdef _WIN32
> #include <windows.h>
> diff --git a/scripts/create_config b/scripts/create_config
> index b1adbf5..7a54f2d 100755
> --- a/scripts/create_config
> +++ b/scripts/create_config
> @@ -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
> diff --git a/ui/console.c b/ui/console.c
> index aad4fc9..ad90950 100644
> --- a/ui/console.c
> +++ b/ui/console.c
> @@ -27,6 +27,7 @@
> #include "qemu/timer.h"
> #include "qmp-commands.h"
> #include "sysemu/char.h"
> +#include "qemu/module.h"
Why?
>
> //#define DEBUG_CONSOLE
> #define DEFAULT_BACKSCROLL 512
> diff --git a/util/Makefile.objs b/util/Makefile.objs
> index dc72ab0..33e56b0 100644
> --- a/util/Makefile.objs
> +++ b/util/Makefile.objs
> @@ -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
> diff --git a/util/module.c b/util/module.c
> index 7acc33d..7254b1a 100644
> --- a/util/module.c
> +++ b/util/module.c
> @@ -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);
> + 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.
> + 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
> + if (!g_module) {
> + fprintf(stderr, "Failed to open module file %s\n",
> + g_module_error());
> + continue;
> + }
> + printf("Loaded module %s\n", fname);
> + }
> + }
> +}
> diff --git a/vl.c b/vl.c
> index dfbc071..716c2db 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -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);
>
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Qemu-devel] [RFC PATCH v2 3/6] Makefile: introduce common-obj-m and block-obj-m for DSO
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 3/6] Makefile: introduce common-obj-m and block-obj-m for DSO Fam Zheng
@ 2013-09-06 10:09 ` Paolo Bonzini
2013-09-06 11:47 ` Fam Zheng
0 siblings, 1 reply; 19+ messages in thread
From: Paolo Bonzini @ 2013-09-06 10:09 UTC (permalink / raw)
To: Fam Zheng; +Cc: peter.maydell, mjt, qemu-devel, stefanha, vilanova, rth
Il 06/09/2013 09:28, Fam Zheng ha scritto:
> 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 -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).
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!
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
> Makefile | 32 +++++++++++++++++++++++++++++---
> Makefile.objs | 14 +++++++++++++-
> configure | 3 +++
> rules.mak | 10 ++++++++++
> 4 files changed, 55 insertions(+), 4 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 806946e..cf47ea9 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -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)))
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?
> +# 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.
> +# 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
?
> +$(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"...
> +
> +
> +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".
>
> 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
> diff --git a/Makefile.objs b/Makefile.objs
> index f46a4cd..8984a20 100644
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -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)
> diff --git a/configure b/configure
> index af6b048..75abb87 100755
> --- a/configure
> +++ b/configure
> @@ -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
> diff --git a/rules.mak b/rules.mak
> index e581d55..0a39499 100644
> --- a/rules.mak
> +++ b/rules.mak
> @@ -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
> %$(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
>
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Qemu-devel] [RFC PATCH v2 2/6] rule.mak: allow per object cflags and libs
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 2/6] rule.mak: allow per object cflags and libs Fam Zheng
@ 2013-09-06 10:42 ` Michael Tokarev
2013-09-06 10:52 ` Fam Zheng
0 siblings, 1 reply; 19+ messages in thread
From: Michael Tokarev @ 2013-09-06 10:42 UTC (permalink / raw)
To: Fam Zheng; +Cc: peter.maydell, qemu-devel, stefanha, pbonzini, vilanova, rth
06.09.2013 11:28, Fam Zheng wrote:
> 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,
>
> $(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
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Qemu-devel] [RFC PATCH v2 2/6] rule.mak: allow per object cflags and libs
2013-09-06 10:42 ` Michael Tokarev
@ 2013-09-06 10:52 ` Fam Zheng
0 siblings, 0 replies; 19+ messages in thread
From: Fam Zheng @ 2013-09-06 10:52 UTC (permalink / raw)
To: Michael Tokarev
Cc: peter.maydell, qemu-devel, stefanha, pbonzini, vilanova, rth
On Fri, 09/06 14:42, Michael Tokarev wrote:
> 06.09.2013 11:28, Fam Zheng wrote:
> > 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,
> >
> > $(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
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Qemu-devel] [RFC PATCH v2 3/6] Makefile: introduce common-obj-m and block-obj-m for DSO
2013-09-06 10:09 ` Paolo Bonzini
@ 2013-09-06 11:47 ` Fam Zheng
2013-09-06 12:11 ` Paolo Bonzini
0 siblings, 1 reply; 19+ messages in thread
From: Fam Zheng @ 2013-09-06 11:47 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: peter.maydell, mjt, qemu-devel, stefanha, vilanova, rth
On Fri, 09/06 12:09, Paolo Bonzini wrote:
> Il 06/09/2013 09:28, Fam Zheng ha scritto:
> > 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 -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).
>
> 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!
>
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> > Makefile | 32 +++++++++++++++++++++++++++++---
> > Makefile.objs | 14 +++++++++++++-
> > configure | 3 +++
> > rules.mak | 10 ++++++++++
> > 4 files changed, 55 insertions(+), 4 deletions(-)
> >
> > diff --git a/Makefile b/Makefile
> > index 806946e..cf47ea9 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -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)))
>
>
> Why common-obj-m only, what about block-obj-m?
>
Because common-obj-m = $(block-obj-m), in Makefile.objs below.
> 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.
>
> > +# 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.
>
> > +# 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
>
> ?
>
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.
> > +$(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 don't understand, do you mean a "cc -shared" output can be statically linked
into a executable?
> 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"...
>
> > +
> > +
> > +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".
>
> >
> > 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
> > diff --git a/Makefile.objs b/Makefile.objs
> > index f46a4cd..8984a20 100644
> > --- a/Makefile.objs
> > +++ b/Makefile.objs
> > @@ -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)
> > diff --git a/configure b/configure
> > index af6b048..75abb87 100755
> > --- a/configure
> > +++ b/configure
> > @@ -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
> > diff --git a/rules.mak b/rules.mak
> > index e581d55..0a39499 100644
> > --- a/rules.mak
> > +++ b/rules.mak
> > @@ -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
>
> > %$(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
> >
>
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Qemu-devel] [RFC PATCH v2 3/6] Makefile: introduce common-obj-m and block-obj-m for DSO
2013-09-06 11:47 ` Fam Zheng
@ 2013-09-06 12:11 ` Paolo Bonzini
2013-09-09 2:26 ` Fam Zheng
0 siblings, 1 reply; 19+ messages in thread
From: Paolo Bonzini @ 2013-09-06 12:11 UTC (permalink / raw)
To: famz; +Cc: peter.maydell, mjt, qemu-devel, stefanha, vilanova, rth
Il 06/09/2013 13:47, Fam Zheng ha scritto:
> On Fri, 09/06 12:09, Paolo Bonzini wrote:
>> Il 06/09/2013 09:28, Fam Zheng ha scritto:
>>> 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 -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).
>>
>> 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!
>>
>>> Signed-off-by: Fam Zheng <famz@redhat.com>
>>> ---
>>> Makefile | 32 +++++++++++++++++++++++++++++---
>>> Makefile.objs | 14 +++++++++++++-
>>> configure | 3 +++
>>> rules.mak | 10 ++++++++++
>>> 4 files changed, 55 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/Makefile b/Makefile
>>> index 806946e..cf47ea9 100644
>>> --- a/Makefile
>>> +++ b/Makefile
>>> @@ -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)))
>>
>>
>> Why common-obj-m only, what about block-obj-m?
>>
> Because common-obj-m = $(block-obj-m), in Makefile.objs below.
>
>> 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.
>>> +# 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.
>>
>>> +# 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
>>
>> ?
>>
> 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.
Ah, I see now. See below for an idea (if it works).
>>> +$(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 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
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Qemu-devel] [RFC PATCH v2 1/6] make.rule: fix $(obj) to a real relative path
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 1/6] make.rule: fix $(obj) to a real relative path Fam Zheng
@ 2013-09-06 17:19 ` Lluís Vilanova
2013-09-09 1:34 ` Fam Zheng
2013-09-09 10:46 ` Peter Maydell
0 siblings, 2 replies; 19+ messages in thread
From: Lluís Vilanova @ 2013-09-06 17:19 UTC (permalink / raw)
To: Fam Zheng; +Cc: peter.maydell, mjt, qemu-devel, stefanha, pbonzini, rth
Fam Zheng writes:
[...]
> 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
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Qemu-devel] [RFC PATCH v2 1/6] make.rule: fix $(obj) to a real relative path
2013-09-06 17:19 ` Lluís Vilanova
@ 2013-09-09 1:34 ` Fam Zheng
2013-09-09 10:41 ` Paolo Bonzini
2013-09-09 10:46 ` Peter Maydell
1 sibling, 1 reply; 19+ messages in thread
From: Fam Zheng @ 2013-09-09 1:34 UTC (permalink / raw)
To: qemu-devel, peter.maydell, mjt, stefanha, pbonzini, rth
On Fri, 09/06 20:19, Lluís Vilanova wrote:
> Fam Zheng writes:
> [...]
> > 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
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Qemu-devel] [RFC PATCH v2 3/6] Makefile: introduce common-obj-m and block-obj-m for DSO
2013-09-06 12:11 ` Paolo Bonzini
@ 2013-09-09 2:26 ` Fam Zheng
2013-09-09 10:43 ` Paolo Bonzini
0 siblings, 1 reply; 19+ messages in thread
From: Fam Zheng @ 2013-09-09 2:26 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: peter.maydell, mjt, qemu-devel, stefanha, vilanova, rth
On Fri, 09/06 14:11, Paolo Bonzini wrote:
> Il 06/09/2013 13:47, Fam Zheng ha scritto:
> > On Fri, 09/06 12:09, Paolo Bonzini wrote:
> >> Il 06/09/2013 09:28, Fam Zheng ha scritto:
> >>> 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 -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).
> >>
> >> 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!
> >>
> >>> Signed-off-by: Fam Zheng <famz@redhat.com>
> >>> ---
> >>> Makefile | 32 +++++++++++++++++++++++++++++---
> >>> Makefile.objs | 14 +++++++++++++-
> >>> configure | 3 +++
> >>> rules.mak | 10 ++++++++++
> >>> 4 files changed, 55 insertions(+), 4 deletions(-)
> >>>
> >>> diff --git a/Makefile b/Makefile
> >>> index 806946e..cf47ea9 100644
> >>> --- a/Makefile
> >>> +++ b/Makefile
> >>> @@ -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)))
> >>
> >>
> >> Why common-obj-m only, what about block-obj-m?
> >>
> > Because common-obj-m = $(block-obj-m), in Makefile.objs below.
> >
> >> 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.
>
> >>> +# 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.
> >>
> >>> +# 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
> >>
> >> ?
> >>
> > 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.
>
> Ah, I see now. See below for an idea (if it works).
>
> >>> +$(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 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.
>
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
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Qemu-devel] [RFC PATCH v2 1/6] make.rule: fix $(obj) to a real relative path
2013-09-09 1:34 ` Fam Zheng
@ 2013-09-09 10:41 ` Paolo Bonzini
0 siblings, 0 replies; 19+ messages in thread
From: Paolo Bonzini @ 2013-09-09 10:41 UTC (permalink / raw)
To: famz; +Cc: peter.maydell, mjt, qemu-devel, stefanha, rth
Il 09/09/2013 03:34, Fam Zheng ha scritto:
> On Fri, 09/06 20:19, Lluís Vilanova wrote:
>> Fam Zheng writes:
>> [...]
>>> 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
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Qemu-devel] [RFC PATCH v2 3/6] Makefile: introduce common-obj-m and block-obj-m for DSO
2013-09-09 2:26 ` Fam Zheng
@ 2013-09-09 10:43 ` Paolo Bonzini
0 siblings, 0 replies; 19+ messages in thread
From: Paolo Bonzini @ 2013-09-09 10:43 UTC (permalink / raw)
To: famz; +Cc: peter.maydell, mjt, qemu-devel, stefanha, vilanova, rth
Il 09/09/2013 04:26, Fam Zheng ha scritto:
> 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
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Qemu-devel] [RFC PATCH v2 1/6] make.rule: fix $(obj) to a real relative path
2013-09-06 17:19 ` Lluís Vilanova
2013-09-09 1:34 ` Fam Zheng
@ 2013-09-09 10:46 ` Peter Maydell
1 sibling, 0 replies; 19+ messages in thread
From: Peter Maydell @ 2013-09-09 10:46 UTC (permalink / raw)
To: Fam Zheng, QEMU Developers, Peter Maydell, Michael Tokarev,
Stefan Hajnoczi, Paolo Bonzini, Richard Henderson
On 6 September 2013 18:19, Lluís Vilanova <vilanova@ac.upc.edu> wrote:
> Fam Zheng writes:
> [...]
>> 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
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2013-09-09 10:46 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-06 7:28 [Qemu-devel] [RFC PATCH v2 0/6] Shared Library Module Support Fam Zheng
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 1/6] make.rule: fix $(obj) to a real relative path Fam Zheng
2013-09-06 17:19 ` Lluís Vilanova
2013-09-09 1:34 ` Fam Zheng
2013-09-09 10:41 ` Paolo Bonzini
2013-09-09 10:46 ` Peter Maydell
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 2/6] rule.mak: allow per object cflags and libs Fam Zheng
2013-09-06 10:42 ` Michael Tokarev
2013-09-06 10:52 ` Fam Zheng
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 3/6] Makefile: introduce common-obj-m and block-obj-m for DSO Fam Zheng
2013-09-06 10:09 ` Paolo Bonzini
2013-09-06 11:47 ` Fam Zheng
2013-09-06 12:11 ` Paolo Bonzini
2013-09-09 2:26 ` Fam Zheng
2013-09-09 10:43 ` Paolo Bonzini
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 4/6] module: implement module loading function Fam Zheng
2013-09-06 9:47 ` Paolo Bonzini
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 5/6] curl: build as shared library Fam Zheng
2013-09-06 7:28 ` [Qemu-devel] [RFC PATCH v2 6/6] qed: " Fam Zheng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).