[lkml]   [2004]   [Nov]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    SubjectRe: [2.6 patch] kill IN_STRING_C
    On Mon, 8 Nov 2004, Adrian Bunk wrote:

    > On Mon, Nov 08, 2004 at 02:12:18PM -0500, linux-os wrote:
    >> On this compiler 3.3.3, -O2 will cause it to use strcpy().
    > Not for me:
    > .file "test.c"
    > .section .rodata.str1.1,"aMS",@progbits,1
    > .LC0:
    > .string "%s"
    > .text
    > .p2align 4,,15
    > .globl test
    > .type test, @function
    > test:
    > pushl %ebp
    > movl %esp, %ebp
    > subl $12, %esp
    > movl %eax, 8(%esp)
    > movl $.LC0, %eax
    > movl %eax, 4(%esp)
    > movl $buf, (%esp)
    > call sprintf
    > movl %ebp, %esp
    > popl %ebp
    > 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.3.5 (Debian 1:3.3.5-2)"
    > Are you using exactly my example file?
    > Are you using the complete gcc command line as shown by "make V=1"?
    > Which gcc 3.3.3 are you using?

    No, I am using (no headers):
    extern int sprintf(char *, const char *,...);
    extern int puts(const char *);
    static const char hello[]="Hello";
    int xxx(void);
    int xxx(){
    char buf[0x100];
    sprintf(buf, "%s", hello);
    return 0;

    Compiled as:

    gcc -O2 -Wall -S -o xxx xxx.c

    I get:

    .file "xxx.c"
    .section .rodata
    .type hello, @object
    .size hello, 6
    .string "Hello"
    .p2align 2,,3
    .globl xxx
    .type xxx, @function
    pushl %ebp
    movl %esp, %ebp
    pushl %ebx
    subl $268, %esp
    pushl $hello
    leal -264(%ebp), %ebx
    pushl %ebx
    call strcpy
    movl %ebx, (%esp)
    call puts
    xorl %eax, %eax
    movl -4(%ebp), %ebx
    .size xxx, .-xxx
    .section .note.GNU-stack,"",@progbits
    .ident "GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"

    If I don't use -O2, I get the sprintf() call. If I use
    the constant string "Hello" instead of the allocated string,
    it just bypasses everything and calls puts() directly.

    If I use -fno-builtin, then it doesn't bypass sprintf().
    However, there is no ISO C standard of "built-in" so
    I don't think any compiler should default to something
    that is undefined and decide to do whatever its current
    whims are. Certainly, a compiler that has some capabilities,
    not defined by a standard, should be able to use those
    capabilities, but it certainly shouldn't decide to do
    these things on its own.

    Reviewing `man gcc` I see where I should be able to
    find out what the built-in commands are:

    gcc -dumpspecs

    However, this man page is wrong because I don't get a
    listing of any built-in functions, only the linking
    and compiler defaults.

    The compiler is a tool. It should be just like other
    tools. Any killer options should be something that
    take a special effort to turn ON. It shouldn't default
    to firing the bullet out both ends of the barrel!

    Dick Johnson
    Penguin : Linux version 2.6.9 on an i686 machine (5537.79 BogoMips).
    Notice : All mail here is now cached for review by John Ashcroft.
    98.36% of all statistics are fiction.
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to
    More majordomo info at
    Please read the FAQ at

     \ /
      Last update: 2005-03-22 14:07    [W:0.035 / U:112.092 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site