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

Bug#331064: marked as done (Compilation fails with sys/mman.h mmap with -std=c89 on GCC 4.0.1)



Your message dated Sun, 13 Mar 2016 18:28:47 +0100
with message-id <20160313172847.GA3421@aurel32.net>
and subject line Bug#331064: Compilation fails with sys/mman.h mmap with -std=c89 on GCC 4.0.1
has caused the Debian Bug report #331064,
regarding Compilation fails with sys/mman.h mmap with -std=c89 on GCC 4.0.1
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact owner@bugs.debian.org
immediately.)


-- 
331064: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=331064
Debian Bug Tracking System
Contact owner@bugs.debian.org with problems
--- Begin Message ---
Package: libc6-dev
Version: 2.3.5-6

Hi,

I'm trying to compile this:

<clip>
/* #define __USE_MISC */

#include <sys/mman.h>
#include <unistd.h>

static int pageCount(size_t len)
{
	unsigned long ps = getpagesize();
	return ((len + (ps - 1)) / ps) * ps;
}

static void* execMalloc(size_t requested_length)
{
	const int MMAP_BASE_ADDRESS = 1024*1024;
	void* addr = (mmap (((void *) MMAP_BASE_ADDRESS),
						(size_t)pageCount(requested_length),
						(PROT_EXEC | PROT_READ | PROT_WRITE),
						(MAP_PRIVATE | MAP_ANONYMOUS),
						/* Ignored by GNU/Linux, required by FreeBSD and Solaris. */
						(-1),
						0));
	return ((addr == MAP_FAILED) ? 0 : addr);
}
</clip>

with gcc 4.0.1.  The above fails to compile with -std=c89:

<clip>
janne@nurbian:~/dev$ gcc -std=c89 -c mmap.c
mmap.c: In function 'execMalloc':
mmap.c:14: error: 'MAP_ANONYMOUS' undeclared (first use in this function)
mmap.c:14: error: (Each undeclared identifier is reported only once
mmap.c:14: error: for each function it appears in.)
</clip>

If I don't specify -std=c89, it works nicely.  If I define __USE_MISC,
then it compiles again.

Is this the way it should work?

I am using Debian GNU/Linux 2.6.

janne@nurbian:~/dev$ gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib --enable-nls
--without-included-gettext --enable-threads=posix
--program-suffix=-4.0 --enable-__cxa_atexit
--enable-libstdcxx-allocator=mt --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre
--enable-mpfr --disable-werror --enable-checking=release
i486-linux-gnu
Thread model: posix
gcc version 4.0.1 (Debian 4.0.1-2)


--- End Message ---
--- Begin Message ---
On 2005-10-01 13:59, Janne Hellsten wrote:
> Package: libc6-dev
> Version: 2.3.5-6
> 
> Hi,
> 
> I'm trying to compile this:
> 
> <clip>
> /* #define __USE_MISC */
> 
> #include <sys/mman.h>
> #include <unistd.h>
> 
> static int pageCount(size_t len)
> {
> 	unsigned long ps = getpagesize();
> 	return ((len + (ps - 1)) / ps) * ps;
> }
> 
> static void* execMalloc(size_t requested_length)
> {
> 	const int MMAP_BASE_ADDRESS = 1024*1024;
> 	void* addr = (mmap (((void *) MMAP_BASE_ADDRESS),
> 						(size_t)pageCount(requested_length),
> 						(PROT_EXEC | PROT_READ | PROT_WRITE),
> 						(MAP_PRIVATE | MAP_ANONYMOUS),
> 						/* Ignored by GNU/Linux, required by FreeBSD and Solaris. */
> 						(-1),
> 						0));
> 	return ((addr == MAP_FAILED) ? 0 : addr);
> }
> </clip>
> 
> with gcc 4.0.1.  The above fails to compile with -std=c89:
> 
> <clip>
> janne@nurbian:~/dev$ gcc -std=c89 -c mmap.c
> mmap.c: In function 'execMalloc':
> mmap.c:14: error: 'MAP_ANONYMOUS' undeclared (first use in this function)
> mmap.c:14: error: (Each undeclared identifier is reported only once
> mmap.c:14: error: for each function it appears in.)
> </clip>
> 
> If I don't specify -std=c89, it works nicely.  If I define __USE_MISC,
> then it compiles again.
> 
> Is this the way it should work?
> 

Yes, this is the way it should work. MAP_ANONYMOUS is a GNU extension
and therefore not part of the C or POSIX standards. By specifying
-std=c89, you explicitly disable this extension. You can specify
-std=gnu89 if you want both the C89 standard and the GNU extensions.

By default GCC default to gnu89 for GCC 4.0 (or gnu11 for recent GCC
versions), that's why the code compiles fine without any option.

This is therefore not a bug, I am closing it.

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                 http://www.aurel32.net

--- End Message ---

Reply to: