2021-03-26 00:06:53

by Nathan Chancellor

[permalink] [raw]
Subject: [PATCH 0/3] Fix cross compiling x86 with clang

Hi all,

This series fixes cross compiling x86 with clang, which was initially
brought up by John here:

https://lore.kernel.org/r/[email protected]/

I have picked up that patch and added the same fix in a couple of other
places where it is needed.

I have tested this on an ARM based server with both defconfig and
allmodconfig, where the build now passes.

Please let me know if there are any problems.

Cheers,
Nathan

John Millikin (1):
x86: Propagate $(CLANG_FLAGS) to $(REALMODE_FLAGS)

Nathan Chancellor (2):
x86/boot: Add $(CLANG_FLAGS) to compressed KBUILD_CFLAGS
efi/libstub: Add $(CLANG_FLAGS) to x86 flags

arch/x86/Makefile | 1 +
arch/x86/boot/compressed/Makefile | 1 +
drivers/firmware/efi/libstub/Makefile | 3 ++-
3 files changed, 4 insertions(+), 1 deletion(-)


base-commit: 0d02ec6b3136c73c09e7859f0d0e4e2c4c07b49b
--
2.31.0


2021-03-26 00:07:31

by Nathan Chancellor

[permalink] [raw]
Subject: [PATCH 3/3] efi/libstub: Add $(CLANG_FLAGS) to x86 flags

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 <[email protected]>
---
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
--
2.31.0

2021-03-26 00:08:00

by Nathan Chancellor

[permalink] [raw]
Subject: [PATCH 2/3] x86/boot: Add $(CLANG_FLAGS) to compressed KBUILD_CFLAGS

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 <[email protected]>
---
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
--
2.31.0

2021-03-26 08:44:35

by Ard Biesheuvel

[permalink] [raw]
Subject: Re: [PATCH 0/3] Fix cross compiling x86 with clang

On Fri, 26 Mar 2021 at 01:04, Nathan Chancellor <[email protected]> wrote:
>
> Hi all,
>
> This series fixes cross compiling x86 with clang, which was initially
> brought up by John here:
>
> https://lore.kernel.org/r/[email protected]/
>
> I have picked up that patch and added the same fix in a couple of other
> places where it is needed.
>
> I have tested this on an ARM based server with both defconfig and
> allmodconfig, where the build now passes.
>
> Please let me know if there are any problems.
>
> Cheers,
> Nathan
>
> John Millikin (1):
> x86: Propagate $(CLANG_FLAGS) to $(REALMODE_FLAGS)
>
> Nathan Chancellor (2):
> x86/boot: Add $(CLANG_FLAGS) to compressed KBUILD_CFLAGS
> efi/libstub: Add $(CLANG_FLAGS) to x86 flags
>

Acked-by: Ard Biesheuvel <[email protected]>

> arch/x86/Makefile | 1 +
> arch/x86/boot/compressed/Makefile | 1 +
> drivers/firmware/efi/libstub/Makefile | 3 ++-
> 3 files changed, 4 insertions(+), 1 deletion(-)
>
>
> base-commit: 0d02ec6b3136c73c09e7859f0d0e4e2c4c07b49b
> --
> 2.31.0
>

2021-03-26 13:15:29

by tip-bot2 for Hou Wenlong

[permalink] [raw]
Subject: [tip: x86/build] efi/libstub: Add $(CLANG_FLAGS) to x86 flags

The following commit has been merged into the x86/build branch of tip:

Commit-ID: 58d746c119dfa28e72fc35aacaf3d2a3ac625cd0
Gitweb: https://git.kernel.org/tip/58d746c119dfa28e72fc35aacaf3d2a3ac625cd0
Author: Nathan Chancellor <[email protected]>
AuthorDate: Thu, 25 Mar 2021 17:04:35 -07:00
Committer: Borislav Petkov <[email protected]>
CommitterDate: Fri, 26 Mar 2021 11:34:58 +01:00

efi/libstub: Add $(CLANG_FLAGS) to x86 flags

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 <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Acked-by: Ard Biesheuvel <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
---
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 c23466e..d053757 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

2021-03-26 13:15:59

by tip-bot2 for Hou Wenlong

[permalink] [raw]
Subject: [tip: x86/build] x86/boot: Add $(CLANG_FLAGS) to compressed KBUILD_CFLAGS

The following commit has been merged into the x86/build branch of tip:

Commit-ID: d5cbd80e302dfea59726c44c56ab7957f822409f
Gitweb: https://git.kernel.org/tip/d5cbd80e302dfea59726c44c56ab7957f822409f
Author: Nathan Chancellor <[email protected]>
AuthorDate: Thu, 25 Mar 2021 17:04:34 -07:00
Committer: Borislav Petkov <[email protected]>
CommitterDate: Fri, 26 Mar 2021 11:32:55 +01:00

x86/boot: Add $(CLANG_FLAGS) to compressed KBUILD_CFLAGS

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 <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Acked-by: Ard Biesheuvel <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
---
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 e0bc398..6e5522a 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