All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Gutschke <markus@google.com>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org, dkegel@google.com
Subject: Re: [PATCH 1/1] x86: Make _syscallX() macros compile in PIC mode on i386 (updated patch)
Date: Fri, 10 Mar 2006 14:42:12 -0800	[thread overview]
Message-ID: <441200C4.8040502@google.com> (raw)
In-Reply-To: <20060309192232.2fd4767c.akpm@osdl.org>

[-- Attachment #1: Type: text/plain, Size: 1310 bytes --]

From: Markus Gutschke <markus@google.com>

Gcc reserves %ebx when compiling position-independent-code on i386. This 
means, the _syscallX() macros in include/asm-i386/unistd.h will not 
compile. This patch is against 2.6.15.6 and changes the existing macros 
to take special care to preserve %ebx.

The bug can be tracked at http://bugzilla.kernel.org/show_bug.cgi?id=6204

Signed-off-by: Markus Gutschke <markus@google.com>

---

Andrew Morton wrote:
> Markus Gutschke <markus@google.com> wrote:
>>That is certainly possible. The new macros work in both modes, but they 
>>are slightly less efficient than the old macros, if you have access to 
>>%ebx (i.e. in non-PIC code). If you prefer, we could just remove the old 
>>macros and unconditionally replace them with the new ones. 
> 
> I'd be OK with that - the kernel doesn't (shouldn't) care about the
> performance of __KERNEL_SYSCALLS__ stuff.  I doubt if glibc is borrowing
> the kernel's macros.

Would you like this patch better? It now unconditionally replaces the 
old macros with a fixed version. This will entail a minor performance 
penalty in non-PIC mode. But for the vast majority of applications the 
difference should be entire negligible.

Once this change has made it into the kernel, I will try to get it 
propagated into libc.


Markus

[-- Attachment #2: unistd.h.diff --]
[-- Type: text/x-patch, Size: 3226 bytes --]

--- linux-2.6.15.6/include/asm-i386/unistd.h.orig	2006-03-05 11:07:54.000000000 -0800
+++ linux-2.6.15.6/include/asm-i386/unistd.h	2006-03-10 14:33:10.000000000 -0800
@@ -330,9 +330,9 @@
 type name(type1 arg1) \
 { \
 long __res; \
-__asm__ volatile ("int $0x80" \
+__asm__ volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \
 	: "=a" (__res) \
-	: "0" (__NR_##name),"b" ((long)(arg1)) : "memory"); \
+	: "0" (__NR_##name),"ri" ((long)(arg1)) : "memory"); \
 __syscall_return(type,__res); \
 }
 
@@ -340,9 +340,10 @@
 type name(type1 arg1,type2 arg2) \
 { \
 long __res; \
-__asm__ volatile ("int $0x80" \
+__asm__ volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \
 	: "=a" (__res) \
-	: "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)) : "memory"); \
+	: "0" (__NR_##name),"ri" ((long)(arg1)),"c" ((long)(arg2)) \
+	: "memory"); \
 __syscall_return(type,__res); \
 }
 
@@ -350,9 +351,9 @@
 type name(type1 arg1,type2 arg2,type3 arg3) \
 { \
 long __res; \
-__asm__ volatile ("int $0x80" \
+__asm__ volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \
 	: "=a" (__res) \
-	: "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
+	: "0" (__NR_##name),"ri" ((long)(arg1)),"c" ((long)(arg2)), \
 		  "d" ((long)(arg3)) : "memory"); \
 __syscall_return(type,__res); \
 }
@@ -361,9 +362,9 @@
 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
 { \
 long __res; \
-__asm__ volatile ("int $0x80" \
+__asm__ volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \
 	: "=a" (__res) \
-	: "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
+	: "0" (__NR_##name),"ri" ((long)(arg1)),"c" ((long)(arg2)), \
 	  "d" ((long)(arg3)),"S" ((long)(arg4)) : "memory"); \
 __syscall_return(type,__res); \
 } 
@@ -373,10 +374,12 @@
 type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
 { \
 long __res; \
-__asm__ volatile ("int $0x80" \
+__asm__ volatile ("push %%ebx ; movl %2,%%ebx ; movl %1,%%eax ; " \
+                  "int $0x80 ; pop %%ebx" \
 	: "=a" (__res) \
-	: "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
-	  "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5)) : "memory"); \
+	: "i" (__NR_##name),"ri" ((long)(arg1)),"c" ((long)(arg2)), \
+	  "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5)) \
+	: "memory"); \
 __syscall_return(type,__res); \
 }
 
@@ -385,11 +388,14 @@
 type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,type6 arg6) \
 { \
 long __res; \
-__asm__ volatile ("push %%ebp ; movl %%eax,%%ebp ; movl %1,%%eax ; int $0x80 ; pop %%ebp" \
-	: "=a" (__res) \
-	: "i" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
-	  "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5)), \
-	  "0" ((long)(arg6)) : "memory"); \
+  struct { long __a1; long __a6; } __s = { (long)arg1, (long)arg6 }; \
+__asm__ volatile ("push %%ebp ; push %%ebx ; movl 4(%2),%%ebp ; " \
+                  "movl 0(%2),%%ebx ; movl %1,%%eax ; int $0x80 ; " \
+                  "pop %%ebx ;  pop %%ebp" \
+	: "=a" (__res) \
+	: "i" (__NR_##name),"0" ((long)(&__s)),"c" ((long)(arg2)), \
+	  "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5)) \
+	: "memory"); \
 __syscall_return(type,__res); \
 }
 

  parent reply	other threads:[~2006-03-10 22:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-09 23:33 [PATCH 1/1] x86: Make _syscallX() macros compile in PIC mode on i386 Markus Gutschke
2006-03-10  2:47 ` Andrew Morton
2006-03-10  3:03   ` Markus Gutschke
2006-03-10  3:22     ` Andrew Morton
2006-03-10  3:36       ` dkegel
2006-03-10 23:40         ` Daniel Jacobowitz
2006-03-10 23:53           ` dkegel
2006-03-10 22:42       ` Markus Gutschke [this message]
2006-03-10 23:02         ` [PATCH 1/1] x86: Make _syscallX() macros compile in PIC mode on i386 (updated patch) dkegel
2006-03-11  0:05       ` [PATCH 1/1] x86: Make _syscallX() macros compile in PIC mode on i386 Arnd Bergmann
2006-03-10 14:37   ` Jan Engelhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=441200C4.8040502@google.com \
    --to=markus@google.com \
    --cc=akpm@osdl.org \
    --cc=dkegel@google.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.