Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apple clang complaining of unknown 'dynamic_lookup' #2098

Closed
Atlante45 opened this issue May 23, 2024 · 2 comments
Closed

Apple clang complaining of unknown 'dynamic_lookup' #2098

Atlante45 opened this issue May 23, 2024 · 2 comments

Comments

@Atlante45
Copy link
Contributor

afl-clang-fast++ gives the following error on macos when building a LLVMFuzzerTestOneInput harness with -fsanitize=fuzzer

clang++: error: no such file or directory: 'dynamic_lookup'

Steps to reproduce the behavior:

  1. Compile the following file:
#include <cstdint>
#include <cstddef>

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
    return 0;
}
  1. Using the following command:
afl-clang-fast++ -o fuzz main.cpp -fsanitize=fuzzer

Expected behavior
The compiler should not fail

Screen output/Screenshots

> afl-clang-fast++ --version
afl-cc++4.21a by Michal Zalewski, Laszlo Szekeres, Marc Heuse - mode: LLVM-PCGUARD
Homebrew clang version 18.1.5
Target: arm64-apple-darwin23.5.0
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/llvm/18.1.5/bin

> clang++ --version
Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: arm64-apple-darwin23.5.0
Thread model: posix
InstalledDir: /Applications/Xcode-15.0.0.15A240d.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

> cat main.cpp
#include <cstdint>
#include <cstddef>

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
    return 0;
}

> afl-clang-fast++ -o fuzz main.cpp -fsanitize=fuzzer
afl-cc++4.21a by Michal Zalewski, Laszlo Szekeres, Marc Heuse - mode: LLVM-PCGUARD
[+] Found '-fsanitize=fuzzer', replacing with libAFLDriver.a
clang++: error: no such file or directory: 'dynamic_lookup'

Additional context
I dug into the issue a bit myself and was able to fix it by applying this small patch before building AFL++:

diff --git a/src/afl-cc.c b/src/afl-cc.c
index 15a5bd8e..7fdb1fba 100644
--- a/src/afl-cc.c
+++ b/src/afl-cc.c
@@ -2360,8 +2360,7 @@ static void add_aflpplib(aflcc_state_t *aflcc) {
     insert_param(aflcc, afllib);

 #ifdef __APPLE__
-    insert_param(aflcc, "-Wl,-undefined");
-    insert_param(aflcc, "dynamic_lookup");
+    insert_param(aflcc, "-Wl,-undefined,dynamic_lookup");
 #endif

   }

I'm happy to submit a PR for it if you'd like but I'm not sure which versions of clang might be affected and if this can be applied to all of them indiscriminately.

With the patch:

> afl-clang-fast++ -o fuzz main.cpp -fsanitize=fuzzer
afl-cc++4.21a by Michal Zalewski, Laszlo Szekeres, Marc Heuse - mode: LLVM-PCGUARD
[+] Found '-fsanitize=fuzzer', replacing with libAFLDriver.a
SanitizerCoveragePCGUARD++4.21a
[+] Instrumented 1 locations with no collisions (non-hardened mode) of which are 0 handled and 0 unhandled selects.
@vanhauser-thc
Copy link
Member

Ah thanks. Send a pr if you want to - this way you are visible as a contributor :)

@Atlante45
Copy link
Contributor Author

That sounds good, thanks!
I'll put one up in the morning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants