From patchwork Fri Mar 26 00:04:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nathan Chancellor X-Patchwork-Id: 409101 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50AEDC433E1 for ; Fri, 26 Mar 2021 00:05:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 27A0C61A36 for ; Fri, 26 Mar 2021 00:05:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230045AbhCZAFC (ORCPT ); Thu, 25 Mar 2021 20:05:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:60168 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230013AbhCZAE7 (ORCPT ); Thu, 25 Mar 2021 20:04:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0145561A13; Fri, 26 Mar 2021 00:04:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616717099; bh=cX3mQeEGrADEox7GGuslEi3aDF4L5XBwmaqXSbfj2Ts=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ii6iPhXwoK6cz7rzV5rK9BAdkr102MSShtXptn9J+eL7UmySEkjHFGNRNOXMFslMU sIy84W8LVaXgui7biGhcpvUTgEENHr9ufuio2Oy1wlj2qFDXojZtlFi5+0RYJOk5ig Vi/7fm6hMOo/TaIlQT3GDHFbQYpR/K5eHCmxwl2+k1jVZvxMy7lUyyjIiGBOELU+Vf l9mjgwmyxyehwG0xvhcxCLL18nXK7rf5q/244GKVxkldwCUulX3gOX5qKtbBQigovt 6NcUVaEJbqcArfFUsCxRJhQWJiajBvQ19un1KZFQpeg8RkR+Ez9ks6cu0q2d/4kJYg iYVy8OjjG1Myg== From: Nathan Chancellor To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, Ard Biesheuvel Cc: Nick Desaulniers , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, John Millikin , Sedat Dilek , Nathan Chancellor Subject: [PATCH 1/3] x86: Propagate $(CLANG_FLAGS) to $(REALMODE_FLAGS) Date: Thu, 25 Mar 2021 17:04:33 -0700 Message-Id: <20210326000435.4785-2-nathan@kernel.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210326000435.4785-1-nathan@kernel.org> References: <20210326000435.4785-1-nathan@kernel.org> MIME-Version: 1.0 X-Patchwork-Bot: notify Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: John Millikin When cross-compiling with Clang, the `$(CLANG_FLAGS)' variable contains additional flags needed to build C and assembly sources for the target platform. Normally this variable is automatically included in `$(KBUILD_CFLAGS)' by via the top-level Makefile. The x86 real-mode makefile builds `$(REALMODE_CFLAGS)' from a plain assignment and therefore drops the Clang flags. This causes Clang to not recognize x86-specific assembler directives:   arch/x86/realmode/rm/header.S:36:1: error: unknown directive   .type real_mode_header STT_OBJECT ; .size real_mode_header, .-real_mode_header   ^ Explicit propagation of `$(CLANG_FLAGS)' to `$(REALMODE_CFLAGS)', which is inherited by real-mode make rules, fixes cross-compilation with Clang for x86 targets. Relevant flags: * `--target' sets the target architecture when cross-compiling. This   flag must be set for both compilation and assembly (`KBUILD_AFLAGS')   to support architecture-specific assembler directives. * `-no-integrated-as' tells clang to assemble with GNU Assembler   instead of its built-in LLVM assembler. This flag is set by default   unless `LLVM_IAS=1' is set, because the LLVM assembler can't yet   parse certain GNU extensions. Signed-off-by: John Millikin Tested-by: Sedat Dilek Signed-off-by: Nathan Chancellor Tested-by: Sedat Dilek --- arch/x86/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 2d6d5a28c3bf..9a73e0cea19c 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -33,6 +33,7 @@ REALMODE_CFLAGS += -ffreestanding REALMODE_CFLAGS += -fno-stack-protector REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -Wno-address-of-packed-member) REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), $(cc_stack_align4)) +REALMODE_CFLAGS += $(CLANG_FLAGS) export REALMODE_CFLAGS # BITS is used as extension for files which are available in a 32 bit From patchwork Fri Mar 26 00:04:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Chancellor X-Patchwork-Id: 410361 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B06CCC433DB for ; Fri, 26 Mar 2021 00:06:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F20A61A13 for ; Fri, 26 Mar 2021 00:06:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229779AbhCZAFd (ORCPT ); Thu, 25 Mar 2021 20:05:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:60224 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230035AbhCZAFC (ORCPT ); Thu, 25 Mar 2021 20:05:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3EA7C61A36; Fri, 26 Mar 2021 00:05:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616717102; bh=9/29N/4yLblEnOYYfPpTSkMrTA51czELTdv1FroKk14=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aB1LzYuEPu8fVe1jy4nf23gaZvjSO/LqgsDj9GjIHg0j7vlEYUJqBjzkFoX/E42Sj 4PvO42XhIEcB/okZVfaDGGd92F9SeTDeXL6HzOqQso/BN4sSRqgVoxjm5d6XHrUbrX QpWfg5CEX648X5IAozxW8CUAuQIINXytnL/wadfsUDQYkGqpNfxBW51u+zeE2hvYJN KlGxOYwuXDtygNl3Zh7FivikovMQ9V34f5U32ChpASgZFu+Qj+LY56wdoo/MoU0B+X h5HqPPQIUElcgvoHTC0OhXUJrprNO2BomAAs7gv8L0meoaqWK9yI/Qml1+9h9dfIwH bK9woXfXsfWag== From: Nathan Chancellor To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, Ard Biesheuvel Cc: Nick Desaulniers , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, Nathan Chancellor Subject: [PATCH 2/3] x86/boot: Add $(CLANG_FLAGS) to compressed KBUILD_CFLAGS Date: Thu, 25 Mar 2021 17:04:34 -0700 Message-Id: <20210326000435.4785-3-nathan@kernel.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210326000435.4785-1-nathan@kernel.org> References: <20210326000435.4785-1-nathan@kernel.org> MIME-Version: 1.0 X-Patchwork-Bot: notify Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org When cross compiling x86 on an ARM machine with clang, there are several errors along the lines of: arch/x86/include/asm/string_64.h:27:10: error: invalid output constraint '=&c' in asm This happens because the compressed boot Makefile reassigns KBUILD_CFLAGS and drops the clang flags that set the target architecture ('--target=') and the path to the GNU cross tools ('--prefix='), meaning that the host architecture is targeted. These flags are available as $(CLANG_FLAGS) from the main Makefile so add them to the compressed boot folder's KBUILD_CFLAGS so that cross compiling works as expected. Signed-off-by: Nathan Chancellor --- arch/x86/boot/compressed/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index e0bc3988c3fa..6e5522aebbbd 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -46,6 +46,7 @@ KBUILD_CFLAGS += -D__DISABLE_EXPORTS # Disable relocation relaxation in case the link is not PIE. KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mrelax-relocations=no) KBUILD_CFLAGS += -include $(srctree)/include/linux/hidden.h +KBUILD_CFLAGS += $(CLANG_FLAGS) # sev-es.c indirectly inludes inat-table.h which is generated during # compilation and stored in $(objtree). Add the directory to the includes so From patchwork Fri Mar 26 00:04:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Chancellor X-Patchwork-Id: 409773 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C78BCC433C1 for ; Fri, 26 Mar 2021 00:06:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A355B61A0A for ; Fri, 26 Mar 2021 00:06:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230013AbhCZAFe (ORCPT ); Thu, 25 Mar 2021 20:05:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:60294 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229631AbhCZAFF (ORCPT ); Thu, 25 Mar 2021 20:05:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 995C261A0A; Fri, 26 Mar 2021 00:05:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616717105; bh=wK/BFrBTE/0tBXGMmuGyDcFbZJG2Gsid1VRthtJvonc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UeGYgk1XDEILPxorhA3iIVOF9HnzT+TEjpYcjpbwI7twldA4T0jU3SED2npzBIDem fzgPMI+3s5OPIj2jRkkctakVjbfwyW87TLa+P8KBfayXrui20WDjiRMfmGRmCiblec 6IhLRgF/XhD62Ua1REDHkqogfIRwmEkgBJ8Rz1feIy8rM2iPuRZ4raqHtl5c2HfSbw mcFNjzDD7poz5tdSSkXy4bLVWWbsTFp1Z667x+jBEsOiI5tAuSi3YBQPc33TeMuZqE 2xZeAvQB7bP3MzFVs/JtvjO3KBI1awX2vK+xYMj13zu7+izYxFIioK6KDmaiKTOMnM fgUvgzMvUhQag== From: Nathan Chancellor To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, Ard Biesheuvel Cc: Nick Desaulniers , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, Nathan Chancellor Subject: [PATCH 3/3] efi/libstub: Add $(CLANG_FLAGS) to x86 flags Date: Thu, 25 Mar 2021 17:04:35 -0700 Message-Id: <20210326000435.4785-4-nathan@kernel.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210326000435.4785-1-nathan@kernel.org> References: <20210326000435.4785-1-nathan@kernel.org> MIME-Version: 1.0 X-Patchwork-Bot: notify Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org When cross compiling x86 on an ARM machine with clang, there are several errors along the lines of: arch/x86/include/asm/page_64.h:52:7: error: invalid output constraint '=D' in asm This happens because the x86 flags in the EFI stub are not derived from KBUILD_CFLAGS like the other architectures are and the clang flags that set the target architecture ('--target=') and the path to the GNU cross tools ('--prefix=') are not present, meaning that the host architecture is targeted. These flags are available as $(CLANG_FLAGS) from the main Makefile so add them to the cflags for x86 so that cross compiling works as expected. Signed-off-by: Nathan Chancellor --- drivers/firmware/efi/libstub/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile index c23466e05e60..d0537573501e 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -13,7 +13,8 @@ cflags-$(CONFIG_X86) += -m$(BITS) -D__KERNEL__ \ -Wno-pointer-sign \ $(call cc-disable-warning, address-of-packed-member) \ $(call cc-disable-warning, gnu) \ - -fno-asynchronous-unwind-tables + -fno-asynchronous-unwind-tables \ + $(CLANG_FLAGS) # arm64 uses the full KBUILD_CFLAGS so it's necessary to explicitly # disable the stackleak plugin