Skip to contentSkip to conversation

Allow building xen with clang/llvm

PATCH In review Tim Deegan 6 participants 28 messages Mar 7, 2011 – Mar 8, 2011

lore
Share & tools
lore

Tim Deegan

author
#0 lore raw

PATCH 1/1 Allow building xen with clang/llvm

This series of patches allows Xen builds with clang/llvm as well as GCC. It only fixes Xen, not tools &c, and only 64-bit, so far.

Building Xen with clang isn't useful in itself (and indeed produces a hypervisor that can be up to 10% slower for a default -O2 build); rather it's a stepping-stone to doing full link-time optimizations on the LLVM bitcode of the whole hypervisor. I will post a second series to enable that, but it's not so clean as this one.

I think all the changes in this series are reasonable and won't inconvenience any normal users, but obviously they're meant for the xen-unstable tree only.

Cheers,

Tim.

author
#1 lore raw

PATCH 1/1 x86: make spinlock's 16-bit asm operand explicitly 16-bit

This is needed to compile xen with clang.

# HG changeset patch
# User Tim Deegan <[email protected]>
# Date 1299496871 0
# Node ID c574ec6f7c8633397804aee7c96f428779688ce9 # Parent bbc03993d31f5b9c56c44b068cdd00f08971c21c
x86: make spinlock's 16-bit asm operand explicitly 16-bit. This is needed to compile xen with clang.

xen/include/asm-x86/spinlock.h +1 -1
diff -r bbc03993d31f -r c574ec6f7c86 xen/include/asm-x86/spinlock.h
@@ -27,7 +27,7 @@ static always_inline int _raw_spin_trylo
     asm volatile (
         "xchgw %w0,%1"
         :"=r" (oldval), "=m" (lock->lock)
-        :"0" (0) : "memory" );
+        :"0" ((s16)0) : "memory" );
     return (oldval > 0);
 }
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

author
#2 lore raw

PATCH 1/1 x86: add explicit size suffixes to some assembly instructions

In reply to Tim Deegan

This is needed to compile xen with clang.

# HG changeset patch
# User Tim Deegan <[email protected]>
# Date 1299496871 0
# Node ID b7eaf2bcdca1307bf4eca8aac353d0f26076633b
# Parent c574ec6f7c8633397804aee7c96f428779688ce9
x86: add explicit size suffixes to some assembly instructions. This is needed to compile xen with clang.

xen/arch/x86/acpi/suspend.c +2 -2
diff -r c574ec6f7c86 -r b7eaf2bcdca1 xen/arch/x86/acpi/suspend.c
@@ -28,7 +28,7 @@ void save_rest_processor_state(void)
 
 #if defined(CONFIG_X86_64)
     asm volatile (
-        "mov %%ds,(%0); mov %%es,2(%0); mov %%fs,4(%0); mov %%gs,6(%0)"
+        "movw %%ds,(%0); movw %%es,2(%0); movw %%fs,4(%0); movw %%gs,6(%0)"
         : : "r" (saved_segs) : "memory" );
     rdmsrl(MSR_FS_BASE, saved_fs_base);
     rdmsrl(MSR_GS_BASE, saved_gs_base);
@@ -75,7 +75,7 @@ void restore_rest_processor_state(void)
     if ( !is_idle_vcpu(curr) )
     {
         asm volatile (
-            "mov (%0),%%ds; mov 2(%0),%%es; mov 4(%0),%%fs"
+            "movw (%0),%%ds; movw 2(%0),%%es; movw 4(%0),%%fs"
             : : "r" (saved_segs) : "memory" );
         do_set_segment_base(SEGBASE_GS_USER_SEL, saved_segs[3]);
     }
