Skip to contentSkip to conversation

xen/x86: Fix build with Clang 3.5

PATCH In review Andrew Cooper 7 participants 26 messages Feb 9, 2016 – Feb 16, 2016

lore
Share & tools
lore
#0 lore raw

cover xen/x86: Fix build with Clang 3.5

This is a misc assortment of patches to fix the build with Clang 3.5. The result also appears to function.

Andrew Cooper (8):
xen/lib: Fix ASSERT() to build with clang
xen/misc: Remove or annotate possibly-unused functions xen/x86: Remove %z modifier from inline assembly xen/x86: Fix section type mismatch in mm.c
xen/x86: Improve annotation of autogen_entrypoints[] xen/x86: Avoid overriding initialisers in arrays xen/x86: Fix get_cpu_info() when built with clang x86/efi: Generate uefi_call_wrapper() when compiling with clang

 xen/arch/x86/cpu/mtrr/generic.c      |  3 +--
 xen/arch/x86/mm.c                    |  2 +-
 xen/arch/x86/mm/p2m-ept.c            | 27 ++++++++++++++++-----------
 xen/arch/x86/mm/shadow/multi.c       |  2 ++
 xen/arch/x86/traps.c                 |  2 +-
 xen/arch/x86/xen.lds.S               |  2 +-
 xen/arch/x86/xstate.c                |  3 ++-
 xen/common/rcupdate.c                |  6 ------
 xen/include/asm-x86/current.h        |  6 ++++++
 xen/include/asm-x86/spinlock.h       |  3 ++-
 xen/include/asm-x86/x86_64/efibind.h |  2 +-
 xen/include/xen/compat.h             | 14 ++++++++------
 xen/include/xen/lib.h                |  2 +-
 13 files changed, 42 insertions(+), 32 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/8 xen/lib: Fix ASSERT() to build with clang

Clang warns about a semicolon immediately following an if() clause as a possible mistake, and recommends putting the semicolon on a new line if it was intentional. A newline is not an option here, so use a set of empty braces instead.

---
CC: Jan Beulich <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Ian Campbell <[email protected]>

---
 xen/include/xen/lib.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/include/xen/lib.h +1 -1
index 4258912..76232b2 100644
@@ -32,7 +32,7 @@
 #define ASSERT_UNREACHABLE() assert_failed("unreachable")
 #define debug_build() 1
 #else
-#define ASSERT(p) do { if ( 0 && (p) ); } while (0)
+#define ASSERT(p) do { if ( 0 && (p) ){} } while (0)
 #define ASSERT_UNREACHABLE() do { } while (0)
 #define debug_build() 0
 #endif
Signature · 1 line
2.1.4
#2 lore raw

PATCH 2/8 xen/misc: Remove or annotate possibly-unused functions

In reply to Andrew Cooper

Clang notices more unused functions than GCC.

* sh_next_page() is only used at GUEST_PAGING_LEVELS=2, so remove it from the other guest level translation units
* rcu_batch_after() is completely unused.
* Various of the COMPAT() generated functions are used only for their BUILD_BUG_ON() properties. Annotate them all as __maybe_used.

---
CC: Jan Beulich <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Ian Campbell <[email protected]>

---
 xen/arch/x86/mm/shadow/multi.c |  2 ++
 xen/common/rcupdate.c          |  6 ------
 xen/include/xen/compat.h       | 14 ++++++++------
 3 files changed, 10 insertions(+), 12 deletions(-)
xen/arch/x86/mm/shadow/multi.c +2 -0
index 4d0b317..aaf8db7 100644
@@ -436,6 +436,7 @@ sh_cmpxchg_guest_entry(struct vcpu *v, intpte_t *p, intpte_t *old,
  * space.)
  */
 
+#if GUEST_PAGING_LEVELS == 2
 /* From one page of a multi-page shadow, find the next one */
 static inline mfn_t sh_next_page(mfn_t smfn)
 {
@@ -454,6 +455,7 @@ static inline mfn_t sh_next_page(mfn_t smfn)
     ASSERT(!next->u.sh.head);
     return page_to_mfn(next);
 }
+#endif
 
 static inline u32
 guest_index(void *ptr)
xen/common/rcupdate.c +0 -6
index f13b87b..8cc5a82 100644
@@ -141,12 +141,6 @@ static inline int rcu_batch_before(long a, long b)
     return (a - b) < 0;
 }
 
