gcn/mkoffload.cc: Re-add fprintf for #include of stdlib.h/stdbool.h (was: [Patch, v3] gcn/mkoffload.cc: Use #embed for including the generated ELF file)

Message ID 7d9caf7d-36f9-4dd5-906a-8e37023f6aeb@baylibre.com
State Committed
Commit dfb750798b07e7f412d52c22145ca8bce1911ac8
Headers
Series gcn/mkoffload.cc: Re-add fprintf for #include of stdlib.h/stdbool.h (was: [Patch, v3] gcn/mkoffload.cc: Use #embed for including the generated ELF file) |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Test passed

Commit Message

Tobias Burnus Sept. 20, 2024, 10:52 p.m. UTC
  Hi Thomas,

See attached patch for adding the include lines:

+  if (gcn_stack_size)
+    {
+      fprintf (cfile, "#include <stdlib.h>\n");
+      fprintf (cfile, "#include <stdbool.h>\n\n");

but contrary to previously there is no 'stdint.h'
and they are also not unconditionally included.

(The 'stdbool.h' is only used for a single 'true', but on the other hand it
is only #included under this condition and 'stdbool.h' is a very simple file.)

I intent to apply this patch as obvious, unless there are further comments.

* * *

Thomas Schwinge wrote:

> I've not verified, but I very much suspect that this change: […]
>>      gcn/mkoffload.cc: Use #embed for including the generated ELF file
>> ... is responsible for: […]
>      /tmp/ccHVeRbm.c:80:21: error: implicit declaration of function 'getenv' [-Wimplicit-function-declaration]
> […] Did you not see that happen in your testing?

I vaguely remember some fails in this area — but after digging and 
re-testing, it did not show up, for whatever reason. As it only triggers 
with -mstack-size, it somehow must have fallen through the cracks. :-/

Tobias
  

Comments

Tobias Burnus Sept. 23, 2024, 1:56 p.m. UTC | #1
Now committed as r15-3797-ga030fcad4f9f49 / 
https://gcc.gnu.org/r15-3797-ga030fcad4f9f49 as obvious.

Tobias

Am 21.09.24 um 00:52 schrieb Tobias Burnus:
> See attached patch for adding the include lines:
>
> +  if (gcn_stack_size)
> +    {
> +      fprintf (cfile, "#include <stdlib.h>\n");
> +      fprintf (cfile, "#include <stdbool.h>\n\n");
>
> but contrary to previously there is no 'stdint.h'
> and they are also not unconditionally included.
>
> (The 'stdbool.h' is only used for a single 'true', but on the other 
> hand it
> is only #included under this condition and 'stdbool.h' is a very 
> simple file.)
>
> I intent to apply this patch as obvious, unless there are further 
> comments.
>
> * * *
>
> Thomas Schwinge wrote:
>
>> I've not verified, but I very much suspect that this change: […]
>>>      gcn/mkoffload.cc: Use #embed for including the generated ELF file
>>> ... is responsible for: […]
>>      /tmp/ccHVeRbm.c:80:21: error: implicit declaration of function 
>> 'getenv' [-Wimplicit-function-declaration]
>> […] Did you not see that happen in your testing?
>
> I vaguely remember some fails in this area — but after digging and 
> re-testing, it did not show up, for whatever reason. As it only 
> triggers with -mstack-size, it somehow must have fallen through the 
> cracks. :-/
  

Patch

gcn/mkoffload.cc: Re-add fprintf for #include of stdlib.h/stdbool.h

In commit r15-3629-g508ef585243d4674d06b0737bfe8769fc18f824f, #embed
was added and no longer required fprintf '#include' removed, missing
somehow that with -mstack-size=, the generated configure_stack_size
will use 'setenv' and 'true'.

gcc/ChangeLog:

	* config/gcn/mkoffload.cc (process_asm): (Re)add the fprintf
	lines for stdlib.h/stdbool.h inclusion if gcn_stack_size is used.

diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc
index 1f6337719e9..1a524ced653 100644
--- a/gcc/config/gcn/mkoffload.cc
+++ b/gcc/config/gcn/mkoffload.cc
@@ -613,6 +613,12 @@  process_asm (FILE *in, FILE *out, FILE *cfile)
   struct oaccdims *dims = XOBFINISH (&dims_os, struct oaccdims *);
   struct regcount *regcounts = XOBFINISH (&regcounts_os, struct regcount *);
 
+  if (gcn_stack_size)
+    {
+      fprintf (cfile, "#include <stdlib.h>\n");
+      fprintf (cfile, "#include <stdbool.h>\n\n");
+    }
+
   fprintf (cfile, "static const int gcn_num_vars = %d;\n\n", var_count);
   fprintf (cfile, "static const int gcn_num_ind_funcs = %d;\n\n", ind_fn_count);