This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [RFC Patch]: Implement remainder() as built-in function [PR fortran/24518]
- From: Paul Brook <paul at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: "H. J. Lu" <hjl at lucon dot org>, Roger Sayle <roger at eyesopen dot com>, Mike Stump <mrs at apple dot com>, "Kaveh R. GHAZI" <ghazi at caip dot rutgers dot edu>, Richard Guenther <richard dot guenther at gmail dot com>, Uros Bizjak <ubizjak at gmail dot com>, FX Coudert <fxcoudert at gmail dot com>
- Date: Wed, 25 Oct 2006 21:41:45 +0100
- Subject: Re: [RFC Patch]: Implement remainder() as built-in function [PR fortran/24518]
- References: <5680C5C0-7A87-4413-8726-CF48212FB6D7@apple.com> <Pine.LNX.4.44.0610251328440.15088-100000@www.eyesopen.com> <20061025203201.GA27312@lucon.org>
>
> Will
>
> #include <stdio.h>
>
> FILE *__libgcc_stdout;
>
> static
> init_stdout (void)
> {
> __libgcc_stdout = stdout;
> }
>
> static void (*const init_array []) (void)
> __attribute__ ((section (".init_array"), aligned (sizeof (void *))))
> =
> {
> &init_stdout
> };
>
> work?
No. Consider:
void__attribute__((constructor))
foo(void)
{
printf ("Hello World\n");
}
int main()
{
return 0;
}
foo() may be called before __libgcc_stdout is initialized.
I'm not sure if it's safe to use printf from a constructor. If it is safe you
get the problem mentioned above. If it's not safe then presumably it's not
safe to access stdout either, so your libgcc init routine is also broken.
Paul