s390(64) per_cpu in modules (ipv6)
Hi, Martin,
I tried to build ipv6 as a module in 2.6.7, and it bombs, producing a module which wants per_cpu____icmpv6_socket (obviously, undefined).
The problem appears to be caused by this:
#define __get_got_cpu_var(var,offset) \
(*({ unsigned long *__ptr; \
asm ( "larl %0,per_cpu__"#var"@GOTENT" : "=a" (__ptr) ); \
((typeof(&per_cpu__##var))((*__ptr) + offset)); \
}))The net/ipv6/icmp.c has this:
static DEFINE_PER_CPU(struct socket *, __icmpv6_socket) = NULL;
It is a static variable, and all references to it come from asm code. The gcc does not know that they are present and optimizes the variable away. It simply emits no code to define per_cpu____icmpv6_socket whatsoever, as verified with gcc -S.
If the DEFINE_PER_CPU() is used without static, or if a bogus reference is added to the C code (a printk), everything works.
I tried to add a fake input argument to the asm, like this:
include/asm-s390/percpu.h 2004-06-29 22:03:23.000000000 -0400 renamed from include/asm-s390/percpu.h 2004-06-16 01:20:04.000000000 -0400 +1 -1
@@ -15,7 +15,7 @@ #if defined(__s390x__) && defined(MODULE) #define __get_got_cpu_var(var,offset) \ (*({ unsigned long *__ptr; \ - asm ( "larl %0,per_cpu__"#var"@GOTENT" : "=a" (__ptr) ); \ + asm ( "larl %0,per_cpu__"#var"@GOTENT" : "=a" (__ptr) : "a" (&per_cpu__##var) ); \ ((typeof(&per_cpu__##var))((*__ptr) + offset)); \ })) #undef __get_cpu_var
It seems to work fine, but I'm wondering if a better fix can be found. Ideas?
-- Pete
Quoted 3 lines · Pete Zaitcev
It seems to work fine, but I'm wondering if a better fix can be found. Ideas?
-- Pete
How does __attribute__((used)) fare?
-- wli
Pete> It seems to work fine, but I'm wondering if a better fix can Pete> be found. Ideas?
Not sure if it will work (and I don't have an s390 toolchain handy!) but this (static variable used only by asm) seems to be exactly the situation that __attribute_used__ is intended for.
- Roland
Quoted 5 lines · Pete Zaitcev
Hi, Martin,
I tried to build ipv6 as a module in 2.6.7, and it bombs, producing a module which wants
per_cpu____icmpv6_socket(obviously, undefined).
Quoted 7 lines
The problem appears to be caused by this:
#define
__get_got_cpu_var(var,offset)\(*({ unsigned long *__ptr; \ asm ( "larl %0,per_cpu__"#var"@GOTENT" : "=a" (__ptr) ); \ ((typeof(&per_cpu__##var))((*__ptr) + offset)); \ }))
Heh, I ran into the same problem trying to do this trick for PPC64. You really need to use __thread and make GCC do the work, AFAICT.
The worse problem is that a (static) per-cpu var declared *inside* a function gets renamed by gcc; IIRC some generic code used to do this.
Rusty.
Signature · 1 line
Anyone who quotes me in their signature is an idiot -- Rusty Russell