Skip to content

Commit

Permalink
crypto: move crypto objects out of libqemuutil.la
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Daniel P. Berrange <[email protected]>
  • Loading branch information
berrange committed Sep 15, 2015
1 parent b124533 commit fb37726
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ dummy := $(call unnest-vars,, \
qga-vss-dll-obj-y \
block-obj-y \
block-obj-m \
crypto-obj-y \
crypto-aes-obj-y \
common-obj-y \
common-obj-m)

Expand All @@ -173,6 +175,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-%:
Expand Down Expand Up @@ -227,9 +230,9 @@ util/module.o-cflags = -D'CONFIG_BLOCK_MODULES=$(block-modules)'

qemu-img.o: qemu-img-cmds.h

qemu-img$(EXESUF): qemu-img.o $(block-obj-y) libqemuutil.a libqemustub.a
qemu-nbd$(EXESUF): qemu-nbd.o $(block-obj-y) libqemuutil.a libqemustub.a
qemu-io$(EXESUF): qemu-io.o $(block-obj-y) libqemuutil.a libqemustub.a
qemu-img$(EXESUF): qemu-img.o $(block-obj-y) $(crypto-obj-y) libqemuutil.a libqemustub.a
qemu-nbd$(EXESUF): qemu-nbd.o $(block-obj-y) $(crypto-obj-y) libqemuutil.a libqemustub.a
qemu-io$(EXESUF): qemu-io.o $(block-obj-y) $(crypto-obj-y) libqemuutil.a libqemustub.a

qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o

Expand Down
6 changes: 5 additions & 1 deletion Makefile.objs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Common libraries for tools and emulators
stub-obj-y = stubs/
util-obj-y = util/ qobject/ qapi/ qapi-types.o qapi-visit.o qapi-event.o
util-obj-y += crypto/

#######################################################################
# block-obj-y is code used by both qemu system emulation and qemu-img
Expand All @@ -21,6 +20,11 @@ block-obj-y += coroutine-$(CONFIG_COROUTINE_BACKEND).o

block-obj-m = block/

#######################################################################
# crypto-obj-y is code used by both qemu system emulation and qemu-img

crypto-obj-y = crypto/
crypto-aes-obj-y = crypto/

######################################################################
# smartcard
Expand Down
4 changes: 4 additions & 0 deletions Makefile.target
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,16 @@ target-obj-y-save := $(target-obj-y)
dummy := $(call unnest-vars,.., \
block-obj-y \
block-obj-m \
crypto-obj-y \
crypto-aes-obj-y \
common-obj-y \
common-obj-m)
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)

$(QEMU_PROG_BUILD): config-devices.mak

Expand Down
13 changes: 8 additions & 5 deletions crypto/Makefile.objs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
util-obj-y += init.o
util-obj-y += hash.o
util-obj-y += aes.o
util-obj-y += desrfb.o
util-obj-y += cipher.o
crypto-obj-y = init.o
crypto-obj-y += hash.o
crypto-obj-y += aes.o
crypto-obj-y += desrfb.o
crypto-obj-y += cipher.o

# Let the userspace emulators avoid linking gnutls/etc
crypto-aes-obj-y = aes.o
7 changes: 4 additions & 3 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ test-qom-obj-y = qom/object.o qom/qom-qobject.o \
test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \
tests/test-qapi-event.o \
$(test-qom-obj-y)
test-block-obj-y = $(block-obj-y) $(test-util-obj-y)
test-crypto-obj-y = $(crypto-obj-y) $(test-util-obj-y)
test-block-obj-y = $(block-obj-y) $(test-crypto-obj-y)

tests/check-qint$(EXESUF): tests/check-qint.o $(test-util-obj-y)
tests/check-qstring$(EXESUF): tests/check-qstring.o $(test-util-obj-y)
Expand Down Expand Up @@ -357,8 +358,8 @@ tests/test-opts-visitor$(EXESUF): tests/test-opts-visitor.o $(test-qapi-obj-y)

tests/test-mul64$(EXESUF): tests/test-mul64.o $(test-util-obj-y)
tests/test-bitops$(EXESUF): tests/test-bitops.o $(test-util-obj-y)
tests/test-crypto-hash$(EXESUF): tests/test-crypto-hash.o $(test-util-obj-y)
tests/test-crypto-cipher$(EXESUF): tests/test-crypto-cipher.o $(test-util-obj-y)
tests/test-crypto-hash$(EXESUF): tests/test-crypto-hash.o $(test-crypto-obj-y)
tests/test-crypto-cipher$(EXESUF): tests/test-crypto-cipher.o $(test-crypto-obj-y)

libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o tests/libqos/malloc.o
libqos-obj-y += tests/libqos/i2c.o tests/libqos/libqos.o
Expand Down

0 comments on commit fb37726

Please sign in to comment.