-/* Is batch a after batch b ? */
-static inline int rcu_batch_after(long a, long b)
-{
-    return (a - b) > 0;
-}
-
 static void force_quiescent_state(struct rcu_data *rdp,
                                   struct rcu_ctrlblk *rcp)
 {
xen/include/xen/compat.h +8 -6
index e5c23e2..3f4cef6 100644
@@ -134,14 +134,16 @@
 #define CHECK_NAME_(k, n, tag) __check ## tag ## k ## _ ## n
 
 #define CHECK_TYPE(name) \
-static inline int CHECK_NAME(name, T)(xen_ ## name ## _t *x, \
-                                      compat_ ## name ## _t *c) \
+static inline int __maybe_unused \
+CHECK_NAME(name, T)(xen_ ## name ## _t *x, \
+                    compat_ ## name ## _t *c) \
 { \
     return x == c; \
 }
 #define CHECK_TYPE_(k, n) \
-static inline int CHECK_NAME_(k, n, T)(k xen_ ## n *x, \
-                                       k compat_ ## n *c) \
+static inline int __maybe_unused \
+CHECK_NAME_(k, n, T)(k xen_ ## n *x, \
+                     k compat_ ## n *c) \
 { \
     return x == c; \
 }
@@ -154,14 +156,14 @@ static inline int CHECK_NAME_(k, n, T)(k xen_ ## n *x, \
                                           sizeof(k compat_ ## n)) * 2]
 
 #define CHECK_FIELD_COMMON(name, t, f) \
-static inline int name(xen_ ## t ## _t *x, compat_ ## t ## _t *c) \
+static inline int __maybe_unused name(xen_ ## t ## _t *x, compat_ ## t ## _t *c) \
 { \
     BUILD_BUG_ON(offsetof(xen_ ## t ## _t, f) != \
                  offsetof(compat_ ## t ## _t, f)); \
     return &x->f == &c->f; \
 }
 #define CHECK_FIELD_COMMON_(k, name, n, f) \
-static inline int name(k xen_ ## n *x, k compat_ ## n *c) \
+static inline int __maybe_unused name(k xen_ ## n *x, k compat_ ## n *c) \
 { \
     BUILD_BUG_ON(offsetof(k xen_ ## n, f) != \
                  offsetof(k compat_ ## n, f)); \
Signature · 1 line
2.1.4
#3 lore raw

Re: [PATCH 2/8] xen/misc: Remove or annotate possibly-unused functions

Quoted 9 lines · Andrew Cooper

Clang notices more unused functions than GCC.

* sh_next_page() is only used at GUEST_PAGING_LEVELS=2, so remove it from the other guest level translation units
* rcu_batch_after() is completely unused.
* Various of the COMPAT() generated functions are used only for their BUILD_BUG_ON() properties. Annotate them all as __maybe_used.

Shadow stuff Acked-by: Tim Deegan <[email protected]>

#4 lore raw

Re: [PATCH 2/8] xen/misc: Remove or annotate possibly-unused functions

In reply to Andrew Cooper

xen/common/rcupdate.c static inline int rcu_batch_before(long a, long b) · line 148

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 09.02.16 at 21:01, <[email protected]> wrote:
xen/common/rcupdate.c +0 -5
@@ -141,12 +141,6 @@ static inline int rcu_batch_before(long a, long b)
     return (a - b) < 0;
 }
 
-/* Is batch a after batch b ? */
-static inline int rcu_batch_after(long a, long b)
-{
-    return (a - b) > 0;
-}

To me it is the nature of inline functions that they may or may not be used, regardless of whether they live in a header file (where I would have supposed Clang won't warn about, but the change below makes me assume I'm wrong) or in a source file.

Quoted 30 lines
xen/include/xen/compat.h +7 -5
@@ -134,14 +134,16 @@
 #define CHECK_NAME_(k, n, tag) __check ## tag ## k ## _ ## n
 
 #define CHECK_TYPE(name) \
-static inline int CHECK_NAME(name, T)(xen_ ## name ## _t *x, \
-                                      compat_ ## name ## _t *c) \
+static inline int __maybe_unused \
+CHECK_NAME(name, T)(xen_ ## name ## _t *x, \
+                    compat_ ## name ## _t *c) \
 { \
     return x == c; \
 }
 #define CHECK_TYPE_(k, n) \
-static inline int CHECK_NAME_(k, n, T)(k xen_ ## n *x, \
-                                       k compat_ ## n *c) \
+static inline int __maybe_unused \
+CHECK_NAME_(k, n, T)(k xen_ ## n *x, \
+                     k compat_ ## n *c) \
 { \
     return x == c; \
 }
@@ -154,14 +156,14 @@ static inline int CHECK_NAME_(k, n, T)(k xen_ ## n *x, \
                                           sizeof(k compat_ ## n)) * 2]
 
 #define CHECK_FIELD_COMMON(name, t, f) \
-static inline int name(xen_ ## t ## _t *x, compat_ ## t ## _t *c) \
+static inline int __maybe_unused name(xen_ ## t ## _t *x, compat_ ## t ## _t *c) \
 { \

xen/include/xen/compat.h static inline int CHECK_NAME_(k, n, T)(k xen_ ## n *x, \ · line 169

Quoted 10 lines
xen/include/xen/compat.h +1 -1
     BUILD_BUG_ON(offsetof(xen_ ## t ## _t, f) != \
                  offsetof(compat_ ## t ## _t, f)); \
     return &x->f == &c->f; \
 }
 #define CHECK_FIELD_COMMON_(k, name, n, f) \
-static inline int name(k xen_ ## n *x, k compat_ ## n *c) \
+static inline int __maybe_unused name(k xen_ ## n *x, k compat_ ## n *c) \
 { \
     BUILD_BUG_ON(offsetof(k xen_ ## n, f) != \
                  offsetof(k compat_ ## n, f)); \

So if these are all noticed to be unused, why would others in other header files not be? I think there's at the very least some aspect missing in the description, explaining what makes these stand out from the others.

Jan

#5 lore raw

Re: [PATCH 2/8] xen/misc: Remove or annotate possibly-unused functions

Quoted 43 lines · Jan Beulich

xen/common/rcupdate.c static inline int rcu_batch_before(long a, long b) · line 148

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 09.02.16 at 21:01, <[email protected]> wrote:
xen/common/rcupdate.c +0 -5
@@ -141,12 +141,6 @@ static inline int rcu_batch_before(long a, long b)
     return (a - b) < 0;
 }
 
-/* Is batch a after batch b ? */
-static inline int rcu_batch_after(long a, long b)
-{
-    return (a - b) > 0;
-}

To me it is the nature of inline functions that they may or may not be used, regardless of whether they live in a header file (where I would have supposed Clang won't warn about, but the change below makes me assume I'm wrong) or in a source file.

Quoted 26 lines
xen/include/xen/compat.h +6 -4
@@ -134,14 +134,16 @@
 #define CHECK_NAME_(k, n, tag) __check ## tag ## k ## _ ## n
 
 #define CHECK_TYPE(name) \
-static inline int CHECK_NAME(name, T)(xen_ ## name ## _t *x, \
-                                      compat_ ## name ## _t *c) \
+static inline int __maybe_unused \
+CHECK_NAME(name, T)(xen_ ## name ## _t *x, \
+                    compat_ ## name ## _t *c) \
 { \
     return x == c; \
 }
 #define CHECK_TYPE_(k, n) \
-static inline int CHECK_NAME_(k, n, T)(k xen_ ## n *x, \
-                                       k compat_ ## n *c) \
+static inline int __maybe_unused \
+CHECK_NAME_(k, n, T)(k xen_ ## n *x, \
+                     k compat_ ## n *c) \
 { \
     return x == c; \
 }
@@ -154,14 +156,14 @@ static inline int CHECK_NAME_(k, n, T)(k xen_ ## n *x, \
                                           sizeof(k compat_ ## n)) * 2]
 
Quoted 16 lines
Quoted 4 lines
xen/include/xen/compat.h +1 -1
 #define CHECK_FIELD_COMMON(name, t, f) \
-static inline int name(xen_ ## t ## _t *x, compat_ ## t ## _t *c) \
+static inline int __maybe_unused name(xen_ ## t ## _t *x, compat_ ## t ## _t *c) \
 { \

xen/include/xen/compat.h static inline int CHECK_NAME_(k, n, T)(k xen_ ## n *x, \ · line 169

Quoted 10 lines
xen/include/xen/compat.h +1 -1
     BUILD_BUG_ON(offsetof(xen_ ## t ## _t, f) != \
                  offsetof(compat_ ## t ## _t, f)); \
     return &x->f == &c->f; \
 }
 #define CHECK_FIELD_COMMON_(k, name, n, f) \
-static inline int name(k xen_ ## n *x, k compat_ ## n *c) \
+static inline int __maybe_unused name(k xen_ ## n *x, k compat_ ## n *c) \
 { \
     BUILD_BUG_ON(offsetof(k xen_ ## n, f) != \
                  offsetof(k compat_ ## n, f)); \

So if these are all noticed to be unused, why would others in other header files not be?

Because they are instantiated in translation units, with no callers, by code like common/trace.c:

#ifdef CONFIG_COMPAT
#include <compat/trace.h>
#define xen_t_buf t_buf
CHECK_t_buf;
#undef xen_t_buf
#else
#define compat_t_rec t_rec
#endif

This was the first example which blew up.

~Andrew

#6 lore raw

PATCH 3/8 xen/x86: Remove %z modifier from inline assembly

In reply to Andrew Cooper

Clang doesn't support the %z modifier. Replace both uses with an explicit l suffix, and cover the changes with BUILD_BUG_ON()s

---
CC: Jan Beulich <[email protected]>

---
 xen/arch/x86/xstate.c          | 3 ++-
 xen/include/asm-x86/spinlock.h | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
xen/arch/x86/xstate.c +2 -1
index c5d17ff..4f2fb8e 100644
@@ -353,11 +353,12 @@ void xrstor(struct vcpu *v, uint64_t mask)
     {
         switch ( __builtin_expect(ptr->fpu_sse.x[FPU_WORD_SIZE_OFFSET], 8) )
         {
+            BUILD_BUG_ON(sizeof(faults) != 4); /* Clang doesn't support %z in asm. */
 #define XRSTOR(pfx) \
         alternative_io("1: .byte " pfx "0x0f,0xae,0x2f\n" \
                        "3:\n" \
                        "   .section .fixup,\"ax\"\n" \
-                       "2: inc%z[faults] %[faults]\n" \
+                       "2: incl %[faults]\n" \
                        "   jmp 3b\n" \
                        "   .previous\n" \
                        _ASM_EXTABLE(1b, 2b), \
xen/include/asm-x86/spinlock.h +2 -1
index 70a85af..be72c0f 100644
@@ -2,7 +2,8 @@
 #define __ASM_SPINLOCK_H
 
 #define _raw_read_unlock(l) \
-    asm volatile ( "lock; dec%z0 %0" : "+m" ((l)->lock) :: "memory" )
+    BUILD_BUG_ON(sizeof((l)->lock) != 4); /* Clang doesn't support %z in asm. */ \
+    asm volatile ( "lock; decl %0" : "+m" ((l)->lock) :: "memory" )
 
 /*
  * On x86 the only reordering is of reads with older writes.  In the
Signature · 1 line
2.1.4
#8 lore raw

PATCH 4/8 xen/x86: Fix section type mismatch in mm.c

In reply to Andrew Cooper

Clang doesn't like mixing const and non-const data in the same section. Move zero_page into .bss.page_aligned.const and wildcard .bss.page_aligned when linking.

---
CC: Jan Beulich <[email protected]>
CC: George Dunlap <[email protected]>

---
 xen/arch/x86/mm.c      | 2 +-
 xen/arch/x86/xen.lds.S | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/mm.c +1 -1
index d62d9ec..c214fc5 100644
@@ -577,7 +577,7 @@ static inline void guest_get_eff_kern_l1e(struct vcpu *v, unsigned long addr,
     TOGGLE_MODE();
 }
 
-static const char __section(".bss.page_aligned") zero_page[PAGE_SIZE];
+static const char __section(".bss.page_aligned.const") zero_page[PAGE_SIZE];
 
 static void invalidate_shadow_ldt(struct vcpu *v, int flush)
 {
xen/arch/x86/xen.lds.S +1 -1
index c1ce027..3b199ca 100644
@@ -170,7 +170,7 @@ SECTIONS
        __bss_start = .;
        *(.bss.stack_aligned)
        . = ALIGN(PAGE_SIZE);
-       *(.bss.page_aligned)
+       *(.bss.page_aligned*)
        *(.bss)
        . = ALIGN(SMP_CACHE_BYTES);
        __per_cpu_start = .;
Signature · 1 line
2.1.4
Acked-by on v1 4/8
#9 lore raw

Re: [PATCH 4/8] xen/x86: Fix section type mismatch in mm.c

Quoted 5 lines · Andrew Cooper

Clang doesn't like mixing const and non-const data in the same section. Move zero_page into .bss.page_aligned.const and wildcard .bss.page_aligned when linking.

Quoted 35 lines

---
CC: Jan Beulich <[email protected]>
CC: George Dunlap <[email protected]>

---
 xen/arch/x86/mm.c      | 2 +-
 xen/arch/x86/xen.lds.S | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/mm.c +1 -1
index d62d9ec..c214fc5 100644
@@ -577,7 +577,7 @@ static inline void guest_get_eff_kern_l1e(struct vcpu *v, unsigned long addr,
     TOGGLE_MODE();
 }
 
-static const char __section(".bss.page_aligned") zero_page[PAGE_SIZE];
+static const char __section(".bss.page_aligned.const") zero_page[PAGE_SIZE];
 
 static void invalidate_shadow_ldt(struct vcpu *v, int flush)
 {
xen/arch/x86/xen.lds.S +1 -1
index c1ce027..3b199ca 100644
@@ -170,7 +170,7 @@ SECTIONS
        __bss_start = .;
        *(.bss.stack_aligned)
        . = ALIGN(PAGE_SIZE);
-       *(.bss.page_aligned)
+       *(.bss.page_aligned*)
        *(.bss)
        . = ALIGN(SMP_CACHE_BYTES);
        __per_cpu_start = .;
#10 lore raw

PATCH 5/8 xen/x86: Improve annotation of autogen_entrypoints[]

In reply to Andrew Cooper

Clang complains that the __used attribute is not applicable to an extern. In this case, the only relevent attribute is that the data is constant.

---
CC: Jan Beulich <[email protected]>

---
 xen/arch/x86/traps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/traps.c +1 -1
index e105b95..d19250a 100644
@@ -3689,7 +3689,7 @@ void __init init_idt_traps(void)
     this_cpu(compat_gdt_table) = boot_cpu_compat_gdt_table;
 }
 
-extern void (*__initconst autogen_entrypoints[NR_VECTORS])(void);
+extern void (*const autogen_entrypoints[NR_VECTORS])(void);
 void __init trap_init(void)
 {
     unsigned int vector;
Signature · 1 line
2.1.4
#11 lore raw

PATCH 6/8 xen/x86: Avoid overriding initialisers in arrays

In reply to Andrew Cooper

Clang objects to having multiple initialisers when creating an array.

As this warning is useful for spotting obscure bugs, disabling it is unhelpful. Instead, fix our two deliberate usecases.

In the p2m-ept case, pull the array out into a helper function, so the helper can guarentee to cover the NULL pointer case.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: George Dunlap <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>

---
 xen/arch/x86/cpu/mtrr/generic.c |  3 +--
 xen/arch/x86/mm/p2m-ept.c       | 27 ++++++++++++++++-----------
 2 files changed, 17 insertions(+), 13 deletions(-)
xen/arch/x86/cpu/mtrr/generic.c +1 -2
index ea0efe2..8839f8d 100644
@@ -91,7 +91,6 @@ static const char *__init mtrr_attrib_to_str(mtrr_type x)
 {
 	static const char __initconst strings[MTRR_NUM_TYPES][16] =
 	{
-		[0 ... MTRR_NUM_TYPES - 1] = "?",
 		[MTRR_TYPE_UNCACHABLE]     = "uncachable",
 		[MTRR_TYPE_WRCOMB]         = "write-combining",
 		[MTRR_TYPE_WRTHROUGH]      = "write-through",
@@ -99,7 +98,7 @@ static const char *__init mtrr_attrib_to_str(mtrr_type x)
 		[MTRR_TYPE_WRBACK]         = "write-back",
 	};
 
-	return x < MTRR_NUM_TYPES ? strings[x] : "?";
+	return x < MTRR_NUM_TYPES ? (strings[x] ?: "?") : "?";
 }
 
 static unsigned int __initdata last_fixed_start;
xen/arch/x86/mm/p2m-ept.c +16 -11
index c094320..c5fe906 100644
@@ -1201,6 +1201,20 @@ void ept_p2m_uninit(struct p2m_domain *p2m)
     free_cpumask_var(ept->invalidate);
 }
 
+static const char *memory_type_to_str(unsigned int x)
+{
+    static const char memory_types[8][2] = {
+        [MTRR_TYPE_UNCACHABLE]     = "UC",
+        [MTRR_TYPE_WRCOMB]         = "WC",
+        [MTRR_TYPE_WRTHROUGH]      = "WT",
+        [MTRR_TYPE_WRPROT]         = "WP",
+        [MTRR_TYPE_WRBACK]         = "WB",
+        [MTRR_NUM_TYPES]           = "??"
+    };
+
+    return x < ARRAY_SIZE(memory_types) ? (memory_types[x] ?: "?") : "?";
+}
+
 static void ept_dump_p2m_table(unsigned char key)
 {
     struct domain *d;
@@ -1212,15 +1226,6 @@ static void ept_dump_p2m_table(unsigned char key)
     unsigned long record_counter = 0;
     struct p2m_domain *p2m;
     struct ept_data *ept;
-    static const char memory_types[8][2] = {
-        [0 ... 7] = "?",
-        [MTRR_TYPE_UNCACHABLE]     = "UC",
-        [MTRR_TYPE_WRCOMB]         = "WC",
-        [MTRR_TYPE_WRTHROUGH]      = "WT",
-        [MTRR_TYPE_WRPROT]         = "WP",
-        [MTRR_TYPE_WRBACK]         = "WB",
-        [MTRR_NUM_TYPES]           = "??"
-    };
 
     for_each_domain(d)
     {
@@ -1260,8 +1265,8 @@ static void ept_dump_p2m_table(unsigned char key)
                            ept_entry->r ? 'r' : ' ',
                            ept_entry->w ? 'w' : ' ',
                            ept_entry->x ? 'x' : ' ',
-                           memory_types[ept_entry->emt][0],
-                           memory_types[ept_entry->emt][1]
+                           memory_type_to_str(ept_entry->emt)[0],
+                           memory_type_to_str(ept_entry->emt)[1]
                            ?: ept_entry->emt + '0',
                            c ?: ept_entry->ipat ? '!' : ' ');
 
Signature · 1 line
2.1.4
Acked-by on v1 6/8
#12 lore raw

Re: [PATCH 6/8] xen/x86: Avoid overriding initialisers in arrays

Quoted 11 lines · Andrew Cooper

Clang objects to having multiple initialisers when creating an array.

As this warning is useful for spotting obscure bugs, disabling it is unhelpful. Instead, fix our two deliberate usecases.

In the p2m-ept case, pull the array out into a helper function, so the helper can guarentee to cover the NULL pointer case.

No functional change.

Quoted 84 lines

---
CC: Jan Beulich <[email protected]>
CC: George Dunlap <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>

---
 xen/arch/x86/cpu/mtrr/generic.c |  3 +--
 xen/arch/x86/mm/p2m-ept.c       | 27 ++++++++++++++++-----------
 2 files changed, 17 insertions(+), 13 deletions(-)
xen/arch/x86/cpu/mtrr/generic.c +1 -2
index ea0efe2..8839f8d 100644
@@ -91,7 +91,6 @@ static const char *__init mtrr_attrib_to_str(mtrr_type x)
 {
 	static const char __initconst strings[MTRR_NUM_TYPES][16] =
 	{
-		[0 ... MTRR_NUM_TYPES - 1] = "?",
 		[MTRR_TYPE_UNCACHABLE]     = "uncachable",
 		[MTRR_TYPE_WRCOMB]         = "write-combining",
 		[MTRR_TYPE_WRTHROUGH]      = "write-through",
@@ -99,7 +98,7 @@ static const char *__init mtrr_attrib_to_str(mtrr_type x)
 		[MTRR_TYPE_WRBACK]         = "write-back",
 	};
 
-	return x < MTRR_NUM_TYPES ? strings[x] : "?";
+	return x < MTRR_NUM_TYPES ? (strings[x] ?: "?") : "?";
 }
 
 static unsigned int __initdata last_fixed_start;
xen/arch/x86/mm/p2m-ept.c +16 -11
index c094320..c5fe906 100644
@@ -1201,6 +1201,20 @@ void ept_p2m_uninit(struct p2m_domain *p2m)
     free_cpumask_var(ept->invalidate);
 }
 
+static const char *memory_type_to_str(unsigned int x)
+{
+    static const char memory_types[8][2] = {
+        [MTRR_TYPE_UNCACHABLE]     = "UC",
+        [MTRR_TYPE_WRCOMB]         = "WC",
+        [MTRR_TYPE_WRTHROUGH]      = "WT",
+        [MTRR_TYPE_WRPROT]         = "WP",
+        [MTRR_TYPE_WRBACK]         = "WB",
+        [MTRR_NUM_TYPES]           = "??"
+    };
+
+    return x < ARRAY_SIZE(memory_types) ? (memory_types[x] ?: "?") : "?";
+}
+
 static void ept_dump_p2m_table(unsigned char key)
 {
     struct domain *d;
@@ -1212,15 +1226,6 @@ static void ept_dump_p2m_table(unsigned char key)
     unsigned long record_counter = 0;
     struct p2m_domain *p2m;
     struct ept_data *ept;
-    static const char memory_types[8][2] = {
-        [0 ... 7] = "?",
-        [MTRR_TYPE_UNCACHABLE]     = "UC",
-        [MTRR_TYPE_WRCOMB]         = "WC",
-        [MTRR_TYPE_WRTHROUGH]      = "WT",
-        [MTRR_TYPE_WRPROT]         = "WP",
-        [MTRR_TYPE_WRBACK]         = "WB",
-        [MTRR_NUM_TYPES]           = "??"
-    };
 
     for_each_domain(d)
     {
@@ -1260,8 +1265,8 @@ static void ept_dump_p2m_table(unsigned char key)
                            ept_entry->r ? 'r' : ' ',
                            ept_entry->w ? 'w' : ' ',
                            ept_entry->x ? 'x' : ' ',
-                           memory_types[ept_entry->emt][0],
-                           memory_types[ept_entry->emt][1]
+                           memory_type_to_str(ept_entry->emt)[0],
+                           memory_type_to_str(ept_entry->emt)[1]
                            ?: ept_entry->emt + '0',
                            c ?: ept_entry->ipat ? '!' : ' ');
 
#13 lore raw

Re: [PATCH 6/8] xen/x86: Avoid overriding initialisers in arrays

In reply to Andrew Cooper
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 09.02.16 at 21:01, <[email protected]> wrote:

Clang objects to having multiple initialisers when creating an array.

As this warning is useful for spotting obscure bugs, disabling it is unhelpful. Instead, fix our two deliberate usecases.

Ugly again, but - well ...

Quoted 8 lines
xen/arch/x86/mm/p2m-ept.c +2 -0
@@ -1201,6 +1201,20 @@ void ept_p2m_uninit(struct p2m_domain *p2m)
     free_cpumask_var(ept->invalidate);
 }
 
+static const char *memory_type_to_str(unsigned int x)
+{

xen/arch/x86/mm/p2m-ept.c void ept_p2m_uninit(struct p2m_domain *p2m) · line 1215

Quoted 10 lines
xen/arch/x86/mm/p2m-ept.c +10 -0
+    static const char memory_types[8][2] = {
+        [MTRR_TYPE_UNCACHABLE]     = "UC",
+        [MTRR_TYPE_WRCOMB]         = "WC",
+        [MTRR_TYPE_WRTHROUGH]      = "WT",
+        [MTRR_TYPE_WRPROT]         = "WP",
+        [MTRR_TYPE_WRBACK]         = "WB",
+        [MTRR_NUM_TYPES]           = "??"
+    };
+
+    return x < ARRAY_SIZE(memory_types) ? (memory_types[x] ?: "?") : "?";

I think this should really ASSERT() the first condition.

Quoted 17 lines
xen/arch/x86/mm/p2m-ept.c +0 -9
@@ -1212,15 +1226,6 @@ static void ept_dump_p2m_table(unsigned char key)
     unsigned long record_counter = 0;
     struct p2m_domain *p2m;
     struct ept_data *ept;
-    static const char memory_types[8][2] = {
-        [0 ... 7] = "?",
-        [MTRR_TYPE_UNCACHABLE]     = "UC",
-        [MTRR_TYPE_WRCOMB]         = "WC",
-        [MTRR_TYPE_WRTHROUGH]      = "WT",
-        [MTRR_TYPE_WRPROT]         = "WP",
-        [MTRR_TYPE_WRBACK]         = "WB",
-        [MTRR_NUM_TYPES]           = "??"
-    };
 
     for_each_domain(d)
     {

xen/arch/x86/mm/p2m-ept.c static void ept_dump_p2m_table(unsigned char key) · line 1271

Quoted 9 lines
xen/arch/x86/mm/p2m-ept.c +2 -2
@@ -1260,8 +1265,8 @@ static void ept_dump_p2m_table(unsigned char key)
                            ept_entry->r ? 'r' : ' ',
                            ept_entry->w ? 'w' : ' ',
                            ept_entry->x ? 'x' : ' ',
-                           memory_types[ept_entry->emt][0],
-                           memory_types[ept_entry->emt][1]
+                           memory_type_to_str(ept_entry->emt)[0],
+                           memory_type_to_str(ept_entry->emt)[1]
                            ?: ept_entry->emt + '0',
                            c ?: ept_entry->ipat ? '!' : ' ');

There's actually a bug here, which I think is worth fixing at once:
The default initializer was a string of length 1, resulting in a premature NUL character to get placed into the fully expanded string, causing - afaict - truncation of the intended message. I therefore think the default string should be e.g. "? ".

Jan

#14 lore raw

Re: [PATCH 6/8] xen/x86: Avoid overriding initialisers in arrays

Quoted 50 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 09.02.16 at 21:01, <[email protected]> wrote:

Clang objects to having multiple initialisers when creating an array.

As this warning is useful for spotting obscure bugs, disabling it is unhelpful. Instead, fix our two deliberate usecases.

Ugly again, but - well ...

Quoted 8 lines
xen/arch/x86/mm/p2m-ept.c +2 -0
@@ -1201,6 +1201,20 @@ void ept_p2m_uninit(struct p2m_domain *p2m)
     free_cpumask_var(ept->invalidate);
 }
 
+static const char *memory_type_to_str(unsigned int x)
+{

xen/arch/x86/mm/p2m-ept.c void ept_p2m_uninit(struct p2m_domain *p2m) · line 1215

Quoted 10 lines
xen/arch/x86/mm/p2m-ept.c +10 -0
+    static const char memory_types[8][2] = {
+        [MTRR_TYPE_UNCACHABLE]     = "UC",
+        [MTRR_TYPE_WRCOMB]         = "WC",
+        [MTRR_TYPE_WRTHROUGH]      = "WT",
+        [MTRR_TYPE_WRPROT]         = "WP",
+        [MTRR_TYPE_WRBACK]         = "WB",
+        [MTRR_NUM_TYPES]           = "??"
+    };
+
+    return x < ARRAY_SIZE(memory_types) ? (memory_types[x] ?: "?") : "?";

I think this should really ASSERT() the first condition.

Quoted 23 lines
xen/arch/x86/mm/p2m-ept.c +1 -11
@@ -1212,15 +1226,6 @@ static void ept_dump_p2m_table(unsigned char key)
     unsigned long record_counter = 0;
     struct p2m_domain *p2m;
     struct ept_data *ept;
-    static const char memory_types[8][2] = {
-        [0 ... 7] = "?",
-        [MTRR_TYPE_UNCACHABLE]     = "UC",
-        [MTRR_TYPE_WRCOMB]         = "WC",
-        [MTRR_TYPE_WRTHROUGH]      = "WT",
-        [MTRR_TYPE_WRPROT]         = "WP",
-        [MTRR_TYPE_WRBACK]         = "WB",
-        [MTRR_NUM_TYPES]           = "??"
-    };
 
     for_each_domain(d)
     {
@@ -1260,8 +1265,8 @@ static void ept_dump_p2m_table(unsigned char key)
                            ept_entry->r ? 'r' : ' ',
                            ept_entry->w ? 'w' : ' ',
                            ept_entry->x ? 'x' : ' ',
-                           memory_types[ept_entry->emt][0],
-                           memory_types[ept_entry->emt][1]
+                           memory_type_to_str(ept_entry->emt)[0],
Quoted 8 lines

xen/arch/x86/mm/p2m-ept.c static void ept_dump_p2m_table(unsigned char key) · line 1271

Quoted 3 lines
xen/arch/x86/mm/p2m-ept.c +1 -0
+                           memory_type_to_str(ept_entry->emt)[1]
                            ?: ept_entry->emt + '0',
                            c ?: ept_entry->ipat ? '!' : ' ');

There's actually a bug here, which I think is worth fixing at once:
The default initializer was a string of length 1, resulting in a premature NUL character to get placed into the fully expanded string, causing - afaict - truncation of the intended message. I therefore think the default string should be e.g. "? ".

The code is very opaque. However, that appears to be precisely how it is intended to work. (Having said that - it is your code from c/s 90e9c95f).

The following line will only format the raw emt value as a number if there is a NUL character returned from memory_type_to_str(). Putting a space in instead would break this.

~Andrew

#15 lore raw

Re: [PATCH 6/8] xen/x86: Avoid overriding initialisers in arrays

Quoted 61 lines
Quoted 1 line
Quoted 1 line · On 10.02.16 at 14:50, <[email protected]> wrote:
Quoted 50 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 09.02.16 at 21:01, <[email protected]> wrote:

Clang objects to having multiple initialisers when creating an array.

As this warning is useful for spotting obscure bugs, disabling it is unhelpful. Instead, fix our two deliberate usecases.

Ugly again, but - well ...

Quoted 8 lines
xen/arch/x86/mm/p2m-ept.c +2 -0
@@ -1201,6 +1201,20 @@ void ept_p2m_uninit(struct p2m_domain *p2m)
     free_cpumask_var(ept->invalidate);
 }
 
+static const char *memory_type_to_str(unsigned int x)
+{

xen/arch/x86/mm/p2m-ept.c void ept_p2m_uninit(struct p2m_domain *p2m) · line 1215

Quoted 10 lines
xen/arch/x86/mm/p2m-ept.c +10 -0
+    static const char memory_types[8][2] = {
+        [MTRR_TYPE_UNCACHABLE]     = "UC",
+        [MTRR_TYPE_WRCOMB]         = "WC",
+        [MTRR_TYPE_WRTHROUGH]      = "WT",
+        [MTRR_TYPE_WRPROT]         = "WP",
+        [MTRR_TYPE_WRBACK]         = "WB",
+        [MTRR_NUM_TYPES]           = "??"
+    };
+
+    return x < ARRAY_SIZE(memory_types) ? (memory_types[x] ?: "?") : "?";

I think this should really ASSERT() the first condition.

Quoted 23 lines
xen/arch/x86/mm/p2m-ept.c +1 -11
@@ -1212,15 +1226,6 @@ static void ept_dump_p2m_table(unsigned char key)
     unsigned long record_counter = 0;
     struct p2m_domain *p2m;
     struct ept_data *ept;
-    static const char memory_types[8][2] = {
-        [0 ... 7] = "?",
-        [MTRR_TYPE_UNCACHABLE]     = "UC",
-        [MTRR_TYPE_WRCOMB]         = "WC",
-        [MTRR_TYPE_WRTHROUGH]      = "WT",
-        [MTRR_TYPE_WRPROT]         = "WP",
-        [MTRR_TYPE_WRBACK]         = "WB",
-        [MTRR_NUM_TYPES]           = "??"
-    };
 
     for_each_domain(d)
     {
@@ -1260,8 +1265,8 @@ static void ept_dump_p2m_table(unsigned char key)
                            ept_entry->r ? 'r' : ' ',
                            ept_entry->w ? 'w' : ' ',
                            ept_entry->x ? 'x' : ' ',
-                           memory_types[ept_entry->emt][0],
-                           memory_types[ept_entry->emt][1]
+                           memory_type_to_str(ept_entry->emt)[0],
Quoted 8 lines

xen/arch/x86/mm/p2m-ept.c static void ept_dump_p2m_table(unsigned char key) · line 1271

Quoted 3 lines
xen/arch/x86/mm/p2m-ept.c +1 -0
+                           memory_type_to_str(ept_entry->emt)[1]
                            ?: ept_entry->emt + '0',
                            c ?: ept_entry->ipat ? '!' : ' ');

There's actually a bug here, which I think is worth fixing at once:
The default initializer was a string of length 1, resulting in a premature NUL character to get placed into the fully expanded string, causing - afaict - truncation of the intended message. I therefore think the default string should be e.g. "? ".

Quoted 3 lines

The code is very opaque. However, that appears to be precisely how it is intended to work. (Having said that - it is your code from c/s 90e9c95f).

I know.

Quoted 3 lines

The following line will only format the raw emt value as a number if there is a NUL character returned from memory_type_to_str(). Putting a space in instead would break this.

Oh, right - this is the operand to a ?:, not by itself passed to printk(). Line breaks like this (to aid people with old editors) are really undesirable in places like this...

Sorry for the noise,

Jan

#16 lore raw

Re: [PATCH 6/8] xen/x86: Avoid overriding initialisers in arrays

Quoted 67 lines · Jan Beulich
Quoted 61 lines
Quoted 1 line
Quoted 1 line · On 10.02.16 at 14:50, <[email protected]> wrote:
Quoted 50 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 09.02.16 at 21:01, <[email protected]> wrote:

Clang objects to having multiple initialisers when creating an array.

As this warning is useful for spotting obscure bugs, disabling it is unhelpful. Instead, fix our two deliberate usecases.

Ugly again, but - well ...

Quoted 8 lines
xen/arch/x86/mm/p2m-ept.c +2 -0
@@ -1201,6 +1201,20 @@ void ept_p2m_uninit(struct p2m_domain *p2m)
     free_cpumask_var(ept->invalidate);
 }
 
+static const char *memory_type_to_str(unsigned int x)
+{

xen/arch/x86/mm/p2m-ept.c void ept_p2m_uninit(struct p2m_domain *p2m) · line 1215

Quoted 10 lines
xen/arch/x86/mm/p2m-ept.c +10 -0
+    static const char memory_types[8][2] = {
+        [MTRR_TYPE_UNCACHABLE]     = "UC",
+        [MTRR_TYPE_WRCOMB]         = "WC",
+        [MTRR_TYPE_WRTHROUGH]      = "WT",
+        [MTRR_TYPE_WRPROT]         = "WP",
+        [MTRR_TYPE_WRBACK]         = "WB",
+        [MTRR_NUM_TYPES]           = "??"
+    };
+
+    return x < ARRAY_SIZE(memory_types) ? (memory_types[x] ?: "?") : "?";

I think this should really ASSERT() the first condition.

Quoted 23 lines
xen/arch/x86/mm/p2m-ept.c +1 -11
@@ -1212,15 +1226,6 @@ static void ept_dump_p2m_table(unsigned char key)
     unsigned long record_counter = 0;
     struct p2m_domain *p2m;
     struct ept_data *ept;
-    static const char memory_types[8][2] = {
-        [0 ... 7] = "?",
-        [MTRR_TYPE_UNCACHABLE]     = "UC",
-        [MTRR_TYPE_WRCOMB]         = "WC",
-        [MTRR_TYPE_WRTHROUGH]      = "WT",
-        [MTRR_TYPE_WRPROT]         = "WP",
-        [MTRR_TYPE_WRBACK]         = "WB",
-        [MTRR_NUM_TYPES]           = "??"
-    };
 
     for_each_domain(d)
     {
@@ -1260,8 +1265,8 @@ static void ept_dump_p2m_table(unsigned char key)
                            ept_entry->r ? 'r' : ' ',
                            ept_entry->w ? 'w' : ' ',
                            ept_entry->x ? 'x' : ' ',
-                           memory_types[ept_entry->emt][0],
-                           memory_types[ept_entry->emt][1]
+                           memory_type_to_str(ept_entry->emt)[0],
Quoted 8 lines

xen/arch/x86/mm/p2m-ept.c static void ept_dump_p2m_table(unsigned char key) · line 1271

Quoted 3 lines
xen/arch/x86/mm/p2m-ept.c +1 -0
+                           memory_type_to_str(ept_entry->emt)[1]
                            ?: ept_entry->emt + '0',
                            c ?: ept_entry->ipat ? '!' : ' ');

There's actually a bug here, which I think is worth fixing at once:
The default initializer was a string of length 1, resulting in a premature NUL character to get placed into the fully expanded string, causing - afaict - truncation of the intended message. I therefore think the default string should be e.g. "? ".

Quoted 3 lines

The code is very opaque. However, that appears to be precisely how it is intended to work. (Having said that - it is your code from c/s 90e9c95f).

I know.

Quoted 7 lines
Quoted 3 lines

The following line will only format the raw emt value as a number if there is a NUL character returned from memory_type_to_str(). Putting a space in instead would break this.

Oh, right - this is the operand to a ?:, not by itself passed to printk(). Line breaks like this (to aid people with old editors) are really undesirable in places like this...

Even more so over-clever undocumented code. If you're going to do things like this, you need to leave a comment near the string definition saying that the second byte being NULL is a flag for the printing routine to print the number, so that people who come along later (maybe even yourself, as in this case) know there's a dependency there.

-George

Acked-by on v1 6/8
#17 lore raw

Re: [PATCH 6/8] xen/x86: Avoid overriding initialisers in arrays

In reply to Andrew Cooper
Quoted 8 lines

From: Andrew Cooper [mailto:[email protected]]
Sent: Wednesday, February 10, 2016 4:02 AM

Clang objects to having multiple initialisers when creating an array.

As this warning is useful for spotting obscure bugs, disabling it is unhelpful. Instead, fix our two deliberate usecases.

Quoted 6 lines

In the p2m-ept case, pull the array out into a helper function, so the helper can guarentee to cover the NULL pointer case.

No functional change.

#18 lore raw

PATCH 7/8 xen/x86: Fix get_cpu_info() when built with clang

In reply to Andrew Cooper

Clang understands the GCCism in use here, but still complains that sp is unintialised. In such cases, resort to the older version of this code, which directly reads %rsp into the temporary variable.

Note that we still keep the GCCism in the default case, as it causes GCC to create rather better assembly.

---
CC: Jan Beulich <[email protected]>

---
 xen/include/asm-x86/current.h | 6 ++++++
 1 file changed, 6 insertions(+)
xen/include/asm-x86/current.h +6 -0
index f011d2d..15b99ff 100644
@@ -47,7 +47,13 @@ struct cpu_info {
 
 static inline struct cpu_info *get_cpu_info(void)
 {
+#ifdef __clang__
+    /* Clang complains that sp in the else case is not initialised. */
+    unsigned long sp;
+    asm ( "mov %%rsp, %0" : "=r" (sp) );
+#else
     register unsigned long sp asm("rsp");
+#endif
 
     return (struct cpu_info *)((sp & ~(STACK_SIZE-1)) + STACK_SIZE) - 1;
 }
Signature · 1 line
2.1.4
#19 lore raw

PATCH 8/8 x86/efi: Generate uefi_call_wrapper() when compiling with clang

In reply to Andrew Cooper

---
CC: Jan Beulich <[email protected]>

What is the GCC version check supposed to be achieving here? GCC has supported this syntax since 3.0

---
 xen/include/asm-x86/x86_64/efibind.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/include/asm-x86/x86_64/efibind.h +1 -1
index 2db3568..af5f424 100644
@@ -274,7 +274,7 @@ typedef uint64_t   UINTN;
 #endif
 #endif
 
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) || __clang__
 #define uefi_call_wrapper(func, va_num, ...)	func(__VA_ARGS__)
 #else
 /* for x86_64, EFI_FUNCTION_WRAPPER must be defined */
Signature · 1 line
2.1.4
#20 lore raw

Re: [PATCH 8/8] x86/efi: Generate uefi_call_wrapper() when compiling with clang

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 09.02.16 at 21:01, <[email protected]> wrote:

---
CC: Jan Beulich <[email protected]>

What is the GCC version check supposed to be achieving here? GCC has supported this syntax since 3.0

This is best answered by looking at where we've got these headers from - the gnu-efi package. It has ...

xen/include/asm-x86/x86_64/efibind.h typedef uint64_t UINTN; · line 280

Quoted 11 lines
xen/include/asm-x86/x86_64/efibind.h +1 -1
@@ -274,7 +274,7 @@ typedef uint64_t   UINTN;
 #endif
 #endif
 
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) || __clang__
 #define uefi_call_wrapper(func, va_num, ...)	func(__VA_ARGS__)
 #else
 /* for x86_64, EFI_FUNCTION_WRAPPER must be defined */

/* for x86_64, EFI_FUNCTION_WRAPPER must be defined */ #if defined(HAVE_USE_MS_ABI)
#define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__) #else
UINTN uefi_call_wrapper(void *func, unsigned long va_num, ...); #endif
#define EFI_FUNCTION __attribute__((ms_abi))

I think this makes clear that the needed feature here is the attribute, which certainly wasn't available in older gcc.

With that the question is whether the Clang case won't also need a version check, since I can't imagine them having supported this prior to gcc introducing it.

Jan

#21 lore raw

Re: [PATCH 8/8] x86/efi: Generate uefi_call_wrapper() when compiling with clang

Quoted 29 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 09.02.16 at 21:01, <[email protected]> wrote:

---
CC: Jan Beulich <[email protected]>

What is the GCC version check supposed to be achieving here? GCC has supported this syntax since 3.0

This is best answered by looking at where we've got these headers from - the gnu-efi package. It has ...

xen/include/asm-x86/x86_64/efibind.h typedef uint64_t UINTN; · line 280

Quoted 11 lines
xen/include/asm-x86/x86_64/efibind.h +1 -1
@@ -274,7 +274,7 @@ typedef uint64_t   UINTN;
 #endif
 #endif
 
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) || __clang__
 #define uefi_call_wrapper(func, va_num, ...)	func(__VA_ARGS__)
 #else
 /* for x86_64, EFI_FUNCTION_WRAPPER must be defined */

/* for x86_64, EFI_FUNCTION_WRAPPER must be defined */ #if defined(HAVE_USE_MS_ABI)
#define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__) #else
UINTN uefi_call_wrapper(void *func, unsigned long va_num, ...); #endif
#define EFI_FUNCTION __attribute__((ms_abi))

Quoted 6 lines

I think this makes clear that the needed feature here is the attribute, which certainly wasn't available in older gcc.

With that the question is whether the Clang case won't also need a version check, since I can't imagine them having supported this prior to gcc introducing it.

Clang has an substantially more sane way than GCC of checking for individual features. I will introduce and use the __has_{attribute,feature}() infrastructure to tests like this.

Experimentally, Clang 3.5 does have ms_abi support

~Andrew

#22 lore raw

Re: [PATCH 8/8] x86/efi: Generate uefi_call_wrapper() when compiling with clang

Quoted 33 lines · Andrew Cooper
Quoted 32 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 09.02.16 at 21:01, <[email protected]> wrote:

---
CC: Jan Beulich <[email protected]>

What is the GCC version check supposed to be achieving here? GCC has supported this syntax since 3.0

This is best answered by looking at where we've got these headers from - the gnu-efi package. It has ...

xen/include/asm-x86/x86_64/efibind.h typedef uint64_t UINTN; · line 280

Quoted 11 lines
xen/include/asm-x86/x86_64/efibind.h +1 -1
@@ -274,7 +274,7 @@ typedef uint64_t   UINTN;
 #endif
 #endif
 
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) || __clang__
 #define uefi_call_wrapper(func, va_num, ...)	func(__VA_ARGS__)
 #else
 /* for x86_64, EFI_FUNCTION_WRAPPER must be defined */

/* for x86_64, EFI_FUNCTION_WRAPPER must be defined */ #if defined(HAVE_USE_MS_ABI)
#define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__) #else
UINTN uefi_call_wrapper(void *func, unsigned long va_num, ...); #endif
#define EFI_FUNCTION __attribute__((ms_abi))

I think this makes clear that the needed feature here is the attribute, which certainly wasn't available in older gcc.

Quoted 8 lines
Quoted 3 lines

With that the question is whether the Clang case won't also need a version check, since I can't imagine them having supported this prior to gcc introducing it.

Clang has an substantially more sane way than GCC of checking for individual features. I will introduce and use the __has_{attribute,feature}() infrastructure to tests like this.

Experimentally, Clang 3.5 does have ms_abi support

Looking at it further, this entire block is unsed. Nothing in tree refers to uefi_call_wrapper() or EFI_FUNCTION_WRAPPER other than this small bit; all declarations use EFIABI directly.

i.e. this:

(quoted diff) +0 -0

b/xen/include/asm-x86/x86_64/efibind.h
index af5f424..b013db1 100644

xen/include/asm-x86/x86_64/efibind.h +0 -11
@@ -274,17 +274,6 @@ typedef uint64_t   UINTN;
 #endif
 #endif
 
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
-#define uefi_call_wrapper(func, va_num, ...)   func(__VA_ARGS__)
-#else
-/* for x86_64, EFI_FUNCTION_WRAPPER must be defined */
-#ifdef  EFI_FUNCTION_WRAPPER
-UINTN uefi_call_wrapper(void *func, unsigned long va_num, ...);
-#else
-#error "EFI_FUNCTION_WRAPPER must be defined for x86_64 architecture"
-#endif
-#endif
-
 #ifdef _MSC_EXTENSIONS
 #pragma warning ( disable : 4731 )  // Suppress warnings about

modification of EBP
#endif

works correctly for GCC and clang. Would dropping this completely be acceptable?

~Andrew

#23 lore raw

Re: [PATCH 8/8] x86/efi: Generate uefi_call_wrapper() when compiling with clang

Quoted 75 lines
Quoted 1 line
Quoted 1 line · On 10.02.16 at 20:11, <[email protected]> wrote:
Quoted 33 lines · Andrew Cooper
Quoted 32 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 09.02.16 at 21:01, <[email protected]> wrote:

---
CC: Jan Beulich <[email protected]>

What is the GCC version check supposed to be achieving here? GCC has supported this syntax since 3.0

This is best answered by looking at where we've got these headers from - the gnu-efi package. It has ...

xen/include/asm-x86/x86_64/efibind.h typedef uint64_t UINTN; · line 280

Quoted 11 lines
xen/include/asm-x86/x86_64/efibind.h +1 -1
@@ -274,7 +274,7 @@ typedef uint64_t   UINTN;
 #endif
 #endif
 
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) || __clang__
 #define uefi_call_wrapper(func, va_num, ...)	func(__VA_ARGS__)
 #else
 /* for x86_64, EFI_FUNCTION_WRAPPER must be defined */

/* for x86_64, EFI_FUNCTION_WRAPPER must be defined */ #if defined(HAVE_USE_MS_ABI)
#define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__) #else
UINTN uefi_call_wrapper(void *func, unsigned long va_num, ...); #endif
#define EFI_FUNCTION __attribute__((ms_abi))

I think this makes clear that the needed feature here is the attribute, which certainly wasn't available in older gcc.

Quoted 8 lines
Quoted 3 lines

With that the question is whether the Clang case won't also need a version check, since I can't imagine them having supported this prior to gcc introducing it.

Clang has an substantially more sane way than GCC of checking for individual features. I will introduce and use the __has_{attribute,feature}() infrastructure to tests like this.

Experimentally, Clang 3.5 does have ms_abi support

Looking at it further, this entire block is unsed. Nothing in tree refers to uefi_call_wrapper() or EFI_FUNCTION_WRAPPER other than this small bit; all declarations use EFIABI directly.

i.e. this:

xen/include/asm-x86/x86_64/efibind.h +0 -11
index af5f424..b013db1 100644
@@ -274,17 +274,6 @@ typedef uint64_t   UINTN;
 #endif
 #endif
 
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
-#define uefi_call_wrapper(func, va_num, ...)   func(__VA_ARGS__)
-#else
-/* for x86_64, EFI_FUNCTION_WRAPPER must be defined */
-#ifdef  EFI_FUNCTION_WRAPPER
-UINTN uefi_call_wrapper(void *func, unsigned long va_num, ...);
-#else
-#error "EFI_FUNCTION_WRAPPER must be defined for x86_64 architecture"
-#endif
-#endif
-
 #ifdef _MSC_EXTENSIONS
 #pragma warning ( disable : 4731 )  // Suppress warnings about

modification of EBP
#endif

Quoted 2 lines

works correctly for GCC and clang. Would dropping this completely be acceptable?

We perhaps might as well; I had mainly kept it to stay as close to the original header as possible (without leaving around a latent build breakage).

Jan

#25 lore raw
In reply to Andrew Cooper
Quoted 1 line · Andrew Cooper

This is a misc assortment of patches to fix the build with Clang 3.5.

FWIW clang 3.5 appears to be in Debian Jessie, which means the path to having a build job in osstest is far shorter than it once was if anyone is interested in adding such a thing.

Ian.