From patchwork Fri Feb 23 04:56:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 129330 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp189691lja; Thu, 22 Feb 2018 20:59:00 -0800 (PST) X-Google-Smtp-Source: AH8x226xobn70ErMWjFGPircgGozAGfnlkyDAW4VejOcxMQJeJHnJGUdX+VEAupDvOIEDZ0mv5J8 X-Received: by 10.99.116.25 with SMTP id p25mr411858pgc.109.1519361940693; Thu, 22 Feb 2018 20:59:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519361940; cv=none; d=google.com; s=arc-20160816; b=hLPwv4ovWPNftB7/+7Sx5jpn7UOMurobujG4n+gNoHYxIPH/OTMXVYPaNyeWtMFOpG 84ixTHLtBbehW1i7KkWZU9hPNeTP585L+qUf0vu9okwh3g/E93nuTdV7xpMFiioRFSN3 r06cdbibPQltkcre6xQTbAv7lxnEIhiVdV7dQFy7rVzaFVrAHLJc7SD++rrjp5JJtDfO D45jdr78i/s2Vupt7dZ4sbZqHjB7RSYpUfXqc/yRCE//YrwrkvN7V73DG/90V7OtQLem 2Ba8ehLvfbrSOL7huUX+7XrjKgdnMOvRapt1sT9eqi0xAxen5v2LLvYMiwdjvW/5tziq 1Acw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=c94CzZXaICBETuLbyrkOPLALL6MwXImEuVsXqRc+Yns=; b=idD4cOIJRcGjlEbNqN96sY8kyiBj6rG8QCxclS/Q/SbsIHD510Ljd6RLo8A6gWIKHz TlXdOjbhEizAC/KzsKDZmmW1ySviT/Dq3PLhCWl5dqAAov07LMZlU8QOn8KWYZvYyoKi 8nBzOhtQjK5kCQexh5oq3SZ8GEXdg09TF1LAomvWIL8ggdT/pvyxueg/Fokste1nmDQN 8ok2cbm8dXxcSKqkCZPwjA8EaF9/JtkFayeaUBs7uMJkVUQhLrHZJY1SFahHRAAMvQnf 3C9m3K8X6eyc0+xvpSyOjG2NQAhjBDtxvzGLQvpyFeBA7xOo21vjuLVEjOvthtF/sYvu iKuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=TWcBGWXT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b59-v6si1191682plb.354.2018.02.22.20.59.00; Thu, 22 Feb 2018 20:59:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=TWcBGWXT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751507AbeBWE6t (ORCPT + 28 others); Thu, 22 Feb 2018 23:58:49 -0500 Received: from conuserg-12.nifty.com ([210.131.2.79]:26797 "EHLO conuserg-12.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751296AbeBWE6r (ORCPT ); Thu, 22 Feb 2018 23:58:47 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-12.nifty.com with ESMTP id w1N4uwWB024939; Fri, 23 Feb 2018 13:57:00 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com w1N4uwWB024939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1519361820; bh=c94CzZXaICBETuLbyrkOPLALL6MwXImEuVsXqRc+Yns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TWcBGWXT4wmYUliJIw1PJSgdsuAoy90TwyidLp6STTp1tsQWE2M/fR8HtyprJoc+l 7B1JPoOzQPbHbLWQX1WBICJovv04i0Q3UcesRGfJmjsA4Ittzp4C1N0vwpsJPn73yw be3W29n1Z4x5W9LhvjhckyEXwI3Xvv37rwod8rcowqhia313DlB2Pc9qxkwwlp+Sb2 dJ3Twmvjsn+HiFFVJ8s9adaX7sao0LTVTwiEi7QvYR8yA5DNLA/6Mg7rPn/4uQH8nq gFG0clOl74Tm/8QXi3w5im8YTG68RDXU8/VuoQO6ncClzZx9hImvp8/cydsTvpImSA /mZE9hqwvy8Cw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Arnd Bergmann , Sam Ravnborg , Nick Desaulniers , Matthias Kaehlcke , Masahiro Yamada , Cao jin , Mark Charlebois , Michael Forney , linux-kernel@vger.kernel.org, Douglas Anderson , Josh Poimboeuf , Ingo Molnar Subject: [PATCH 2/2] kbuild: simplify ld-option implementation Date: Fri, 23 Feb 2018 13:56:53 +0900 Message-Id: <1519361813-8553-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519361813-8553-1-git-send-email-yamada.masahiro@socionext.com> References: <1519361813-8553-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, linker options are tested by the coordination of $(CC) and $(LD) because LD needs some object to link. As commit 86a9df597cdd ("kbuild: fix linker feature test macros when cross compiling with Clang") addressed, we need to make sure $(CC) and $(LD) agree the underlying architecture of the passed object. This could be a bit complex when we combine tools from different groups. For example, we can use clang for $(CC), but we still need to rely on GCC toolchain for $(LD). So, I was searching a way for standalone testing of linker options. A trick I found is to use '-v'. This prints the version string, but also tests if the given option is recognized. If a given option is supported, $ aarch64-linux-gnu-ld -v --fix-cortex-a53-843419 GNU ld (Linaro_Binutils-2017.11) 2.28.2.20170706 $ echo $? 0 If unsupported, $ aarch64-linux-gnu-ld -v --fix-cortex-a53-843419 GNU ld (crosstool-NG linaro-1.13.1-4.7-2013.04-20130415 - Linaro GCC 2013.04) 2.23.1 aarch64-linux-gnu-ld: unrecognized option '--fix-cortex-a53-843419' aarch64-linux-gnu-ld: use the --help option for usage information $ echo $? 1 Gold works likewise. $ aarch64-linux-gnu-ld.gold -v --fix-cortex-a53-843419 GNU gold (Linaro_Binutils-2017.11 2.28.2.20170706) 1.14 masahiro@pug:~/ref/linux$ echo $? 0 $ aarch64-linux-gnu-ld.gold -v --fix-cortex-a53-999999 GNU gold (Linaro_Binutils-2017.11 2.28.2.20170706) 1.14 aarch64-linux-gnu-ld.gold: --fix-cortex-a53-999999: unknown option aarch64-linux-gnu-ld.gold: use the --help option for usage information $ echo $? 1 LLD too. $ ld.lld -v --gc-sections LLD 7.0.0 (http://llvm.org/git/lld.git 4a0e4190e74cea19f8a8dc625ccaebdf8b5d1585) (compatible with GNU linkers) $ echo $? 0 $ ld.lld -v --fix-cortex-a53-843419 LLD 7.0.0 (http://llvm.org/git/lld.git 4a0e4190e74cea19f8a8dc625ccaebdf8b5d1585) (compatible with GNU linkers) $ echo $? 0 $ ld.lld -v --fix-cortex-a53-999999 ld.lld: error: unknown argument: --fix-cortex-a53-999999 LLD 7.0.0 (http://llvm.org/git/lld.git 4a0e4190e74cea19f8a8dc625ccaebdf8b5d1585) (compatible with GNU linkers) $ echo $? 1 Signed-off-by: Masahiro Yamada --- scripts/Kbuild.include | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) -- 2.7.4 Signed-off-by: Nick Desaulniers Tested-by: Nick Desaulniers diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 34cbd81..f9c2f07 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -237,9 +237,7 @@ cc-ldoption = $(call try-run-cached,\ # ld-option # Usage: LDFLAGS += $(call ld-option, -X) -ld-option = $(call try-run-cached,\ - $(CC) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -x c /dev/null -c -o "$$TMPO"; \ - $(LD) $(LDFLAGS) $(1) "$$TMPO" -o "$$TMP",$(1),$(2)) +ld-option = $(call try-run-cached, $(LD) $(LDFLAGS) $(1) -v,$(1),$(2)) # ar-option # Usage: KBUILD_ARFLAGS := $(call ar-option,D)