linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [2.6 patch] kill IN_STRING_C
@ 2004-11-07 14:24 Adrian Bunk
  2004-11-08 13:44 ` Andi Kleen
       [not found] ` <200411081942.38954.pluto@pld-linux.org>
  0 siblings, 2 replies; 31+ messages in thread
From: Adrian Bunk @ 2004-11-07 14:24 UTC (permalink / raw)
  To: Andi Kleen; +Cc: linux-kernel

Hi Andi,

some months ago, you invented a IN_STRING_C with the following comment:

<--  snip  -->

gcc 3.4 optimizes sprintf(foo,"%s",string) into strcpy.  

Unfortunately that isn't seen by the inliner and linux/i386 has no 
out-of-line strcpy so you end up with a linker error.

This patch adds out of line copies for most string functions to avoid 
this.
...

<--  snip  -->


I tried 2.6.10-rc1-mm3 with gcc 3.4.2 and the patch below and didn't 
observe the problems you described.


Can you still reproduce this problem?
If not, I'll suggest to apply the patch below which saves a few kB in 
lib/string.o .



Signed-off-by: Adrian Bunk <bunk@stusta.de>

--- linux-2.6.10-rc1-mm3-full/include/asm-i386/string.h.old	2004-11-07 13:27:44.000000000 +0100
+++ linux-2.6.10-rc1-mm3-full/include/asm-i386/string.h	2004-11-07 13:28:47.000000000 +0100
@@ -25,7 +25,6 @@
 
 /* AK: in fact I bet it would be better to move this stuff all out of line.
  */
-#if !defined(IN_STRING_C)
 
 #define __HAVE_ARCH_STRCPY
 static inline char * strcpy(char * dest,const char *src)
@@ -180,8 +179,6 @@
 return __res;
 }
 
