Bug#299188: gcc: -ffreestanding and builtins don't work as expected
Adrian Bunk wrote:
[snip]
> #define sprintf __builtin_sprintf
>
> int main()
> {
> char str[] = "abc";
> char buf[10];
>
> sprintf(buf,"%s",str);
>
> return 0;
> }
[snip]
> call strcpy
[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.
You explicitly requested the __builtin_sprintf implementation, which is
allowed to decay to strcpy, and overrode the -ffreestanding in this
case. AFAICS the documentation is correct (but not that explicit for
that cornercase).
Thiemo
Reply to: