From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49262) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XNCQC-0007qL-Sn for qemu-devel@nongnu.org; Thu, 28 Aug 2014 23:00:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XNCQ6-0005Pr-KV for qemu-devel@nongnu.org; Thu, 28 Aug 2014 23:00:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53959) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XNCQ6-0005Pk-Cm for qemu-devel@nongnu.org; Thu, 28 Aug 2014 23:00:10 -0400 From: Fam Zheng Date: Fri, 29 Aug 2014 11:00:15 +0800 Message-Id: <1409281215-30711-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH] rules.mak: Fix DSO build by pulling in archive symbols List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, Peter Maydell , Fam Zheng , Michael Tokarev , stefanha@redhat.com, Paolo Bonzini , Richard Henderson This fixes an issue with module build system. block/iscsi.so is currently broken: $ ~/build/last/qemu-img Failed to open module: /home/fam/build/master/block-iscsi.so: undefined symbol: qmp_query_uuid qemu-img: Not enough arguments Try 'qemu-img --help' for more information To fix this, we should (at least) let qemu-img link qmp_query_uuid from libqemustub.a. (There are a few other symbols missing, as well.) This patch changes the linking rules to: 1) Build ".mo" with "ld -r -o $@ $^" for each ".so", and later build .so with it. 2) Always build all the .mo before linking the executables. This is achieved by adding those .mo files to the executables' "-y" variables. 3) When linking an executable, those .mo files in its "-y" variables are filtered out, and replaced by one or more -Wl,-u,$symbol flags. This is done in the added macro "process-archive-undefs". These "-Wl,-u,$symbol" flags will force ld to pull in the function definition from the archives when linking. Note that the .mo objects, that are actually meant to be linked in the executables, are already expanded in unnest-vars, before the linking command. So we are safe to simply filter out .mo for the purpose of pulling undefined symbols. process-archive-undefs works as this: For each ".mo", find all the undefined symbols in it, filter ones that are defined in the archives. For each of these symbols, generate a "-Wl,-u,$symbol" in the link command, and put them before archive names in the command line. Signed-off-by: Fam Zheng --- rules.mak | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/rules.mak b/rules.mak index ba2f4c1..2bb2446 100644 --- a/rules.mak +++ b/rules.mak @@ -22,6 +22,32 @@ QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d # Same as -I$(SRC_PATH) -I., but for the nested source/object directories QEMU_INCLUDES += -I$(