@@ -255,7 +255,7 @@ slirp/all: .git-submodule-status
CFLAGS="$(QEMU_CFLAGS) $(CFLAGS)" LDFLAGS="$(QEMU_LDFLAGS)")
$(filter %/all, $(TARGET_DIRS_RULES)): libqemuutil.a $(common-obj-y) \
- $(qom-obj-y)
+ $(qom-obj-y) block.syms qemu.syms
$(filter %/fuzz, $(TARGET_DIRS_RULES)): libqemuutil.a $(common-obj-y) \
$(qom-obj-y) $(crypto-user-obj-$(CONFIG_USER_ONLY))
@@ -463,14 +463,6 @@ install: all $(if $(BUILD_DOCS),install-doc) \
ifneq ($(TOOLS),)
$(call install-prog,$(TOOLS),$(DESTDIR)$(bindir))
endif
-ifneq ($(CONFIG_MODULES),)
- $(INSTALL_DIR) "$(DESTDIR)$(qemu_moddir)"
- for s in $(modules-m:.mo=$(DSOSUF)); do \
- t="$(DESTDIR)$(qemu_moddir)/$$(echo $$s | tr / -)"; \
- $(INSTALL_LIB) $$s "$$t"; \
- test -z "$(STRIP)" || $(STRIP) "$$t"; \
- done
-endif
ifneq ($(HELPERS-y),)
$(call install-prog,$(HELPERS-y),$(DESTDIR)$(libexecdir))
endif
@@ -162,6 +162,12 @@ obj-y += qapi/
obj-y += migration/ram.o
LIBS := $(libs_softmmu) $(LIBS)
+# Temporary until emulators are linked by Meson
+LIBS := $(LIBS) @../block.syms @../qemu.syms
+ifneq ($(CONFIG_MODULES),y)
+LIBS := $(LIBS)
+endif
+
# Hardware support
ifeq ($(TARGET_NAME), sparc64)
obj-y += hw/sparc64/
@@ -10,6 +10,7 @@ sh = find_program('sh')
cc = meson.get_compiler('c')
config_host = keyval.load(meson.current_build_dir() / 'config-host.mak')
config_all_disas = keyval.load(meson.current_build_dir() / 'config-all-disas.mak')
+enable_modules = 'CONFIG_MODULES' in config_host
add_project_arguments(config_host['QEMU_CFLAGS'].split(),
language: ['c', 'objc'])
@@ -312,6 +313,7 @@ genh += hxdep
util_ss = ss.source_set()
stub_ss = ss.source_set()
trace_ss = ss.source_set()
+block_ss = ss.source_set()
common_ss = ss.source_set()
softmmu_ss = ss.source_set()
user_ss = ss.source_set()
@@ -319,6 +321,7 @@ bsd_user_ss = ss.source_set()
linux_user_ss = ss.source_set()
specific_ss = ss.source_set()
+modules = {}
hw_arch = {}
target_arch = {}
target_softmmu_arch = {}
@@ -428,6 +431,12 @@ subdir('crypto')
subdir('storage-daemon')
subdir('ui')
+
+if enable_modules
+ libmodulecommon = static_library('module-common', files('module-common.c') + genh, pic: true, c_args: '-DBUILD_DSO')
+ modulecommon = declare_dependency(link_whole: libmodulecommon, compile_args: '-DBUILD_DSO')
+endif
+
# Build targets from sourcesets
stub_ss = stub_ss.apply(config_all, strict: false)
@@ -444,6 +453,48 @@ subdir('io')
subdir('fsdev')
subdir('target')
+block_mods = []
+softmmu_mods = []
+foreach d, list : modules
+ foreach m, module_ss : list
+ if enable_modules and host_machine.system() != 'windows'
+ module_ss = module_ss.apply(config_host, strict: false)
+ sl = static_library(d + '-' + m, [genh, module_ss.sources()],
+ dependencies: [modulecommon, module_ss.dependencies()], pic: true)
+ if d == 'block'
+ block_mods += sl
+ else
+ softmmu_mods += sl
+ endif
+ else
+ if d == 'block'
+ block_ss.add_all(module_ss)
+ else
+ softmmu_ss.add_all(module_ss)
+ endif
+ endif
+ endforeach
+endforeach
+
+nm = find_program('nm')
+undefsym = find_program('scripts/undefsym.sh')
+block_syms = custom_target('block.syms', output: 'block.syms',
+ input: [libqemuutil, block_mods],
+ capture: true,
+ command: [undefsym, nm, '@INPUT@'])
+qemu_syms = custom_target('qemu.syms', output: 'qemu.syms',
+ input: [libqemuutil, softmmu_mods],
+ capture: true,
+ command: [undefsym, nm, '@INPUT@'])
+
+foreach m : block_mods + softmmu_mods
+ shared_module(m.name(),
+ name_prefix: '',
+ link_whole: m,
+ install: true,
+ install_dir: config_host['qemu_moddir'])
+endforeach
+
common_ss.add_all(when: 'CONFIG_SOFTMMU', if_true: softmmu_ss)
common_ss.add_all(when: 'CONFIG_USER_ONLY', if_true: user_ss)
@@ -61,17 +61,17 @@ endif
# This is necessary because the exectuable itself may not use the function, in
# which case the function would not be linked in. Then the DSO loading will
# fail because of the missing symbol.
-process-archive-undefs = $(filter-out %.a %.fa %.mo,$1) \
+process-archive-undefs = $(filter-out %.a %.fa %.mo %$(DSOSUF),$1) \
$(addprefix $(WL_U), \
$(filter $(call defined-symbols,$(filter %.a %.fa, $1)), \
- $(call undefined-symbols,$(filter %.mo,$1)))) \
+ $(call undefined-symbols,$(filter %.mo %$(DSOSUF),$1)))) \
$(foreach l,$(filter %.fa,$1),$(call whole-archive,$l)) \
$(filter %.a,$1)
-extract-libs = $(strip $(foreach o,$(filter-out %.mo,$1),$($o-libs)))
+extract-libs = $(strip $(foreach o,$(filter-out %.mo %$(DSOSUF),$1),$($o-libs)))
expand-objs = $(strip $(sort $(filter %.o,$1)) \
- $(foreach o,$(filter %.mo,$1),$($o-objs)) \
- $(filter-out %.o %.mo,$1))
+ $(foreach o,$(filter %.mo %$(DSOSUF),$1),$($o-objs)) \
+ $(filter-out %.o %.mo %$(DSOSUF),$1))
%.o: %.c
@mkdir -p $(dir $@)
new file mode 100755
@@ -0,0 +1,20 @@
+#! /usr/bin/env bash
+
+# Before a shared module's DSO is produced, a static library is built for it
+# and passed to this script. The script generates -Wl,-u options to force
+# the inclusion of symbol from libqemuutil.a if the shared modules need them,
+# This is necessary because the modules may use functions not needed by the
+# executable itself, which would cause the function to not be linked in.
+# Then the DSO loading would fail because of the missing symbol.
+
+if test $# -le 2; then
+ exit 0
+fi
+
+NM=$1
+staticlib=$2
+shift 2
+# Find symbols defined in static libraries and undefined in shared modules
+comm -12 \
+ <( $NM -P -g $staticlib | awk '$2!="U"{print "-Wl,-u," $1}' | sort -u) \
+ <( $NM -P -g "$@" | awk '$2=="U"{print "-Wl,-u," $1}' | sort -u)