libiberty: Fix C89-isms in configure tests
Checks
Commit Message
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(-)
base-commit: 54b316ff0d4f3bd823ad0b4d0011900948c5d40e
Comments
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
* 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
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
* 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
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
@@ -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,
@@ -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