google / AFL

american fuzzy lop - a security-oriented fuzzer
https://lcamtuf.coredump.cx/afl/
Apache License 2.0
3.56k stars 625 forks source link

Android Linker error #127

Closed destrudos closed 3 years ago

destrudos commented 3 years ago

Hello! I have a problem during AFL build with android AOSP. Step to reproduce:

destrudo@ubuntu:~$ cd android-11.0.0_r17/
destrudo@ubuntu:~/android-11.0.0_r17$ git clone https://github.com/google/AFL.git
Cloning into 'AFL'...
remote: Enumerating objects: 527, done.
remote: Total 527 (delta 0), reused 0 (delta 0), pack-reused 527
Receiving objects: 100% (527/527), 938.74 KiB | 1.99 MiB/s, done.
Resolving deltas: 100% (193/193), done.
destrudo@ubuntu:~/android-11.0.0_r17$ . build/envsetup.sh 
destrudo@ubuntu:~/android-11.0.0_r17$ cd AFL/
destrudo@ubuntu:~/android-11.0.0_r17/AFL$ mm

04:40:55 ************************************************************
04:40:55 You are building on a machine with 15.6GB of RAM
04:40:55 
04:40:55 The minimum required amount of free memory is around 16GB,
04:40:55 and even with that, some configurations may not work.
04:40:55 
04:40:55 If you run into segfaults or other errors, try reducing your
04:40:55 -j value.
04:40:55 ************************************************************
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=11
TARGET_PRODUCT=aosp_arm
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=generic
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.4.0-58-generic-x86_64-Ubuntu-18.04.5-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=RP1A.201105.002
OUT_DIR=out
PRODUCT_SOONG_NAMESPACES=device/generic/goldfish device/generic/goldfish-opengl hardware/google/camera hardware/google/camera/devices/EmulatedCamera device/generic/goldfish device/generic/goldfish-opengl
============================================
[ 98% 1870/1890] //AFL:afl-fuzz link afl-fuzz
FAILED: out/soong/.intermediates/AFL/afl-fuzz/android_arm_armv7-a-neon/unstripped/afl-fuzz
prebuilts/clang/host/linux-x86/clang-r383902b/bin/clang++ out/soong/.intermediates/bionic/libc/crtbegin_static/android_arm_armv7-a-neon/crtbegin_static.o @out/soong/.intermediates/AFL/afl-fuzz/android_arm_armv7-a-neon/unstripped/afl-fuzz.rsp out/soong/.intermediates/external/libcxx/libc++_static/android_arm_armv7-a-neon_static/libc++_static.a out/soong/.intermediates/external/libcxxabi/libc++demangle/android_arm_armv7-a-neon_static/libc++demangle.a out/soong/.intermediates/bionic/libm/libm/android_arm_armv7-a-neon_static/libm.a out/soong/.intermediates/bionic/libc/libc/android_arm_armv7-a-neon_static/libc.a out/soong/.intermediates/external/libunwind_llvm/libunwind_llvm/android_arm_armv7-a-neon_static/libunwind_llvm.a -Wl,--start-group out/soong/.intermediates/bionic/libc/libc/android_arm_armv7-a-neon_static/libc.a prebuilts/clang/host/linux-x86/clang-r383902b/lib64/clang/11.0.2/lib/linux/libclang_rt.builtins-arm-android.a prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/arm-linux-androideabi/lib/libatomic.a -Wl,--end-group out/soong/.intermediates/bionic/libc/crtend_android/android_arm_armv7-a-neon/obj/bionic/libc/arch-common/bionic/crtend.o -o out/soong/.intermediates/AFL/afl-fuzz/android_arm_armv7-a-neon/unstripped/afl-fuzz -target armv7a-linux-androideabi10000 -Bprebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/arm-linux-androideabi/bin -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--build-id=md5 -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined-version -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_stripped.a -Wl,--exclude-libs,libunwind_llvm.a -fuse-ld=lld -Wl,--pack-dyn-relocs=android+relr -Wl,--use-android-relr-tags -Wl,--no-undefined -Wl,--icf=safe -Wl,--hash-style=gnu -Wl,-m,armelf -Wl,--exclude-libs=libclang_rt.builtins-arm-android.a  -static -nostdlib -Bstatic -Wl,--gc-sections -Wl,--exclude-libs,libunwind_llvm.a 
ld.lld: error: undefined symbol: dlopen
>>> referenced by afl-fuzz.c:1416 (AFL/afl-fuzz.c:1416)
>>>               out/soong/.intermediates/AFL/afl-fuzz/android_arm_armv7-a-neon/obj/AFL/afl-fuzz.o:(main)

ld.lld: error: undefined symbol: dlsym
>>> referenced by afl-fuzz.c:1419 (AFL/afl-fuzz.c:1419)
>>>               out/soong/.intermediates/AFL/afl-fuzz/android_arm_armv7-a-neon/obj/AFL/afl-fuzz.o:(main)

ld.lld: error: undefined symbol: dlerror
>>> referenced by afl-fuzz.c:1417 (AFL/afl-fuzz.c:1417)
>>>               out/soong/.intermediates/AFL/afl-fuzz/android_arm_armv7-a-neon/obj/AFL/afl-fuzz.o:(main)
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
[ 99% 1875/1890] //bionic/libc:libc.llndk versioner preprocess include
warning: attempted to generate guard with empty availability: obsoleted = 23
warning: attempted to generate guard with empty availability: obsoleted = 21
04:47:58 ninja failed with: exit status 1

#### failed to build some targets (09:34 (mm:ss)) ####

Please help me solve this issue. Regards, Destrudo

KeuntaeShin commented 3 years ago

Turn on static_libs like below:

cc_binary { name: "afl-fuzz", static_executable: false, host_supported: false,

defaults: [ "afl-defaults", ],

srcs: [ "afl-fuzz.c", ],

static_libs:["libdl"], }