AFLplusplus / AFLplusplus

The fuzzer afl++ is afl with community patches, qemu 5.1 upgrade, collision-free coverage, enhanced laf-intel & redqueen, AFLfast++ power schedules, MOpt mutators, unicorn_mode, and a lot more!

Home Page:https://aflplus.plus

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

macOS build fails due to undeclared identifier `CLOCK_MONOTONIC_COARSE`

BenWibking opened this issue · comments

Describe the bug
afl-common.c uses a symbol that does not exist in time.h:

src/afl-common.c:999:38: error: use of undeclared identifier 'CLOCK_MONOTONIC_COARSE'; did you mean '_CLOCK_MONOTONIC_RAW'?

To Reproduce
Steps to reproduce the behavior:

  1. gmake on macOS 14
  2. See error.

Expected behavior
A clear and concise description of what you expected to happen.

Screen output/Screenshots

➜  AFLplusplus git:(dev) gmake
[*] Compiling AFL++ for OS Darwin on ARCH arm64
[!] Note: skipping x86 compilation checks (AFL_NO_X86 set).
[+] shmat seems to be working.
[-] You seem to need to install the package python3-dev or python-dev (and perhaps python[3]-apt), but it is optional so we continue
[+] Everything seems to be working, ready to compile. (Apple clang version 15.0.0 (clang-1500.1.0.2.5))
cc -O2   -g -Wno-pointer-sign -Wno-variadic-macros -Wall -Wextra -Wno-pointer-arith -fPIC -I include/ -DAFL_PATH=\"/usr/local/lib/afl\" -DBIN_PATH=\"/usr/local/bin\" -DDOC_PATH=\"/usr/local/share/doc/afl\" -flto=full  -c src/afl-common.c -o src/afl-common.o
src/afl-common.c:999:38: error: use of undeclared identifier 'CLOCK_MONOTONIC_COARSE'; did you mean '_CLOCK_MONOTONIC_RAW'?
  int             rc = clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
                                     ^~~~~~~~~~~~~~~~~~~~~~
                                     _CLOCK_MONOTONIC_RAW
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/time.h:159:1: note: '_CLOCK_MONOTONIC_RAW' declared here
_CLOCK_MONOTONIC_RAW __CLOCK_AVAILABILITY = 4,
^
src/afl-common.c:1016:38: error: use of undeclared identifier 'CLOCK_MONOTONIC_COARSE'; did you mean '_CLOCK_MONOTONIC_RAW'?
  int             rc = clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
                                     ^~~~~~~~~~~~~~~~~~~~~~
                                     _CLOCK_MONOTONIC_RAW
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/time.h:159:1: note: '_CLOCK_MONOTONIC_RAW' declared here
_CLOCK_MONOTONIC_RAW __CLOCK_AVAILABILITY = 4,
^
2 errors generated.
gmake: *** [GNUmakefile:466: src/afl-common.o] Error 1

Additional context
N/A

The same error appears when using the Homebrew version of LLVM/Clang:

 ➜  AFLplusplus git:(dev) gmake
[*] Compiling AFL++ for OS Darwin on ARCH arm64
[!] Note: skipping x86 compilation checks (AFL_NO_X86 set).
[+] shmat seems to be working.
[-] You seem to need to install the package python3-dev or python-dev (and perhaps python[3]-apt), but it is optional so we continue
[+] Everything seems to be working, ready to compile. (Homebrew clang version 17.0.6)
clang -O2   -g -Wno-pointer-sign -Wno-variadic-macros -Wall -Wextra -Wno-pointer-arith -fPIC -I include/ -DAFL_PATH=\"/usr/local/lib/afl\" -DBIN_PATH=\"/usr/local/bin\" -DDOC_PATH=\"/usr/local/share/doc/afl\" -flto=full  -c src/afl-common.c -o src/afl-common.o
src/afl-common.c:999:38: error: use of undeclared identifier 'CLOCK_MONOTONIC_COARSE'; did you mean '_CLOCK_MONOTONIC_RAW'?
  999 |   int             rc = clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
      |                                      ^~~~~~~~~~~~~~~~~~~~~~
      |                                      _CLOCK_MONOTONIC_RAW
/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/time.h:159:1: note: '_CLOCK_MONOTONIC_RAW' declared here
  159 | _CLOCK_MONOTONIC_RAW __CLOCK_AVAILABILITY = 4,
      | ^
src/afl-common.c:1016:38: error: use of undeclared identifier 'CLOCK_MONOTONIC_COARSE'; did you mean '_CLOCK_MONOTONIC_RAW'?
 1016 |   int             rc = clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
      |                                      ^~~~~~~~~~~~~~~~~~~~~~
      |                                      _CLOCK_MONOTONIC_RAW
/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/time.h:159:1: note: '_CLOCK_MONOTONIC_RAW' declared here
  159 | _CLOCK_MONOTONIC_RAW __CLOCK_AVAILABILITY = 4,
      | ^
2 errors generated.
gmake: *** [GNUmakefile:466: src/afl-common.o] Error 1

The compiler does not matter, macos libc just does not support it. Doing something like '#define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC` for mac in appropriate place(s) should work.

Ok, that works. This patch fixes it:

diff --git a/src/afl-common.c b/src/afl-common.c
index a956fef9..e1533169 100644
--- a/src/afl-common.c
+++ b/src/afl-common.c
@@ -32,6 +32,8 @@
 #ifndef __USE_GNU
   #define __USE_GNU
 #endif
+#define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC
+
 #include <string.h>
 #include <strings.h>
 #include <time.h>

feel free to open a PR :)

@devnexen do you know if CLOCK_MONOTONIC_COARSE exists on netbsd?

I doubt it but let me check.

Well not in native mode :) and the Linux compatibility layer returns ENOTSUP with this constant.

Fixed by 29544e4.

Thanks for reporting!