public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libiberty: Fix C89-isms in configure tests
@ 2022-10-18 10:05 Florian Weimer
  2022-10-18 12:57 ` Jakub Jelinek
  0 siblings, 1 reply; 6+ messages in thread
From: Florian Weimer @ 2022-10-18 10:05 UTC (permalink / raw)
  To: gcc-patches

libiberty/

	* acinclude.m4 (check for working strncmp): Add missing
	int return type and parameter list to the definition of main.
	Include <string.h> for string functions.  Avoid calling
	undeclared exit function.
        (stack direction for C alloca): Avoid calling undeclared exit
        function.
	* configure: Regenerate.

---
 libiberty/acinclude.m4 | 12 +++++++-----
 libiberty/configure    | 12 +++++++-----
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/libiberty/acinclude.m4 b/libiberty/acinclude.m4
index 6bd127e9826..6e23ae906fc 100644
--- a/libiberty/acinclude.m4
+++ b/libiberty/acinclude.m4
@@ -24,6 +24,7 @@ AC_CACHE_CHECK([for working strncmp], ac_cv_func_strncmp_works,
 [AC_TRY_RUN([
 /* Test by Jim Wilson and Kaveh Ghazi.
    Check whether strncmp reads past the end of its string parameters. */
+#include <string.h>
 #include <sys/types.h>
 
 #ifdef HAVE_FCNTL_H
@@ -51,7 +52,8 @@ AC_CACHE_CHECK([for working strncmp], ac_cv_func_strncmp_works,
 
 #define MAP_LEN 0x10000
 
-main ()
+int
+main (void)
 {
 #if defined(HAVE_MMAP) || defined(HAVE_MMAP_ANYWHERE)
   char *p;
@@ -59,7 +61,7 @@ main ()
 
   dev_zero = open ("/dev/zero", O_RDONLY);
   if (dev_zero < 0)
-    exit (1);
+    return 1;
 
   p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE,
 		     MAP_ANON|MAP_PRIVATE, dev_zero, 0);
@@ -67,7 +69,7 @@ main ()
     p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE,
 		       MAP_ANON|MAP_PRIVATE, -1, 0);
   if (p == (char *)-1)
-    exit (2);
+    return 2;
   else
     {
       char *string = "__si_type_info";
@@ -79,7 +81,7 @@ main ()
       strncmp (r, q, 14);
     }
 #endif /* HAVE_MMAP || HAVE_MMAP_ANYWHERE */
-  exit (0);
+  return 0;
 }
 ], ac_cv_func_strncmp_works=yes, ac_cv_func_strncmp_works=no,
   ac_cv_func_strncmp_works=yes)
@@ -171,7 +173,7 @@ AC_CACHE_CHECK(stack direction for C alloca, ac_cv_c_stack_direction,
 }
 main ()
 {
-  exit (find_stack_direction() < 0);
+  return find_stack_direction() < 0;
 }],
   ac_cv_c_stack_direction=1,
   ac_cv_c_stack_direction=-1,
diff --git a/libiberty/configure b/libiberty/configure
index 65fc5002002..c871cc559ca 100755
--- a/libiberty/configure
+++ b/libiberty/configure
@@ -6798,7 +6798,7 @@ find_stack_direction ()
 }
 main ()
 {
-  exit (find_stack_direction() < 0);
+  return find_stack_direction() < 0;
 }
 _ACEOF
 if ac_fn_c_try_run "$LINENO"; then :
@@ -7621,6 +7621,7 @@ else
 
 /* Test by Jim Wilson and Kaveh Ghazi.
    Check whether strncmp reads past the end of its string parameters. */
+#include <string.h>
 #include <sys/types.h>
 
 #ifdef HAVE_FCNTL_H
@@ -7648,7 +7649,8 @@ else
 
 #define MAP_LEN 0x10000
 
-main ()
+int
+main (void)
 {
 #if defined(HAVE_MMAP) || defined(HAVE_MMAP_ANYWHERE)
   char *p;
@@ -7656,7 +7658,7 @@ main ()
 
   dev_zero = open ("/dev/zero", O_RDONLY);
   if (dev_zero < 0)
-    exit (1);
+    return 1;
 
   p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE,
 		     MAP_ANON|MAP_PRIVATE, dev_zero, 0);
@@ -7664,7 +7666,7 @@ main ()
     p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE,
 		       MAP_ANON|MAP_PRIVATE, -1, 0);
   if (p == (char *)-1)
-    exit (2);
+    return 2;
   else
     {
       char *string = "__si_type_info";
@@ -7676,7 +7678,7 @@ main ()
       strncmp (r, q, 14);
     }
 #endif /* HAVE_MMAP || HAVE_MMAP_ANYWHERE */
-  exit (0);
+  return 0;
 }
 
 _ACEOF

base-commit: 54b316ff0d4f3bd823ad0b4d0011900948c5d40e


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] libiberty: Fix C89-isms in configure tests
  2022-10-18 10:05 [PATCH] libiberty: Fix C89-isms in configure tests Florian Weimer
@ 2022-10-18 12:57 ` Jakub Jelinek
  2022-10-18 14:06   ` Florian Weimer
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Jelinek @ 2022-10-18 12:57 UTC (permalink / raw)
  To: Florian Weimer; +Cc: gcc-patches

On Tue, Oct 18, 2022 at 12:05:49PM +0200, Florian Weimer via Gcc-patches wrote:
> libiberty/
> 
> 	* acinclude.m4 (check for working strncmp): Add missing
> 	int return type and parameter list to the definition of main.
> 	Include <string.h> for string functions.  Avoid calling
> 	undeclared exit function.
>         (stack direction for C alloca): Avoid calling undeclared exit
>         function.

Spaces instead of tabs.
I'd think we should #include <stdlib.h> for exit and keep exit, I vaguely
remember non-zero return from main doesn't always work reliably, which is
why e.g. in the testsuite we usually abort instead of return non-zero
from main.  Don't remember if it is just for some bare metal cases or
what, which on the either side probably don't have mmap.

	Jakub


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] libiberty: Fix C89-isms in configure tests
  2022-10-18 12:57 ` Jakub Jelinek