xen/arch/x86/x86_emulate/x86_emulate.c +13 -13
diff -r c574ec6f7c86 -r b7eaf2bcdca1 xen/arch/x86/x86_emulate/x86_emulate.c
@@ -2678,7 +2678,7 @@ x86_emulate(
                 emulate_fpu_insn_memsrc("fiaddl", src.val);
                 break;
             case 1: /* fimul m64i */
-                emulate_fpu_insn_memsrc("fimul", src.val);
+                emulate_fpu_insn_memsrc("fimuls", src.val);
                 break;
             case 2: /* ficom m64i */
                 emulate_fpu_insn_memsrc("ficoml", src.val);
@@ -2897,28 +2897,28 @@ x86_emulate(
             switch ( modrm_reg & 7 )
             {
             case 0: /* fiadd m16i */
-                emulate_fpu_insn_memsrc("fiadd", src.val);
+                emulate_fpu_insn_memsrc("fiadds", src.val);
                 break;
             case 1: /* fimul m16i */
-                emulate_fpu_insn_memsrc("fimul", src.val);
+                emulate_fpu_insn_memsrc("fimuls", src.val);
                 break;
             case 2: /* ficom m16i */
-                emulate_fpu_insn_memsrc("ficom", src.val);
+                emulate_fpu_insn_memsrc("ficoms", src.val);
                 break;
             case 3: /* ficomp m16i */
-                emulate_fpu_insn_memsrc("ficomp", src.val);
+                emulate_fpu_insn_memsrc("ficomps", src.val);
                 break;
             case 4: /* fisub m16i */
-                emulate_fpu_insn_memsrc("fisub", src.val);
+                emulate_fpu_insn_memsrc("fisubs", src.val);
                 break;
             case 5: /* fisubr m16i */
-                emulate_fpu_insn_memsrc("fisubr", src.val);
+                emulate_fpu_insn_memsrc("fisubrs", src.val);
                 break;
             case 6: /* fidiv m16i */
-                emulate_fpu_insn_memsrc("fidiv", src.val);
+                emulate_fpu_insn_memsrc("fidivs", src.val);
                 break;
             case 7: /* fidivr m16i */
-                emulate_fpu_insn_memsrc("fidivr", src.val);
+                emulate_fpu_insn_memsrc("fidivrs", src.val);
                 break;
             default:
                 goto cannot_emulate;
@@ -2950,25 +2950,25 @@ x86_emulate(
                 if ( (rc = ops->read(src.mem.seg, src.mem.off, &src.val,
                                      src.bytes, ctxt)) != 0 )
                     goto done;
-                emulate_fpu_insn_memsrc("fild", src.val);
+                emulate_fpu_insn_memsrc("filds", src.val);
                 break;
             case 1: /* fisttp m16i */
                 ea.bytes = 2;
                 dst = ea;
                 dst.type = OP_MEM;
-                emulate_fpu_insn_memdst("fisttp", dst.val);
+                emulate_fpu_insn_memdst("fisttps", dst.val);
                 break;
             case 2: /* fist m16i */
                 ea.bytes = 2;
                 dst = ea;
                 dst.type = OP_MEM;
-                emulate_fpu_insn_memdst("fist", dst.val);
+                emulate_fpu_insn_memdst("fists", dst.val);
                 break;
             case 3: /* fistp m16i */
                 ea.bytes = 2;
                 dst = ea;
                 dst.type = OP_MEM;
-                emulate_fpu_insn_memdst("fistp", dst.val);
+                emulate_fpu_insn_memdst("fistps", dst.val);
                 break;
             case 4: /* fbld m80dec */
                 ea.bytes = 10;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

author
#7 lore raw

PATCH 1/1 x86: redefine a few empty macros as explicit nops

In reply to Tim Deegan

This is needed to compile xen with clang.

# HG changeset patch
# User Tim Deegan <[email protected]> # Date 1299496871 0
# Node ID 692a97ea255e8150f088cb9e71f32fd9f9825e06 # Parent b7eaf2bcdca1307bf4eca8aac353d0f26076633b
x86: redefine a few empty macros as explicit nops. This is needed to compile xen with clang.

xen/include/asm-x86/apic.h +1 -1
diff -r b7eaf2bcdca1 -r 692a97ea255e xen/include/asm-x86/apic.h
@@ -6,7 +6,7 @@
 #include <asm/fixmap.h>
 #include <asm/msr.h>
 
-#define Dprintk(x...)
+#define Dprintk(x...) do {} while (0)
 
 /*
  * Debugging macros
xen/include/asm-x86/hvm/support.h +1 -1
diff -r b7eaf2bcdca1 -r 692a97ea255e xen/include/asm-x86/hvm/support.h
@@ -61,7 +61,7 @@ extern unsigned int opt_hvm_debug_level;
                    ## _a);                                                    \
     } while (0)
 #else
-#define HVM_DBG_LOG(level, _f, _a...)
+#define HVM_DBG_LOG(level, _f, _a...) do {} while (0)
 #endif
 
 extern unsigned long hvm_io_bitmap[];

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

author
#8 lore raw

PATCH 1/1 xen: adjust cpumask initializers to suit clang's incomplete gccisms

In reply to Tim Deegan

This is needed to compile xen with clang.

# HG changeset patch
# User Tim Deegan <[email protected]>
# Date 1299496871 0
# Node ID fed25f206a372891b7a0f1368592e25eda479788
# Parent 692a97ea255e8150f088cb9e71f32fd9f9825e06
xen: adjust cpumask initializers to suit clang's incomplete gccisms. This is needed to compile xen with clang.

xen/arch/x86/io_apic.c +2 -1
diff -r 692a97ea255e -r fed25f206a37 xen/arch/x86/io_apic.c
@@ -1907,6 +1907,7 @@ static void __init check_timer(void)
     int apic1, pin1, apic2, pin2;
     int vector, ret;
     unsigned long flags;
+    cpumask_t mask_all = CPU_MASK_ALL;
 
     local_irq_save(flags);
 
@@ -1917,7 +1918,7 @@ static void __init check_timer(void)
     vector = FIRST_HIPRIORITY_VECTOR;
     clear_irq_vector(0);
 
-    if ((ret = bind_irq_vector(0, vector, (cpumask_t)CPU_MASK_ALL)))
+    if ((ret = bind_irq_vector(0, vector, mask_all)))
         printk(KERN_ERR"..IRQ0 is not set correctly with ioapic!!!, err:%d\n", ret);
     
     irq_desc[0].depth  = 0;
xen/include/xen/cpumask.h +1 -1
diff -r 692a97ea255e -r fed25f206a37 xen/include/xen/cpumask.h
@@ -296,7 +296,7 @@ static inline const cpumask_t *cpumask_o
 
 #define CPU_MASK_NONE							\
 /*(cpumask_t)*/ { {							\
-	[0 ... BITS_TO_LONGS(NR_CPUS)-1] =  0UL				\
+	0UL								\
 } }
 
 #define CPU_MASK_CPU0							\

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

author
#9 lore raw

PATCH 1/1 credit2: remove two nested functions, replacing them with static ones

In reply to Tim Deegan

and passing the outer scope's variables in explicitly. This is needed to compile xen with clang.

# HG changeset patch
# User Tim Deegan <[email protected]>
# Date 1299496871 0
# Node ID c72c074d0e084dcabb5314ac71e3b7730898c764
# Parent fed25f206a372891b7a0f1368592e25eda479788
credit2: remove two nested functions, replacing them with static ones and passing the outer scope's variables in explicitly. This is needed to compile xen with clang.

xen/common/sched_credit2.c +117 -107
diff -r fed25f206a37 -r c72c074d0e08 xen/common/sched_credit2.c
@@ -1109,86 +1109,96 @@ out_up:
     return new_cpu;
 }
 
+/* Working state of the load-balancing algorithm */
+typedef struct {
+    /* NB: Modified by consider() */
+    s_time_t load_delta;
+    struct csched_vcpu * best_push_svc, *best_pull_svc;
+    /* NB: Read by consider() */
+    struct csched_runqueue_data *lrqd;
+    struct csched_runqueue_data *orqd;                  
+} balance_state_t;
+
+static void consider(balance_state_t *st, 
+                     struct csched_vcpu *push_svc,
+                     struct csched_vcpu *pull_svc)
+{
+    s_time_t l_load, o_load, delta;
+
+    l_load = st->lrqd->b_avgload;
+    o_load = st->orqd->b_avgload;
+    if ( push_svc )
+    {
+        /* What happens to the load on both if we push? */
+        l_load -= push_svc->avgload;
+        o_load += push_svc->avgload;
+    }
+    if ( pull_svc )
+    {
+        /* What happens to the load on both if we pull? */
+        l_load += pull_svc->avgload;
+        o_load -= pull_svc->avgload;
+    }
+
+    delta = l_load - o_load;
+    if ( delta < 0 )
+        delta = -delta;
+
+    if ( delta < st->load_delta )
+    {
+        st->load_delta = delta;
+        st->best_push_svc=push_svc;
+        st->best_pull_svc=pull_svc;
+    }
+}
+
+
+void migrate(const struct scheduler *ops,
+             struct csched_vcpu *svc, 
+             struct csched_runqueue_data *trqd, 
+             s_time_t now)
+{
+    if ( test_bit(__CSFLAG_scheduled, &svc->flags) )
+    {
+        d2printk("d%dv%d %d-%d a\n", svc->vcpu->domain->domain_id, svc->vcpu->vcpu_id,
+                 svc->rqd->id, trqd->id);
+        /* It's running; mark it to migrate. */
+        svc->migrate_rqd = trqd;
+        set_bit(_VPF_migrating, &svc->vcpu->pause_flags);
+        set_bit(__CSFLAG_runq_migrate_request, &svc->flags);
+    }
+    else
+    {
+        int on_runq=0;
+        /* It's not running; just move it */
+        d2printk("d%dv%d %d-%d i\n", svc->vcpu->domain->domain_id, svc->vcpu->vcpu_id,
+                 svc->rqd->id, trqd->id);
+        if ( __vcpu_on_runq(svc) )
+        {
+            __runq_remove(svc);
+            update_load(ops, svc->rqd, svc, -1, now);
+            on_runq=1;
+        }
+        __runq_deassign(svc);
+        svc->vcpu->processor = first_cpu(trqd->active);
+        __runq_assign(svc, trqd);
+        if ( on_runq )
+        {
+            update_load(ops, svc->rqd, svc, 1, now);
+            runq_insert(ops, svc->vcpu->processor, svc);
+            runq_tickle(ops, svc->vcpu->processor, svc, now);
+        }
+    }
+}
+
+
 static void balance_load(const struct scheduler *ops, int cpu, s_time_t now)
 {
     struct csched_private *prv = CSCHED_PRIV(ops);
     int i, max_delta_rqi = -1;
     struct list_head *push_iter, *pull_iter;
 
-    /* NB: Modified by consider() */
-    s_time_t load_delta;
-    struct csched_vcpu * best_push_svc=NULL, *best_pull_svc=NULL;
-    /* NB: Read by consider() */
-    struct csched_runqueue_data *lrqd;
-    struct csched_runqueue_data *orqd;
-    
-    void consider(struct csched_vcpu *push_svc,
-                  struct csched_vcpu *pull_svc)
-    {
-        s_time_t l_load, o_load, delta;
-
-        l_load = lrqd->b_avgload;
-        o_load = orqd->b_avgload;
-        if ( push_svc )
-        {
-            /* What happens to the load on both if we push? */
-            l_load -= push_svc->avgload;
-            o_load += push_svc->avgload;
-        }
-        if ( pull_svc )
-        {
-            /* What happens to the load on both if we pull? */
-            l_load += pull_svc->avgload;
-            o_load -= pull_svc->avgload;
-        }
-        
-        delta = l_load - o_load;
-        if ( delta < 0 )
-            delta = -delta;
-
-        if ( delta < load_delta )
-        {
-            load_delta = delta;
-            best_push_svc=push_svc;
-            best_pull_svc=pull_svc;
-        }
-    }
-
-    void migrate(struct csched_vcpu *svc, struct csched_runqueue_data *trqd)
-    {
-        if ( test_bit(__CSFLAG_scheduled, &svc->flags) )
-        {
-            d2printk("d%dv%d %d-%d a\n", svc->vcpu->domain->domain_id, svc->vcpu->vcpu_id,
-                     svc->rqd->id, trqd->id);
-            /* It's running; mark it to migrate. */
-            svc->migrate_rqd = trqd;
-            set_bit(_VPF_migrating, &svc->vcpu->pause_flags);
-            set_bit(__CSFLAG_runq_migrate_request, &svc->flags);
-        }
-        else
-        {
-            int on_runq=0;
-            /* It's not running; just move it */
-            d2printk("d%dv%d %d-%d i\n", svc->vcpu->domain->domain_id, svc->vcpu->vcpu_id,
-                     svc->rqd->id, trqd->id);
-            if ( __vcpu_on_runq(svc) )
-            {
-                __runq_remove(svc);
-                update_load(ops, svc->rqd, svc, -1, now);
-                on_runq=1;
-            }
-            __runq_deassign(svc);
-            svc->vcpu->processor = first_cpu(trqd->active);
-            __runq_assign(svc, trqd);
-            if ( on_runq )
-            {
-                update_load(ops, svc->rqd, svc, 1, now);
-                runq_insert(ops, svc->vcpu->processor, svc);
-                runq_tickle(ops, svc->vcpu->processor, svc, now);
-            }
-        }
-    }
-                  
+    balance_state_t st = { .best_push_svc = NULL, .best_pull_svc = NULL };
     
     /*
      * Basic algorithm: Push, pull, or swap.
@@ -1200,39 +1210,39 @@ static void balance_load(const struct sc
     /* Locking:
      * - pcpu schedule lock should be already locked
      */
-    lrqd = RQD(ops, cpu);
+    st.lrqd = RQD(ops, cpu);
 
-    __update_runq_load(ops, lrqd, 0, now);
+    __update_runq_load(ops, st.lrqd, 0, now);
 
 retry:
     if ( !spin_trylock(&prv->lock) )
         return;
 
-    load_delta = 0;
+    st.load_delta = 0;
 
     for_each_cpu_mask(i, prv->active_queues)
     {
         s_time_t delta;
         
-        orqd = prv->rqd + i;
+        st.orqd = prv->rqd + i;
 
-        if ( orqd == lrqd
-             || !spin_trylock(&orqd->lock) )
+        if ( st.orqd == st.lrqd
+             || !spin_trylock(&st.orqd->lock) )
             continue;
 
-        __update_runq_load(ops, orqd, 0, now);
+        __update_runq_load(ops, st.orqd, 0, now);
     
-        delta = lrqd->b_avgload - orqd->b_avgload;
+        delta = st.lrqd->b_avgload - st.orqd->b_avgload;
         if ( delta < 0 )
             delta = -delta;
 
-        if ( delta > load_delta )
+        if ( delta > st.load_delta )
         {
-            load_delta = delta;
+            st.load_delta = delta;
             max_delta_rqi = i;
         }
 
-        spin_unlock(&orqd->lock);
+        spin_unlock(&st.orqd->lock);
     }
 
     /* Minimize holding the big lock */
@@ -1245,23 +1255,23 @@ retry:
         int cpus_max;
 
         
-        load_max = lrqd->b_avgload;
-        if ( orqd->b_avgload > load_max )
-            load_max = orqd->b_avgload;
+        load_max = st.lrqd->b_avgload;
+        if ( st.orqd->b_avgload > load_max )
+            load_max = st.orqd->b_avgload;
 
-        cpus_max=cpus_weight(lrqd->active);
-        if ( cpus_weight(orqd->active) > cpus_max )
-            cpus_max = cpus_weight(orqd->active);
+        cpus_max=cpus_weight(st.lrqd->active);
+        if ( cpus_weight(st.orqd->active) > cpus_max )
+            cpus_max = cpus_weight(st.orqd->active);
 
         /* If we're under 100% capacaty, only shift if load difference
          * is > 1.  otherwise, shift if under 12.5% */
         if ( load_max < (1ULL<<(prv->load_window_shift))*cpus_max )
         {
-            if ( load_delta < (1ULL<<(prv->load_window_shift+opt_underload_balance_tolerance) ) )
+            if ( st.load_delta < (1ULL<<(prv->load_window_shift+opt_underload_balance_tolerance) ) )
                  goto out;
         }
         else
-            if ( load_delta < (1ULL<<(prv->load_window_shift+opt_overload_balance_tolerance)) )
+            if ( st.load_delta < (1ULL<<(prv->load_window_shift+opt_overload_balance_tolerance)) )
                 goto out;
     }
              
@@ -1269,19 +1279,19 @@ retry:
      * meantime, try the process over again.  This can't deadlock
      * because if it doesn't get any other rqd locks, it will simply
      * give up and return. */
-    orqd = prv->rqd + max_delta_rqi;
-    if ( !spin_trylock(&orqd->lock) )
+    st.orqd = prv->rqd + max_delta_rqi;
+    if ( !spin_trylock(&st.orqd->lock) )
         goto retry;
 
     /* Make sure the runqueue hasn't been deactivated since we released prv->lock */
-    if ( unlikely(orqd->id < 0) )
+    if ( unlikely(st.orqd->id < 0) )
         goto out_up;
 
     /* Look for "swap" which gives the best load average
      * FIXME: O(n^2)! */
 
     /* Reuse load delta (as we're trying to minimize it) */
-    list_for_each( push_iter, &lrqd->svc )
+    list_for_each( push_iter, &st.lrqd->svc )
     {
         int inner_load_updated = 0;
         struct csched_vcpu * push_svc = list_entry(push_iter, struct csched_vcpu, rqd_elem);
@@ -1292,7 +1302,7 @@ retry:
         if ( test_bit(__CSFLAG_runq_migrate_request, &push_svc->flags) )
             continue;
 
-        list_for_each( pull_iter, &orqd->svc )
+        list_for_each( pull_iter, &st.orqd->svc )
         {
             struct csched_vcpu * pull_svc = list_entry(pull_iter, struct csched_vcpu, rqd_elem);
             
@@ -1305,16 +1315,16 @@ retry:
             if ( test_bit(__CSFLAG_runq_migrate_request, &pull_svc->flags) )
                 continue;
 
-            consider(push_svc, pull_svc);
+            consider(&st, push_svc, pull_svc);
         }
 
         inner_load_updated = 1;
 
         /* Consider push only */
-        consider(push_svc, NULL);
+        consider(&st, push_svc, NULL);
     }
 
-    list_for_each( pull_iter, &orqd->svc )
+    list_for_each( pull_iter, &st.orqd->svc )
     {
         struct csched_vcpu * pull_svc = list_entry(pull_iter, struct csched_vcpu, rqd_elem);
         
@@ -1323,17 +1333,17 @@ retry:
             continue;
 
         /* Consider pull only */
-        consider(NULL, pull_svc);
+        consider(&st, NULL, pull_svc);
     }
 
     /* OK, now we have some candidates; do the moving */
-    if ( best_push_svc )
-        migrate(best_push_svc, orqd);
-    if ( best_pull_svc )
-        migrate(best_pull_svc, lrqd);
+    if ( st.best_push_svc )
+        migrate(ops, st.best_push_svc, st.orqd, now);
+    if ( st.best_pull_svc )
+        migrate(ops, st.best_pull_svc, st.lrqd, now);
 
 out_up:
-    spin_unlock(&orqd->lock);
+    spin_unlock(&st.orqd->lock);
 
 out:
     return;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

author
#11 lore raw

PATCH 1/1 Xen: remove run_in_exception_handler() and recode its only caller

In reply to Tim Deegan

(dump_execution_state()) as its own bug-trap.

This is needed to compile xen with clang, which can't handle using a function name in an asm immediate.

# HG changeset patch
# User Tim Deegan <[email protected]>
# Date 1299496871 0
# Node ID 04783b003d5c5691930af6baa3614389247ddda1
# Parent c72c074d0e084dcabb5314ac71e3b7730898c764
Xen: remove run_in_exception_handler() and recode its only caller (dump_execution_state()) as its own bug-trap.

This is needed to compile xen with clang, which can't handle using a function name in an asm immediate.

xen/arch/x86/traps.c +9 -10
diff -r c72c074d0e08 -r 04783b003d5c xen/arch/x86/traps.c
@@ -907,6 +907,15 @@ asmlinkage void do_invalid_op(struct cpu
         goto die;
     eip += sizeof(bug);
 
+    id = bug.id & 3;
+
+    if ( id == BUGFRAME_state )
+    {
+        show_execution_state(regs);
+        regs->eip = (unsigned long)eip;
+        return;
+    }
+
     /* Decode first pointer argument. */
     if ( !is_kernel(eip) ||
          __copy_from_user(&bug_str, eip, sizeof(bug_str)) ||
@@ -917,16 +926,6 @@ asmlinkage void do_invalid_op(struct cpu
         goto die;
     eip += sizeof(bug_str);
 
-    id = bug.id & 3;
-
-    if ( id == BUGFRAME_run_fn )
-    {
-        void (*fn)(struct cpu_user_regs *) = (void *)p;
-        (*fn)(regs);
-        regs->eip = (unsigned long)eip;
-        return;
-    }
-
     /* WARN, BUG or ASSERT: decode the filename pointer and line number. */
     filename = p;
     lineno = bug.id >> 2;
xen/include/asm-x86/bug.h +4 -5
diff -r c72c074d0e08 -r 04783b003d5c xen/include/asm-x86/bug.h
@@ -13,16 +13,15 @@ struct bug_frame {
     unsigned short id; /* BUGFRAME_??? */
 } __attribute__((packed));
 
-#define BUGFRAME_run_fn 0
+#define BUGFRAME_state  0
 #define BUGFRAME_warn   1
 #define BUGFRAME_bug    2
 #define BUGFRAME_assert 3
 
-#define run_in_exception_handler(fn)               \
+#define dump_execution_state()                     \
     asm volatile (                                 \
-        "ud2 ; ret %0" BUG_STR(1)                  \
-        : : "i" (BUGFRAME_run_fn),                 \
-            "i" (fn) )
+        "ud2 ; ret %0"                             \
+        : : "i" (BUGFRAME_state) )
 
 #define WARN()                                     \
     asm volatile (                                 \
xen/include/asm-x86/processor.h +0 -1
diff -r c72c074d0e08 -r 04783b003d5c xen/include/asm-x86/processor.h
@@ -542,7 +542,6 @@ void show_stack(struct cpu_user_regs *re
 void show_stack_overflow(unsigned int cpu, unsigned long esp);
 void show_registers(struct cpu_user_regs *regs);
 void show_execution_state(struct cpu_user_regs *regs);
-#define dump_execution_state() run_in_exception_handler(show_execution_state)
 void show_page_walk(unsigned long addr);
 asmlinkage void fatal_trap(int trapnr, struct cpu_user_regs *regs);
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

author
#20 lore raw

PATCH 1/1 x86: redefine REX64_PREFIX for clang, which doesn't like 'rex64/'

In reply to Tim Deegan

# HG changeset patch
# User Tim Deegan <[email protected]>
# Date 1299496871 0
# Node ID 804007170cf03ea832022e2d589507a3bc0505dc
# Parent 04783b003d5c5691930af6baa3614389247ddda1
x86: redefine REX64_PREFIX for clang, which doesn't like 'rex64/'.

xen/include/asm-x86/x86_64/asm_defns.h +2 -0
diff -r 04783b003d5c -r 804007170cf0 xen/include/asm-x86/x86_64/asm_defns.h
@@ -84,6 +84,8 @@ 1:      addq  $8,%rsp;
 
 #ifdef __sun__
 #define REX64_PREFIX "rex64\\"
+#elif defined(__clang__)
+#define REX64_PREFIX ".byte 0x48; "
 #else
 #define REX64_PREFIX "rex64/"
 #endif

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

author
#21 lore raw

PATCH 1/1 xen: add "clang=y" option to build Xen with clang/llvm instead of gcc

In reply to Tim Deegan

Tested with svn snapshot of clang and llvm from 17 February 2011. Only x86_64 hypervisor builds (make dist-xen clang=y) are supported and I haven't even begun to look at cross-compiling.

# HG changeset patch
# User Tim Deegan <[email protected]>
# Date 1299496871 0
# Node ID d91e6a8d36ad3dbf89f42264334baec0cb37063f
# Parent 804007170cf03ea832022e2d589507a3bc0505dc
xen: add "clang=y" option to build Xen with clang/llvm instead of gcc.

Tested with svn snapshot of clang and llvm from 17 February 2011. Only x86_64 hypervisor builds (make dist-xen clang=y) are supported and I haven't even begun to look at cross-compiling.

Config.mk +7 -0
diff -r 804007170cf0 -r d91e6a8d36ad Config.mk
@@ -148,6 +148,13 @@ CFLAGS += -Wall -Wstrict-prototypes
 # result of any casted expression causes a warning.
 CFLAGS += -Wno-unused-value
 
+ifeq ($(clang),y)
+# Clang complains about macros that expand to 'if ( ( foo == bar ) ) ...'
+CFLAGS += -Wno-parentheses
+# And is over-zealous with the printf format lint
+CFLAGS += -Wno-format
+endif
+
 $(call cc-option-add,HOSTCFLAGS,HOSTCC,-Wdeclaration-after-statement)
 $(call cc-option-add,CFLAGS,CC,-Wdeclaration-after-statement)
 
config/StdGNU.mk +9 -1
diff -r 804007170cf0 -r d91e6a8d36ad config/StdGNU.mk
@@ -1,6 +1,11 @@
 AS         = $(CROSS_COMPILE)as
+ifeq ($(clang),y)
+LD         = $(CROSS_COMPILE)gold
+CC         = $(CROSS_COMPILE)clang
+else
 LD         = $(CROSS_COMPILE)ld
 CC         = $(CROSS_COMPILE)gcc
+endif
 CPP        = $(CC) -E
 AR         = $(CROSS_COMPILE)ar
 RANLIB     = $(CROSS_COMPILE)ranlib
@@ -69,5 +74,8 @@ ifneq ($(debug),y)
 CFLAGS += -O2 -fomit-frame-pointer
 else
 # Less than -O1 produces bad code and large stack frames
-CFLAGS += -O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls
+CFLAGS += -O1 -fno-omit-frame-pointer
+ifneq ($(clang),y)
+CFLAGS += -fno-optimize-sibling-calls
 endif
+endif
xen/Makefile +1 -1
diff -r 804007170cf0 -r d91e6a8d36ad xen/Makefile
@@ -88,7 +88,7 @@ include/xen/compile.h: include/xen/compi
 	    -e 's/@@whoami@@/$(XEN_WHOAMI)/g' \
 	    -e 's/@@domain@@/$(XEN_DOMAIN)/g' \
 	    -e 's/@@hostname@@/$(shell hostname)/g' \
-	    -e 's!@@compiler@@!$(shell $(CC) $(CFLAGS) -v 2>&1 | tail -1)!g' \
+	    -e 's!@@compiler@@!$(shell $(CC) $(CFLAGS) -v 2>&1 | grep version | tail -1)!g' \
 	    -e 's/@@version@@/$(XEN_VERSION)/g' \
 	    -e 's/@@subversion@@/$(XEN_SUBVERSION)/g' \
 	    -e 's/@@extraversion@@/$(XEN_EXTRAVERSION)/g' \
xen/Rules.mk +3 -0
diff -r 804007170cf0 -r d91e6a8d36ad xen/Rules.mk
@@ -62,6 +62,9 @@ endif
 
 AFLAGS-y                += -D__ASSEMBLY__
 
+# Clang's built-in assembler can't handle .code16/.code32/.code64 yet
+AFLAGS-$(clang)         += -no-integrated-as
+
 ALL_OBJS := $(ALL_OBJS-y)
 
 # Get gcc to generate the dependencies for us.
xen/arch/x86/Rules.mk +5 -0
diff -r 804007170cf0 -r d91e6a8d36ad xen/arch/x86/Rules.mk
@@ -12,9 +12,12 @@ xenoprof := y
 supervisor_mode_kernel ?= n
 
 # Solaris grabs stdarg.h and friends from the system include directory.
+# Clang likewise.
 ifneq ($(XEN_OS),SunOS)
+ifneq ($(clang),y)
 CFLAGS += -nostdinc
 endif
+endif
 
 CFLAGS += -fno-builtin -fno-common -Wredundant-decls
 CFLAGS += -iwithprefix include -Werror -Wno-pointer-arith -pipe
@@ -49,5 +52,7 @@ x86_32 := n
 x86_64 := y
 endif
 
+ifneq ($(clang),y)
 # Require GCC v3.4+ (to avoid issues with alignment constraints in Xen headers)
 $(call cc-ver-check,CC,0x030400,"Xen requires at least gcc-3.4")
+endif

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Acked-by on v1 1/1
#27 lore raw
In reply to Tim Deegan

These and the first LTO one are all fine by me.

Quoted 21 lines · Tim Deegan

This series of patches allows Xen builds with clang/llvm as well as GCC. It only fixes Xen, not tools &c, and only 64-bit, so far.

Building Xen with clang isn't useful in itself (and indeed produces a hypervisor that can be up to 10% slower for a default -O2 build); rather it's a stepping-stone to doing full link-time optimizations on the LLVM bitcode of the whole hypervisor. I will post a second series to enable that, but it's not so clean as this one.

I think all the changes in this series are reasonable and won't inconvenience any normal users, but obviously they're meant for the xen-unstable tree only.

Cheers,

Tim.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#22 lore raw

Re: [PATCH 8 of 8] xen: add "clang=y" option to build Xen with clang/llvm instead of gcc

In reply to Tim Deegan
Quoted 23 lines · Tim Deegan

# HG changeset patch
# User Tim Deegan <[email protected]>
# Date 1299496871 0
# Node ID d91e6a8d36ad3dbf89f42264334baec0cb37063f
# Parent 804007170cf03ea832022e2d589507a3bc0505dc
xen: add "clang=y" option to build Xen with clang/llvm instead of gcc.

Tested with svn snapshot of clang and llvm from 17 February 2011. Only x86_64 hypervisor builds (make dist-xen clang=y) are supported and I haven't even begun to look at cross-compiling.

diff -r 804007170cf0 -r d91e6a8d36ad Config.mk

Config.mk Mon Mar 07 11:21:11 2011 +0000 +2 -0
@@ -148,6 +148,13 @@ CFLAGS += -Wall -Wstrict-prototypes
 # result of any casted expression causes a warning.
 CFLAGS += -Wno-unused-value
 
+ifeq ($(clang),y)
+# Clang complains about macros that expand to 'if ( ( foo == bar )

) ...'

Config.mk Mon Mar 07 11:21:11 2011 +0000

Quoted 4 lines
Config.mk Mon Mar 07 11:21:11 2011 +0000 +4 -0
+CFLAGS += -Wno-parentheses
+# And is over-zealous with the printf format lint
+CFLAGS += -Wno-format
+endif

Is it worth arranging for "gcc := y" when clang is not enabled? Then a whole bunch of this sort of thing devolves into the

	CFLAGS-$(a-particular-cc) += -Wfoo

pattern.

Quoted 9 lines

+
$(call cc-option-add,HOSTCFLAGS,HOSTCC,-Wdeclaration-after-statement) $(call cc-option-add,CFLAGS,CC,-Wdeclaration-after-statement)

diff -r 804007170cf0 -r d91e6a8d36ad config/StdGNU.mk

config/StdGNU.mk Mon Mar 07 11:21:11 2011 +0000 +0 -0
@@ -1,6 +1,11 @@
 AS         = $(CROSS_COMPILE)as

config/StdGNU.mk Mon Mar 07 11:21:11 2011 +0000 line 11

Quoted 10 lines
config/StdGNU.mk Mon Mar 07 11:21:11 2011 +0000 +5 -0
+ifeq ($(clang),y)
+LD         = $(CROSS_COMPILE)gold
+CC         = $(CROSS_COMPILE)clang
+else
 LD         = $(CROSS_COMPILE)ld
 CC         = $(CROSS_COMPILE)gcc
+endif
 CPP        = $(CC) -E
 AR         = $(CROSS_COMPILE)ar
 RANLIB     = $(CROSS_COMPILE)ranlib

LD-$(clang) = ...
LD-$(gcc) = ...

LD := $(LD-y)

?

config/StdGNU.mk Mon Mar 07 11:21:11 2011 +0000 ifneq ($(debug),y) · line 79

Quoted 8 lines
config/StdGNU.mk Mon Mar 07 11:21:11 2011 +0000 +3 -1
@@ -69,5 +74,8 @@ ifneq ($(debug),y)
 CFLAGS += -O2 -fomit-frame-pointer
 else
 # Less than -O1 produces bad code and large stack frames
-CFLAGS += -O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls
+CFLAGS += -O1 -fno-omit-frame-pointer
+ifneq ($(clang),y)
+CFLAGS += -fno-optimize-sibling-calls

CFLAGS-$(gcc) += ...

etc etc

Ian.

#12 lore raw

Re: [PATCH 6 of 8] Xen: remove run_in_exception_handler() and recode its only caller

In reply to Tim Deegan
Quoted 4 lines · Tim Deegan

(dump_execution_state()) as its own bug-trap.

This is needed to compile xen with clang, which can't handle using a function name in an asm immediate.

Actually run_in_exception_handler() does have another user, in ns16550.c. Although non-essential, it makes the 'd' debug key much more useful when running the UART in polled mode.

So I suggest we keep run_in_exception_handler but modify it to pass the function pointer in (say) rAX. I think we won't easily be able to use BUG_STR() logic but r_i_e_h is only used (directly or indirectly) in a few places so the BUG_STR optimisation is unimportant. The only other disadvantage is that rAX is less interesting in the state dump, but any value the function pointer displaces can still be found in the stack dump, albeit with likely a little extra effort.

Sound good?

-- Keir

Quoted 7 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#13 lore raw

Re: [PATCH 6 of 8] Xen: remove run_in_exception_handler() and recode its only caller

Quoted 7 lines · Keir Fraser
Quoted 4 lines · Tim Deegan

(dump_execution_state()) as its own bug-trap.

This is needed to compile xen with clang, which can't handle using a function name in an asm immediate.

Quoted 6 lines

Actually run_in_exception_handler() does have another user, in ns16550.c. Although non-essential, it makes the 'd' debug key much more useful when running the UART in polled mode.

So I suggest we keep run_in_exception_handler but modify it to pass the function pointer in (say) rAX.

Like the attached patch (against latest tip).

-- Keir

Quoted 7 lines

I think we won't easily be able to use
BUG_STR() logic but r_i_e_h is only used (directly or indirectly) in a few places so the BUG_STR optimisation is unimportant. The only other disadvantage is that rAX is less interesting in the state dump, but any value the function pointer displaces can still be found in the stack dump, albeit with likely a little extra effort.

Quoted 13 lines

Sound good?

-- Keir

Quoted 7 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Acked-by on v1 1/1
#10 lore raw

Re: [PATCH 5 of 8] credit2: remove two nested functions, replacing them with static ones

In reply to Tim Deegan

Yeah, I kind of knew those nested functions were skanky when I wrote them. :-)

Quoted 13 lines · Tim Deegan

and passing the outer scope's variables in explicitly. This is needed to compile xen with clang.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

author
#14 lore raw

Re: [PATCH 6 of 8] Xen: remove run_in_exception_handler() and recode its only caller

In reply to Keir Fraser
Quoted 9 lines · Keir Fraser
Quoted 7 lines · Keir Fraser
Quoted 4 lines · Tim Deegan

(dump_execution_state()) as its own bug-trap.

This is needed to compile xen with clang, which can't handle using a function name in an asm immediate.

Quoted 8 lines
Quoted 6 lines

Actually run_in_exception_handler() does have another user, in ns16550.c. Although non-essential, it makes the 'd' debug key much more useful when running the UART in polled mode.

So I suggest we keep run_in_exception_handler but modify it to pass the function pointer in (say) rAX.

Like the attached patch (against latest tip).

Sorry, I had missed that other user. I'll see if I can find a way to make clang use the function address directly; if not, I'd be inclined to have dump_execution_state have its own ID anyway, to keep %rax valid(er) in BUG()s.

Tim.

Quoted 21 lines
Quoted 20 lines

I think we won't easily be able to use
BUG_STR() logic but r_i_e_h is only used (directly or indirectly) in a few places so the BUG_STR optimisation is unimportant. The only other disadvantage is that rAX is less interesting in the state dump, but any value the function pointer displaces can still be found in the stack dump, albeit with likely a little extra effort.

Sound good?

-- Keir

Quoted 7 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
#15 lore raw

Re: [PATCH 6 of 8] Xen: remove run_in_exception_handler() and recode its only caller

Quoted 17 lines · Tim Deegan
Quoted 16 lines · Keir Fraser
Quoted 13 lines · Keir Fraser
Quoted 4 lines · Tim Deegan

(dump_execution_state()) as its own bug-trap.

This is needed to compile xen with clang, which can't handle using a function name in an asm immediate.

Actually run_in_exception_handler() does have another user, in ns16550.c. Although non-essential, it makes the 'd' debug key much more useful when running the UART in polled mode.

So I suggest we keep run_in_exception_handler but modify it to pass the function pointer in (say) rAX.

Quoted 6 lines
Quoted 1 line

Like the attached patch (against latest tip).

Sorry, I had missed that other user. I'll see if I can find a way to make clang use the function address directly; if not, I'd be inclined to have dump_execution_state have its own ID anyway, to keep %rax valid(er) in BUG()s.

But actually dump_execution_state() isn't used for BUGs and WARNs and ASSERTs. In fact it's practically dead on x86 -- it's used in one rather unlikely ACPI error function, and also in __bug/__warn which are never used on x86. And that's it. Actually the user of run_in_exception_handler() in ns16550.c is really the only one we care about!

-- Keir

Quoted 25 lines

Tim.

Quoted 21 lines
Quoted 20 lines

I think we won't easily be able to use
BUG_STR() logic but r_i_e_h is only used (directly or indirectly) in a few places so the BUG_STR optimisation is unimportant. The only other disadvantage is that rAX is less interesting in the state dump, but any value the function pointer displaces can still be found in the stack dump, albeit with likely a little extra effort.

Sound good?

-- Keir

Quoted 7 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#16 lore raw

Re: [PATCH 6 of 8] Xen: remove run_in_exception_handler() and recode its only caller

Quoted 11 lines · Keir Fraser
Quoted 5 lines

Sorry, I had missed that other user. I'll see if I can find a way to make clang use the function address directly; if not, I'd be inclined to have dump_execution_state have its own ID anyway, to keep %rax valid(er) in BUG()s.

But actually dump_execution_state() isn't used for BUGs and WARNs and ASSERTs. In fact it's practically dead on x86 -- it's used in one rather unlikely ACPI error function, and also in __bug/__warn which are never used on x86. And that's it. Actually the user of run_in_exception_handler() in ns16550.c is really the only one we care about!

And furthermore, the GPRs dumped from the 'd' key via a UART in polled mode are always uninteresting. Because the backtrace will start from ns16550_poll and out from there through Xen's timer subsystem. The fact we clobber rAX in r_i_e_h() would not make things worse. :-)

So if you can't find a way to force a function address through clang then my patch would be a perfectly fine alternative.

-- Keir

Quoted 29 lines

-- Keir

Quoted 25 lines

Tim.

Quoted 21 lines
Quoted 20 lines

I think we won't easily be able to use
BUG_STR() logic but r_i_e_h is only used (directly or indirectly) in a few places so the BUG_STR optimisation is unimportant. The only other disadvantage is that rAX is less interesting in the state dump, but any value the function pointer displaces can still be found in the stack dump, albeit with likely a little extra effort.

Sound good?

-- Keir

Quoted 7 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

author
#17 lore raw

Re: [PATCH 6 of 8] Xen: remove run_in_exception_handler() and recode its only caller

In reply to Tim Deegan
Quoted 13 lines · Tim Deegan
Quoted 12 lines · Keir Fraser
Quoted 10 lines · Keir Fraser
Quoted 2 lines · Tim Deegan

This is needed to compile xen with clang, which can't handle using a function name in an asm immediate.

Actually run_in_exception_handler() does have another user, in ns16550.c. Although non-essential, it makes the 'd' debug key much more useful when running the UART in polled mode.

So I suggest we keep run_in_exception_handler but modify it to pass the function pointer in (say) rAX.

Quoted 6 lines
Quoted 1 line

Like the attached patch (against latest tip).

Sorry, I had missed that other user. I'll see if I can find a way to make clang use the function address directly; if not, I'd be inclined to have dump_execution_state have its own ID anyway, to keep %rax valid(er) in BUG()s.

Turns out to be very straightforward: another level of indirection makes the parser happy. If it's OK with you, I'll revert 22987:3147f2d1c6fb and apply this instead:

xen/include/asm-x86/bug.h +1 -1
diff -r 3147f2d1c6fb xen/include/asm-x86/bug.h
@@ -22,7 +22,7 @@ struct bug_frame {
     asm volatile (                                 \
         "ud2 ; ret %0" BUG_STR(1)                  \
         : : "i" (BUGFRAME_run_fn),                 \
-            "i" (fn) )
+            "i" (&(fn)) )
 
 #define WARN()                                     \
     asm volatile (                                 \

Cheers,

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
#18 lore raw

Re: [PATCH 6 of 8] Xen: remove run_in_exception_handler() and recode its only caller

Quoted 6 lines · Tim Deegan
Quoted 5 lines · Tim Deegan
Quoted 3 lines · Keir Fraser

On 07/03/2011 15:05, "Keir Fraser" <[email protected]> wrote:

Like the attached patch (against latest tip).

Quoted 8 lines
Quoted 4 lines

Sorry, I had missed that other user. I'll see if I can find a way to make clang use the function address directly; if not, I'd be inclined to have dump_execution_state have its own ID anyway, to keep %rax valid(er) in BUG()s.

Turns out to be very straightforward: another level of indirection makes the parser happy. If it's OK with you, I'll revert 22987:3147f2d1c6fb and apply this instead:

If you've successfully both build- and run-tested it with gcc then it's fine with me. It needs testing as it's a moderately skanky construct in the first place.

-- Keir

Quoted 16 lines

diff -r 3147f2d1c6fb xen/include/asm-x86/bug.h

xen/include/asm-x86/bug.h Mon Mar 07 15:48:32 2011 +0000 renamed from xen/include/asm-x86/bug.h Mon Mar 07 15:47:59 2011 +0000 +1 -1
@@ -22,7 +22,7 @@ struct bug_frame {
     asm volatile (                                 \
         "ud2 ; ret %0" BUG_STR(1)                  \
         : : "i" (BUGFRAME_run_fn),                 \
-            "i" (fn) )
+            "i" (&(fn)) )
 
 #define WARN()                                     \
     asm volatile (                                 \

Cheers,

Tim.

author
#19 lore raw

Re: [PATCH 6 of 8] Xen: remove run_in_exception_handler() and recode its only caller

Quoted 13 lines · Keir Fraser
Quoted 11 lines · Tim Deegan
Quoted 9 lines · Tim Deegan
Quoted 3 lines · Keir Fraser

On 07/03/2011 15:05, "Keir Fraser" <[email protected]> wrote:

Like the attached patch (against latest tip).

Sorry, I had missed that other user. I'll see if I can find a way to make clang use the function address directly; if not, I'd be inclined to have dump_execution_state have its own ID anyway, to keep %rax valid(er) in BUG()s.

Quoted 7 lines
Quoted 3 lines

Turns out to be very straightforward: another level of indirection makes the parser happy. If it's OK with you, I'll revert 22987:3147f2d1c6fb and apply this instead:

If you've successfully both build- and run-tested it with gcc then it's fine with me. It needs testing as it's a moderately skanky construct in the first place.

I have, and at least with 64bit gcc 4.4.5 dump_execution_state() still works fine. :)

Tim.

Quoted 20 lines

-- Keir

Quoted 16 lines

diff -r 3147f2d1c6fb xen/include/asm-x86/bug.h

xen/include/asm-x86/bug.h Mon Mar 07 15:48:32 2011 +0000 renamed from xen/include/asm-x86/bug.h Mon Mar 07 15:47:59 2011 +0000 +1 -1
@@ -22,7 +22,7 @@ struct bug_frame {
     asm volatile (                                 \
         "ud2 ; ret %0" BUG_STR(1)                  \
         : : "i" (BUGFRAME_run_fn),                 \
-            "i" (fn) )
+            "i" (&(fn)) )
 
 #define WARN()                                     \
     asm volatile (                                 \

Cheers,

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
author
#23 lore raw

Re: [PATCH 8 of 8] xen: add "clang=y" option to build Xen with clang/llvm instead of gcc

In reply to Ian Campbell
Quoted 4 lines · Ian Campbell

Is it worth arranging for "gcc := y" when clang is not enabled? Then a whole bunch of this sort of thing devolves into the

	CFLAGS-$(a-particular-cc) += -Wfoo

pattern.

Something like the attached? It tidies up four such ifeqs, at the cost of one new one to define $(gcc).
(4 files changed, 17 insertions(+), 16 deletions(-))

Quoted 16 lines

Review line 11

Quoted 12 lines
(quoted diff) +5 -0
@@ -1,6 +1,11 @@
 AS         = $(CROSS_COMPILE)as
+ifeq ($(clang),y)
+LD         = $(CROSS_COMPILE)gold
+CC         = $(CROSS_COMPILE)clang
+else
 LD         = $(CROSS_COMPILE)ld
 CC         = $(CROSS_COMPILE)gcc
+endif
 CPP        = $(CC) -E
 AR         = $(CROSS_COMPILE)ar
 RANLIB     = $(CROSS_COMPILE)ranlib

LD-$(clang) = ...
LD-$(gcc) = ...

Quoted 1 line

LD := $(LD-y)

I tried that but it looks about as bad, and actually has more repetition.

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
Config.mk +11 -5
diff -r ca556b7bad5c Config.mk
@@ -23,6 +23,15 @@ DESTDIR     ?= /
 # Allow phony attribute to be listed as dependency rather than fake target
 .PHONY: .phony
 
+# Use Clang/LLVM instead of GCC?
+clang ?= n
+ifeq ($(clang),n)
+gcc := y
+else
+gcc := n
+endif
+
+
 include $(XEN_ROOT)/config/$(XEN_OS).mk
 include $(XEN_ROOT)/config/$(XEN_TARGET_ARCH).mk
 
@@ -148,12 +157,9 @@ CFLAGS += -Wall -Wstrict-prototypes
 # result of any casted expression causes a warning.
 CFLAGS += -Wno-unused-value
 
-ifeq ($(clang),y)
 # Clang complains about macros that expand to 'if ( ( foo == bar ) ) ...'
-CFLAGS += -Wno-parentheses
-# And is over-zealous with the printf format lint
-CFLAGS += -Wno-format
-endif
+# and is over-zealous with the printf format lint
+CFLAGS-$(clang) += -Wno-parentheses -Wno-format
 
 $(call cc-option-add,HOSTCFLAGS,HOSTCC,-Wdeclaration-after-statement)
 $(call cc-option-add,CFLAGS,CC,-Wdeclaration-after-statement)
config/StdGNU.mk +2 -6
diff -r ca556b7bad5c config/StdGNU.mk
@@ -76,14 +76,10 @@ CFLAGS += -O2 -fomit-frame-pointer
 else
 # Less than -O1 produces bad code and large stack frames
 CFLAGS += -O1 -fno-omit-frame-pointer
-ifneq ($(clang),y)
-CFLAGS += -fno-optimize-sibling-calls
-endif
+CFLAGS-$(gcc) += -fno-optimize-sibling-calls
 endif
 
 ifeq ($(lto),y)
 CFLAGS += -flto
-ifeq ($(clang),y)
-LDFLAGS += -plugin LLVMgold.so
+LDFLAGS-$(clang) += -plugin LLVMgold.so
 endif
-endif
xen/Rules.mk +2 -1
diff -r ca556b7bad5c xen/Rules.mk
@@ -9,7 +9,6 @@ perfc_arrays  ?= n
 lock_profile  ?= n
 crash_debug   ?= n
 frame_pointer ?= n
-clang         ?= n
 lto           ?= n
 
 XEN_ROOT=$(BASEDIR)/..
@@ -83,6 +82,8 @@ AFLAGS += $(AFLAGS-y) $(filter-out -std=
 # LDFLAGS are only passed directly to $(LD)
 LDFLAGS += $(LDFLAGS_DIRECT)
 
+LDFLAGS += $(LDFLAGS-y)
+
 include Makefile
 
 # Ensure each subdirectory has exactly one trailing slash.
xen/arch/x86/Rules.mk +2 -4
diff -r ca556b7bad5c xen/arch/x86/Rules.mk
@@ -14,9 +14,7 @@ supervisor_mode_kernel ?= n
 # Solaris grabs stdarg.h and friends from the system include directory.
 # Clang likewise.
 ifneq ($(XEN_OS),SunOS)
-ifneq ($(clang),y)
-CFLAGS += -nostdinc
-endif
+CFLAGS-$(gcc) += -nostdinc
 endif
 
 CFLAGS += -fno-builtin -fno-common -Wredundant-decls
@@ -52,7 +50,7 @@ x86_32 := n
 x86_64 := y
 endif
 
-ifneq ($(clang),y)
+ifeq ($(gcc),y)
 # Require GCC v3.4+ (to avoid issues with alignment constraints in Xen headers)
 $(call cc-ver-check,CC,0x030400,"Xen requires at least gcc-3.4")
 endif

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#24 lore raw

Re: [PATCH 8 of 8] xen: add "clang=y" option to build Xen with clang/llvm instead of gcc

Quoted 9 lines · Tim Deegan
Quoted 4 lines · Ian Campbell

Is it worth arranging for "gcc := y" when clang is not enabled? Then a whole bunch of this sort of thing devolves into the CFLAGS-$(a-particular-cc) += -Wfoo
pattern.

Something like the attached? It tidies up four such ifeqs, at the cost of one new one to define $(gcc).
(4 files changed, 17 insertions(+), 16 deletions(-))

This looks like a definite improvement in readability, to me. I'd like it to be applied.

-- Keir

Quoted 22 lines
Quoted 16 lines

Review line 11

Quoted 12 lines
(quoted diff) +5 -0
@@ -1,6 +1,11 @@
 AS         = $(CROSS_COMPILE)as
+ifeq ($(clang),y)
+LD         = $(CROSS_COMPILE)gold
+CC         = $(CROSS_COMPILE)clang
+else
 LD         = $(CROSS_COMPILE)ld
 CC         = $(CROSS_COMPILE)gcc
+endif
 CPP        = $(CC) -E
 AR         = $(CROSS_COMPILE)ar
 RANLIB     = $(CROSS_COMPILE)ranlib

LD-$(clang) = ...
LD-$(gcc) = ...

Quoted 1 line

LD := $(LD-y)

I tried that but it looks about as bad, and actually has more repetition.

Tim.

#3 lore raw

Re: [PATCH 2 of 8] x86: add explicit size suffixes to some assembly instructions

In reply to Tim Deegan

xen/arch/x86/x86_emulate/x86_emulate.c x86_emulate( · line 2681

Quoted 9 lines
Quoted 1 line
Quoted 1 line · Tim Deegan
xen/arch/x86/x86_emulate/x86_emulate.c +1 -1
@@ -2678,7 +2678,7 @@ x86_emulate(
                emulate_fpu_insn_memsrc("fiaddl", src.val);
                break;
            case 1: /* fimul m64i */
-                emulate_fpu_insn_memsrc("fimul", src.val);
+                emulate_fpu_insn_memsrc("fimuls", src.val);

fimull.

xen/arch/x86/x86_emulate/x86_emulate.c x86_emulate( · line 2684

Quoted 3 lines
xen/arch/x86/x86_emulate/x86_emulate.c +0 -0
                break;
            case 2: /* ficom m64i */
                emulate_fpu_insn_memsrc("ficoml", src.val);

(Side note: The comments in this section are all wrong - they should say "m32i"; there are no 64-bit integer operations other than loads and stores.)

Jan

#26 lore raw

Re: [PATCH 8 of 8] xen: add "clang=y" option to build Xen with clang/llvm instead of gcc

In reply to Tim Deegan
Quoted 8 lines · Tim Deegan
Quoted 4 lines · Ian Campbell

Is it worth arranging for "gcc := y" when clang is not enabled? Then a whole bunch of this sort of thing devolves into the

	CFLAGS-$(a-particular-cc) += -Wfoo

pattern.

Something like the attached? It tidies up four such ifeqs, at the cost of one new one to define $(gcc).

I think that one is worth it to clean up all the others -- at least all the nastiness will be contained to 1 place. Imagine a far distant future where we also support e.g. icc or something...

Quoted 18 lines

(4 files changed, 17 insertions(+), 16 deletions(-))

Quoted 16 lines

Review line 11

Quoted 12 lines
(quoted diff) +5 -0
@@ -1,6 +1,11 @@
 AS         = $(CROSS_COMPILE)as
+ifeq ($(clang),y)
+LD         = $(CROSS_COMPILE)gold
+CC         = $(CROSS_COMPILE)clang
+else
 LD         = $(CROSS_COMPILE)ld
 CC         = $(CROSS_COMPILE)gcc
+endif
 CPP        = $(CC) -E
 AR         = $(CROSS_COMPILE)ar
 RANLIB     = $(CROSS_COMPILE)ranlib

LD-$(clang) = ...
LD-$(gcc) = ...

Quoted 4 lines
Quoted 1 line

LD := $(LD-y)

I tried that but it looks about as bad, and actually has more repetition.

Sure.

Ian.

author
#25 lore raw

Re: [PATCH 8 of 8] xen: add "clang=y" option to build Xen with clang/llvm instead of gcc

In reply to Keir Fraser
Quoted 8 lines · Keir Fraser
Quoted 6 lines · Tim Deegan
Quoted 4 lines · Ian Campbell

Is it worth arranging for "gcc := y" when clang is not enabled? Then a whole bunch of this sort of thing devolves into the CFLAGS-$(a-particular-cc) += -Wfoo
pattern.

Quoted 6 lines
Quoted 3 lines

Something like the attached? It tidies up four such ifeqs, at the cost of one new one to define $(gcc).
(4 files changed, 17 insertions(+), 16 deletions(-))

This looks like a definite improvement in readability, to me. I'd like it to be applied.

Done (I'm interpreting this as an Acked-by:).

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
author
#4 lore raw

Re: [PATCH 2 of 8] x86: add explicit size suffixes to some assembly instructions

In reply to Jan Beulich
Quoted 11 lines · Jan Beulich

xen/arch/x86/x86_emulate/x86_emulate.c x86_emulate( · line 2681

Quoted 9 lines
Quoted 1 line
Quoted 1 line · Tim Deegan
xen/arch/x86/x86_emulate/x86_emulate.c +1 -1
@@ -2678,7 +2678,7 @@ x86_emulate(
                emulate_fpu_insn_memsrc("fiaddl", src.val);
                break;
            case 1: /* fimul m64i */
-                emulate_fpu_insn_memsrc("fimul", src.val);
+                emulate_fpu_insn_memsrc("fimuls", src.val);

fimull.

fimuls is what the previous code generates, but it does look like that was wrong. I'll fix it, thanks.

Tim.

Quoted 7 lines

xen/arch/x86/x86_emulate/x86_emulate.c x86_emulate( · line 2684

Quoted 3 lines
xen/arch/x86/x86_emulate/x86_emulate.c +0 -0
                break;
            case 2: /* ficom m64i */
                emulate_fpu_insn_memsrc("ficoml", src.val);

(Side note: The comments in this section are all wrong - they should say "m32i"; there are no 64-bit integer operations other than loads and stores.)

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
#5 lore raw

Re: [PATCH 2 of 8] x86: add explicit size suffixes to some assembly instructions

Quoted 14 lines
Quoted 1 line
Quoted 1 line · Tim Deegan
Quoted 11 lines · Jan Beulich

xen/arch/x86/x86_emulate/x86_emulate.c x86_emulate( · line 2681

Quoted 9 lines
Quoted 1 line
Quoted 1 line · Tim Deegan
xen/arch/x86/x86_emulate/x86_emulate.c +1 -1
@@ -2678,7 +2678,7 @@ x86_emulate(
                emulate_fpu_insn_memsrc("fiaddl", src.val);
                break;
            case 1: /* fimul m64i */
-                emulate_fpu_insn_memsrc("fimul", src.val);
+                emulate_fpu_insn_memsrc("fimuls", src.val);

fimull.

Quoted 2 lines

fimuls is what the previous code generates, but it does look like that was wrong. I'll fix it, thanks.

And perhaps that fix by itself should go into 4.1/4.0 too.

Jan

#6 lore raw

Re: [PATCH 2 of 8] x86: add explicit size suffixes to some assembly instructions

Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · Tim Deegan
Quoted 11 lines · Jan Beulich

xen/arch/x86/x86_emulate/x86_emulate.c Mon Mar 07 11:21:11 2011 +0000 x86_emulate( · line 2681

Quoted 9 lines
Quoted 1 line
Quoted 1 line · Tim Deegan
xen/arch/x86/x86_emulate/x86_emulate.c Mon Mar 07 11:21:11 2011 +0000 +1 -1
@@ -2678,7 +2678,7 @@ x86_emulate(
                emulate_fpu_insn_memsrc("fiaddl", src.val);
                break;
            case 1: /* fimul m64i */
-                emulate_fpu_insn_memsrc("fimul", src.val);
+                emulate_fpu_insn_memsrc("fimuls", src.val);

fimull.

Quoted 4 lines
Quoted 2 lines

fimuls is what the previous code generates, but it does look like that was wrong. I'll fix it, thanks.

And perhaps that fix by itself should go into 4.1/4.0 too.

Done. Also I fixed the comments to read 'm32i' and also noted and fixed src.bytes=ea.bytes=4 rather than 8.

-- Keir

Quoted 7 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel