0

I'm trying to build an application which uses the MAP_FIXED_NOREPLACE mmap flag. From the man page, it seems that the flag is supported since linux kernel 4.17. I currently have 5.4.0-53-generic installed on my Ubuntu 18.04.5 system. When I try to build the application, I get the following error:

cc -MD -c -o ../nondebug/libpmemblk/set.o -std=gnu99 -Wall -Werror -Wmissing-prototypes -Wpointer-arith -Wsign-conversion -Wsign-compare -Wconversion -Wunused-macros -Wmissing-field-initializers -Wfloat-equal -Wswitch-default -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -std=gnu99 -fno-common -pthread -DSRCVERSION=\"1.6+git703.g8cb972fe3\" -DSDS_ENABLED     -I../include -I../common/  -fPIC  ../../src/../src/common/set.c
../../src/../src/common/set.c: In function ‘util_replica_map_local_addr’:
../../src/../src/common/set.c:2661:13: error: ‘MAP_FIXED_NOREPLACE’ undeclared (first use in this function); did you mean ‘_IOS_NOREPLACE’?
     flags | MAP_FIXED_NOREPLACE, 0) != 0) {
             ^~~~~~~~~~~~~~~~~~~
             _IOS_NOREPLACE
../../src/../src/common/set.c:2661:13: note: each undeclared identifier is reported only once for each function it appears in
../Makefile.inc:328: recipe for target '../nondebug/libpmemblk/set.o' failed

I checked, and the file set.c does include sys/mman.h header required for mmap. I'm not sure why the compiler is complaining about MAP_FIXED_NOREPLACE, and how to fix this.

nsane
  • 1,715
  • 4
  • 21
  • 31
  • Try `#define _GNU_SOURCE` at the very top of your file, or `-D_GNU_SOURCE` on the command line. The man page doesn't list `MAP_FIXED_NOREPLACE` as one of the flags that requires this, but in my system headers, it's controlled by the same ifdefs as those that do. I guess it's a documentation bug. – Nate Eldredge Nov 13 '20 at 04:34
  • @NateEldredge `#define _GNU_SOURCE` is already there at the top of the file. – nsane Nov 13 '20 at 04:56
  • You could try to trace the chain of includes from `` to find the file that actually defines the macro. For me on Ubuntu 20.04 with glibc 2.31, it's in `/usr/include/bits/mman-map-flags-generic.h`. – Nate Eldredge Nov 13 '20 at 06:01
  • You could bodge it by `#include ` `#ifndef MAP_FIXED_NOREPLACE` `#define MAP_FIXED_NOREPLACE 0x100000` `#endif`. – Ian Abbott Nov 13 '20 at 12:26
  • 2
    The `MAP_FIXED_NOREPLACE` support was added in GNU C Library (glibc) version 2.29, so should be defined in Ubuntu's "libc6-dev" package version 2.29 onwards. – Ian Abbott Nov 13 '20 at 12:54
  • @IanAbbott: Aha, and Ubuntu 18.04 uses [glibc 2.27](https://packages.ubuntu.com/source/bionic-updates/glibc). So that explains why it's not there. – Nate Eldredge Nov 13 '20 at 13:33
  • Thanks guys! I upgraded the OS to 20.04 and was able to build the application without any issues. – nsane Nov 13 '20 at 14:35

0 Answers0