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
This commit is contained in:
Daniel P. Berrange 2018-02-15 13:36:09 -05:00 committed by Lioncash
parent 195a86283f
commit 4c726ca49b
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
4 changed files with 20 additions and 5 deletions

View file

@ -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-%:

View file

@ -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

View file

@ -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 " ")

View file

@ -1,3 +1,6 @@
util-obj-y = init.o
util-obj-y += hash.o
util-obj-y += aes.o
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