libgloss fix for bfin port

Message ID f45890f5-3ec2-4238-85f1-fd3f412dde35@gmail.com
State New
Headers
Series libgloss fix for bfin port |

Commit Message

Jeff Law Dec. 17, 2023, 4:57 a.m. UTC
  gcc-14 will complain loudly both for calling a function without an 
in-scope prototype or when the in scope prototype differs from the known 
signature.

"main" happens to be one of the functions the compiler knows about.  So 
not only do we need to prototype it, we need to make sure the prototype 
matches what GCC thinks it should be.

This fixes the bfin libgloss port to do the right thing for bfin-elf.

OK for the trunk?

Jeff
  

Comments

Mike Frysinger Dec. 18, 2023, 4:35 p.m. UTC | #1
On 16 Dec 2023 21:57, Jeff Law wrote:
> gcc-14 will complain loudly both for calling a function without an 
> in-scope prototype or when the in scope prototype differs from the known 
> signature.
> 
> "main" happens to be one of the functions the compiler knows about.  So 
> not only do we need to prototype it, we need to make sure the prototype 
> matches what GCC thinks it should be.
> 
> This fixes the bfin libgloss port to do the right thing for bfin-elf.
> 
> OK for the trunk?

OK

> --- a/libgloss/bfin/syscalls.c
> +++ b/libgloss/bfin/syscalls.c
> @@ -27,6 +27,8 @@
>  #include <reent.h>
>  #include <unistd.h>
>  
> +int main (int, char **, char **);

shouldn't it have `extern` for completeness at least ?

would be nice if we had more clarity on 2-vs-3 signature main in newlib,
but it's fine here to just set another register to 0 before calling.
-mike
  
Jeff Law Dec. 19, 2023, 4:09 a.m. UTC | #2
On 12/18/23 09:35, Mike Frysinger wrote:
> On 16 Dec 2023 21:57, Jeff Law wrote:
>> gcc-14 will complain loudly both for calling a function without an
>> in-scope prototype or when the in scope prototype differs from the known
>> signature.
>>
>> "main" happens to be one of the functions the compiler knows about.  So
>> not only do we need to prototype it, we need to make sure the prototype
>> matches what GCC thinks it should be.
>>
>> This fixes the bfin libgloss port to do the right thing for bfin-elf.
>>
>> OK for the trunk?
> 
> OK
> 
>> --- a/libgloss/bfin/syscalls.c
>> +++ b/libgloss/bfin/syscalls.c
>> @@ -27,6 +27,8 @@
>>   #include <reent.h>
>>   #include <unistd.h>
>>   
>> +int main (int, char **, char **);
> 
> shouldn't it have `extern` for completeness at least ?
Sure.  Easy enough to fix.

> 
> would be nice if we had more clarity on 2-vs-3 signature main in newlib,
> but it's fine here to just set another register to 0 before calling.
Yea.  IIRC we can't pass environments on some targets, or at least not 
easily.  -fpermissive might be the only way forward for those, though 
I'd like to avoid -fpermissive if we can.

jeff
  

Patch

diff --git a/libgloss/bfin/syscalls.c b/libgloss/bfin/syscalls.c
index 7bd0bede1..2282049e9 100644
--- a/libgloss/bfin/syscalls.c
+++ b/libgloss/bfin/syscalls.c
@@ -27,6 +27,8 @@ 
 #include <reent.h>
 #include <unistd.h>
 
+int main (int, char **, char **);
+
 register char *stack_ptr asm ("SP");
 
 static inline int
@@ -254,7 +256,7 @@  __setup_argv_for_main (int argc)
     do_syscall (SYS_argn, (void *)block);
   }
 
-  return main (argc, argv);
+  return main (argc, argv, NULL);
 }
 
 int
@@ -263,7 +265,7 @@  __setup_argv_and_call_main ()
   int argc = do_syscall (SYS_argc, 0);
 
   if (argc <= 0)
-    return main (argc, NULL);
+    return main (argc, NULL, NULL);
   else
     return __setup_argv_for_main (argc);
 }