bug-libsigsegv
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: perhaps a dumb question re libsigsegv


From: Bruno Haible
Subject: Re: perhaps a dumb question re libsigsegv
Date: Sat, 08 Oct 2022 16:05:53 +0200

[CCing the mailing list.]

Dennis Clarke wrote:
> 
> Should libsigsegv be a C99 clean code base ? I have been looking at 
> libsigsegv back to 2.12 on FreeBSD amd64 and on Linux ppc64 and a few 
> other places and mmap() simply will not work with MAP_ANONYMOUS when I 
> ask for strict C99 or even C11.
> 
> The test code in configure is trivial :
> 
> 
> enceladus$
> enceladus$ uname -a
> Linux enceladus 6.0.0-genunix #1 SMP Tue Oct 4 03:08:55 GMT 2022 ppc64 
> GNU/Linux
> enceladus$ cat /var/tmp/dclarke/mmap_test.c
> 
> #include <stdlib.h>
> #include <sys/types.h> 
> 
> #include <sys/mman.h> 
> 
> int main () 
> 
> { 
> 
>      void *p = mmap (0, 0x10000,
>                      PROT_READ | PROT_WRITE, MAP_ANONYMOUS | 
> MAP_PRIVATE, -1, 0);
> 
>      return EXIT_SUCCESS;
> }
> enceladus$
> 
> 
> enceladus$ gcc --version
> gcc (GENUNIX Mon Sep 19 06:45:26 PM UTC 2022) 12.2.0
> Copyright (C) 2022 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> 
> enceladus$ gcc -std=iso9899:1999 -g -O0 -fno-builtin -m64 
> -D_POSIX_PTHREAD_SEMANTICS -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 
> -c -o /var/tmp/dclarke/mmap_test.o /var/tmp/dclarke/mmap_test.c
> /var/tmp/dclarke/mmap_test.c: In function 'main':
> /var/tmp/dclarke/mmap_test.c:8:45: error: 'MAP_ANONYMOUS' undeclared 
> (first use in this function)
>      8 |                     PROT_READ | PROT_WRITE, MAP_ANONYMOUS | 
> MAP_PRIVATE, -1, 0);
>        |                                             ^~~~~~~~~~~~~
> /var/tmp/dclarke/mmap_test.c:8:45: note: each undeclared identifier is 
> reported only once for each function it appears in
> enceladus$
> 
> 
> Also c11 :
> 
> 
> enceladus$
> enceladus$ gcc -std=iso9899:2011 -g -O0 -fno-builtin -m64 
> -D_POSIX_PTHREAD_SEMANTICS -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 
> -c -o /var/tmp/dclarke/mmap_test.o /var/tmp/dclarke/mmap_test.c
> /var/tmp/dclarke/mmap_test.c: In function 'main':
> /var/tmp/dclarke/mmap_test.c:8:45: error: 'MAP_ANONYMOUS' undeclared 
> (first use in this function)
>      8 |                     PROT_READ | PROT_WRITE, MAP_ANONYMOUS | 
> MAP_PRIVATE, -1, 0);
>        |                                             ^~~~~~~~~~~~~
> /var/tmp/dclarke/mmap_test.c:8:45: note: each undeclared identifier is 
> reported only once for each function it appears in
> enceladus$
> 
> 
> 
> However *if* I specify no standard at all then gcc will default to the 
> whatever gnu17 is :
> 
> 
> enceladus$
> enceladus$ gcc -g -O0 -fno-builtin -m64 -D_POSIX_PTHREAD_SEMANTICS 
> -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o 
> /var/tmp/dclarke/mmap_test.o /var/tmp/dclarke/mmap_test.c
> enceladus$ gcc -g -O0 -fno-builtin -m64 -D_POSIX_PTHREAD_SEMANTICS 
> -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -o 
> /var/tmp/dclarke/mmap_test /var/tmp/dclarke/mmap_test.o
> enceladus$ /var/tmp/dclarke/mmap_test
> enceladus$ echo $?
> 0
> enceladus$
> 
> 
> So I guess the question is , gee, what is the C lang spec that I should 
> be using on all platforms for this ?

First, you should be aware what relevant standards exist:
  - C,
  - POSIX: contains additional functions typically found on Unix-like systems,
  - GNU: roughly the same as the LSB, contains additional functions provided
    by the glibc. (And remember that glibc provides access to most Linux
    kernel system calls.)

The C standard can be chosen for a program that is written in portable C,
for example a program that computes and prints N digits of pi.

The POSIX standard can be chosen for a program that uses Unix features (e.g.
mmap), for example a database program.

The GNU "standard" should be chosen for a program that accesses all kinds
of non-portable features.

Second, the GCC manual [1] translates these choices into command-line options
for GCC.

Now, ask yourself: In which category is GNU libsigsegv? A library which makes
use of a signal 'SIGSEGV', which exists in POSIX but not in C.

Bruno

[1] https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/C-Dialect-Options.html






reply via email to

[Prev in Thread] Current Thread [Next in Thread]