-#endif
-
 #define __HAVE_ARCH_STRLEN
 static inline size_t strlen(const char * s)
 {
--- linux-2.6.10-rc1-mm3-full/lib/string.c.old	2004-11-07 13:29:00.000000000 +0100
+++ linux-2.6.10-rc1-mm3-full/lib/string.c	2004-11-07 13:29:05.000000000 +0100
@@ -19,8 +19,6 @@
  * -  Kissed strtok() goodbye
  */
 
-#define IN_STRING_C 1
- 
 #include <linux/types.h>
 #include <linux/string.h>
 #include <linux/ctype.h>

^ permalink raw reply	[flat|nested] 31+ messages in thread
* Re: [2.6 patch] kill IN_STRING_C
@ 2004-11-08 18:43 Paweł Sikora
  0 siblings, 0 replies; 31+ messages in thread
From: Paweł Sikora @ 2004-11-08 18:43 UTC (permalink / raw)
  To: linux-kernel

On Monday 08 of November 2004 19:31, you wrote:
> On Mon, Nov 08, 2004 at 07:04:13PM +0100, Pawe?? Sikora wrote:
> > On Monday 08 of November 2004 17:31, you wrote:
> > > On Mon, Nov 08, 2004 at 05:19:35PM +0100, Andi Kleen wrote:
> > > > > Rethinking it, I don't even understand the sprintf example in your
> > > > > changelog entry - shouldn't an inclusion of kernel.h always get it
> > > > > right?
> > > >
> > > > Newer gcc rewrites sprintf(buf,"%s",str) to strcpy(buf,str)
> > > > transparently.
> > >
> > > Which gcc is "Newer"?
> > >
> > > My gcc 3.4.2 didn't show this problem.
> >
> > #include <stdio.h>
> > #include <string.h>
> > char buf[128];
> > void test(char *str)
> > {
> >     sprintf(buf, "%s", str);
> > }
> >...
> >         jmp     strcpy
> >...
>
> This is the userspace example.
>
> The kernel example is:
>
> #include <linux/string.h>
> #include <linux/kernel.h>
>
> char buf[128];
> void test(char *str)
> {
>   sprintf(buf, "%s", str);
> }
>
>
> This results with gcc-3.4 (GCC) 3.4.2 (Debian 3.4.2-3) in:
>
>         .file   "test.c"
>         .section        .rodata.str1.1,"aMS",@progbits,1
> .LC0:
>         .string "%s"
>         .text
>         .p2align 4,,15
> .globl test
>         .type   test, @function
> test:
>         pushl   %eax
>         pushl   $.LC0
>         pushl   $buf
>         call    sprintf
>         addl    $12, %esp
>         ret
>         .size   test, .-test
> .globl buf
>         .bss
>         .align 32
>         .type   buf, @object
>         .size   buf, 128
> buf:
>         .zero   128
>         .section        .note.GNU-stack,"",@progbits
>         .ident  "GCC: (GNU) 3.4.2 (Debian 3.4.2-3)"

[~/rpm/BUILD] # cat sp.c

#include <linux/string.h>
#include <linux/kernel.h>

char buf[128];
void test(char *str)
{
    sprintf(buf, "%s", str);
}

[~/rpm/BUILD] # gcc -Wall sp.c -S -O2 -fomit-frame-pointer -mregparm=3
                    -nostdinc -isystem /usr/src/linux/include

sp.c: In function `test':
sp.c:7: warning: implicit declaration of function `sprintf'

[~/rpm/BUILD] # cat sp.s

        .file   "sp.c"
        .text
        .p2align 4,,15
.globl test
        .type   test, @function
test:
        movl    %eax, %edx
        movl    $buf, %eax
        jmp     strcpy
        .size   test, .-test
        .comm   buf,128,32
        .section        .note.GNU-stack,"",@progbits
        .ident  "GCC: (GNU) 3.4.3 (PLD Linux)"


What now?

-- 
/* Copyright (C) 2003, SCO, Inc. This is valuable Intellectual Property. */

                           #define say(x) lie(x)

^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2004-11-10 21:20 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-07 14:24 [2.6 patch] kill IN_STRING_C Adrian Bunk
2004-11-08 13:44 ` Andi Kleen
2004-11-08 15:34   ` Adrian Bunk
2004-11-08 16:19     ` Andi Kleen
2004-11-08 16:31       ` Adrian Bunk
2004-11-08 17:51         ` Andi Kleen
2004-11-08 18:34           ` Adrian Bunk
2004-11-08 19:01             ` Andi Kleen
2004-11-08 23:38               ` Use -ffreestanding? Adrian Bunk
2004-11-09  5:01                 ` Andi Kleen
2004-11-10  1:45                   ` [2.6 patch] " Adrian Bunk
2004-11-10  1:51                     ` Linus Torvalds
2004-11-10  1:57                       ` Adrian Bunk
2004-11-10 21:01                       ` Bill Davidsen
2004-11-08 18:04         ` [2.6 patch] kill IN_STRING_C Paweł Sikora
2004-11-08 18:31           ` Adrian Bunk
2004-11-08 19:12             ` linux-os
2004-11-08 21:27               ` Adrian Bunk
2004-11-08 22:15                 ` linux-os
2004-11-08 22:29                   ` Adrian Bunk
2004-11-08 22:57                     ` linux-os
2004-11-08 23:08                       ` Adrian Bunk
2004-11-09 12:44                         ` linux-os
2004-11-09 13:43                           ` linux-os
2004-11-08 18:22       ` linux-os
2004-11-08 19:31         ` Ryan Cumming
2004-11-09 13:58     ` Arnd Bergmann
2004-11-10  2:30       ` Adrian Bunk
     [not found] ` <200411081942.38954.pluto@pld-linux.org>
     [not found]   ` <20041108185222.GE15077@stusta.de>
2004-11-08 19:11     ` Paweł Sikora
2004-11-08 21:25       ` Adrian Bunk
  -- strict thread matches above, loose matches on Subject: below --
2004-11-08 18:43 Paweł Sikora

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).