[02/40] sim: Check known getrusage declaration existence

Message ID b05adb17e401d621dbdad791281bc7af7806906e.1666258361.git.research_trasio@irq.a4lg.com
State Committed
Headers
Series sim+gdb: Suppress warnings if built with Clang (big batch 1) |

Commit Message

Tsukasa OI Oct. 20, 2022, 9:32 a.m. UTC
  Clang generates a warning if there is a function declaration/definition
with zero arguments. Such declarations/definitions without a prototype (an
argument list) are deprecated forms of indefinite arguments
("-Wdeprecated-non-prototype"). On the default configuration, it causes a
build failure (unless "--disable-werror" is specified).

Such getrusage function declarations are placed in three files under sim/ppc
and to avoid defining those on the modern environments, this commit will
make the configuration script to find the known declaration of getrusage
and defines HAVE_DECL_GETRUSAGE if it finds one.

If we find one (and we *will* in most modern environments), we don't need
to rely on the deprecated declarations.
---
 sim/config.h.in  |  4 ++++
 sim/configure    | 32 ++++++++++++++++++++++++++++++++
 sim/configure.ac | 10 ++++++++++
 3 files changed, 46 insertions(+)
  

Comments

Mike Frysinger Oct. 23, 2022, 1:59 p.m. UTC | #1
On 20 Oct 2022 09:32, Tsukasa OI wrote:
> Clang generates a warning if there is a function declaration/definition
> with zero arguments. Such declarations/definitions without a prototype (an
> argument list) are deprecated forms of indefinite arguments
> ("-Wdeprecated-non-prototype"). On the default configuration, it causes a
> build failure (unless "--disable-werror" is specified).
> 
> Such getrusage function declarations are placed in three files under sim/ppc
> and to avoid defining those on the modern environments, this commit will
> make the configuration script to find the known declaration of getrusage
> and defines HAVE_DECL_GETRUSAGE if it finds one.
> 
> If we find one (and we *will* in most modern environments), we don't need
> to rely on the deprecated declarations.
> ---
>  sim/config.h.in  |  4 ++++
>  sim/configure    | 32 ++++++++++++++++++++++++++++++++
>  sim/configure.ac | 10 ++++++++++
>  3 files changed, 46 insertions(+)

you didn't actually fix the bad prototypes in the ppc code -- just delete them.
pretty sure once you do, you won't need any of these changes.
-mike
  
Tsukasa OI Oct. 24, 2022, 10:47 a.m. UTC | #2
On 2022/10/23 22:59, Mike Frysinger wrote:
> On 20 Oct 2022 09:32, Tsukasa OI wrote:
>> Clang generates a warning if there is a function declaration/definition
>> with zero arguments. Such declarations/definitions without a prototype (an
>> argument list) are deprecated forms of indefinite arguments
>> ("-Wdeprecated-non-prototype"). On the default configuration, it causes a
>> build failure (unless "--disable-werror" is specified).
>>
>> Such getrusage function declarations are placed in three files under sim/ppc
>> and to avoid defining those on the modern environments, this commit will
>> make the configuration script to find the known declaration of getrusage
>> and defines HAVE_DECL_GETRUSAGE if it finds one.
>>
>> If we find one (and we *will* in most modern environments), we don't need
>> to rely on the deprecated declarations.
>> ---
>>  sim/config.h.in  |  4 ++++
>>  sim/configure    | 32 ++++++++++++++++++++++++++++++++
>>  sim/configure.ac | 10 ++++++++++
>>  3 files changed, 46 insertions(+)
> 
> you didn't actually fix the bad prototypes in the ppc code -- just delete them.
> pretty sure once you do, you won't need any of these changes.
> -mike

I wasn't sure that we could remove getrusage declarations without
prototype because it drops support for *really* old environments.  If we
can "just" remove getrusage declarations (it seems you are okay with
it), that will get definitely simpler.

Thanks,
Tsukasa
  
Mike Frysinger Oct. 24, 2022, 4:03 p.m. UTC | #3
On 24 Oct 2022 19:47, Tsukasa OI wrote:
> On 2022/10/23 22:59, Mike Frysinger wrote:
> > On 20 Oct 2022 09:32, Tsukasa OI wrote:
> >> Clang generates a warning if there is a function declaration/definition
> >> with zero arguments. Such declarations/definitions without a prototype (an
> >> argument list) are deprecated forms of indefinite arguments
> >> ("-Wdeprecated-non-prototype"). On the default configuration, it causes a
> >> build failure (unless "--disable-werror" is specified).
> >>
> >> Such getrusage function declarations are placed in three files under sim/ppc
> >> and to avoid defining those on the modern environments, this commit will
> >> make the configuration script to find the known declaration of getrusage
> >> and defines HAVE_DECL_GETRUSAGE if it finds one.
> >>
> >> If we find one (and we *will* in most modern environments), we don't need
> >> to rely on the deprecated declarations.
> >> ---
> >>  sim/config.h.in  |  4 ++++
> >>  sim/configure    | 32 ++++++++++++++++++++++++++++++++
> >>  sim/configure.ac | 10 ++++++++++
> >>  3 files changed, 46 insertions(+)
> > 
> > you didn't actually fix the bad prototypes in the ppc code -- just delete them.
> > pretty sure once you do, you won't need any of these changes.
> 
> I wasn't sure that we could remove getrusage declarations without
> prototype because it drops support for *really* old environments.  If we
> can "just" remove getrusage declarations (it seems you are okay with
> it), that will get definitely simpler.

the GNU sim documentation says we require an ISO C11 compiler & corresponding
runtime.  if such a system exists that someone cares about, they can propose
a patch & corresponding documentation.  putting bandaids on bandaids that we
can't test isn't really sustainable.
-mike
  

Patch

diff --git a/sim/config.h.in b/sim/config.h.in
index 9a94b289e46..bc7ec588ec6 100644
--- a/sim/config.h.in
+++ b/sim/config.h.in
@@ -44,6 +44,10 @@ 
 /* Is the prototype for getopt in <unistd.h> in the expected format? */
 #undef HAVE_DECL_GETOPT
 
+/* Is the prototype for getrusage in <sys/resource.h> in the expected format?
+   */
+#undef HAVE_DECL_GETRUSAGE
+
 /* Define to 1 if you have the declaration of `tzname', and to 0 if you don't.
    */
 #undef HAVE_DECL_TZNAME
diff --git a/sim/configure b/sim/configure
index dac7f085be1..fbdd256d374 100755
--- a/sim/configure
+++ b/sim/configure
@@ -16460,6 +16460,38 @@  $as_echo "#define HAVE_DECL_GETOPT 1" >>confdefs.h
 
 fi
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a known getrusage prototype in sys/resource.h" >&5
+$as_echo_n "checking for a known getrusage prototype in sys/resource.h... " >&6; }
+if ${sim_cv_decl_getrusage_sys_resource_h+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/resource.h>
+int
+main ()
+{
+extern int getrusage (int, struct rusage *);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  sim_cv_decl_getrusage_sys_resource_h=yes
+else
+  sim_cv_decl_getrusage_sys_resource_h=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $sim_cv_decl_getrusage_sys_resource_h" >&5
+$as_echo "$sim_cv_decl_getrusage_sys_resource_h" >&6; }
+if test $sim_cv_decl_getrusage_sys_resource_h = yes; then
+
+$as_echo "#define HAVE_DECL_GETRUSAGE 1" >>confdefs.h
+
+fi
+
 
 
 
diff --git a/sim/configure.ac b/sim/configure.ac
index be0cfdbea32..9411fc10f9d 100644
--- a/sim/configure.ac
+++ b/sim/configure.ac
@@ -187,6 +187,16 @@  if test $sim_cv_decl_getopt_unistd_h = yes; then
 	    [Is the prototype for getopt in <unistd.h> in the expected format?])
 fi
 
+AC_MSG_CHECKING(for a known getrusage prototype in sys/resource.h)
+AC_CACHE_VAL(sim_cv_decl_getrusage_sys_resource_h,
+[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/resource.h>], [extern int getrusage (int, struct rusage *);])],
+sim_cv_decl_getrusage_sys_resource_h=yes, sim_cv_decl_getrusage_sys_resource_h=no)])
+AC_MSG_RESULT($sim_cv_decl_getrusage_sys_resource_h)
+if test $sim_cv_decl_getrusage_sys_resource_h = yes; then
+  AC_DEFINE([HAVE_DECL_GETRUSAGE], 1,
+	    [Is the prototype for getrusage in <sys/resource.h> in the expected format?])
+fi
+
 dnl These are unfortunate.  They are conditionally called by other sim macros
 dnl but always used by common/Make-common.in.  So we have to subst here even
 dnl when the rest of the code is in the respective macros.  Once we merge the