[PATCH 1/5] xen/x86: always consider '/' as a division in assembly

Roger Pau Monne posted 5 patches 2 months ago
There is a newer version of this series
[PATCH 1/5] xen/x86: always consider '/' as a division in assembly
Posted by Roger Pau Monne 2 months ago
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 <jbeulich@suse.com>
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Changes since v1:
 - Guard option setting to x86 only.
 - Adjust comment.
---
 xen/Makefile | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/xen/Makefile b/xen/Makefile
index a054315fa4a2..4c83e2a46477 100644
--- a/xen/Makefile
+++ b/xen/Makefile
@@ -413,6 +413,13 @@ ifneq ($(CONFIG_CC_IS_CLANG),y)
 CFLAGS += -Wa,--strip-local-absolute
 endif
 
+ifeq ($(CONFIG_X86),y)
+# 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)
+endif
+
 $(call cc-option-add,AFLAGS,CC,-Wa$$(comma)--noexecstack)
 
 LDFLAGS-$(call ld-option,--warn-rwx-segments) += --no-warn-rwx-segments
-- 
2.51.0


Re: [PATCH 1/5] xen/x86: always consider '/' as a division in assembly
Posted by Jan Beulich 2 months ago
On 11.02.2026 11:46, Roger Pau Monne wrote:
> --- a/xen/Makefile
> +++ b/xen/Makefile
> @@ -413,6 +413,13 @@ ifneq ($(CONFIG_CC_IS_CLANG),y)
>  CFLAGS += -Wa,--strip-local-absolute
>  endif
>  
> +ifeq ($(CONFIG_X86),y)
> +# 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)
> +endif

As said before, I don't think this should be put here. Not even with the
new ifeq(,) around it. It should go in x86/arch.mk, or a reason should be
given why it can't.

Jan
Re: [PATCH 1/5] xen/x86: always consider '/' as a division in assembly
Posted by Roger Pau Monné 2 months ago
On Wed, Feb 11, 2026 at 12:11:32PM +0100, Jan Beulich wrote:
> On 11.02.2026 11:46, Roger Pau Monne wrote:
> > --- a/xen/Makefile
> > +++ b/xen/Makefile
> > @@ -413,6 +413,13 @@ ifneq ($(CONFIG_CC_IS_CLANG),y)
> >  CFLAGS += -Wa,--strip-local-absolute
> >  endif
> >  
> > +ifeq ($(CONFIG_X86),y)
> > +# 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)
> > +endif
> 
> As said before, I don't think this should be put here. Not even with the
> new ifeq(,) around it. It should go in x86/arch.mk, or a reason should be
> given why it can't.

My bad.  I've attempted to put it there but got complains from the
build in x86/boot/.  I think that was because I had leftover stale
objects in there, and nothing do to with the patch itself.  I can
confirm it works when the chunk is placed in x86/arch.mk.

Thanks, Roger.
Re: [PATCH 1/5] xen/x86: always consider '/' as a division in assembly
Posted by Bertrand Marquis 2 months ago
Hi Roger,

> On 11 Feb 2026, at 11:46, Roger Pau Monne <roger.pau@citrix.com> wrote:
> 
> 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.

Works to build x86 and arm still working on Mac OS.

> 
> Reported-by: Jan Beulich <jbeulich@suse.com>
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>

Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>

Cheers
Bertrand

> ---
> Changes since v1:
> - Guard option setting to x86 only.
> - Adjust comment.
> ---
> xen/Makefile | 7 +++++++
> 1 file changed, 7 insertions(+)
> 
> diff --git a/xen/Makefile b/xen/Makefile
> index a054315fa4a2..4c83e2a46477 100644
> --- a/xen/Makefile
> +++ b/xen/Makefile
> @@ -413,6 +413,13 @@ ifneq ($(CONFIG_CC_IS_CLANG),y)
> CFLAGS += -Wa,--strip-local-absolute
> endif
> 
> +ifeq ($(CONFIG_X86),y)
> +# 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)
> +endif
> +
> $(call cc-option-add,AFLAGS,CC,-Wa$$(comma)--noexecstack)
> 
> LDFLAGS-$(call ld-option,--warn-rwx-segments) += --no-warn-rwx-segments
> -- 
> 2.51.0
> 
>