From nobody Mon Feb 9 11:51:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1576157092; cv=none; d=zohomail.com; s=zohoarc; b=h1Z78M2CQMhT1TIumGGrl8ehdRtsdEQYkxnQVbUMoLHbvC3M2tunwcPx5kyeO2LW1D83bygv80Z0NlSEZ7ayLo7yFx92dQkJXfamnzY2HGdJ+wb7PBKwQka0JPwIPQ31xQaKh2IlW7gaT/eSwuVchYJZaDDvQ46fJ09P/x/Q3O0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576157092; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4HAQ8wWS3VYmUYf9FPMsr6xrEJyr4/7OCIkvd9SDiw4=; b=QMpaUhR3swHUr9+G9Bd8J87dehqIiV3q/t7emntIhLm8cqEzWVOgEdFOLUvv3LCi7JFOxDU89aDKEniX5PqpD3BCBprlZEJco5RrHngAdi1qSTALQcP0Mtznm/rby6D54zAe6mrR+Q8p1N87WqqAoh5Vtjw8qj8g44R54Y2WSUk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576157092044979.452847227038; Thu, 12 Dec 2019 05:24:52 -0800 (PST) Received: from localhost ([::1]:59248 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifOSY-0008Qr-2K for importer@patchew.org; Thu, 12 Dec 2019 08:24:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34389) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifNyQ-0003bO-1O for qemu-devel@nongnu.org; Thu, 12 Dec 2019 07:53:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ifNyN-0006pi-QF for qemu-devel@nongnu.org; Thu, 12 Dec 2019 07:53:41 -0500 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]:55237) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ifNyN-0006o3-Ht for qemu-devel@nongnu.org; Thu, 12 Dec 2019 07:53:39 -0500 Received: by mail-wm1-x335.google.com with SMTP id b11so2236289wmj.4 for ; Thu, 12 Dec 2019 04:53:39 -0800 (PST) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id n189sm5193825wme.33.2019.12.12.04.53.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Dec 2019 04:53:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4HAQ8wWS3VYmUYf9FPMsr6xrEJyr4/7OCIkvd9SDiw4=; b=qzBJGAnbksEuJi2L9k503S5RuesS2h6MMvBaqg+ssV+PrSfOSTlI13tsirpT1UKI7a s8/caukV1lfE8tkRg2JHkgSGLvB206rqpL7yKSlxJX8TjsgzDsvxQXPRfm8wI2HfBNY/ 0uf6gNzlIj2G5AhjJOjQgQb3KX2Xc/AB9+wXBqMdFs5FpFpJUmNVk21QcyRi6R4vIbn1 2cdrXfjgcxN1+5inLlKhsKHtdzKeZWo8y60lqoXgjEgbjQxsptHxCP/8dC8WX9uY2Rl9 hwMpOcKGVlMaJIDHlxk8DNfJ7tOqwgBCXeMgIjK+6xaD1zvvOGXquvngdJ9APSaedQcv jjDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=4HAQ8wWS3VYmUYf9FPMsr6xrEJyr4/7OCIkvd9SDiw4=; b=IIDIhA+GQhEm17LoKxoZLIsbT7Hg7gDdeBPA37TfUX1cpk+wTiUe7XV8+zqxs7DUw8 w7VVGj6PcDgVLIEX5Bq9rCN50OwEoYSk57OCCTsKv7wWaU79FY4c1dy8y4ojG/FRBRGC RNDrgpzQAMHyAxTHcVy0UnF2srODXnOuvvOHbFRaHCIiiEdwqfsMZzTDsS/2bXiWsgRp JS/iIR9I5nQTryEDiWOT/Did+JdriRfcfrtvSH06yB4Koe8ZJAXUts0Gdhhzs3r5FKNk k0rCPEw8Qe4FKI7s1M+hZuKPkKqcT6qTJMLCHkRqnNDs6hbbuGcaDRsy/DnhWrQrRi9M VGGQ== X-Gm-Message-State: APjAAAVB55D1uQ700TNC2HabyAm3ZJ0GQM4iHirzENce8ZxzvrJzk6M+ rRXlws6Q4pOCxuqyuWajZ9usC/dU X-Google-Smtp-Source: APXvYqyTfnmYs6qD70TI1YSWxnoMHJzmrrgReLBoZ343IDfUxR0t7tDZ9+D4cZvYQfr5cpl05RxbAA== X-Received: by 2002:a7b:c935:: with SMTP id h21mr6275648wml.173.1576155218044; Thu, 12 Dec 2019 04:53:38 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 040/132] meson: add modules infrastructure Date: Thu, 12 Dec 2019 13:51:24 +0100 Message-Id: <1576155176-2464-41-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1576155176-2464-1-git-send-email-pbonzini@redhat.com> References: <1576155176-2464-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::335 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau --- Makefile | 10 +--------- Makefile.target | 6 ++++++ meson.build | 53 +++++++++++++++++++++++++++++++++++++++++++++++++= ++++ rules.mak | 10 +++++----- scripts/undefsym.sh | 20 ++++++++++++++++++++ 5 files changed, 85 insertions(+), 14 deletions(-) create mode 100755 scripts/undefsym.sh diff --git a/Makefile b/Makefile index bae96ec..c8c402a 100644 --- a/Makefile +++ b/Makefile @@ -212,7 +212,7 @@ subdir-capstone: capstone/all subdir-slirp: slirp/all =20 $(filter %/all, $(TARGET_DIRS_RULES)): libqemuutil.a $(common-obj-y) \ - $(qom-obj-y) + $(qom-obj-y) block.syms qemu.syms =20 ROM_DIRS =3D $(addprefix pc-bios/, $(ROMS)) ROM_DIRS_RULES=3D$(foreach t, all clean, $(addsuffix /$(t), $(ROM_DIRS))) @@ -431,14 +431,6 @@ install: all $(if $(BUILD_DOCS),install-doc) install-d= atadir install-localstated ifneq ($(TOOLS),) $(call install-prog,$(TOOLS),$(DESTDIR)$(bindir)) endif -ifneq ($(CONFIG_MODULES),) - $(INSTALL_DIR) "$(DESTDIR)$(qemu_moddir)" - for s in $(modules-m:.mo=3D$(DSOSUF)); do \ - t=3D"$(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 diff --git a/Makefile.target b/Makefile.target index 74e8295..a0eb332 100644 --- a/Makefile.target +++ b/Makefile.target @@ -161,6 +161,12 @@ obj-y +=3D memory_mapping.o obj-y +=3D migration/ram.o LIBS :=3D $(libs_softmmu) $(LIBS) =20 +# Temporary until emulators are linked by Meson +LIBS :=3D $(LIBS) @../block.syms @../qemu.syms +ifneq ($(CONFIG_MODULES),y) +LIBS :=3D $(LIBS) +endif + # Hardware support ifeq ($(TARGET_NAME), sparc64) obj-y +=3D hw/sparc64/ diff --git a/meson.build b/meson.build index 8d5b28b..3c292c6 100644 --- a/meson.build +++ b/meson.build @@ -6,6 +6,8 @@ ss =3D import('sourceset') config_host =3D kconfig.load(meson.current_build_dir() / 'config-host.mak') config_all_disas =3D kconfig.load(meson.current_build_dir() / 'config-all-= disas.mak') =20 +enable_modules =3D 'CONFIG_MODULES' in config_host + add_project_arguments(config_host['CFLAGS'].split(), language: ['c', 'objc']) add_project_arguments(config_host['QEMU_CFLAGS'].split(), @@ -264,6 +266,7 @@ endforeach util_ss =3D ss.source_set() stub_ss =3D ss.source_set() trace_ss =3D ss.source_set() +block_ss =3D ss.source_set() common_ss =3D ss.source_set() softmmu_ss =3D ss.source_set() user_ss =3D ss.source_set() @@ -271,6 +274,7 @@ bsd_user_ss =3D ss.source_set() linux_user_ss =3D ss.source_set() specific_ss =3D ss.source_set() =20 +modules =3D {} hw_arch =3D {} target_arch =3D {} target_softmmu_arch =3D {} @@ -372,6 +376,12 @@ subdir('authz') subdir('crypto') subdir('ui') =20 + +if enable_modules + libmodulecommon =3D static_library('module-common', files('module-common= .c') + genh, pic: true, c_args: '-DBUILD_DSO') + modulecommon =3D declare_dependency(link_whole: libmodulecommon, compile= _args: '-DBUILD_DSO') +endif + # Build targets from sourcesets =20 stub_ss =3D stub_ss.apply(config_host, strict: false) @@ -387,6 +397,49 @@ qemuutil =3D declare_dependency(link_with: libqemuutil, subdir('io') subdir('fsdev') =20 +mods =3D [] +block_mods =3D [] +softmmu_mods =3D [] +foreach d, list : modules + foreach m : list + if enable_modules and host_machine.system() !=3D 'windows' + sl =3D static_library(d + '-' + m[0], m[1], dependencies: [m[2], mod= ulecommon], pic: true) + if d =3D=3D 'block' + block_mods +=3D sl + else + softmmu_mods +=3D sl + endif + mods +=3D {'dir': d, 'name': m[0], 'lib': sl, 'deps': m[2]} + else + if d =3D=3D 'block' + block_ss.add(when: m[2], if_true: m[1]) + else + softmmu_ss.add(when: m[2], if_true: m[1]) + endif + endif + endforeach +endforeach + +nm =3D find_program('nm') +undefsym =3D find_program('scripts/undefsym.sh') +block_syms =3D custom_target('block.syms', output: 'block.syms', + input: [libqemuutil, block_mods], + capture: true, + command: [undefsym, nm, '@INPUT@']) +qemu_syms =3D custom_target('qemu.syms', output: 'qemu.syms', + input: [libqemuutil, softmmu_mods], + capture: true, + command: [undefsym, nm, '@INPUT@']) + + +foreach m : mods + shared_module(m['dir'] + '-' + m['name'], + name_prefix: '', + link_whole: [m['lib']], + 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) =20 diff --git a/rules.mak b/rules.mak index 9dd3b7e..8571aec 100644 --- a/rules.mak +++ b/rules.mak @@ -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 =3D $(filter-out %.a %.fa %.mo,$1) \ +process-archive-undefs =3D $(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) =20 -extract-libs =3D $(strip $(foreach o,$(filter-out %.mo,$1),$($o-libs))) +extract-libs =3D $(strip $(foreach o,$(filter-out %.mo %$(DSOSUF),$1),$($o= -libs))) expand-objs =3D $(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)) =20 %.o: %.c @mkdir -p $(dir $@) diff --git a/scripts/undefsym.sh b/scripts/undefsym.sh new file mode 100755 index 0000000..d4871f0 --- /dev/null +++ b/scripts/undefsym.sh @@ -0,0 +1,20 @@ +#! /bin/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 th= em, +# 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=3D$1 +staticlib=3D$2 +shift 2 +# Find symbols defined in static libraries and undefined in shared modules +comm -12 \ + <( $NM -P -g $staticlib | awk '$2!=3D"U"{print "-Wl,-u," $1}' | sort -u)= \ + <( $NM -P -g "$@" | awk '$2=3D=3D"U"{print "-Wl,-u," $1}' | sort -u) --=20 1.8.3.1