From patchwork Tue Oct 3 20:48:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 9983535 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EBEFB60365 for ; Tue, 3 Oct 2017 20:50:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8A1628975 for ; Tue, 3 Oct 2017 20:50:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD2A728A40; Tue, 3 Oct 2017 20:50:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65D3C28975 for ; Tue, 3 Oct 2017 20:50:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751484AbdJCUto (ORCPT ); Tue, 3 Oct 2017 16:49:44 -0400 Received: from mail-pf0-f182.google.com ([209.85.192.182]:49330 "EHLO mail-pf0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751255AbdJCUtl (ORCPT ); Tue, 3 Oct 2017 16:49:41 -0400 Received: by mail-pf0-f182.google.com with SMTP id l188so5173223pfc.6 for ; Tue, 03 Oct 2017 13:49:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7+Zu8g68dKfHALmqA6+pEqLZwZR8gbQY00I0XsBuEtg=; b=O7U5q8neQq8A5kORUFKENlwBaRiKBULrYFpCLQ4fKECdAwUSgMnccAjHIFC2XCW4du ZlIRI5RPhVniXsfCN6aYXRxpCxasax57VS+gBc0hX2kiqsqiIbih/GPjzE4aawGcGJ3r b+DtmBght2Kqw5pdyqi+/ZdI58DAXMPbR7ZuE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7+Zu8g68dKfHALmqA6+pEqLZwZR8gbQY00I0XsBuEtg=; b=CjiBjHrV7RqpRW1XNu3gUeedZzXGWwtemRO6oEeW991/aL92WfH28C9CXFSKDwKtcT JoIKfTDAlRuJdLGEtA4iwob1IPViw/CaLa6kYFjJZhMnP7/Lj0ah1HfuxLNlr3ORZnKr R3kEE9KmASBC6iC6g2Y8zp0qnT4NMnhfGdfoatXKPHECDxY4k3jUWzUH6n1pH80gRhB4 phSzMbNCaWEoCA9o/+29kR9KQQG1cui3e1z4YyaRV6S4JZygk9pdlEHbJnHDkBewq344 Mabqa3TQLsPPpXeaOtrpx8eKDVo1sFmmEcKYl1o/YW9HFvAnEEMp6C+2OZkRQfaqW/qA iqWg== X-Gm-Message-State: AHPjjUjfZjGP65v+nd6oixh9GmmpZtpDYlJ8nOKPObCneWy8E1lppzGX BtSKIpnbFR5IUnX9dUO2sqIucQ== X-Google-Smtp-Source: AOwi7QDN5j9W0hJKuBYDaznxWOwrndTToE82uZlYabPCIMugx9FTmINiMvGAED7GR5+vYbucOFjaiA== X-Received: by 10.101.89.11 with SMTP id f11mr16589491pgu.393.1507063780721; Tue, 03 Oct 2017 13:49:40 -0700 (PDT) Received: from tictac.mtv.corp.google.com ([172.22.112.154]) by smtp.gmail.com with ESMTPSA id b1sm22585107pgn.94.2017.10.03.13.49.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 03 Oct 2017 13:49:39 -0700 (PDT) From: Douglas Anderson To: yamada.masahiro@socionext.com, mmarek@suse.com, acme@redhat.com Cc: groeck@chromium.org, Dmitry Torokhov , mka@chromium.org, Douglas Anderson , linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org Subject: [RFC PATCH 1/2] kbuild: Pass HOSTCC and similar to tools Makefiles Date: Tue, 3 Oct 2017 13:48:38 -0700 Message-Id: <20171003204839.27551-2-dianders@chromium.org> X-Mailer: git-send-email 2.14.2.920.gcf0c67979c-goog In-Reply-To: <20171003204839.27551-1-dianders@chromium.org> References: <20171003204839.27551-1-dianders@chromium.org> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The main Linux Makefiles and the tools sub-Makefiles have different conventions for passing in CC / CFLAGS. Here's brief summary for the kernel: * CC: target C compiler (must be passed as an argument to make to override) * HOSTCC: host C compiler (must be passed as an argument to make to override) * CFLAGS: ignored (kernel manages its own CFLAGS) * KCFLAGS: extra cflags for the target (expected as an env var) * HOSTCFLAGS: host C compiler flags (not modifiable by the caller of make) Here's a brief summary for the tools: * CC: host C compiler (must be passed as an argument to make to override) * CFLAGS: base arguments for the host C compiler which are added to by sub builds (expected as an env var) When the main kernel Makefile calls into the tools Makefile, it should adapt things from its syntax to the tools Makefile syntax. If we don't do this, we have a few issues: * If someone wants to user another compiler (like clang, maybe) for hostcc then the tools will still be compiled with gcc. * If you happen to be building and you left ${CFLAGS} set to something random (maybe it matches ${CC}, the _target_ C compiler, not the _host_ C compiler) then this random value will be used to compile the tools. In any case, it seems like it makes sense to pass CC, CFLAGS, and similar properly into the tools Makefile. NOTE: in order to do this properly, we need to add some new definitions of HOSTAS and HOSTLD into the main kernel Makefile. If we don't do this and someone overrides "AS" or "LD" on the command line then those (which were intended for the target) will be used to build host side tools. We also make up some imaginary "HOSTASFLAGS" and "HOSTLDFLAGS". Someone could specify these, but if they don't at least these blank variables will properly clobber ASFLAGS and LDFLAGS from the kernel. This was discovered in the Chrome OS build system where CFLAGS (an environment variable) was accidentally left pointing to flags that would be an appropriate match to CC. The kernel didn't use these CFLAGS so it was never an issue. Turning on STACKVALIDATION, however, suddenly invoked a tools build that blew up. Signed-off-by: Douglas Anderson Reviewed-by: Guenter Roeck Tested-by: Guenter Roeck --- Makefile | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index cf007a31d575..0d3af0677d88 100644 --- a/Makefile +++ b/Makefile @@ -298,7 +298,9 @@ HOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS) HOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS) HOST_LFS_LIBS := $(shell getconf LFS_LIBS) +HOSTAS = as HOSTCC = gcc +HOSTLD = ld HOSTCXX = g++ HOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \ -fomit-frame-pointer -std=gnu89 $(HOST_LFS_CFLAGS) @@ -1616,11 +1618,35 @@ image_name: # Clear a bunch of variables before executing the submake tools/: FORCE $(Q)mkdir -p $(objtree)/tools - $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(src)/tools/ + $(Q)ASFLAGS="$(HOSTASFLAGS)"\ + LDFLAGS="$(HOSTLDFLAGS)" \ + CFLAGS="$(HOSTCFLAGS)" \ + CXXFLAGS="$(HOSTCXXFLAGS)" \ + $(MAKE) \ + AS="$(HOSTAS)" \ + CC="$(HOSTCC)" \ + CXX="$(HOSTCXX)" \ + LD="$(HOSTLD)" \ + MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" \ + O=$(abspath $(objtree)) \ + subdir=tools \ + -C $(src)/tools/ tools/%: FORCE $(Q)mkdir -p $(objtree)/tools - $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(src)/tools/ $* + $(Q)ASFLAGS="$(HOSTASFLAGS)"\ + LDFLAGS="$(HOSTLDFLAGS)" \ + CFLAGS="$(HOSTCFLAGS)" \ + CXXFLAGS="$(HOSTCXXFLAGS)" \ + $(MAKE) \ + AS="$(HOSTAS)" \ + CC="$(HOSTCC)" \ + CXX="$(HOSTCXX)" \ + LD="$(HOSTLD)" \ + MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" \ + O=$(abspath $(objtree)) \ + subdir=tools \ + -C $(src)/tools/ $* # Single targets # ---------------------------------------------------------------------------