diff mbox series

[kvm-unit-tests,v2,01/10] x86: Makefile: Allow division on x86_64-elf binutils

Message ID 20200901085056.33391-2-r.bolshakov@yadro.com (mailing list archive)
State New, archived
Headers show
Series Add support for generic ELF cross-compiler | expand

Commit Message

Roman Bolshakov Sept. 1, 2020, 8:50 a.m. UTC
For compatibility with other SVR4 assemblers, '/' starts a comment on
*-elf binutils target and thus division operator is not allowed [1][2].
That breaks cstart64.S build:

  x86/cstart64.S: Assembler messages:
  x86/cstart64.S:294: Error: unbalanced parenthesis in operand 1.

configure should detect if --divide needs to be passed to assembler by
compiling a small snippet where division is used inside parentheses.

1. https://sourceware.org/binutils/docs/as/i386_002dChars.html
2. https://sourceware.org/binutils/docs/as/i386_002dOptions.html#index-_002d_002ddivide-option_002c-i386

Cc: Cameron Esfahani <dirty@apple.com>
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
---
 configure           | 12 ++++++++++++
 x86/Makefile.common |  3 +++
 2 files changed, 15 insertions(+)

Comments

Thomas Huth Sept. 3, 2020, 3:19 p.m. UTC | #1
On 01/09/2020 10.50, Roman Bolshakov wrote:
> For compatibility with other SVR4 assemblers, '/' starts a comment on
> *-elf binutils target and thus division operator is not allowed [1][2].
> That breaks cstart64.S build:
> 
>   x86/cstart64.S: Assembler messages:
>   x86/cstart64.S:294: Error: unbalanced parenthesis in operand 1.
> 
> configure should detect if --divide needs to be passed to assembler by
> compiling a small snippet where division is used inside parentheses.
> 
> 1. https://sourceware.org/binutils/docs/as/i386_002dChars.html
> 2. https://sourceware.org/binutils/docs/as/i386_002dOptions.html#index-_002d_002ddivide-option_002c-i386
> 
> Cc: Cameron Esfahani <dirty@apple.com>
> Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
> ---
>  configure           | 12 ++++++++++++
>  x86/Makefile.common |  3 +++
>  2 files changed, 15 insertions(+)

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

Patch

diff --git a/configure b/configure
index f9d030f..4eb504f 100755
--- a/configure
+++ b/configure
@@ -15,6 +15,7 @@  endian=""
 pretty_print_stacks=yes
 environ_default=yes
 u32_long=
+wa_divide=
 vmm="qemu"
 errata_force=0
 erratatxt="$srcdir/errata.txt"
@@ -156,6 +157,16 @@  EOF
 u32_long=$("$cross_prefix$cc" -E lib-test.c | grep -v '^#' | grep -q long && echo yes)
 rm -f lib-test.c
 
+# check if slash can be used for division
+if [ "$arch" = "i386" ] || [ "$arch" = "x86_64" ]; then
+  cat << EOF > lib-test.S
+foo:
+    movl (8 / 2), %eax
+EOF
+  wa_divide=$("$cross_prefix$cc" -c lib-test.S >/dev/null 2>&1 || echo yes)
+  rm -f lib-test.{o,S}
+fi
+
 # Are we in a separate build tree? If so, link the Makefile
 # and shared stuff so that 'make' and run_tests.sh work.
 if test ! -e Makefile; then
@@ -205,6 +216,7 @@  PRETTY_PRINT_STACKS=$pretty_print_stacks
 ENVIRON_DEFAULT=$environ_default
 ERRATATXT=$erratatxt
 U32_LONG_FMT=$u32_long
+WA_DIVIDE=$wa_divide
 EOF
 
 cat <<EOF > lib/config.h
diff --git a/x86/Makefile.common b/x86/Makefile.common
index 2ea9c9f..c3f7dc4 100644
--- a/x86/Makefile.common
+++ b/x86/Makefile.common
@@ -29,6 +29,9 @@  $(libcflat): LDFLAGS += -nostdlib
 $(libcflat): CFLAGS += -ffreestanding -I $(SRCDIR)/lib -I lib
 
 COMMON_CFLAGS += -m$(bits)
+ifneq ($(WA_DIVIDE),)
+COMMON_CFLAGS += -Wa,--divide
+endif
 COMMON_CFLAGS += -O1
 
 # stack.o relies on frame pointers.