Re: [2.6 patch] kill IN_STRING_C
Date: Mon Nov 08 2004 - 17:23:16 EST
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:
.type test, @function
movl %esp, %ebp
subl $12, %esp
movl %eax, 8(%esp)
movl $.LC0, %eax
movl %eax, 4(%esp)
movl $buf, (%esp)
movl %ebp, %esp
.size test, .-test
.type buf, @object
.size buf, 128
.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";
sprintf(buf, "%s", hello);
gcc -O2 -Wall -S -o xxx xxx.c
.type hello, @object
.size hello, 6
.type xxx, @function
movl %esp, %ebp
subl $268, %esp
leal -264(%ebp), %ebx
movl %ebx, (%esp)
xorl %eax, %eax
movl -4(%ebp), %ebx
.size xxx, .-xxx
.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:
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!
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 majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/