From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Stefano Stabellini <sstabellini@kernel.org>,
Wei Liu <wei.liu2@citrix.com>,
George Dunlap <George.Dunlap@eu.citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>, Tim Deegan <tim@xen.org>,
Jan Beulich <jbeulich@suse.com>,
Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH v3 2/5] x86/clang: fix build with indirect thunks
Date: Mon, 29 Jan 2018 12:26:40 +0000 [thread overview]
Message-ID: <20180129122643.13008-3-roger.pau@citrix.com> (raw)
In-Reply-To: <20180129122643.13008-1-roger.pau@citrix.com>
The build with clang is currently broken because clang integrated
assembler requires asm macros to be declared inside the same inline
asm declaration where they are used.
In order to fix this always include indirect_thunk_asm.h in the same
asm declaration where it's being used.
This has been reported to upstream clang at:
https://bugs.llvm.org/show_bug.cgi?id=36110
This change has been tested with clang 3.5, clang 6.0 and gcc 6.4.0.
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: George Dunlap <George.Dunlap@eu.citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Tim Deegan <tim@xen.org>
Cc: Wei Liu <wei.liu2@citrix.com>
---
Changes since v1:
- Use as-insn to check if the assembler supports .include.
- Open code a check for whether the assembler forgets .macro-s
between asm()-s.
---
Config.mk | 7 +++----
xen/Rules.mk | 6 ++++--
xen/arch/x86/Rules.mk | 17 ++++++++++++++---
xen/arch/x86/extable.c | 3 ++-
xen/arch/x86/x86_emulate/x86_emulate.c | 3 ++-
xen/common/wait.c | 1 +
xen/include/asm-x86/asm_defns.h | 28 +++++++++++++++++++++++++---
7 files changed, 51 insertions(+), 14 deletions(-)
diff --git a/Config.mk b/Config.mk
index 51adc27d83..c55f023f35 100644
--- a/Config.mk
+++ b/Config.mk
@@ -157,17 +157,16 @@ ifndef XEN_HAS_CHECKPOLICY
endif
# as-insn: Check whether assembler supports an instruction.
-# Usage: cflags-y += $(call as-insn "insn",option-yes,option-no)
+# Usage: cflags-y += $(call as-insn cc,"insn",option-yes,option-no,FLAGS)
as-insn = $(if $(shell echo 'void _(void) { asm volatile ( $(2) ); }' \
- | $(1) $(filter-out -M% %.d -include %/include/xen/config.h,$(AFLAGS)) \
+ | $(1) $(filter-out -M% %.d -include %/include/xen/config.h,$(5)) \
-c -x c -o /dev/null - 2>&1),$(4),$(3))
-
# as-insn-check: Add an option to compilation flags, but only if insn is
# supported by assembler.
# Usage: $(call as-insn-check CFLAGS,CC,"nop",-DHAVE_GAS_NOP)
as-insn-check = $(eval $(call as-insn-check-closure,$(1),$(2),$(3),$(4)))
define as-insn-check-closure
- ifeq ($$(call as-insn,$$($(2)),$(3),y,n),y)
+ ifeq ($$(call as-insn,$$($(2)),$(3),y,n,$$(AFLAGS)),y)
$(1) += $(4)
endif
endef
diff --git a/xen/Rules.mk b/xen/Rules.mk
index 3cf40754a6..205f0aff30 100644
--- a/xen/Rules.mk
+++ b/xen/Rules.mk
@@ -66,8 +66,10 @@ endif
AFLAGS-y += -D__ASSEMBLY__
-# Clang's built-in assembler can't handle embedded .include's
-CFLAGS-$(clang) += -no-integrated-as
+# Clang's built-in assembler doesn't understand .skip or .rept assembler
+# directives without an absolute value:
+# https://bugs.llvm.org/show_bug.cgi?id=27369
+AFLAGS-$(clang) += -no-integrated-as
ALL_OBJS := $(ALL_OBJS-y)
diff --git a/xen/arch/x86/Rules.mk b/xen/arch/x86/Rules.mk
index 56b2ea8356..aeae01cd97 100644
--- a/xen/arch/x86/Rules.mk
+++ b/xen/arch/x86/Rules.mk
@@ -42,8 +42,19 @@ CFLAGS += -DCONFIG_INDIRECT_THUNK
export CONFIG_INDIRECT_THUNK=y
endif
-# Set up the assembler include path properly for older GCC toolchains. Clang
-# objects to the agument being passed however.
-ifneq ($(clang),y)
+# Set up the assembler include path properly for older toolchains.
CFLAGS += -Wa,-I$(BASEDIR)/include
+
+ifeq ($(clang),y)
+ # Check whether clang asm()-s support .include.
+ ifeq ($(call as-insn,$(CC),".include \"asm/indirect_thunk_asm.h\"",y,n,$(CFLAGS)),n)
+ CFLAGS += -no-integrated-as
+ endif
+ # Check if the assembler keeps .macro-s between asm()-s.
+ ifeq ($(if $(shell echo 'void _(void) { asm volatile ( ".macro FOO\n.endm" ); \
+ asm volatile ( ".macro FOO\n.endm" ); }' \
+ | $(CC) $(filter-out -M% %.d -include %/include/xen/config.h,$(CFLAGS)) \
+ -c -x c -o /dev/null - 2>&1),n,y),y)
+ CFLAGS += -DCONFIG_INCLUDE_THUNK_INLINE
+ endif
endif
diff --git a/xen/arch/x86/extable.c b/xen/arch/x86/extable.c
index 72f30d9060..30893c3770 100644
--- a/xen/arch/x86/extable.c
+++ b/xen/arch/x86/extable.c
@@ -158,7 +158,8 @@ static int __init stub_selftest(void)
memcpy(ptr, tests[i].opc, ARRAY_SIZE(tests[i].opc));
unmap_domain_page(ptr);
- asm volatile ( "INDIRECT_CALL %[stb]\n"
+ asm volatile ( INCLUDE_INDIRECT_THUNK
+ "INDIRECT_CALL %[stb]\n"
".Lret%=:\n\t"
".pushsection .fixup,\"ax\"\n"
".Lfix%=:\n\t"
diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c b/xen/arch/x86/x86_emulate/x86_emulate.c
index ff0a003902..e525e6bb0d 100644
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -867,7 +867,8 @@ static inline int mkec(uint8_t e, int32_t ec, ...)
#ifdef __XEN__
# define invoke_stub(pre, post, constraints...) do { \
union stub_exception_token res_ = { .raw = ~0 }; \
- asm volatile ( pre "\n\tINDIRECT_CALL %[stub]\n\t" post "\n" \
+ asm volatile ( INCLUDE_INDIRECT_THUNK \
+ pre "\n\tINDIRECT_CALL %[stub]\n\t" post "\n" \
".Lret%=:\n\t" \
".pushsection .fixup,\"ax\"\n" \
".Lfix%=:\n\t" \
diff --git a/xen/common/wait.c b/xen/common/wait.c
index a57bc10d61..91dcd46342 100644
--- a/xen/common/wait.c
+++ b/xen/common/wait.c
@@ -207,6 +207,7 @@ void check_wakeup_from_wait(void)
* restored from the stack, so are available for use here.
*/
asm volatile (
+ INCLUDE_INDIRECT_THUNK
"mov %1,%%"__OP"sp; INDIRECT_JMP %[ip]"
: : "S" (wqv->stack), "D" (wqv->esp),
"c" ((char *)get_cpu_info() - (char *)wqv->esp),
diff --git a/xen/include/asm-x86/asm_defns.h b/xen/include/asm-x86/asm_defns.h
index d2d91ca1fa..447bf67aed 100644
--- a/xen/include/asm-x86/asm_defns.h
+++ b/xen/include/asm-x86/asm_defns.h
@@ -16,9 +16,31 @@
#ifdef __ASSEMBLY__
# include <asm/indirect_thunk_asm.h>
#else
-asm ( "\t.equ CONFIG_INDIRECT_THUNK, "
- __stringify(IS_ENABLED(CONFIG_INDIRECT_THUNK)) );
-asm ( "\t.include \"asm/indirect_thunk_asm.h\"" );
+/*
+ * NB: for clang's integrated assembler the macro must be included in every
+ * asm() instance where it's used. For gcc/gas it only needs to be included
+ * once per file. Note that even guarding the indirect_thunk_asm.h with
+ * something like:
+ *
+ * .ifndef _X86_INDIRECT_THUNK_ASM_H_
+ * .equ _X86_INDIRECT_THUNK_ASM_H_, 1
+ * ...
+ * .endif
+ *
+ * Doesn't work with clang because it will keep the .equ defined between asm()
+ * instances, but will forget the .macro. This has been reported upstream:
+ * https://bugs.llvm.org/show_bug.cgi?id=36110
+ */
+# define INDIRECT_THUNK_ASM \
+ "\t.equ CONFIG_INDIRECT_THUNK, " \
+ __stringify(IS_ENABLED(CONFIG_INDIRECT_THUNK)) "\n" \
+ "\t.include \"asm/indirect_thunk_asm.h\"\n"
+# ifdef CONFIG_INCLUDE_THUNK_INLINE
+# define INCLUDE_INDIRECT_THUNK INDIRECT_THUNK_ASM
+# else
+ asm ( INDIRECT_THUNK_ASM );
+# define INCLUDE_INDIRECT_THUNK
+# endif
#endif
#ifndef __ASSEMBLY__
--
2.15.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-01-29 12:29 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-29 12:26 [PATCH v3 0/5] clang fixes Roger Pau Monne
2018-01-29 12:26 ` [PATCH v3 1/5] build: filter out command line assembler arguments Roger Pau Monne
2018-01-29 14:12 ` Ian Jackson
2018-01-29 12:26 ` Roger Pau Monne [this message]
2018-01-29 16:42 ` [PATCH v3 2/5] x86/clang: fix build with indirect thunks Jan Beulich
2018-01-29 12:26 ` [PATCH v3 3/5] x86: fix indirect thunk usage of CONFIG_INDIRECT_THUNK Roger Pau Monne
2018-01-29 16:45 ` Jan Beulich
2018-01-29 17:00 ` Roger Pau Monné
2018-01-29 12:26 ` [PATCH v3 4/5] x86: move declaration of the exception_table to C Roger Pau Monne
2018-01-29 16:46 ` Jan Beulich
2018-01-29 12:26 ` [PATCH v3 5/5] x86: remove usage of .skip with non-absolute expressions Roger Pau Monne
2018-01-29 12:43 ` Wei Liu
2018-01-29 12:53 ` Roger Pau Monné
2018-01-29 13:02 ` Jan Beulich
2018-01-29 13:05 ` Andrew Cooper
2018-01-29 13:39 ` Jan Beulich
2018-01-29 16:50 ` Jan Beulich
2018-01-29 18:22 ` Andrew Cooper
2018-01-30 9:23 ` Roger Pau Monné
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180129122643.13008-3-roger.pau@citrix.com \
--to=roger.pau@citrix.com \
--cc=George.Dunlap@eu.citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=sstabellini@kernel.org \
--cc=tim@xen.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).