From patchwork Tue Apr 2 07:33:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 10881181 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B4DCB17E0 for ; Tue, 2 Apr 2019 07:33:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A05C2888C for ; Tue, 2 Apr 2019 07:33:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E25B2889B; Tue, 2 Apr 2019 07:33:32 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 2A0F428898 for ; Tue, 2 Apr 2019 07:33:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728968AbfDBHdb (ORCPT ); Tue, 2 Apr 2019 03:33:31 -0400 Received: from mail-it1-f202.google.com ([209.85.166.202]:35130 "EHLO mail-it1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728999AbfDBHd0 (ORCPT ); Tue, 2 Apr 2019 03:33:26 -0400 Received: by mail-it1-f202.google.com with SMTP id a64so2042159ith.0 for ; Tue, 02 Apr 2019 00:33:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=q6AEs42Yptqy+iLpgSDIlp7Uvrf/sOqm7YVBDoal0w8=; b=OVk42bkFWAzTse1R7qCna/cXD/YEW+pcJNSgHWLAbCuvXR5ruo+sAq2OxXNqIOpwiD Ya2gQ+b6TTqPBnAfuWXSYFFePyVNION9J0/1yLUqRs49n2mPD3jKa/3HlPWzYjRvveeD 5JuYZdLFNOoLeKhRvAy84oYIheVHHsF+mwXl3/ek4IcYM9mp1i2EbhEOQt5hnBXePQAu r1oxPVrlVPk3eFTyBGlwcCcLqBkI6MKAuPQOF3lPfeL1/Z5tbZzOA9iqDgKQHYm96+Uv 5WVT/P37j1F/4nfuTJeON1/fR7KylQ1rdSvOx30ageVIaZL/Ts1tv5OOL7Lw1H20ZTMq QcdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=q6AEs42Yptqy+iLpgSDIlp7Uvrf/sOqm7YVBDoal0w8=; b=Io+CguP2o9WSdGlrtFnkZmceIVa+54MwY1a7rfKxgMXRLEn5VFs6r3D8pfyAsJN/BA Q1DaA4sVUTP9Srq0c/1bWfARehD7dYFToEFHMmeQUdyFqYoh57z+vsFRqvTzzhWZUq4L zaIJAFzfdiOwoNloQzdPlAEyFKLgiUP/KZolNVIo6fQJJCFta9KmvxBiyFufSCCRNXn7 imIJIOLl3yb+u/TfILh4JxHMVNWGua87e7HC5K/7ee2cc9lZ91/b5cPS43I/gYspKyE/ dFFpbsu5XHsRxOxt8Gi/CTmzwa7ylCjfg5p6NfmQ//rnxd6eJ9XyiZZwYdGbS0n3IF0U /gkw== X-Gm-Message-State: APjAAAUtFKLVz+WV0WW0hAQLV+VaJ+2Qk2spd5+0hOxohFf6Lh8IWOQ1 2tMSuHqc8tmlQ7ZgS2D1rfeONnd1aIO+wax9ZEY= X-Google-Smtp-Source: APXvYqzAIyTVpTGIKqj9+YaTCaolO8Lo//foJW0vSxi/3IFLTgAgyG7mci+CI+jF5Ne4FuY4HH2NLhQbkITLfgOz+dI= X-Received: by 2002:a05:660c:a45:: with SMTP id j5mr7272933itl.20.1554190405733; Tue, 02 Apr 2019 00:33:25 -0700 (PDT) Date: Tue, 2 Apr 2019 00:33:17 -0700 In-Reply-To: <20190402072726.GA16650@archlinux-ryzen> Message-Id: <20190402073317.56529-1-ndesaulniers@google.com> Mime-Version: 1.0 References: <20190402072726.GA16650@archlinux-ryzen> X-Mailer: git-send-email 2.21.0.392.gf8f6787159e-goog Subject: [PATCH v4] Makefile: lld: tell clang to use lld From: Nick Desaulniers To: yamada.masahiro@socionext.com Cc: keescook@chromium.org, clang-built-linux@googlegroups.com, Nick Desaulniers , Nathan Chancellor , Michal Marek , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.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 This is needed because clang doesn't select which linker to use based on $LD but rather -fuse-ld={bfd,gold,lld,}. This is problematic especially for cc-ldoption, which checks for linker flag support via invoking the compiler, rather than the linker. Select the linker via absolute path from $PATH via `which`. This allows you to build with: $ make LD=ld.lld $ make LD=ld.lld-8 $ make LD=/path/to/ld.lld Add -Qunused-arguments to KBUILD_CPPFLAGS sooner, as otherwise Clang likes to complain about -fuse-lld= being unused when compiling but not linking (-c) such as when cc-option is used. There's no need to guard with cc-option. Link: https://github.com/ClangBuiltLinux/linux/issues/342 Link: https://github.com/ClangBuiltLinux/linux/issues/366 Link: https://github.com/ClangBuiltLinux/linux/issues/357 Suggested-by: Nathan Chancellor Suggested-by: Masahiro Yamada Signed-off-by: Nick Desaulniers Reviewed-by: Nathan Chancellor Tested-by: Nathan Chancellor --- Changes V3->V4: * Unconditionally add -Qunused-arguments sooners, as per Nathan. * Slight modification to commit message for that point. Changes V2->V3: * Use absolute path based on `which $LD` as per Masahiro. * Add -Qunused-arguments. * Drop tested-by/reviewed-by tags, since this patched has changed enough to warrant re-testing/re-review, IMO. * Add more info to the commit message. Changes V1->V2: * add reviewed and tested by tags. * move this addition up 2 statments so that it's properly added to KBUILD_*FLAGS as per Nathan. Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 026fbc450906..b290e76e1ca5 100644 --- a/Makefile +++ b/Makefile @@ -514,6 +514,10 @@ ifneq ($(GCC_TOOLCHAIN),) CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN) endif CLANG_FLAGS += -no-integrated-as +ifneq ($(shell $(LD) --version 2>&1 | head -n 1 | grep LLD),) +CLANG_FLAGS += -fuse-ld=$(shell which $(LD)) +endif +KBUILD_CPPFLAGS += -Qunused-arguments KBUILD_CFLAGS += $(CLANG_FLAGS) KBUILD_AFLAGS += $(CLANG_FLAGS) export CLANG_FLAGS @@ -716,7 +720,6 @@ stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong KBUILD_CFLAGS += $(stackp-flags-y) ifdef CONFIG_CC_IS_CLANG -KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,) KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier) KBUILD_CFLAGS += $(call cc-disable-warning, gnu) KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)