Bug#299188: gcc: -ffreestanding and builtins don't work as expected
Package: gcc-3.4
Version: 3.4.3-11
Severity: normal
The info file says:
<-- snip -->
With the `-fno-builtin-FUNCTION' option only the built-in function
FUNCTION is disabled. FUNCTION must not begin with `__builtin_'.
If a function is named this is not built-in in this version of
GCC, this option is ignored. There is no corresponding
`-fbuiltin-FUNCTION' option; if you wish to enable built-in
functions selectively when using `-fno-builtin' or
`-ffreestanding', you may define macros such as:
#define abs(n) __builtin_abs ((n))
#define strcpy(d, s) __builtin_strcpy ((d), (s))
<-- snip -->
But:
<-- snip -->
$ cat test.c
#define sprintf __builtin_sprintf
int main()
{
char str[] = "abc";
char buf[10];
sprintf(buf,"%s",str);
return 0;
}
$ gcc-3.4 -S -ffreestanding -Wall test.c
$ cat test.s
.file "test.c"
.section .rodata
.LC0:
.string "abc"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $40, %esp
andl $-16, %esp
movl $0, %eax
addl $15, %eax
addl $15, %eax
shrl $4, %eax
sall $4, %eax
subl %eax, %esp
movl .LC0, %eax
movl %eax, -12(%ebp)
subl $8, %esp
leal -12(%ebp), %eax
pushl %eax
leal -40(%ebp), %eax
pushl %eax
call strcpy
addl $16, %esp
movl $0, %eax
leave
ret
.size main, .-main
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.4.4 20050305 (prerelease) (Debian 3.4.3-11)"
$
<-- snip -->
As far as I understand the documentation, the call to strcpy
shouldn't be emitted since this function is not required in a
freestanding environment.
gcc-3.3 and gcc-4.0 behave similar.
I'm not sure whether this is expected, but if it is, the documentation
should be updated.
-- System Information:
Debian Release: 3.1
APT prefers unstable
APT policy: (500, 'unstable'), (500, 'testing'), (1, 'experimental')
Architecture: i386 (i686)
Kernel: Linux 2.6.11-mm2
Locale: LANG=en_US, LC_CTYPE=en_US (charmap=ISO-8859-1)
Versions of packages gcc-3.4 depends on:
ii binutils 2.15-5 The GNU assembler, linker and bina
ii cpp-3.4 3.4.3-11 The GNU C preprocessor
ii gcc-3.4-base 3.4.3-11 The GNU Compiler Collection (base
ii libc6 2.3.2.ds1-20 GNU C Library: Shared libraries an
ii libgcc1 1:4.0-0pre5 GCC support library
-- no debconf information
Reply to: