From 4c726ca49bec7af178fb9d24736f6c6d8cfa903c Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Thu, 15 Feb 2018 13:36:09 -0500 Subject: [PATCH] crypto: move crypto objects out of libqemuutil.la Future patches will be adding more crypto related APIs which rely on QOM infrastructure. This creates a problem, because QOM relies on library constructors to register objects. When you have a file in a static .a library though which is only referenced by a constructor the linker is dumb and will drop that file when linking to the final executable :-( The only workaround for this is to link the .a library to the executable using the -Wl,--whole-archive flag, but this creates its own set of problems because QEMU is relying on lazy linking for libqemuutil.a. Using --whole-archive majorly increases the size of final executables as they now contain a bunch of object code they don't actually use. The least bad option is to thus not include the crypto objects in libqemuutil.la, and instead define a crypto-obj-y variable that is referenced directly by all the executables that need this code (tools + softmmu, but not qemu-ga). We avoid pulling entire of crypto-obj-y into the userspace emulators as that would force them to link to gnutls too, which is not required. Backports commit fb37726db77b21f3731b90693d2c93ade1777528 from qemu --- qemu/Makefile | 3 +++ qemu/Makefile.objs | 7 ++++++- qemu/Makefile.target | 6 +++++- qemu/crypto/Makefile.objs | 9 ++++++--- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/qemu/Makefile b/qemu/Makefile index b9a8f309..ffa8e517 100644 --- a/qemu/Makefile +++ b/qemu/Makefile @@ -106,6 +106,8 @@ dummy := $(call unnest-vars,, \ util-obj-y \ block-obj-y \ block-obj-m \ + crypto-obj-y \ + crypto-aes-obj-y \ common-obj-y \ common-obj-m) @@ -118,6 +120,7 @@ SUBDIR_RULES=$(patsubst %,subdir-%, $(TARGET_DIRS)) SOFTMMU_SUBDIR_RULES=$(filter %-softmmu,$(SUBDIR_RULES)) $(SOFTMMU_SUBDIR_RULES): $(block-obj-y) +$(SOFTMMU_SUBDIR_RULES): $(crypto-obj-y) $(SOFTMMU_SUBDIR_RULES): config-all-devices.mak subdir-%: diff --git a/qemu/Makefile.objs b/qemu/Makefile.objs index e23f884f..f4e3193b 100644 --- a/qemu/Makefile.objs +++ b/qemu/Makefile.objs @@ -1,7 +1,6 @@ ####################################################################### # Common libraries for tools and emulators util-obj-y = util/ qobject/ qapi/ qapi-types.o qapi-visit.o -util-obj-y += crypto/ ####################################################################### # block-obj-y is code used by both qemu system emulation and qemu-img @@ -9,6 +8,12 @@ util-obj-y += crypto/ block-obj-y = block-obj-y += ../uc.o ../list.o glib_compat.o +####################################################################### +# crypto-obj-y is code used by both qemu system emulation and qemu-img + +crypto-obj-y = crypto/ +crypto-aes-obj-y = crypto/ + ####################################################################### # Target independent part of system emulation. The long term path is to # suppress *all* target specific code in case of system emulation, i.e. a diff --git a/qemu/Makefile.target b/qemu/Makefile.target index b9c1a3d1..83490caf 100644 --- a/qemu/Makefile.target +++ b/qemu/Makefile.target @@ -79,7 +79,9 @@ target-obj-y-save := $(target-obj-y) $(util-obj-y) dummy := $(call unnest-vars,.., \ block-obj-y \ - block-obj-m) + block-obj-m \ + crypto-obj-y \ + crypto-aes-obj-y) dummy := $(call unnest-vars,..,common-obj-y,common-obj-m) @@ -87,6 +89,8 @@ target-obj-y := $(target-obj-y-save) all-obj-y += $(common-obj-y) all-obj-y += $(target-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y) +all-obj-$(CONFIG_USER_ONLY) += $(crypto-aes-obj-y) +all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y) # determine shared lib extension IS_APPLE := $(shell $(CC) -dM -E - < /dev/null | grep __apple_build_version__ | wc -l | tr -d " ") diff --git a/qemu/crypto/Makefile.objs b/qemu/crypto/Makefile.objs index a9363537..b7d048e8 100644 --- a/qemu/crypto/Makefile.objs +++ b/qemu/crypto/Makefile.objs @@ -1,3 +1,6 @@ -util-obj-y = init.o -util-obj-y += hash.o -util-obj-y += aes.o \ No newline at end of file +crypto-obj-y = init.o +crypto-obj-y += hash.o +crypto-obj-y += aes.o + +# Let the userspace emulators avoid linking gnutls/etc +crypto-aes-obj-y = aes.o