From patchwork Tue Apr 2 07:08:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 10881147 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 7E1EC17E0 for ; Tue, 2 Apr 2019 07:09:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69D01287B1 for ; Tue, 2 Apr 2019 07:09:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E325287C5; Tue, 2 Apr 2019 07:09:17 +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 E09A8287B1 for ; Tue, 2 Apr 2019 07:09:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726630AbfDBHJQ (ORCPT ); Tue, 2 Apr 2019 03:09:16 -0400 Received: from mail-io1-f73.google.com ([209.85.166.73]:42177 "EHLO mail-io1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726193AbfDBHJQ (ORCPT ); Tue, 2 Apr 2019 03:09:16 -0400 Received: by mail-io1-f73.google.com with SMTP id i1so10238947ioq.9 for ; Tue, 02 Apr 2019 00:09:15 -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=6fjJy8yswnbkmtbxTFEZ/Qrr257jfY2BDV+aITklo40=; b=IOEx5MmrzBQW2a1Uik6PO/3VBDmNvgmOUIZgRpn2ByOjilXHh0sULLQE3eVnKsxLAN cEzdanotzIFZE4Omm1LpNIYJnnmSgsd2wsTXjbO1y0cz89L4ZPL5SIhZLU2zbzLHvC3c hqqLPpSLAcEhUCxg8SdyETezh17JC5YPPJpomqFLfaVKHjBxo44WXDdOU8hV27Pueccb UGonDZWw5675DRCB41bPERZnuZlgI1huUqNCYcrju3IRxGgXVM1/UbfnZ2BWFVKH+15G IW+wAuwfRc4E/ZuUZn3Vx7QQRkOVGJB7UkUnajGvwM5jX/Yfi8jEj2gDWVloual4oEwj lDrw== 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=6fjJy8yswnbkmtbxTFEZ/Qrr257jfY2BDV+aITklo40=; b=lNQVpBo21r4HLd+2lIHHNcRhj3ujcZwp8Xq5c70JuC2BUEzVsmPjMvFwYZW8OrNZGV L6pdEUWx6k9yNitUu4L3XF+DN6jnWHoXLt1LWNTVjEtlkIwvK/MOoaGs0uYQwFdvR6hN +XSZ8o92+U16kn2LBC2TU0RjYkVK7QosUCzWtxHsvamB2Qj5zGmj81vG44s/IiVmN8My /qllu8yDNH9OcXwmNkrVTc/BWsu/sgL2CbEHH8Mpnn6tTOTmVMFACctuV6enIbrtYURA 6F1PuVxNpBRVyB+x/A2sEKeBe5d1gCV5eYymrtxt0dUo90efmQkuHSkxqmdPHaGtDzJa Yfew== X-Gm-Message-State: APjAAAXp92AeD1zrVzJxMDcYJCJYica5ERBbuPMnpe1TUGYYkhi8/0Go oi3Eihlpzf0qKIDJ7IoPlTUCos7k/tE1LET6VaI= X-Google-Smtp-Source: APXvYqy5So56foJ0QDTySf1eU316xGuwVcT836f1flnZX0I0DUUVjpk4wrIqhvALaIK8oet12fd0+0UhZjFWpykKJZ0= X-Received: by 2002:a24:455b:: with SMTP id y88mr7235585ita.14.1554188955497; Tue, 02 Apr 2019 00:09:15 -0700 (PDT) Date: Tue, 2 Apr 2019 00:08:58 -0700 In-Reply-To: Message-Id: <20190402070858.49597-1-ndesaulniers@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.21.0.392.gf8f6787159e-goog Subject: [PATCH v3] 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 when using LLD, as otherwise Clang likes to complain about -fuse-lld= being unused when compiling but not linking (-c) such as when cc-option is used. 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 Reviewed-by: Sedat Dilek --- 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 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 026fbc450906..895c076b6305 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)) +KBUILD_CPPFLAGS += -Qunused-arguments +endif KBUILD_CFLAGS += $(CLANG_FLAGS) KBUILD_AFLAGS += $(CLANG_FLAGS) export CLANG_FLAGS