This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC Patch]: Implement remainder() as built-in function [PR fortran/24518]


>
> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]