linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH 0/3] Support cross compiling with clang
@ 2024-09-03 16:30 Andrew Jones
  2024-09-03 16:30 ` [kvm-unit-tests PATCH 1/3] riscv: Drop mstrict-align Andrew Jones
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Andrew Jones @ 2024-09-03 16:30 UTC (permalink / raw)
  To: kvm, kvm-riscv, kvmarm, linuxppc-dev, linux-s390
  Cc: pbonzini, thuth, lvivier, frankja, imbrenda, nrb, atishp,
	cade.richard, jamestiotio

Modify configure to allow --cc=clang and a cross-prefix to be specified
together (as well as --cflags). This allows compiling with clang, but
using cross binutils for everything else, including the linker. So far
tested on riscv 32- and 64-bit and aarch64 (with some hacks to the code
to get it to compile - which is why there's no gitlab-ci patch for aarch64
in this series). I suspect it should work for other architectures too.

Andrew Jones (3):
  riscv: Drop mstrict-align
  configure: Support cross compiling with clang
  riscv: gitlab-ci: Add clang build tests

 .gitlab-ci.yml | 28 ++++++++++++++++++++++++++++
 configure      | 11 ++++++++---
 riscv/Makefile |  2 +-
 3 files changed, 37 insertions(+), 4 deletions(-)

-- 
2.46.0



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [kvm-unit-tests PATCH 1/3] riscv: Drop mstrict-align
  2024-09-03 16:30 [kvm-unit-tests PATCH 0/3] Support cross compiling with clang Andrew Jones
@ 2024-09-03 16:30 ` Andrew Jones
  2024-09-04  6:12   ` Thomas Huth
  2024-09-03 16:30 ` [kvm-unit-tests PATCH 2/3] configure: Support cross compiling with clang Andrew Jones
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Andrew Jones @ 2024-09-03 16:30 UTC (permalink / raw)
  To: kvm, kvm-riscv, kvmarm, linuxppc-dev, linux-s390
  Cc: pbonzini, thuth, lvivier, frankja, imbrenda, nrb, atishp,
	cade.richard, jamestiotio

The spec says unaligned accesses are supported, so this isn't required
and clang doesn't support it. A platform might have slow unaligned
accesses, but kvm-unit-tests isn't about speed anyway.

Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
---
 riscv/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/riscv/Makefile b/riscv/Makefile
index 179a373dbacf..2ee7c5bb5ad8 100644
--- a/riscv/Makefile
+++ b/riscv/Makefile
@@ -76,7 +76,7 @@ LDFLAGS += -melf32lriscv
 endif
 CFLAGS += -DCONFIG_RELOC
 CFLAGS += -mcmodel=medany
-CFLAGS += -mstrict-align
+#CFLAGS += -mstrict-align
 CFLAGS += -std=gnu99
 CFLAGS += -ffreestanding
 CFLAGS += -O2
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [kvm-unit-tests PATCH 2/3] configure: Support cross compiling with clang
  2024-09-03 16:30 [kvm-unit-tests PATCH 0/3] Support cross compiling with clang Andrew Jones
  2024-09-03 16:30 ` [kvm-unit-tests PATCH 1/3] riscv: Drop mstrict-align Andrew Jones
@ 2024-09-03 16:30 ` Andrew Jones
  2024-09-04  6:10   ` Thomas Huth
  2024-09-03 16:30 ` [kvm-unit-tests PATCH 3/3] riscv: gitlab-ci: Add clang build tests Andrew Jones
  2024-09-04 10:31 ` [kvm-unit-tests PATCH 0/3] Support cross compiling with clang Andrew Jones
  3 siblings, 1 reply; 8+ messages in thread
From: Andrew Jones @ 2024-09-03 16:30 UTC (permalink / raw)
  To: kvm, kvm-riscv, kvmarm, linuxppc-dev, linux-s390
  Cc: pbonzini, thuth, lvivier, frankja, imbrenda, nrb, atishp,
	cade.richard, jamestiotio

When a user specifies the compiler with --cc assume it's already
fully named, even if the user also specifies a cross-prefix. This
allows clang to be selected for the compiler, which doesn't use
prefixes, but also still provide a cross prefix for binutils. If
a user needs a prefix on the compiler that they specify with --cc,
then they'll just have to specify it with the prefix prepended.

Also ensure user provided cflags are used when testing the compiler,
since the flags may drastically change behavior, such as the --target
flag for clang.

With these changes it's possible to cross compile for riscv with
clang after configuring with

 ./configure --arch=riscv64 --cc=clang --cflags='--target=riscv64' \
             --cross-prefix=riscv64-linux-gnu-

Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
---
 configure | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 27ae9cc89657..337af07374df 100755
--- a/configure
+++ b/configure
@@ -130,6 +130,7 @@ while [[ "$1" = -* ]]; do
 	    ;;
 	--cc)
 	    cc="$arg"
+	    cc_selected=yes
 	    ;;
 	--cflags)
 	    cflags="$arg"
@@ -200,6 +201,10 @@ while [[ "$1" = -* ]]; do
     esac
 done
 
+if [ -z "$cc_selected" ] && [ "$cross_prefix" ]; then
+    cc="$cross_prefix$cc"
+fi
+
 if [ -z "$efi" ] || [ "$efi" = "n" ]; then
     [ "$efi_direct" = "y" ] && efi_direct=
 fi
@@ -370,7 +375,7 @@ fi
 cat << EOF > lib-test.c
 __UINT32_TYPE__
 EOF
-u32_long=$("$cross_prefix$cc" -E lib-test.c | grep -v '^#' | grep -q long && echo yes)
+u32_long=$("$cc" $cflags -E lib-test.c | grep -v '^#' | grep -q long && echo yes)
 rm -f lib-test.c
 
 # check if slash can be used for division
@@ -379,7 +384,7 @@ if [ "$arch" = "i386" ] || [ "$arch" = "x86_64" ]; then
 foo:
     movl (8 / 2), %eax
 EOF
-  wa_divide=$("$cross_prefix$cc" -c lib-test.S >/dev/null 2>&1 || echo yes)
+  wa_divide=$("$cc" $cflags -c lib-test.S >/dev/null 2>&1 || echo yes)
   rm -f lib-test.{o,S}
 fi
 
@@ -442,7 +447,7 @@ ARCH=$arch
 ARCH_NAME=$arch_name
 ARCH_LIBDIR=$arch_libdir
 PROCESSOR=$processor
-CC=$cross_prefix$cc
+CC=$cc
 CFLAGS=$cflags
 LD=$cross_prefix$ld
 OBJCOPY=$cross_prefix$objcopy
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [kvm-unit-tests PATCH 3/3] riscv: gitlab-ci: Add clang build tests
  2024-09-03 16:30 [kvm-unit-tests PATCH 0/3] Support cross compiling with clang Andrew Jones
  2024-09-03 16:30 ` [kvm-unit-tests PATCH 1/3] riscv: Drop mstrict-align Andrew Jones
  2024-09-03 16:30 ` [kvm-unit-tests PATCH 2/3] configure: Support cross compiling with clang Andrew Jones
@ 2024-09-03 16:30 ` Andrew Jones
  2024-09-04  6:12   ` Thomas Huth
  2024-09-04 10:31 ` [kvm-unit-tests PATCH 0/3] Support cross compiling with clang Andrew Jones
  3 siblings, 1 reply; 8+ messages in thread
From: Andrew Jones @ 2024-09-03 16:30 UTC (permalink / raw)
  To: kvm, kvm-riscv, kvmarm, linuxppc-dev, linux-s390
  Cc: pbonzini, thuth, lvivier, frankja, imbrenda, nrb, atishp,
	cade.richard, jamestiotio

Test building 32 and 64-bit with clang. Throw a test of in- and out-
of-tree building in too by swapping which is done to which (32-bit
vs. 64-bit) with respect to the gcc build tests.

Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
---
 .gitlab-ci.yml | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 67a9a15733f1..033ed65aec26 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -176,6 +176,34 @@ build-riscv64-efi:
       | tee results.txt
  - grep -q PASS results.txt && ! grep -q FAIL results.txt
 
+build-riscv64-clang:
+ extends: .outoftree_template
+ script:
+ - dnf install -y qemu-system-riscv gcc-riscv64-linux-gnu clang
+ - mkdir build
+ - cd build
+ - ../configure --arch=riscv64 --cc=clang --cflags='--target=riscv64' --cross-prefix=riscv64-linux-gnu-
+ - make -j2
+ - printf "FOO=foo\nBAR=bar\nBAZ=baz\nMVENDORID=0\nMARCHID=0\nMIMPID=0\n" >test-env
+ - ACCEL=tcg KVM_UNIT_TESTS_ENV=test-env ./run_tests.sh
+      selftest
+      sbi
+      | tee results.txt
+ - grep -q PASS results.txt && ! grep -q FAIL results.txt
+
+build-riscv32-clang:
+ extends: .intree_template
+ script:
+ - dnf install -y qemu-system-riscv gcc-riscv64-linux-gnu clang
+ - ./configure --arch=riscv32 --cc=clang --cflags='--target=riscv32' --cross-prefix=riscv64-linux-gnu-
+ - make -j2
+ - printf "FOO=foo\nBAR=bar\nBAZ=baz\nMVENDORID=0\nMARCHID=0\nMIMPID=0\n" >test-env
+ - ACCEL=tcg KVM_UNIT_TESTS_ENV=test-env ./run_tests.sh
+      selftest
+      sbi
+      | tee results.txt
+ - grep -q PASS results.txt && ! grep -q FAIL results.txt
+
 build-s390x:
  extends: .outoftree_template
  script:
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [kvm-unit-tests PATCH 2/3] configure: Support cross compiling with clang
  2024-09-03 16:30 ` [kvm-unit-tests PATCH 2/3] configure: Support cross compiling with clang Andrew Jones
@ 2024-09-04  6:10   ` Thomas Huth
  0 siblings, 0 replies; 8+ messages in thread
From: Thomas Huth @ 2024-09-04  6:10 UTC (permalink / raw)
  To: Andrew Jones, kvm, kvm-riscv, kvmarm, linuxppc-dev, linux-s390
  Cc: pbonzini, lvivier, frankja, imbrenda, nrb, atishp, cade.richard,
	jamestiotio

On 03/09/2024 18.30, Andrew Jones wrote:
> When a user specifies the compiler with --cc assume it's already
> fully named, even if the user also specifies a cross-prefix. This
> allows clang to be selected for the compiler, which doesn't use
> prefixes, but also still provide a cross prefix for binutils. If
> a user needs a prefix on the compiler that they specify with --cc,
> then they'll just have to specify it with the prefix prepended.
> 
> Also ensure user provided cflags are used when testing the compiler,
> since the flags may drastically change behavior, such as the --target
> flag for clang.
> 
> With these changes it's possible to cross compile for riscv with
> clang after configuring with
> 
>   ./configure --arch=riscv64 --cc=clang --cflags='--target=riscv64' \
>               --cross-prefix=riscv64-linux-gnu-
> 
> Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
> ---
>   configure | 11 ++++++++---
>   1 file changed, 8 insertions(+), 3 deletions(-)

Reviewed-by: Thomas Huth <thuth@redhat.com>



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [kvm-unit-tests PATCH 3/3] riscv: gitlab-ci: Add clang build tests
  2024-09-03 16:30 ` [kvm-unit-tests PATCH 3/3] riscv: gitlab-ci: Add clang build tests Andrew Jones
@ 2024-09-04  6:12   ` Thomas Huth
  0 siblings, 0 replies; 8+ messages in thread
From: Thomas Huth @ 2024-09-04  6:12 UTC (permalink / raw)
  To: Andrew Jones, kvm, kvm-riscv, kvmarm, linuxppc-dev, linux-s390
  Cc: pbonzini, lvivier, frankja, imbrenda, nrb, atishp, cade.richard,
	jamestiotio

On 03/09/2024 18.30, Andrew Jones wrote:
> Test building 32 and 64-bit with clang. Throw a test of in- and out-
> of-tree building in too by swapping which is done to which (32-bit
> vs. 64-bit) with respect to the gcc build tests.
> 
> Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
> ---
>   .gitlab-ci.yml | 28 ++++++++++++++++++++++++++++
>   1 file changed, 28 insertions(+)

Acked-by: Thomas Huth <thuth@redhat.com>



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [kvm-unit-tests PATCH 1/3] riscv: Drop mstrict-align
  2024-09-03 16:30 ` [kvm-unit-tests PATCH 1/3] riscv: Drop mstrict-align Andrew Jones
@ 2024-09-04  6:12   ` Thomas Huth
  0 siblings, 0 replies; 8+ messages in thread