@ 2022-10-18 14:06   ` Florian Weimer
  2022-10-18 14:08     ` Jakub Jelinek
  0 siblings, 1 reply; 6+ messages in thread
From: Florian Weimer @ 2022-10-18 14:06 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

* Jakub Jelinek:

> On Tue, Oct 18, 2022 at 12:05:49PM +0200, Florian Weimer via Gcc-patches wrote:
>> libiberty/
>> 
>> 	* acinclude.m4 (check for working strncmp): Add missing
>> 	int return type and parameter list to the definition of main.
>> 	Include <string.h> for string functions.  Avoid calling
>> 	undeclared exit function.
>>         (stack direction for C alloca): Avoid calling undeclared exit
>>         function.
>
> Spaces instead of tabs.

You mean I should use tabs throughout, right?

> I'd think we should #include <stdlib.h> for exit and keep exit, I vaguely
> remember non-zero return from main doesn't always work reliably, which is
> why e.g. in the testsuite we usually abort instead of return non-zero
> from main.  Don't remember if it is just for some bare metal cases or
> what, which on the either side probably don't have mmap.

Okay, will do that and send a v2.

By the way, the stack direction test currently gives incorrect results
on x86-64 due to -O2 and address comparison of unrelated objects.  I
assume this doesn't matter because we don't use it on compilers that
support alloca natively.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] libiberty: Fix C89-isms in configure tests
  2022-10-18 14:06   ` Florian Weimer
@ 2022-10-18 14:08     ` Jakub Jelinek
  2022-10-18 14:14       ` Florian Weimer
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Jelinek @ 2022-10-18 14:08 UTC (permalink / raw)
  To: Florian Weimer; +Cc: gcc-patches

On Tue, Oct 18, 2022 at 04:06:17PM +0200, Florian Weimer wrote:
> By the way, the stack direction test currently gives incorrect results
> on x86-64 due to -O2 and address comparison of unrelated objects.  I
> assume this doesn't matter because we don't use it on compilers that
> support alloca natively.

Guess it would be better to cast the addresses to uintptr_t and
compare that.

	Jakub


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] libiberty: Fix C89-isms in configure tests
  2022-10-18 14:08     ` Jakub Jelinek
@ 2022-10-18 14:14       ` Florian Weimer
  2022-10-18 14:19         ` Jakub Jelinek
  0 siblings, 1 reply; 6+ messages in thread
From: Florian Weimer @ 2022-10-18 14:14 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

* Jakub Jelinek:

> On Tue, Oct 18, 2022 at 04:06:17PM +0200, Florian Weimer wrote:
>> By the way, the stack direction test currently gives incorrect results
>> on x86-64 due to -O2 and address comparison of unrelated objects.  I
>> assume this doesn't matter because we don't use it on compilers that
>> support alloca natively.
>
> Guess it would be better to cast the addresses to uintptr_t and
> compare that.

But can we assume that uintptr_t is defined?  Or that <stdint.h> exists?

Thanks,
Florian


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] libiberty: Fix C89-isms in configure tests
  2022-10-18 14:14       ` Florian Weimer
@ 2022-10-18 14:19         ` Jakub Jelinek
  0 siblings, 0 replies; 6+ messages in thread
From: Jakub Jelinek @ 2022-10-18 14:19 UTC (permalink / raw)
  To: Florian Weimer; +Cc: gcc-patches

On Tue, Oct 18, 2022 at 04:14:53PM +0200, Florian Weimer wrote:
> * Jakub Jelinek:
> 
> > On Tue, Oct 18, 2022 at 04:06:17PM +0200, Florian Weimer wrote:
> >> By the way, the stack direction test currently gives incorrect results
> >> on x86-64 due to -O2 and address comparison of unrelated objects.  I
> >> assume this doesn't matter because we don't use it on compilers that
> >> support alloca natively.
> >
> > Guess it would be better to cast the addresses to uintptr_t and
> > compare that.
> 
> But can we assume that uintptr_t is defined?  Or that <stdint.h> exists?

In libiberty no, I'm afraid.

	Jakub


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-10-18 14:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-18 10:05 [PATCH] libiberty: Fix C89-isms in configure tests Florian Weimer
2022-10-18 12:57 ` Jakub Jelinek
2022-10-18 14:06   ` Florian Weimer
2022-10-18 14:08     ` Jakub Jelinek
2022-10-18 14:14       ` Florian Weimer
2022-10-18 14:19         ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).