* PROBLEM: using _syscall4 to call sys_futex with -fPIC won't compile
@ 2004-07-05 10:39 Benjamin Collar
2004-07-05 15:58 ` Andreas Schwab
0 siblings, 1 reply; 4+ messages in thread
From: Benjamin Collar @ 2004-07-05 10:39 UTC (permalink / raw)
To: linux-kernel
Greetings
[1.]
If I use _syscall4 in order to call sys_futex and compile with -fPIC, I
receive this compiler error:
"can't find a register in class `BREG' while reloading `asm'"
[2.]
I'm using futexes in a project and I have to build a shared library;
thus I need to use -fPIC when compiling. When doing so, I get the error
mentioned in [1.]. A colleague and I figured out that the problem lies
in the intermediate code generated:
int sys_futex(int *futex, int op, int val, struct timespec *rel) {
register long __res;
__asm__ volatile (
"int $0x80"
: "=a" (__res)
: "0" (240),
"b" ((long)(futex)),
"c" ((long)(op)),
"d" ((long)(val)),
"S" ((long)(rel)));
The "b" ((long)(futex)), causes the error.
[3.] syscall
[4.] Linux version 2.6.7 (gcc version 3.3.3 20040412 (Gentoo Linux
3.3.3-r6, ssp-3.3.2-2, pie-8.7.6)) #2 SMP Thu Jun 17 10:38:06 CEST 2004
(I tested on a Debian based machine as well with the same result).
[5.] n/a
[6.] For example, see the futex-2.2.tar.bz2; change the Makefile to use
-fPIC
[7.]
[7.1]
Linux mhpajh5c 2.6.7 #2 SMP Thu Jun 17 10:38:06 CEST 2004 i686 Intel(R)
Pentium(R) 4 CPU 3.20GHz GenuineIntel GNU/Linux
Gnu C 3.3.3
Gnu make 3.80
binutils 2.14.90.0.8
util-linux 2.12
mount 2.12
module-init-tools 3.0
e2fsprogs 1.35
Linux C Library 2.3.3
Dynamic linker (ldd) 2.3.3
Procps 3.1.15
Net-tools 1.60
Kbd 1.12
Sh-utils 5.2.1
Modules Loaded i830 ohci_hcd 3c59x ata_piix libata uhci_hcd
intel_agp agpgart snd_pcm_oss snd_mixer_oss snd_intel8x0 snd_ac97_codec
snd_pcm snd_page_alloc gameport snd_mpu401_uart snd_rawmidi snd_seq_oss
snd_seq_midi_event snd_seq snd_timer snd_seq_device snd e1000 sbp2
ohci1394 ieee1394 usb_storage ehci_hcd usbcore
[7.2]
processor : 0
vendor_id : GenuineIntel
cpu family : 15
model : 2
model name : Intel(R) Pentium(R) 4 CPU 3.20GHz
stepping : 9
cpu MHz : 3192.159
cache size : 512 KB
physical id : 0
siblings : 2
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge
mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe cid
bogomips : 6307.84
[7.3,4,5,6,7] n/a
[X.] This hand-written assembly works for the moment:
int sys_futex(int *futex, int op, int val, struct timespec *rel) {
register long __res;
__asm__ volatile (
"pushl %%ebx\n\
movl 8(%%ebp), %%ebx\n\
int $0x80\n\
popl %%ebx"
: "=a" (__res)
: "0" (240)/*,
"b" ((long)(futex))*/,
"c" ((long)(op)),
"d" ((long)(val)),
"S" ((long)(rel)));
do {
if ((unsigned long)(__res) >= (unsigned long)(-125)) {
(*__errno_location ()) = -(__res);
__res = -1;
}
return (int) (__res);
} while (0);
}
Thanks for any help in figuring out what's wrong.
Sincerely
Ben
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: PROBLEM: using _syscall4 to call sys_futex with -fPIC won't compile
2004-07-05 10:39 PROBLEM: using _syscall4 to call sys_futex with -fPIC won't compile Benjamin Collar
@ 2004-07-05 15:58 ` Andreas Schwab
2004-07-05 16:17 ` Chris Friesen
0 siblings, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2004-07-05 15:58 UTC (permalink / raw)
To: Benjamin Collar; +Cc: linux-kernel
Benjamin Collar <benjamin.collar@siemens.com> writes:
> Greetings
>
> [1.]
> If I use _syscall4 in order to call sys_futex and compile with -fPIC, I
> receive this compiler error:
> "can't find a register in class `BREG' while reloading `asm'"
Don't do that then.
> [2.]
> I'm using futexes in a project and I have to build a shared library;
> thus I need to use -fPIC when compiling. When doing so, I get the error
> mentioned in [1.].
Don't use kernel headers in user space. Use syscall(3) instead.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: PROBLEM: using _syscall4 to call sys_futex with -fPIC won't compile
2004-07-05 15:58 ` Andreas Schwab
@ 2004-07-05 16:17 ` Chris Friesen
2004-07-05 17:57 ` Andreas Schwab
0 siblings, 1 reply; 4+ messages in thread
From: Chris Friesen @ 2004-07-05 16:17 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Benjamin Collar, linux-kernel
Andreas Schwab wrote:
> Benjamin Collar <benjamin.collar@siemens.com> writes:
>
> > Greetings
> >
> > [1.]
> > If I use _syscall4 in order to call sys_futex and compile with -fPIC, I
> > receive this compiler error:
> > "can't find a register in class `BREG' while reloading `asm'"
>
> Don't do that then.
>
> > [2.]
> > I'm using futexes in a project and I have to build a shared library;
> > thus I need to use -fPIC when compiling. When doing so, I get the error
> > mentioned in [1.].
>
> Don't use kernel headers in user space. Use syscall(3) instead.
The "_syscallx" macros are in the userspace versions of the kernel headers, and
as such should be fair game. Also, you need to get a list of syscall numbers
somehow, and those numbers are generally defined in the same file that contains
the "_syscallx" macros.
syscall() doesn't work for all system calls. The man page explicitly warns that
it doesn't work for pipe(2). Interestingly, the glibc manual doesn't have that
warning. Wonder which is correct...
Chris
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: PROBLEM: using _syscall4 to call sys_futex with -fPIC won't compile
2004-07-05 16:17 ` Chris Friesen
@ 2004-07-05 17:57 ` Andreas Schwab
0 siblings, 0 replies; 4+ messages in thread
From: Andreas Schwab @ 2004-07-05 17:57 UTC (permalink / raw)
To: Chris Friesen; +Cc: Benjamin Collar, linux-kernel
Chris Friesen <cfriesen@nortelnetworks.com> writes:
> The "_syscallx" macros are in the userspace versions of the kernel
> headers, and as such should be fair game.
They are known not to work with -fpic (on x86 anyway, other architectures
are less broken). Anyway, just because there is no #ifdef __KERNEL__
doesn't mean a kernel header is meant for user space use.
> Also, you need to get a list of syscall numbers somehow, and those
> numbers are generally defined in the same file that contains the
> "_syscallx" macros.
They are duplicated in <sys/syscall.h> (which is auto-generated from the
list in <asm/unistd.h>).
> syscall() doesn't work for all system calls. The man page explicitly
> warns that it doesn't work for pipe(2).
Only if pipe(2) uses the "two retvals" calling convention (Alpha and ia64,
but not x86 or m68k). But then, pipe is already available without
syscall(), and new syscalls normally use simple enough calling conventions
that are suitable for syscall().
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-07-05 17:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-05 10:39 PROBLEM: using _syscall4 to call sys_futex with -fPIC won't compile Benjamin Collar
2004-07-05 15:58 ` Andreas Schwab
2004-07-05 16:17 ` Chris Friesen
2004-07-05 17:57 ` Andreas Schwab
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.