[Skiboot] [PATCH 03/13] cpu.h: implement this_cpu for clang

Joel Stanley joel at jms.id.au
Wed May 2 18:37:43 AEST 2018


Clang can't use the global register variable, so instead load struct
cpu_thread from r13 and return it.

Signed-off-by: Joel Stanley <joel at jms.id.au>
---
 include/cpu.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/include/cpu.h b/include/cpu.h
index 091b1c940d41..3142c53a339f 100644
--- a/include/cpu.h
+++ b/include/cpu.h
@@ -231,11 +231,33 @@ extern u8 get_available_nr_cores_in_chip(u32 chip_id);
 		core = next_available_core_in_chip(core, chip_id))
 
 /* Return the caller CPU (only after init_cpu_threads) */
+#ifdef __clang__
+static inline __nomcount struct cpu_thread *this_cpu(void)
+{
+	struct cpu_thread *this_cpu;
+
+	/* The clang user manual:
+	 *
+	 *  https://clang.llvm.org/docs/UsersManual.html#gcc-extensions-not-implemented-yet
+	 *
+	 *  clang only supports global register variables when the register
+	 *  specified is non-allocatable (e.g. the stack pointer). Support for
+	 *  general global register variables is unlikely to be implemented soon
+	 *  because it requires additional LLVM backend support.
+	 *
+	 * Emulate it by copying the value from r13 and returning it.
+	 */
+	asm("mr %0, %%r13" : "=r"(this_cpu));
+
+	return this_cpu;
+}
+#else
 register struct cpu_thread *__this_cpu asm("r13");
 static inline __nomcount struct cpu_thread *this_cpu(void)
 {
 	return __this_cpu;
 }
+#endif
 
 /* Get the thread # of a cpu within the core */
 static inline uint32_t cpu_get_thread_index(struct cpu_thread *cpu)
-- 
2.17.0



More information about the Skiboot mailing list