* [kvm-unit-tests PATCH v3 0/5] Support cross compiling with clang
@ 2024-09-11 9:14 Andrew Jones
2024-09-11 9:14 ` [kvm-unit-tests PATCH v3 1/5] riscv: Drop mstrict-align Andrew Jones
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Andrew Jones @ 2024-09-11 9:14 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.
v3:
- Add README patch for cross-compiling, clang, and cross-clang [Nick]
- Add comment to the commenting-out of mstrict-align [Nick]
- Add the reason to ignore warnings vs. fix code to commit message of
patch2
- Picked up Nick's tags
v2:
- fix building with clang and --config-efi by suppressing a warning
- added riscv clang efi build to CI
- picked up Thomas's tags
Andrew Jones (5):
riscv: Drop mstrict-align
Makefile: Prepare for clang EFI builds
configure: Support cross compiling with clang
riscv: gitlab-ci: Add clang build tests
README: Add cross and clang recipes
.gitlab-ci.yml | 43 +++++++++++++++++++++++++++++++++++++++++++
Makefile | 2 ++
README.md | 22 ++++++++++++++++++++++
configure | 11 ++++++++---
riscv/Makefile | 4 +++-
5 files changed, 78 insertions(+), 4 deletions(-)
--
2.46.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [kvm-unit-tests PATCH v3 1/5] riscv: Drop mstrict-align
2024-09-11 9:14 [kvm-unit-tests PATCH v3 0/5] Support cross compiling with clang Andrew Jones
@ 2024-09-11 9:14 ` Andrew Jones
2024-09-11 9:14 ` [kvm-unit-tests PATCH v3 2/5] Makefile: Prepare for clang EFI builds Andrew Jones
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Andrew Jones @ 2024-09-11 9:14 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.
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
---
riscv/Makefile | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/riscv/Makefile b/riscv/Makefile
index 179a373dbacf..22fd273acac3 100644
--- a/riscv/Makefile
+++ b/riscv/Makefile
@@ -76,7 +76,9 @@ LDFLAGS += -melf32lriscv
endif
CFLAGS += -DCONFIG_RELOC
CFLAGS += -mcmodel=medany
-CFLAGS += -mstrict-align
+# Unaligned accesses are allowed, but may be emulated by M-mode.
+# Enable -mstrict-align if that's troublesome (only supported by gcc).
+#CFLAGS += -mstrict-align
CFLAGS += -std=gnu99
CFLAGS += -ffreestanding
CFLAGS += -O2
--
2.46.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [kvm-unit-tests PATCH v3 2/5] Makefile: Prepare for clang EFI builds
2024-09-11 9:14 [kvm-unit-tests PATCH v3 0/5] Support cross compiling with clang Andrew Jones
2024-09-11 9:14 ` [kvm-unit-tests PATCH v3 1/5] riscv: Drop mstrict-align Andrew Jones
@ 2024-09-11 9:14 ` Andrew Jones
2024-09-11 9:14 ` [kvm-unit-tests PATCH v3 3/5] configure: Support cross compiling with clang Andrew Jones
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Andrew Jones @ 2024-09-11 9:14 UTC (permalink / raw)
To: kvm, kvm-riscv, kvmarm, linuxppc-dev, linux-s390
Cc: pbonzini, thuth, lvivier, frankja, imbrenda, nrb, atishp,
cade.richard, jamestiotio, Nicholas Piggin
clang complains about GNU extensions such as variable sized types not
being at the end of structs unless -Wno-gnu is used. We may
eventually want -Wno-gnu, but for now let's just handle the warnings
as they come. Add -Wno-gnu-variable-sized-type-not-at-end to avoid
the warning issued for the initrd_dev_path struct. (Eliminating the
warning is preferred to reworking the struct, because the
implementation is imported verbatim from Linux.)
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
---
Makefile | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Makefile b/Makefile
index 3d51cb726120..7471f7285b78 100644
--- a/Makefile
+++ b/Makefile
@@ -50,6 +50,8 @@ EFI_CFLAGS += -fshort-wchar
# EFI applications use PIC as they are loaded to dynamic addresses, not a fixed
# starting address
EFI_CFLAGS += -fPIC
+# Avoid error with the initrd_dev_path struct
+EFI_CFLAGS += -Wno-gnu-variable-sized-type-not-at-end
# Create shared library
EFI_LDFLAGS := -Bsymbolic -shared -nostdlib
endif
--
2.46.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [kvm-unit-tests PATCH v3 3/5] configure: Support cross compiling with clang
2024-09-11 9:14 [kvm-unit-tests PATCH v3 0/5] Support cross compiling with clang Andrew Jones
2024-09-11 9:14 ` [kvm-unit-tests PATCH v3 1/5] riscv: Drop mstrict-align Andrew Jones
2024-09-11 9:14 ` [kvm-unit-tests PATCH v3 2/5] Makefile: Prepare for clang EFI builds Andrew Jones
@ 2024-09-11 9:14 ` Andrew Jones
2024-09-11 9:14 ` [kvm-unit-tests PATCH v3 4/5] riscv: gitlab-ci: Add clang build tests Andrew Jones
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Andrew Jones @ 2024-09-11 9:14 UTC (permalink / raw)
To: kvm, kvm-riscv, kvmarm, linuxppc-dev, linux-s390
Cc: pbonzini, thuth, lvivier, frankja, imbrenda, nrb, atishp,
cade.richard, jamestiotio, Nicholas Piggin
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-
Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
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] 7+ messages in thread
* [kvm-unit-tests PATCH v3 4/5] riscv: gitlab-ci: Add clang build tests
2024-09-11 9:14 [kvm-unit-tests PATCH v3 0/5] Support cross compiling with clang Andrew Jones
` (2 preceding siblings ...)
2024-09-11 9:14 ` [kvm-unit-tests PATCH v3 3/5] configure: Support cross compiling with clang Andrew Jones
@ 2024-09-11 9:14 ` Andrew Jones
2024-09-11 9:14 ` [kvm-unit-tests PATCH v3 5/5] README: Add cross and clang recipes Andrew Jones
2024-10-24 8:38 ` [kvm-unit-tests PATCH v3 0/5] Support cross compiling with clang Andrew Jones
5 siblings, 0 replies; 7+ messages in thread
From: Andrew Jones @ 2024-09-11 9:14 UTC (permalink / raw)
To: kvm, kvm-riscv, kvmarm, linuxppc-dev, linux-s390
Cc: pbonzini, thuth, lvivier, frankja, imbrenda, nrb, atishp,
cade.richard, jamestiotio, Nicholas Piggin
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.
Acked-by: Thomas Huth <thuth@redhat.com>
Acked-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
---
.gitlab-ci.yml | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 67a9a15733f1..b7ad99870e5a 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -176,6 +176,49 @@ build-riscv64-efi:
| 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-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-riscv64-clang-efi:
+ extends: .intree_template
+ script:
+ - dnf install -y edk2-riscv64 qemu-system-riscv gcc-riscv64-linux-gnu clang
+ - cp /usr/share/edk2/riscv/RISCV_VIRT_CODE.fd .
+ - truncate -s 32M RISCV_VIRT_CODE.fd
+ - ./configure --arch=riscv64 --cc=clang --cflags='--target=riscv64' --cross-prefix=riscv64-linux-gnu- --enable-efi
+ - 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] 7+ messages in thread
* [kvm-unit-tests PATCH v3 5/5] README: Add cross and clang recipes
2024-09-11 9:14 [kvm-unit-tests PATCH v3 0/5] Support cross compiling with clang Andrew Jones
` (3 preceding siblings ...)
2024-09-11 9:14 ` [kvm-unit-tests PATCH v3 4/5] riscv: gitlab-ci: Add clang build tests Andrew Jones
@ 2024-09-11 9:14 ` Andrew Jones
2024-10-24 8:38 ` [kvm-unit-tests PATCH v3 0/5] Support cross compiling with clang Andrew Jones
5 siblings, 0 replies; 7+ messages in thread
From: Andrew Jones @ 2024-09-11 9:14 UTC (permalink / raw)
To: kvm, kvm-riscv, kvmarm, linuxppc-dev, linux-s390
Cc: pbonzini, thuth, lvivier, frankja, imbrenda, nrb, atishp,
cade.richard, jamestiotio
Add configure command line examples for cross-compiling, for
compiling with clang, and for cross-compiling with clang.
Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
---
README.md | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/README.md b/README.md
index 2d6f7db5605c..be07dc28a094 100644
--- a/README.md
+++ b/README.md
@@ -17,6 +17,28 @@ in this directory. Test images are created in ./ARCH/\*.flat
NOTE: GCC cross-compiler is required for [build on macOS](README.macOS.md).
+## Cross-compiling
+
+A cross compiler may be configured by specifying a cross prefix. For example,
+for arm64
+
+ ./configure --arch=arm64 --cross-prefix=aarch64-linux-gnu-
+ make
+
+## clang
+
+clang may be used as an alternative to gcc.
+
+ ./configure --cc=clang
+ make
+
+clang may also be used with cross binutils when cross-compiling. For example,
+for riscv64
+
+ ./configure --arch=riscv64 --cc=clang --cflags='--target=riscv64' \
+ --cross-prefix=riscv64-linux-gnu-
+ make
+
## Standalone tests
The tests can be built as standalone. To create and use standalone tests do:
--
2.46.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [kvm-unit-tests PATCH v3 0/5] Support cross compiling with clang
2024-09-11 9:14 [kvm-unit-tests PATCH v3 0/5] Support cross compiling with clang Andrew Jones
` (4 preceding siblings ...)
2024-09-11 9:14 ` [kvm-unit-tests PATCH v3 5/5] README: Add cross and clang recipes Andrew Jones
@ 2024-10-24 8:38 ` Andrew Jones
5 siblings, 0 replies; 7+ messages in thread
From: Andrew Jones @ 2024-10-24 8:38 UTC (permalink / raw)
To: kvm, kvm-riscv, kvmarm, linuxppc-dev, linux-s390
Cc: pbonzini, thuth, lvivier, frankja, imbrenda, nrb, atishp,
cade.richard, jamestiotio
On Wed, Sep 11, 2024 at 11:14:07AM +0200, 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.
>
> v3:
> - Add README patch for cross-compiling, clang, and cross-clang [Nick]
> - Add comment to the commenting-out of mstrict-align [Nick]
> - Add the reason to ignore warnings vs. fix code to commit message of
> patch2
> - Picked up Nick's tags
> v2:
> - fix building with clang and --config-efi by suppressing a warning
> - added riscv clang efi build to CI
> - picked up Thomas's tags
>
> Andrew Jones (5):
> riscv: Drop mstrict-align
> Makefile: Prepare for clang EFI builds
> configure: Support cross compiling with clang
> riscv: gitlab-ci: Add clang build tests
> README: Add cross and clang recipes
>
> .gitlab-ci.yml | 43 +++++++++++++++++++++++++++++++++++++++++++
> Makefile | 2 ++
> README.md | 22 ++++++++++++++++++++++
> configure | 11 ++++++++---
> riscv/Makefile | 4 +++-
> 5 files changed, 78 insertions(+), 4 deletions(-)
>
> --
> 2.46.0
>
Merged
Thanks,
drew
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-10-24 8:49 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-11 9:14 [kvm-unit-tests PATCH v3 0/5] Support cross compiling with clang Andrew Jones
2024-09-11 9:14 ` [kvm-unit-tests PATCH v3 1/5] riscv: Drop mstrict-align Andrew Jones
2024-09-11 9:14 ` [kvm-unit-tests PATCH v3 2/5] Makefile: Prepare for clang EFI builds Andrew Jones
2024-09-11 9:14 ` [kvm-unit-tests PATCH v3 3/5] configure: Support cross compiling with clang Andrew Jones
2024-09-11 9:14 ` [kvm-unit-tests PATCH v3 4/5] riscv: gitlab-ci: Add clang build tests Andrew Jones
2024-09-11 9:14 ` [kvm-unit-tests PATCH v3 5/5] README: Add cross and clang recipes Andrew Jones
2024-10-24 8:38 ` [kvm-unit-tests PATCH v3 0/5] 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).