darwin: expand cross-builds to also support x86 and testing
v2 cover darwin: expand cross-builds to also support x86 and testing
Hello,
This series expands the recently introduced Darwin hypervisor build support to also allow cross-building an x86 hypervisor, that's done in patches 1 to 3. Patches 4 and 5 introduce some Cirrus-CI testing to do cross-builds from macOS, plus it also introduces some basic smoke testing of the x86 builds using the XTF selftest, just like it's currently done for the FreeBSD builds.
A result of the updated Cirrus-CI pipeline can be seen at:
https://cirrus-ci.com/build/6723050642604032
Thanks, Roger.
Roger Pau Monne (5):
xen/x86: always consider '/' as a division in assembly xen/tools: remove usages of stat -c in check-endbr.sh xen/tools: fix grep reporting 'illegal byte sequence' in
check-endbr.sh
cirrus-ci: add x86 and arm64 macOS hypervisor builds
cirrus-ci: add x86 XTF self-tests for macOS build
.cirrus.yml | 51 ++++++++++++++++++++++++++++++++++------ xen/arch/x86/arch.mk | 5 ++++ xen/tools/check-endbr.sh | 18 +++++++------- 3 files changed, 58 insertions(+), 16 deletions(-)
Signature · 1 line
2.51.0
PATCH v2 1/5 xen/x86: always consider '/' as a division in assembly
On x86 GNU assembler will consider '/' as the start of comment marker for some ELF targets. This is incorrect with Xen's usage, which does use '/' in assembly files as a mathematical operator.
The behavior of the assembler can be altered by passing the --divide option; unconditionally pass this option when available to force the expected behavior.
---
Changes since v1:
- Move option add to x86 specific makefile.
--- xen/arch/x86/arch.mk | 5 +++++ 1 file changed, 5 insertions(+)
xen/arch/x86/arch.mk +5 -0
@@ -123,3 +123,8 @@ endif # Set up the assembler include path properly for older toolchains. CFLAGS += -Wa,-I$(objtree)/include -Wa,-I$(srctree)/include + +# The GNU assembler will interpret '/' as a comment start marker instead of a +# divide for some ELF targets. Pass --divide when when available to signal '/' +# is always used as an operator in assembly. +$(call cc-option-add,CFLAGS,CC,-Wa$$(comma)--divide)
Signature · 1 line
2.51.0
Re: [PATCH v2 1/5] xen/x86: always consider '/' as a division in assembly
Quoted 10 lines · Roger Pau Monne
On x86 GNU assembler will consider '/' as the start of comment marker for some ELF targets. This is incorrect with Xen's usage, which does use '/' in assembly files as a mathematical operator.
The behavior of the assembler can be altered by passing the --divide option; unconditionally pass this option when available to force the expected behavior.
Reported-by Jan Beulich <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>
PATCH v2 2/5 xen/tools: remove usages of `stat -c` in check-endbr.sh
In reply to Roger Pau MonneThe -c option to stat is not POSIX compatible, and hence prevents the check-endbr.sh script from running reliably.
The first instance of stat -c can be removed by fetching the section size from the output of objdump itself, which the script already parses to get the VMA values.
The other two instances can be replaced by counting the lines in the respective files. Those files contain list of addresses, so the size in bytes is not strictly needed, we can count the number of lines instead.
---
Changes since v1:
- Use $(()) to convert from hex to decimal.
--- xen/tools/check-endbr.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
xen/tools/check-endbr.sh +6 -7
@@ -92,14 +92,13 @@ ${OBJDUMP} -j .text $1 -d -w | grep ' endbr64 *$' | cut -f 1 -d ':' > $VALID & # check nevertheless. # eval $(${OBJDUMP} -j .text $1 -h | - $AWK '$2 == ".text" {printf "vma_hi=%s\nvma_lo=%s\n", substr($4, 1, 9), substr($4, 10, 16)}') + $AWK '$2 == ".text" {printf "bin_sz=%s\nvma_hi=%s\nvma_lo=%s\n", "0x" $3, substr($4, 1, 9), substr($4, 10, 16)}') -${OBJCOPY} -j .text $1 -O binary $TEXT_BIN - -bin_sz=$(stat -c '%s' $TEXT_BIN) -[ "$bin_sz" -ge $(((1 << 28) - $vma_lo)) ] && +[ "$(($bin_sz))" -ge $(((1 << 28) - $vma_lo)) ] && { echo "$MSG_PFX Error: .text offsets must not exceed 256M" >&2; exit 1; } +${OBJCOPY} -j .text $1 -O binary $TEXT_BIN + # instruction: hex: oct: # endbr64 f3 0f 1e fa 363 017 036 372 # endbr32 f3 0f 1e fb 363 017 036 373
@@ -116,8 +115,8 @@ fi | $AWK -F':' '{printf "%s%07x\n", "'$vma_hi'", int('$((0x$vma_lo))') + $1}' > wait # Sanity check $VALID and $ALL, in case the string parsing bitrots -val_sz=$(stat -c '%s' $VALID) -all_sz=$(stat -c '%s' $ALL) +val_sz=$(wc -l < $VALID) +all_sz=$(wc -l < $ALL) [ "$val_sz" -eq 0 ] && { echo "$MSG_PFX Error: Empty valid-addrs" >&2; exit 1; } [ "$all_sz" -eq 0 ] && { echo "$MSG_PFX Error: Empty all-addrs" >&2; exit 1; } [ "$all_sz" -lt "$val_sz" ] && { echo "$MSG_PFX Error: More valid-addrs than all-addrs" >&2; exit 1; }
Signature · 1 line
2.51.0
Re: [PATCH v2 2/5] xen/tools: remove usages of `stat -c` in check-endbr.sh
Quoted 7 lines · Roger Pau Monne
The
-coption to stat is not POSIX compatible, and hence prevents thecheck-endbr.shscript from running reliably.The first instance of
stat -ccan be removed by fetching the section size from the output of objdump itself, which the script already parses to get the VMA values.
Quoted 7 lines
The other two instances can be replaced by counting the lines in the respective files. Those files contain list of addresses, so the size in bytes is not strictly needed, we can count the number of lines instead.
Suggested-by Bertrand Marquis <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>Acked-by Bertrand Marquis <[email protected]>
PATCH v2 3/5 xen/tools: fix grep reporting 'illegal byte sequence' in check-endbr.sh
In reply to Roger Pau MonneOn macOS the default encoding is UTF-8. The binary encoding used by the grep matching pattern is not valid when processed as UTF-8. Switch the local to C just for the grep invocation to use the binary match pattern correctly.
--- xen/tools/check-endbr.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
xen/tools/check-endbr.sh +3 -2
@@ -107,8 +107,9 @@ if $perl_re then LC_ALL=C grep -aobP '\xf3\x0f\x1e(\xfa|\xfb)|\x66\x0f\x1f\x01' $TEXT_BIN else - grep -aob -e "$(printf '\363\17\36\372')" -e "$(printf '\363\17\36\373')" \ - -e "$(printf '\146\17\37\1')" $TEXT_BIN + LC_ALL=C grep -aob -e "$(printf '\363\17\36\372')" \ + -e "$(printf '\363\17\36\373')" \ + -e "$(printf '\146\17\37\1')" $TEXT_BIN fi | $AWK -F':' '{printf "%s%07x\n", "'$vma_hi'", int('$((0x$vma_lo))') + $1}' > $ALL # Wait for $VALID to become complete
Signature · 1 line
2.51.0
PATCH v2 4/5 cirrus-ci: add x86 and arm64 macOS hypervisor builds
In reply to Roger Pau MonneIntroduce two new build that run on macOS Cirrus-CI instances. Those build the hypervisor using the elf cross-toolchain from Homebrew for both x86 and arm64.
---
I haven't added any randconfig jobs, we can consider adding those later on if the builds are stable.
--- .cirrus.yml | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-)
.cirrus.yml +37 -1
@@ -1,3 +1,5 @@ +## FreeBSD Build Jobs + # https://cirrus-ci.org/guide/tips-and-tricks/#sharing-configuration-between-tasks freebsd_versions: &FREEBSD_VERSIONS env:
@@ -122,7 +124,41 @@ task: path: xtf/tests/selftest/test-*-selftest type: application/octet-stream -# Test jobs +## macOS Build Jobs + +task: + name: 'macOS: hypervisor build' + + env: + matrix: + ARCH: x86_64 + ARCH: aarch64 + + alias: macos-$ARCH + macos_instance: + image: ghcr.io/cirruslabs/macos-runner:sonoma + + environment: + CIRRUS_CLONE_DEPTH: 1 + CIRRUS_LOG_TIMESTAMP: true + + install_script: + - brew install $ARCH-elf-gcc $ARCH-elf-binutils + + build_script: + - make -j`sysctl -n hw.ncpu` + XEN_TARGET_ARCH=`echo $ARCH | sed -e s/aarch64/arm64/` + CROSS_COMPILE=$ARCH-elf- HOSTCC=clang -C xen + + xen_artifacts: + path: xen/xen + type: application/octet-stream + + debug_artifacts: + path: xen/xen-syms + type: application/octet-stream + +## Test Jobs task: name: 'FreeBSD: XTF selftest'
Signature · 1 line
2.51.0
PATCH v2 5/5 cirrus-ci: add x86 XTF self-tests for macOS build
In reply to Roger Pau MonneLike we do for the FreeBSD builds, introduce some basic smoke testing of the built binary using the XTF selftest image.
Note this is only done for the x86 build, there's no ARM support in XTF yet.
--- .cirrus.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
.cirrus.yml +7 -6
@@ -161,18 +161,19 @@ task: ## Test Jobs task: - name: 'FreeBSD: XTF selftest' + name: 'XTF selftest' << : *FREEBSD_ENV_PRODUCTION env: matrix: - FREEBSD_BUILD: $FREEBSD_LEGACY - FREEBSD_BUILD: $FREEBSD_PRODUCTION - FREEBSD_BUILD: $FREEBSD_CURRENT + BUILD: freebsd_full_$FREEBSD_LEGACY + BUILD: freebsd_full_$FREEBSD_PRODUCTION + BUILD: freebsd_full_$FREEBSD_CURRENT + BUILD: macos-x86_64 depends_on: - - freebsd_full_$FREEBSD_BUILD + - $BUILD - xtf install_script: pkg install -y qemu-nox11 expect
@@ -187,7 +188,7 @@ task: fetch_script: - fetch https://api.cirrus-ci.com/v1/artifact/build/$CIRRUS_BUILD_ID/xtf/xtf.zip - - fetch https://api.cirrus-ci.com/v1/artifact/build/$CIRRUS_BUILD_ID/freebsd_full_$FREEBSD_BUILD/xen.zip + - fetch https://api.cirrus-ci.com/v1/artifact/build/$CIRRUS_BUILD_ID/$BUILD/xen.zip - unzip xtf.zip - unzip xen.zip
Signature · 1 line
2.51.0
Quoted 15 lines · Roger Pau Monne
Hello,
This series expands the recently introduced Darwin hypervisor build support to also allow cross-building an x86 hypervisor, that's done in patches 1 to 3. Patches 4 and 5 introduce some Cirrus-CI testing to do cross-builds from macOS, plus it also introduces some basic smoke testing of the x86 builds using the XTF selftest, just like it's currently done for the FreeBSD builds.
A result of the updated Cirrus-CI pipeline can be seen at:
https://cirrus-ci.com/build/6723050642604032
Thanks, Roger.
Quoted 7 lines
Roger Pau Monne (5):
xen/x86: always consider '/' as a division in assembly xen/tools: remove usages ofstat -cincheck-endbr.shxen/tools: fix grep reporting 'illegal byte sequence' in
check-endbr.sh
cirrus-ci: add x86 and arm64 macOS hypervisor builds
cirrus-ci: add x86 XTF self-tests for macOS build
The CI tests passing makes this a fairly obvious one to take.
But, some further observations from
https://cirrus-ci.com/task/4903778798796800
[10:09:34.952] INIT_O arch/x86/acpi/boot.init.o
[10:09:34.971] LD arch/x86/acpi/built_in.o
[10:09:34.975] x86_64-elf-ld: warning: arch/x86/acpi/boot.init.o: missing .note.GNU-stack section implies executable stack [10:09:34.975] x86_64-elf-ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
...
[10:09:35.720] LD arch/x86/boot/built_in.o [10:09:35.724] CC common/hypfs.o
[10:09:35.727] x86_64-elf-ld: warning: arch/x86/boot/reloc-trampoline.o: missing .note.GNU-stack section implies executable stack [10:09:35.727] x86_64-elf-ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
...
[10:09:40.836] LD arch/x86/hvm/svm/built_in.o
[10:09:40.840] x86_64-elf-ld: warning: arch/x86/hvm/svm/vmcb.o: missing .note.GNU-stack section implies executable stack [10:09:40.840] x86_64-elf-ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
and various other examples too. The warning comes when linking built_in.o's, and while I could believe there's something weird about *.init.o and/or reloc-trampoline.o, the complaint about vmcb.o is weird because that's just a plain C file.
The other impacted (non built_in.o) objects look to be:
arch/x86/hvm/vmx/vvmx.oarch/x86/pv/dom0_build.init.oarch/x86/x86_64/cpufreq.ocommon/unzstd.init.o
and it's not obvious what these have in common to be the (only) objects lacking .note.GNU-stack.
Also, during the final link steps for xen.efi, we twice get:
[10:09:57.995] Warning: relocation to r/o section .text:00000048 [10:09:57.995] Warning: relocation to r/o section .text:00000090
which smells like the multiboot header.
~Andrew
Quoted 6 lines · Andrew Cooper
Also, during the final link steps for xen.efi, we twice get:
[10:09:57.995] Warning: relocation to r/o section .text:00000048 [10:09:57.995] Warning: relocation to r/o section .text:00000090
which smells like the multiboot header.
It is. These diagnostics are seen only when older ld is in use, but the issue exists in all cases. It should really already be on someone's todo list wrt fully secure boot conformant xen.efi, as we did discuss this in the past.
Jan
Quoted 10 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
Also, during the final link steps for xen.efi, we twice get:
[10:09:57.995] Warning: relocation to r/o section .text:00000048 [10:09:57.995] Warning: relocation to r/o section .text:00000090
which smells like the multiboot header.
It is. These diagnostics are seen only when older ld is in use, but the issue exists in all cases.
Oh, it took me a while to figure that out. Newer ld generates the relocations itself, and hence we no longer use mkreloc that would print those warnings. However ld generated relocations will still be against read-execute section, and hence as you say the issue also exists there.
However the ld version on Darwin is:
GNU ld (GNU Binutils) 2.45.1
So the issue is not with the version of ld using in the Darwin build being too old, but rather the checking done in efi-nr-fixups not working well with BSD grep. It needs to be adjusted to use -E, otherwise [[:blank:]] is not recognized. I will send a patch.
Quoted 3 lines
It should really already be on someone's todo
list wrt fully secure boot conformant xen.efi, as we did discuss this in the past.
I did start on it:
https://lore.kernel.org/xen-devel/[email protected]/
However at the time I did this, the XenServer Secure Boot implementation was doing something that would have been incompatible with this work, and hence I set it on the side. Later on, the XenServer implementation changed and picked up most of this work internally. I however never got back to this work, neither the people that internally worked on Secure Boot send an updated version of the patches.
I will see whether I can make some progress on this.
Thanks, Roger.