Re: [Qemu-devel] [PULL 07/12] module: implement module loading
On 20 February 2014 12:28, Paolo Bonzini wrote: > From: Fam Zheng > > This patch adds loading, stamp checking and initialization of modules. > > The init function of dynamic module is no longer directly called as > __attribute__((constructor)) in static linked version, it is called > only after passed the checking of presense of stamp symbol: > > qemu_stamp_$RELEASEHASH > > where $RELEASEHASH is generated by hashing version strings and content > of configure script. > > With this, modules built from a different tree/version/configure will > not be loaded. > > The module loading code requires gmodule-2.0. > > Modules are searched under > - CONFIG_MODDIR > - executable folder (to allow running qemu-{img,io} in the build >directory) > - ../ of executable folder (to allow running system emulator in the >build directory) > > Modules are linked under their subdir respectively, then copied to top > level of build directory for above convinience, e.g.: > $(BUILD_DIR)/block/curl.so -> $(BUILD_DIR)/block-curl.so This commit breaks a static build of arm-linux-user: rm -rf build/arm-linux && mkdir build/arm-linux && (cd build/arm-linux && '../../configure' '--target-list=arm-linux-user' '--cc=ccache gcc' '--disable-tools' '--static' '--enable-debug' --disable-tools) && make -C build/arm-linux -j4 [...] /usr/bin/ld.bfd.real: dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libc.a(strcmp.o)' can not be used when making an executable; recompile with -fPIE and relink with -pie (this is when linking tests/qemu-iotests/socket_scm_helper) thanks -- PMM
[Qemu-devel] [PULL 07/12] module: implement module loading
From: Fam Zheng This patch adds loading, stamp checking and initialization of modules. The init function of dynamic module is no longer directly called as __attribute__((constructor)) in static linked version, it is called only after passed the checking of presense of stamp symbol: qemu_stamp_$RELEASEHASH where $RELEASEHASH is generated by hashing version strings and content of configure script. With this, modules built from a different tree/version/configure will not be loaded. The module loading code requires gmodule-2.0. Modules are searched under - CONFIG_MODDIR - executable folder (to allow running qemu-{img,io} in the build directory) - ../ of executable folder (to allow running system emulator in the build directory) Modules are linked under their subdir respectively, then copied to top level of build directory for above convinience, e.g.: $(BUILD_DIR)/block/curl.so -> $(BUILD_DIR)/block-curl.so Signed-off-by: Paolo Bonzini Signed-off-by: Fam Zheng Signed-off-by: Paolo Bonzini --- Makefile | 3 ++ configure | 42 +++ include/qemu/module.h | 23 +++- module-common.c | 10 rules.mak | 3 ++ scripts/create_config | 3 ++ util/module.c | 145 +- 7 files changed, 217 insertions(+), 12 deletions(-) create mode 100644 module-common.c diff --git a/Makefile b/Makefile index 9d53117..07d1ed7 100644 --- a/Makefile +++ b/Makefile @@ -201,6 +201,9 @@ Makefile: $(version-obj-y) $(version-lobj-y) libqemustub.a: $(stub-obj-y) libqemuutil.a: $(util-obj-y) qapi-types.o qapi-visit.o +block-modules = $(foreach o,$(block-obj-m),"$(basename $(subst /,-,$o))",) NULL +util/module.o-cflags = -D'CONFIG_BLOCK_MODULES=$(block-modules)' + ## qemu-img.o: qemu-img-cmds.h diff --git a/configure b/configure index e3bc04e..136a8f0 100755 --- a/configure +++ b/configure @@ -1137,7 +1137,7 @@ Advanced options (experts only): --libdir=PATHinstall libraries in PATH --sysconfdir=PATHinstall config in PATH$confsuffix --localstatedir=PATH install local state in PATH (set at runtime on win32) - --with-confsuffix=SUFFIX suffix for QEMU data inside datadir and sysconfdir [$confsuffix] + --with-confsuffix=SUFFIX suffix for QEMU data inside datadir/libdir/sysconfdir [$confsuffix] --enable-modules enable modules support --enable-debug-tcg enable TCG debugging --disable-debug-tcg disable TCG debugging (default) @@ -2362,14 +2362,32 @@ if test "$mingw32" = yes; then else glib_req_ver=2.12 fi -if $pkg_config --atleast-version=$glib_req_ver gthread-2.0; then -glib_cflags=`$pkg_config --cflags gthread-2.0` -glib_libs=`$pkg_config --libs gthread-2.0` -CFLAGS="$glib_cflags $CFLAGS" -LIBS="$glib_libs $LIBS" -libs_qga="$glib_libs $libs_qga" -else -error_exit "glib-$glib_req_ver required to compile QEMU" + +for i in gthread-2.0 gmodule-2.0; do +if $pkg_config --atleast-version=$glib_req_ver $i; then +glib_cflags=`$pkg_config --cflags $i` +glib_libs=`$pkg_config --libs $i` +CFLAGS="$glib_cflags $CFLAGS" +LIBS="$glib_libs $LIBS" +libs_qga="$glib_libs $libs_qga" +else +error_exit "glib-$glib_req_ver $i is required to compile QEMU" +fi +done + +## +# SHA command probe for modules +if test "$modules" = yes; then +shacmd_probe="sha1sum sha1 shasum" +for c in $shacmd_probe; do +if which $c &>/dev/null; then +shacmd="$c" +break +fi +done +if test "$shacmd" = ""; then +error_exit "one of the checksum commands is required to enable modules: $shacmd_probe" +fi fi ## @@ -3661,6 +3679,7 @@ if test "$mingw32" = "yes" ; then fi qemu_confdir=$sysconfdir$confsuffix +qemu_moddir=$libdir$confsuffix qemu_datadir=$datadir$confsuffix qemu_localedir="$datadir/locale" @@ -3751,6 +3770,7 @@ echo "Install prefix$prefix" echo "BIOS directory`eval echo $qemu_datadir`" echo "binary directory `eval echo $bindir`" echo "library directory `eval echo $libdir`" +echo "module directory `eval echo $qemu_moddir`" echo "libexec directory `eval echo $libexecdir`" echo "include directory `eval echo $includedir`" echo "config directory `eval echo $sysconfdir`" @@ -3890,6 +3910,7 @@ echo "sysconfdir=$sysconfdir" >> $config_host_mak echo "qemu_confdir=$qemu_confdir" >> $config_host_mak echo "qemu_datadir=$qemu_datadir" >> $config_host_mak echo "qemu_docdir=$qemu_docdir" >> $config_host_mak +echo "qemu_moddir=$qemu_moddir" >> $config_host_mak if test "$mingw32" = "no" ; then echo "qemu_localstatedir=$local_statedir" >> $config_host_mak fi @@ -4023,6 +4044,9 @@ if [ "$docs" = "yes" ] ; then echo "BUILD_DOCS=yes" >> $config_hos
[Qemu-devel] [PULL 07/12] module: implement module loading
From: Fam Zheng This patch adds loading, stamp checking and initialization of modules. The init function of dynamic module is no longer directly called as __attribute__((constructor)) in static linked version, it is called only after passed the checking of presense of stamp symbol: qemu_stamp_$RELEASEHASH where $RELEASEHASH is generated by hashing version strings and content of configure script. With this, modules built from a different tree/version/configure will not be loaded. The module loading code requires gmodule-2.0. Modules are searched under - CONFIG_MODDIR - executable folder (to allow running qemu-{img,io} in the build directory) - ../ of executable folder (to allow running system emulator in the build directory) Modules are linked under their subdir respectively, then copied to top level of build directory for above convinience, e.g.: $(BUILD_DIR)/block/curl.so -> $(BUILD_DIR)/block-curl.so Signed-off-by: Paolo Bonzini Signed-off-by: Fam Zheng Signed-off-by: Paolo Bonzini --- Makefile |3 + configure | 42 +++--- include/qemu/module.h | 23 - module-common.c | 10 rules.mak |3 + scripts/create_config |3 + util/module.c | 145 - 7 files changed, 217 insertions(+), 12 deletions(-) create mode 100644 module-common.c diff --git a/Makefile b/Makefile index 9d53117..07d1ed7 100644 --- a/Makefile +++ b/Makefile @@ -201,6 +201,9 @@ Makefile: $(version-obj-y) $(version-lobj-y) libqemustub.a: $(stub-obj-y) libqemuutil.a: $(util-obj-y) qapi-types.o qapi-visit.o +block-modules = $(foreach o,$(block-obj-m),"$(basename $(subst /,-,$o))",) NULL +util/module.o-cflags = -D'CONFIG_BLOCK_MODULES=$(block-modules)' + ## qemu-img.o: qemu-img-cmds.h diff --git a/configure b/configure index 14f4501..bd21db9 100755 --- a/configure +++ b/configure @@ -1132,7 +1132,7 @@ Advanced options (experts only): --libdir=PATHinstall libraries in PATH --sysconfdir=PATHinstall config in PATH$confsuffix --localstatedir=PATH install local state in PATH (set at runtime on win32) - --with-confsuffix=SUFFIX suffix for QEMU data inside datadir and sysconfdir [$confsuffix] + --with-confsuffix=SUFFIX suffix for QEMU data inside datadir/libdir/sysconfdir [$confsuffix] --enable-modules enable modules support --enable-debug-tcg enable TCG debugging --disable-debug-tcg disable TCG debugging (default) @@ -2348,14 +2348,32 @@ if test "$mingw32" = yes; then else glib_req_ver=2.12 fi -if $pkg_config --atleast-version=$glib_req_ver gthread-2.0; then -glib_cflags=`$pkg_config --cflags gthread-2.0` -glib_libs=`$pkg_config --libs gthread-2.0` -CFLAGS="$glib_cflags $CFLAGS" -LIBS="$glib_libs $LIBS" -libs_qga="$glib_libs $libs_qga" -else -error_exit "glib-$glib_req_ver required to compile QEMU" + +for i in gthread-2.0 gmodule-2.0; do +if $pkg_config --atleast-version=$glib_req_ver $i; then +glib_cflags=`$pkg_config --cflags $i` +glib_libs=`$pkg_config --libs $i` +CFLAGS="$glib_cflags $CFLAGS" +LIBS="$glib_libs $LIBS" +libs_qga="$glib_libs $libs_qga" +else +error_exit "glib-$glib_req_ver $i is required to compile QEMU" +fi +done + +## +# SHA command probe for modules +if test "$modules" = yes; then +shacmd_probe="sha1sum sha1 shasum" +for c in $shacmd_probe; do +if which $c &>/dev/null; then +shacmd="$c" +break +fi +done +if test "$shacmd" = ""; then +error_exit "one of the checksum commands is required to enable modules: $shacmd_probe" +fi fi ## @@ -3633,6 +3651,7 @@ if test "$mingw32" = "yes" ; then fi qemu_confdir=$sysconfdir$confsuffix +qemu_moddir=$libdir$confsuffix qemu_datadir=$datadir$confsuffix qemu_localedir="$datadir/locale" @@ -3723,6 +3742,7 @@ echo "Install prefix$prefix" echo "BIOS directory`eval echo $qemu_datadir`" echo "binary directory `eval echo $bindir`" echo "library directory `eval echo $libdir`" +echo "module directory `eval echo $qemu_moddir`" echo "libexec directory `eval echo $libexecdir`" echo "include directory `eval echo $includedir`" echo "config directory `eval echo $sysconfdir`" @@ -3861,6 +3881,7 @@ echo "sysconfdir=$sysconfdir" >> $config_host_mak echo "qemu_confdir=$qemu_confdir" >> $config_host_mak echo "qemu_datadir=$qemu_datadir" >> $config_host_mak echo "qemu_docdir=$qemu_docdir" >> $config_host_mak +echo "qemu_moddir=$qemu_moddir" >> $config_host_mak if test "$mingw32" = "no" ; then echo "qemu_localstatedir=$local_statedir" >> $config_host_mak fi @@ -3994,6 +4015,9 @@ if [ "$docs" = "yes" ] ; then echo "BUILD_DOCS=yes" >> $config_