From patchwork Wed Jun 5 21:59:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Petazzoni X-Patchwork-Id: 249231 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ozlabs.org (Postfix) with ESMTP id 69A192C013D for ; Thu, 6 Jun 2013 07:59:23 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id DAA698C43D; Wed, 5 Jun 2013 21:59:20 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ajdy6s6pWgqO; Wed, 5 Jun 2013 21:59:17 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 049E88BF16; Wed, 5 Jun 2013 21:59:17 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id BBD228F7A2 for ; Wed, 5 Jun 2013 21:59:22 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id ED7798BC2C for ; Wed, 5 Jun 2013 21:59:15 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jMT4feqfVzUr for ; Wed, 5 Jun 2013 21:59:14 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.free-electrons.com (mail.free-electrons.com [94.23.35.102]) by whitealder.osuosl.org (Postfix) with ESMTP id 1F1358BF16 for ; Wed, 5 Jun 2013 21:59:14 +0000 (UTC) Received: by mail.free-electrons.com (Postfix, from userid 106) id 56BD376F; Wed, 5 Jun 2013 23:59:11 +0200 (CEST) Received: from localhost (unknown [37.160.51.233]) by mail.free-electrons.com (Postfix) with ESMTPSA id BA7575BB for ; Wed, 5 Jun 2013 23:59:10 +0200 (CEST) From: Thomas Petazzoni To: buildroot@uclibc.org Date: Wed, 5 Jun 2013 23:59:02 +0200 Message-Id: <1370469543-20677-1-git-send-email-thomas.petazzoni@free-electrons.com> X-Mailer: git-send-email 1.8.1.2 Subject: [Buildroot] [PATCH 1/2] toolchain: wrap 'ld' so that a ld emulation can be specified X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: buildroot-bounces@busybox.net On some architectures, such as MIPS, the linker supports several 'ld emulation', and depending on which flavor of the architecture you're building for, one should be passing the proper -m option to ld, otherwise ld defaults to the default emulation, which may not necessarily be compatible with the object files that are being linked. See for example the following build failure: http://autobuild.buildroot.org/results/0e1/0e18e02e01148afb36acd2293b3fdc56c6bb8413/build-end.log So, we extend the toolchain wrapper to also wrap the ld linker, and allow a BR_LD_EMULATION variable to be passed to it. Signed-off-by: Thomas Petazzoni Tested-by: Markos Chandras --- arch/Config.in | 3 +++ toolchain/toolchain-external/ext-tool.mk | 6 ++++- .../toolchain-external/ext-toolchain-wrapper.c | 26 +++++++++++++++++----- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/arch/Config.in b/arch/Config.in index 5ca05cd..aab9922 100644 --- a/arch/Config.in +++ b/arch/Config.in @@ -192,6 +192,9 @@ config BR2_GCC_TARGET_CPU config BR2_GCC_TARGET_CPU_REVISION string +config BR2_LD_TARGET_EMULATION + string + # Set up target binary format choice prompt "Target Binary Format" diff --git a/toolchain/toolchain-external/ext-tool.mk b/toolchain/toolchain-external/ext-tool.mk index 93b3b15..c132e6a 100644 --- a/toolchain/toolchain-external/ext-tool.mk +++ b/toolchain/toolchain-external/ext-tool.mk @@ -141,6 +141,7 @@ CC_TARGET_CPU_:=$(call qstrip,$(BR2_GCC_TARGET_CPU)-$(BR2_GCC_TARGET_CPU_REVISIO endif CC_TARGET_ARCH_:=$(call qstrip,$(BR2_GCC_TARGET_ARCH)) CC_TARGET_ABI_:=$(call qstrip,$(BR2_GCC_TARGET_ABI)) +LD_TARGET_EMULATION_:=$(call qstrip,$(BR2_LD_TARGET_EMULATION)) # march/mtune/floating point mode needs to be passed to the external toolchain # to select the right multilib variant @@ -164,6 +165,9 @@ ifneq ($(CC_TARGET_ABI_),) TOOLCHAIN_EXTERNAL_CFLAGS += -mabi=$(CC_TARGET_ABI_) TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_ABI='"$(CC_TARGET_ABI_)"' endif +ifneq ($(LD_TARGET_EMULATION_),) +TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_LD_EMULATION='"$(LD_TARGET_EMULATION_)"' +endif ifeq ($(BR2_BINFMT_FLAT),y) TOOLCHAIN_EXTERNAL_CFLAGS += -Wl,-elf2flt TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_BINFMT_FLAT @@ -468,7 +472,7 @@ $(HOST_DIR)/usr/bin/ext-toolchain-wrapper: $(STAMP_DIR)/ext-toolchain-installed for i in $(TOOLCHAIN_EXTERNAL_CROSS)*; do \ base=$${i##*/}; \ case "$$base" in \ - *cc|*cc-*|*++|*++-*|*cpp) \ + *cc|*cc-*|*++|*++-*|*cpp|*ld) \ ln -sf $(@F) $$base; \ ;; \ *) \ diff --git a/toolchain/toolchain-external/ext-toolchain-wrapper.c b/toolchain/toolchain-external/ext-toolchain-wrapper.c index 9d79d68..e2b945e 100644 --- a/toolchain/toolchain-external/ext-toolchain-wrapper.c +++ b/toolchain/toolchain-external/ext-toolchain-wrapper.c @@ -23,7 +23,7 @@ static char path[PATH_MAX]; static char sysroot[PATH_MAX]; -static char *predef_args[] = { +static char *gcc_predef_args[] = { path, "--sysroot", sysroot, #ifdef BR_ARCH @@ -55,13 +55,21 @@ static char *predef_args[] = { #endif }; +static char *ld_predef_args[] = { + path, +#ifdef BR_LD_EMULATION + "-m", BR_LD_EMULATION, +#endif +}; + int main(int argc, char **argv) { char **args, **cur; char *relbasedir, *absbasedir; char *progpath = argv[0]; char *basename; - int ret, i, count = 0; + char **predef_args; + int ret, i, predef_args_sz, count = 0; /* Calculate the relative paths */ basename = strrchr(progpath, '/'); @@ -113,15 +121,23 @@ int main(int argc, char **argv) return 3; } - cur = args = malloc(sizeof(predef_args) + (sizeof(char *) * argc)); + if (!strncmp("-ld", basename + strlen(basename) - 3, 3)) { + predef_args_sz = sizeof(ld_predef_args); + predef_args = ld_predef_args; + } else { + predef_args_sz = sizeof(gcc_predef_args); + predef_args = gcc_predef_args; + } + + cur = args = malloc(predef_args_sz + (sizeof(char *) * argc)); if (args == NULL) { perror(__FILE__ ": malloc"); return 2; } /* start with predefined args */ - memcpy(cur, predef_args, sizeof(predef_args)); - cur += sizeof(predef_args) / sizeof(predef_args[0]); + memcpy(cur, predef_args, predef_args_sz); + cur += predef_args_sz / sizeof(char *); /* append forward args */ memcpy(cur, &argv[1], sizeof(char *) * (argc - 1));