From: Thomas Huth @ 2024-09-04  6:12 UTC (permalink / raw)
  To: Andrew Jones, kvm, kvm-riscv, kvmarm, linuxppc-dev, linux-s390
  Cc: pbonzini, lvivier, frankja, imbrenda, nrb, atishp, cade.richard,
	jamestiotio

On 03/09/2024 18.30, Andrew Jones wrote:
> The spec says unaligned accesses are supported, so this isn't required
> and clang doesn't support it. A platform might have slow unaligned
> accesses, but kvm-unit-tests isn't about speed anyway.
> 
> Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
> ---
>   riscv/Makefile | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/riscv/Makefile b/riscv/Makefile
> index 179a373dbacf..2ee7c5bb5ad8 100644
> --- a/riscv/Makefile
> +++ b/riscv/Makefile
> @@ -76,7 +76,7 @@ LDFLAGS += -melf32lriscv
>   endif
>   CFLAGS += -DCONFIG_RELOC
>   CFLAGS += -mcmodel=medany
> -CFLAGS += -mstrict-align
> +#CFLAGS += -mstrict-align
>   CFLAGS += -std=gnu99
>   CFLAGS += -ffreestanding
>   CFLAGS += -O2

Reviewed-by: Thomas Huth <thuth@redhat.com>



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [kvm-unit-tests PATCH 0/3] Support cross compiling with clang
  2024-09-03 16:30 [kvm-unit-tests PATCH 0/3] Support cross compiling with clang Andrew Jones
                   ` (2 preceding siblings ...)
  2024-09-03 16:30 ` [kvm-unit-tests PATCH 3/3] riscv: gitlab-ci: Add clang build tests Andrew Jones
@ 2024-09-04 10:31 ` Andrew Jones
  3 siblings, 0 replies; 8+ messages in thread
From: Andrew Jones @ 2024-09-04 10:31 UTC (permalink / raw)
  To: kvm, kvm-riscv, kvmarm, linuxppc-dev, linux-s390
  Cc: pbonzini, thuth, lvivier, frankja, imbrenda, nrb, atishp,
	cade.richard, jamestiotio

On Tue, Sep 03, 2024 at 06:30:47PM GMT, Andrew Jones wrote:
> Modify configure to allow --cc=clang and a cross-prefix to be specified
> together (as well as --cflags). This allows compiling with clang, but
> using cross binutils for everything else, including the linker. So far
> tested on riscv 32- and 64-bit and aarch64 (with some hacks to the code
> to get it to compile - which is why there's no gitlab-ci patch for aarch64
> in this series). I suspect it should work for other architectures too.
> 
> Andrew Jones (3):
>   riscv: Drop mstrict-align
>   configure: Support cross compiling with clang
>   riscv: gitlab-ci: Add clang build tests
> 
>  .gitlab-ci.yml | 28 ++++++++++++++++++++++++++++
>  configure      | 11 ++++++++---
>  riscv/Makefile |  2 +-
>  3 files changed, 37 insertions(+), 4 deletions(-)
> 
> -- 
> 2.46.0

When compiling with clang and --config-efi I hit

lib/efi.c:342:29: error: field 'vendor' with variable sized type 'struct efi_vendor_dev_path' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]
  342 |         struct efi_vendor_dev_path      vendor;
      |                                         ^
1 error generated.

Our efi code is exactly the same as the Linux code, but Linux avoids that
warning with -Wno-gnu. We could also add that to EFI_CFLAGS, but I think
I'll just add -Wno-gnu-variable-sized-type-not-at-end since I like seeing
these things as they come.

I'll send a v2 with a Makefile patch added.

Thanks,
drew


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-09-04 10:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-03 16:30 [kvm-unit-tests PATCH 0/3] Support cross compiling with clang Andrew Jones
2024-09-03 16:30 ` [kvm-unit-tests PATCH 1/3] riscv: Drop mstrict-align Andrew Jones
2024-09-04  6:12   ` Thomas Huth
2024-09-03 16:30 ` [kvm-unit-tests PATCH 2/3] configure: Support cross compiling with clang Andrew Jones
2024-09-04  6:10   ` Thomas Huth
2024-09-03 16:30 ` [kvm-unit-tests PATCH 3/3] riscv: gitlab-ci: Add clang build tests Andrew Jones
2024-09-04  6:12   ` Thomas Huth
2024-09-04 10:31 ` [kvm-unit-tests PATCH 0/3] Support cross compiling with clang Andrew Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).