LibAFL icon indicating copy to clipboard operation
LibAFL copied to clipboard

libafl_qemu fails to build in rust:1.77 Docker image

Open langston-barrett opened this issue 1 year ago • 12 comments

IMPORTANT

  1. You have verified that the issue to be present in the current main branch

Yes Describe the bug The following Dockerfile fails To Reproduce

FROM rust:1.77
RUN apt-get update && \
    apt-get install -y gpg lsb-release wget software-properties-common && \
    echo "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-17 main" > /etc/apt/sources.list.d/apt.llvm.org.list && \
    wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key |  tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc && \
    apt update && \
    apt-get install -y llvm-17-dev llvm-17-tools && \
    apt-get update && \
    apt-get install -y git clang-17 libclang-17-dev libglib2.0-dev libpixman-1-dev libslirp-dev ninja-build pkg-config python3-venv
RUN git clone https://github.com/AFLplusplus/LibAFL && \
    cd LibAFL/libafl_qemu && \
    git checkout 2f7c19e && \
    cargo build
docker build -t libafl_qemu .

Expected behavior That works Screen output/Screenshots

52.76 warning: [email protected]: No emulation mode feature enabled or EMULATION_MODE env specified for libafl_qemu, supported: usermode, systemmmode - defaulting to usermode
52.76 warning: [email protected]: No architecture feature enabled or CPU_TARGET env specified for libafl_qemu, supported: arm, aarch64, i386, x86_64 - defaulting to x86_64
52.76 warning: [email protected]: Qemu not found, cloning with git (c9519ee8b6cb1ba54b7df1001f7f39f07218d514)...
54.95 warning: [email protected]: CROSS_CC is not set, default to cc (things can go wrong if the selected cpu target (x86_64) is not the host arch (x86_64))
55.46 error[E0308]: arguments to this function are incorrect
55.46     --> libafl_qemu/src/emu/mod.rs:1141:23
55.46      |
55.46 1141 |             let num = libafl_qemu_sys::libafl_add_edge_hook(gen, exec, data);
55.46      |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55.46      |
55.46 note: expected unsafe fn, found normal fn
55.46     --> libafl_qemu/src/emu/mod.rs:1141:61
55.46      |
55.46 1141 |             let num = libafl_qemu_sys::libafl_add_edge_hook(gen, exec, data);
55.46      |                                                             ^^^
55.46      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _) -> _>`
55.46                 found enum `std::option::Option<extern "C" fn(_, _, _) -> _>`
55.46 note: expected unsafe fn, found normal fn
55.46     --> libafl_qemu/src/emu/mod.rs:1141:66
55.46      |
55.46 1141 |             let num = libafl_qemu_sys::libafl_add_edge_hook(gen, exec, data);
55.46      |                                                                  ^^^^
55.46      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _)>`
55.46                 found enum `std::option::Option<extern "C" fn(_, _)>`
55.46 note: function defined here
55.46     --> /LibAFL/target/debug/build/libafl_qemu_sys-c915b0231f37eee6/out/bindings.rs:3:361633
55.46      |
55.46 3    | ... -> :: std :: os :: raw :: c_int ; } extern "C" { pub fn libafl_add_edge_hook (gen : :: std :: option :: Option < unsafe extern "C" fn...
55.46      |                                                             ^^^^^^^^^^^^^^^^^^^^
55.46
55.46 error[E0308]: arguments to this function are incorrect
55.46     --> libafl_qemu/src/emu/mod.rs:1159:23
55.46      |
55.46 1159 |             let num = libafl_qemu_sys::libafl_add_block_hook(gen, post_gen, exec, data);
55.46      |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55.46      |
55.46 note: expected unsafe fn, found normal fn
55.46     --> libafl_qemu/src/emu/mod.rs:1159:62
55.46      |
55.46 1159 |             let num = libafl_qemu_sys::libafl_add_block_hook(gen, post_gen, exec, data);
55.46      |                                                              ^^^
55.46      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _) -> _>`
55.46                 found enum `std::option::Option<extern "C" fn(_, _) -> _>`
55.46 note: expected unsafe fn, found normal fn
55.46     --> libafl_qemu/src/emu/mod.rs:1159:67
55.46      |
55.46 1159 |             let num = libafl_qemu_sys::libafl_add_block_hook(gen, post_gen, exec, data);
55.46      |                                                                   ^^^^^^^^
55.46      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _)>`
55.46                 found enum `std::option::Option<extern "C" fn(_, _, _)>`
55.46 note: expected unsafe fn, found normal fn
55.46     --> libafl_qemu/src/emu/mod.rs:1159:77
55.46      |
55.46 1159 |             let num = libafl_qemu_sys::libafl_add_block_hook(gen, post_gen, exec, data);
55.46      |                                                                             ^^^^
55.46      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _)>`
55.46                 found enum `std::option::Option<extern "C" fn(_, _)>`
55.46 note: function defined here
55.46     --> /LibAFL/target/debug/build/libafl_qemu_sys-c915b0231f37eee6/out/bindings.rs:3:362221
55.46      |
55.46 3    | ...arg2 : u64) -> usize >) -> bool ; } extern "C" { pub fn libafl_add_block_hook (gen : :: std :: option :: Option < unsafe extern "C" fn...
55.47      |                                                            ^^^^^^^^^^^^^^^^^^^^^
55.47
55.48 error[E0308]: arguments to this function are incorrect
55.48     --> libafl_qemu/src/emu/mod.rs:1202:23
55.48      |
55.48 1202 |             let num = libafl_qemu_sys::libafl_add_read_hook(
55.48      |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55.48      |
55.48 note: expected unsafe fn, found normal fn
55.48     --> libafl_qemu/src/emu/mod.rs:1203:22
55.48      |
55.48 1203 |                 gen, exec1, exec2, exec4, exec8, exec_n, data,
55.48      |                      ^^^^^
55.48      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _)>`
55.48                 found enum `std::option::Option<extern "C" fn(_, _, _)>`
55.48 note: expected unsafe fn, found normal fn
55.48     --> libafl_qemu/src/emu/mod.rs:1203:29
55.48      |
55.48 1203 |                 gen, exec1, exec2, exec4, exec8, exec_n, data,
55.48      |                             ^^^^^
55.48      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _)>`
55.48                 found enum `std::option::Option<extern "C" fn(_, _, _)>`
55.48 note: expected unsafe fn, found normal fn
55.48     --> libafl_qemu/src/emu/mod.rs:1203:36
55.48      |
55.48 1203 |                 gen, exec1, exec2, exec4, exec8, exec_n, data,
55.48      |                                    ^^^^^
55.48      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _)>`
55.48                 found enum `std::option::Option<extern "C" fn(_, _, _)>`
55.48 note: expected unsafe fn, found normal fn
55.48     --> libafl_qemu/src/emu/mod.rs:1203:43
55.48      |
55.48 1203 |                 gen, exec1, exec2, exec4, exec8, exec_n, data,
55.48      |                                           ^^^^^
55.48      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _)>`
55.48                 found enum `std::option::Option<extern "C" fn(_, _, _)>`
55.48 note: expected unsafe fn, found normal fn
55.48     --> libafl_qemu/src/emu/mod.rs:1203:50
55.48      |
55.48 1203 |                 gen, exec1, exec2, exec4, exec8, exec_n, data,
55.48      |                                                  ^^^^^^
55.48      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _, _)>`
55.48                 found enum `std::option::Option<extern "C" fn(_, _, _, _)>`
55.48 note: function defined here
55.48     --> /LibAFL/target/debug/build/libafl_qemu_sys-c915b0231f37eee6/out/bindings.rs:3:362918
55.48      |
55.48 3    | ... arg2 : u64) -> usize >) -> bool ; } extern "C" { pub fn libafl_add_read_hook (gen : :: std :: option :: Option < unsafe extern "C" fn...
55.48      |                                                             ^^^^^^^^^^^^^^^^^^^^
55.48
55.49 error[E0308]: arguments to this function are incorrect
55.49     --> libafl_qemu/src/emu/mod.rs:1236:23
55.49      |
55.49 1236 |             let num = libafl_qemu_sys::libafl_add_write_hook(
55.49      |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55.49      |
55.49 note: expected unsafe fn, found normal fn
55.49     --> libafl_qemu/src/emu/mod.rs:1237:22
55.49      |
55.49 1237 |                 gen, exec1, exec2, exec4, exec8, exec_n, data,
55.49      |                      ^^^^^
55.49      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _)>`
55.49                 found enum `std::option::Option<extern "C" fn(_, _, _)>`
55.49 note: expected unsafe fn, found normal fn
55.49     --> libafl_qemu/src/emu/mod.rs:1237:29
55.49      |
55.49 1237 |                 gen, exec1, exec2, exec4, exec8, exec_n, data,
55.49      |                             ^^^^^
55.49      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _)>`
55.49                 found enum `std::option::Option<extern "C" fn(_, _, _)>`
55.49 note: expected unsafe fn, found normal fn
55.49     --> libafl_qemu/src/emu/mod.rs:1237:36
55.49      |
55.49 1237 |                 gen, exec1, exec2, exec4, exec8, exec_n, data,
55.49      |                                    ^^^^^
55.49      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _)>`
55.49                 found enum `std::option::Option<extern "C" fn(_, _, _)>`
55.49 note: expected unsafe fn, found normal fn
55.49     --> libafl_qemu/src/emu/mod.rs:1237:43
55.49      |
55.49 1237 |                 gen, exec1, exec2, exec4, exec8, exec_n, data,
55.49      |                                           ^^^^^
55.49      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _)>`
55.49                 found enum `std::option::Option<extern "C" fn(_, _, _)>`
55.49 note: expected unsafe fn, found normal fn
55.49     --> libafl_qemu/src/emu/mod.rs:1237:50
55.49      |
55.49 1237 |                 gen, exec1, exec2, exec4, exec8, exec_n, data,
55.49      |                                                  ^^^^^^
55.49      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _, _)>`
55.49                 found enum `std::option::Option<extern "C" fn(_, _, _, _)>`
55.49 note: function defined here
55.49     --> /LibAFL/target/debug/build/libafl_qemu_sys-c915b0231f37eee6/out/bindings.rs:3:363679
55.49      |
55.49 3    | ...usize) > , data : u64) -> usize ; } extern "C" { pub fn libafl_add_write_hook (gen : :: std :: option :: Option < unsafe extern "C" fn...
55.49      |                                                            ^^^^^^^^^^^^^^^^^^^^^
55.49
55.50 error[E0308]: arguments to this function are incorrect
55.50     --> libafl_qemu/src/emu/mod.rs:1260:23
55.50      |
55.50 1260 |             let num = libafl_qemu_sys::libafl_add_cmp_hook(gen, exec1, exec2, exec4, exec8, data);
55.50      |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55.50      |
55.50 note: expected unsafe fn, found normal fn
55.50     --> libafl_qemu/src/emu/mod.rs:1260:60
55.50      |
55.50 1260 |             let num = libafl_qemu_sys::libafl_add_cmp_hook(gen, exec1, exec2, exec4, exec8, data);
55.50      |                                                            ^^^
55.50      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _) -> _>`
55.50                 found enum `std::option::Option<extern "C" fn(_, _, _) -> _>`
55.50 note: expected unsafe fn, found normal fn
55.50     --> libafl_qemu/src/emu/mod.rs:1260:65
55.50      |
55.50 1260 |             let num = libafl_qemu_sys::libafl_add_cmp_hook(gen, exec1, exec2, exec4, exec8, data);
55.50      |                                                                 ^^^^^
55.50      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _, _)>`
55.50                 found enum `std::option::Option<extern "C" fn(_, _, _, _)>`
55.50 note: expected unsafe fn, found normal fn
55.50     --> libafl_qemu/src/emu/mod.rs:1260:72
55.50      |
55.50 1260 |             let num = libafl_qemu_sys::libafl_add_cmp_hook(gen, exec1, exec2, exec4, exec8, data);
55.50      |                                                                        ^^^^^
55.50      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _, _)>`
55.50                 found enum `std::option::Option<extern "C" fn(_, _, _, _)>`
55.50 note: expected unsafe fn, found normal fn
55.50     --> libafl_qemu/src/emu/mod.rs:1260:79
55.50      |
55.50 1260 |             let num = libafl_qemu_sys::libafl_add_cmp_hook(gen, exec1, exec2, exec4, exec8, data);
55.50      |                                                                               ^^^^^
55.50      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _, _)>`
55.50                 found enum `std::option::Option<extern "C" fn(_, _, _, _)>`
55.50 note: expected unsafe fn, found normal fn
55.50     --> libafl_qemu/src/emu/mod.rs:1260:86
55.50      |
55.50 1260 |             let num = libafl_qemu_sys::libafl_add_cmp_hook(gen, exec1, exec2, exec4, exec8, data);
55.50      |                                                                                      ^^^^^
55.50      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _, _)>`
55.50                 found enum `std::option::Option<extern "C" fn(_, _, _, _)>`
55.50 note: function defined here
55.50     --> /LibAFL/target/debug/build/libafl_qemu_sys-c915b0231f37eee6/out/bindings.rs:3:364887
55.50      |
55.50 3    | ...: * mut TCGTemp , oi : MemOpIdx) ; } extern "C" { pub fn libafl_add_cmp_hook (gen : :: std :: option :: Option < unsafe extern "C" fn ...
55.50      |                                                             ^^^^^^^^^^^^^^^^^^^
55.50
55.53 For more information about this error, try `rustc --explain E0308`.
55.54 The following warnings were emitted during compilation:
55.54
55.54 warning: [email protected]: CROSS_CC is not set, default to cc (things can go wrong if the selected cpu target (x86_64) is not the host arch (x86_64))
55.54
55.54 error: could not compile `libafl_qemu` (lib) due to 5 previous errors

Additional context Add any other context about the problem here.

langston-barrett avatar May 01 '24 15:05 langston-barrett

Thanks for the report. I couldn't reproduce, it seems to build correctly on my side. Could you try to run cargo update and retry maybe?

rmalmain avatar May 02 '24 16:05 rmalmain

Thanks for taking a look! I added a cargo update just before the cargo build and docker build failed with the same output.

langston-barrett avatar May 02 '24 16:05 langston-barrett

could be llvm version. i think i saw this somewhere (but i forgot what was the issue & how to fix it)

tokatoka avatar May 02 '24 16:05 tokatoka

The Dockerfile in the OP installs LLVM 17 from their repos, what other version(s) should I try? (IIRC, I do actually need LLVM 17 because it matches rustc's embedded LLVM, but I can certainly try others)

langston-barrett avatar May 02 '24 16:05 langston-barrett

we use 18

tokatoka avatar May 02 '24 16:05 tokatoka

I get the same output from docker build with a modified Dockerfile that uses LLVM 18 and does cargo update:

FROM rust:1.77
RUN apt-get update && \
    apt-get install -y gpg lsb-release wget software-properties-common && \
    echo "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-18 main" > /etc/apt/sources.list.d/apt.llvm.org.list && \
    wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key |  tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc && \
    apt update && \
    apt-get install -y llvm-18-dev llvm-18-tools && \
    apt-get update && \
    apt-get install -y git clang-18 libclang-18-dev libglib2.0-dev libpixman-1-dev libslirp-dev ninja-build pkg-config python3-venv
RUN git clone https://github.com/AFLplusplus/LibAFL && \
    cd LibAFL/libafl_qemu && \
    git checkout 2f7c19e && \
    cargo update && \
    cargo build

langston-barrett avatar May 02 '24 16:05 langston-barrett

I've tried building both of @langston-barrett's Dockerfiles, and they fail with errors similar to each other, but quite different from Langston's. Here's the result of trying to build the second one, that uses LLVM 18 and does cargo update, on macOS:

...
17.35    Compiling toml v0.4.10
17.40    Compiling serde_yaml v0.8.26
17.53    Compiling dashmap v5.5.3
17.71    Compiling serial_test v2.0.0
20.39    Compiling capstone v0.11.0
46.61 warning: [email protected]: No emulation mode feature enabled or EMULATION_MODE env specified for libafl_qemu, supported: usermode, systemmmode - defaulting to usermode
46.61 warning: [email protected]: No architecture feature enabled or CPU_TARGET env specified for libafl_qemu, supported: arm, aarch64, i386, x86_64 - defaulting to x86_64
46.61 warning: [email protected]: Qemu not found, cloning with git (c9519ee8b6cb1ba54b7df1001f7f39f07218d514)...
46.68 The following warnings were emitted during compilation:
46.68 
46.68 warning: [email protected]: CROSS_CC is not set, default to cc (things can go wrong if the selected cpu target (x86_64) is not the host arch (aarch64))
46.68 
46.68 error: failed to run custom build command for `libafl_qemu v0.12.0 (/LibAFL/libafl_qemu)`
46.68 
46.68 Caused by:
46.68   process didn't exit successfully: `/LibAFL/target/debug/build/libafl_qemu-c58add83468ab46a/build-script-build` (exit status: 101)
46.68   --- stdout
46.68   cargo:rustc-cfg=emulation_mode="usermode"
46.68   cargo:rerun-if-env-changed=EMULATION_MODE
46.68   cargo:rerun-if-changed=build.rs
46.68   cargo:rerun-if-changed=build_linux.rs
46.68   cargo:rerun-if-changed=runtime
46.68   cargo:rerun-if-env-changed=CPU_TARGET
46.68   cargo:rustc-cfg=cpu_target="x86_64"
46.68   cargo:warning=CROSS_CC is not set, default to cc (things can go wrong if the selected cpu target (x86_64) is not the host arch (aarch64))
46.68   cargo:rerun-if-env-changed=CROSS_CC
46.68 
46.68   --- stderr
46.68   runtime/libafl_qemu.h:182:36: error: expected identifier
46.68   runtime/libafl_qemu.h:185:1: error: expected function body after function declarator
46.68   thread 'main' panicked at libafl_qemu/build_linux.rs:97:10:
46.68   Exit bindings generation failed.: ClangDiagnostic("runtime/libafl_qemu.h:182:36: error: expected identifier\nruntime/libafl_qemu.h:185:1: error: expected function body after function declarator\n")
46.68   note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
46.68 warning: build failed, waiting for other jobs to finish...
------
Dockerfile:10
--------------------
   9 |         apt-get install -y git clang-18 libclang-18-dev libglib2.0-dev libpixman-1-dev libslirp-dev ninja-build pkg-config python3-venv
  10 | >>> RUN git clone https://github.com/AFLplusplus/LibAFL && \
  11 | >>>     cd LibAFL/libafl_qemu && \
  12 | >>>     git checkout 2f7c19e && \
  13 | >>>     cargo update && \
  14 | >>>     cargo build
  15 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c git clone https://github.com/AFLplusplus/LibAFL &&     cd LibAFL/libafl_qemu &&     git checkout 2f7c19e &&     cargo update &&     cargo build" did not complete successfully: exit code: 101

samcowger avatar May 02 '24 17:05 samcowger

I put this report in a Dockerfile specifically so that it would be reproducible, it's mystifying to me that Docker would give such different results for each of us! FWIW, my host is NixOS,

nixos-version

23.11.6759.0638fe2715d9 (Tapir)

docker --version

Docker version 24.0.5, build v24.0.5

langston-barrett avatar May 02 '24 17:05 langston-barrett

FWIW, I just tried this second Dockerfile on a Linux machine, and got build failures quite similar, if not identical, to @langston-barrett's. Docker version 26.1.1, build 4cf5afa.

My build logs:
...
54.84    Compiling toml v0.4.10
56.76    Compiling num-derive v0.4.2
58.11    Compiling thread_local v1.1.8
58.36    Compiling typed-arena v2.0.2
58.43    Compiling syscall-numbers v3.1.1
64.66    Compiling capstone v0.11.0
144.8 warning: [email protected]: No emulation mode feature enabled or EMULATION_MODE env specified for libafl_qemu, supported: usermode, systemmmode - defaulting to usermode
144.8 warning: [email protected]: No architecture feature enabled or CPU_TARGET env specified for libafl_qemu, supported: arm, aarch64, i386, x86_64 - defaulting to x86_64
144.8 warning: [email protected]: Qemu not found, cloning with git (c9519ee8b6cb1ba54b7df1001f7f39f07218d514)...
147.9 warning: [email protected]: CROSS_CC is not set, default to cc (things can go wrong if the selected cpu target (x86_64) is not the host arch (x86_64))
148.9 error[E0308]: arguments to this function are incorrect
148.9     --> libafl_qemu/src/emu/mod.rs:1141:23
148.9      |
148.9 1141 |             let num = libafl_qemu_sys::libafl_add_edge_hook(gen, exec, data);
148.9      |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
148.9      |
148.9 note: expected unsafe fn, found normal fn
148.9     --> libafl_qemu/src/emu/mod.rs:1141:61
148.9      |
148.9 1141 |             let num = libafl_qemu_sys::libafl_add_edge_hook(gen, exec, data);
148.9      |                                                             ^^^
148.9      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _) -> _>`
148.9                 found enum `std::option::Option<extern "C" fn(_, _, _) -> _>`
148.9 note: expected unsafe fn, found normal fn
148.9     --> libafl_qemu/src/emu/mod.rs:1141:66
148.9      |
148.9 1141 |             let num = libafl_qemu_sys::libafl_add_edge_hook(gen, exec, data);
148.9      |                                                                  ^^^^
148.9      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _)>`
148.9                 found enum `std::option::Option<extern "C" fn(_, _)>`
148.9 note: function defined here
148.9     --> /LibAFL/target/debug/build/libafl_qemu_sys-c915b0231f37eee6/out/bindings.rs:3:361695
148.9      |
148.9 3    | ... -> :: std :: os :: raw :: c_int ; } extern "C" { pub fn libafl_add_edge_hook (gen : :: std :: option :: Option < unsafe extern "C" fn...
148.9      |                                                             ^^^^^^^^^^^^^^^^^^^^
148.9 
148.9 error[E0308]: arguments to this function are incorrect
148.9     --> libafl_qemu/src/emu/mod.rs:1159:23
148.9      |
148.9 1159 |             let num = libafl_qemu_sys::libafl_add_block_hook(gen, post_gen, exec, data);
148.9      |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
148.9      |
148.9 note: expected unsafe fn, found normal fn
148.9     --> libafl_qemu/src/emu/mod.rs:1159:62
148.9      |
148.9 1159 |             let num = libafl_qemu_sys::libafl_add_block_hook(gen, post_gen, exec, data);
148.9      |                                                              ^^^
148.9      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _) -> _>`
148.9                 found enum `std::option::Option<extern "C" fn(_, _) -> _>`
148.9 note: expected unsafe fn, found normal fn
148.9     --> libafl_qemu/src/emu/mod.rs:1159:67
148.9      |
148.9 1159 |             let num = libafl_qemu_sys::libafl_add_block_hook(gen, post_gen, exec, data);
148.9      |                                                                   ^^^^^^^^
148.9      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _)>`
148.9                 found enum `std::option::Option<extern "C" fn(_, _, _)>`
148.9 note: expected unsafe fn, found normal fn
148.9     --> libafl_qemu/src/emu/mod.rs:1159:77
148.9      |
148.9 1159 |             let num = libafl_qemu_sys::libafl_add_block_hook(gen, post_gen, exec, data);
148.9      |                                                                             ^^^^
148.9      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _)>`
148.9                 found enum `std::option::Option<extern "C" fn(_, _)>`
148.9 note: function defined here
148.9     --> /LibAFL/target/debug/build/libafl_qemu_sys-c915b0231f37eee6/out/bindings.rs:3:362283
148.9      |
148.9 3    | ...arg2 : u64) -> usize >) -> bool ; } extern "C" { pub fn libafl_add_block_hook (gen : :: std :: option :: Option < unsafe extern "C" fn...
148.9      |                                                            ^^^^^^^^^^^^^^^^^^^^^
148.9 
148.9 error[E0308]: arguments to this function are incorrect
148.9     --> libafl_qemu/src/emu/mod.rs:1202:23
148.9      |
148.9 1202 |             let num = libafl_qemu_sys::libafl_add_read_hook(
148.9      |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
148.9      |
148.9 note: expected unsafe fn, found normal fn
148.9     --> libafl_qemu/src/emu/mod.rs:1203:22
148.9      |
148.9 1203 |                 gen, exec1, exec2, exec4, exec8, exec_n, data,
148.9      |                      ^^^^^
148.9      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _)>`
148.9                 found enum `std::option::Option<extern "C" fn(_, _, _)>`
148.9 note: expected unsafe fn, found normal fn
148.9     --> libafl_qemu/src/emu/mod.rs:1203:29
148.9      |
148.9 1203 |                 gen, exec1, exec2, exec4, exec8, exec_n, data,
148.9      |                             ^^^^^
148.9      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _)>`
148.9                 found enum `std::option::Option<extern "C" fn(_, _, _)>`
148.9 note: expected unsafe fn, found normal fn
148.9     --> libafl_qemu/src/emu/mod.rs:1203:36
148.9      |
148.9 1203 |                 gen, exec1, exec2, exec4, exec8, exec_n, data,
148.9      |                                    ^^^^^
148.9      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _)>`
148.9                 found enum `std::option::Option<extern "C" fn(_, _, _)>`
148.9 note: expected unsafe fn, found normal fn
148.9     --> libafl_qemu/src/emu/mod.rs:1203:43
148.9      |
148.9 1203 |                 gen, exec1, exec2, exec4, exec8, exec_n, data,
148.9      |                                           ^^^^^
148.9      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _)>`
148.9                 found enum `std::option::Option<extern "C" fn(_, _, _)>`
148.9 note: expected unsafe fn, found normal fn
148.9     --> libafl_qemu/src/emu/mod.rs:1203:50
148.9      |
148.9 1203 |                 gen, exec1, exec2, exec4, exec8, exec_n, data,
148.9      |                                                  ^^^^^^
148.9      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _, _)>`
148.9                 found enum `std::option::Option<extern "C" fn(_, _, _, _)>`
148.9 note: function defined here
148.9     --> /LibAFL/target/debug/build/libafl_qemu_sys-c915b0231f37eee6/out/bindings.rs:3:362980
148.9      |
148.9 3    | ... arg2 : u64) -> usize >) -> bool ; } extern "C" { pub fn libafl_add_read_hook (gen : :: std :: option :: Option < unsafe extern "C" fn...
148.9      |                                                             ^^^^^^^^^^^^^^^^^^^^
148.9 
149.0 error[E0308]: arguments to this function are incorrect
149.0     --> libafl_qemu/src/emu/mod.rs:1236:23
149.0      |
149.0 1236 |             let num = libafl_qemu_sys::libafl_add_write_hook(
149.0      |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
149.0      |
149.0 note: expected unsafe fn, found normal fn
149.0     --> libafl_qemu/src/emu/mod.rs:1237:22
149.0      |
149.0 1237 |                 gen, exec1, exec2, exec4, exec8, exec_n, data,
149.0      |                      ^^^^^
149.0      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _)>`
149.0                 found enum `std::option::Option<extern "C" fn(_, _, _)>`
149.0 note: expected unsafe fn, found normal fn
149.0     --> libafl_qemu/src/emu/mod.rs:1237:29
149.0      |
149.0 1237 |                 gen, exec1, exec2, exec4, exec8, exec_n, data,
149.0      |                             ^^^^^
149.0      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _)>`
149.0                 found enum `std::option::Option<extern "C" fn(_, _, _)>`
149.0 note: expected unsafe fn, found normal fn
149.0     --> libafl_qemu/src/emu/mod.rs:1237:36
149.0      |
149.0 1237 |                 gen, exec1, exec2, exec4, exec8, exec_n, data,
149.0      |                                    ^^^^^
149.0      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _)>`
149.0                 found enum `std::option::Option<extern "C" fn(_, _, _)>`
149.0 note: expected unsafe fn, found normal fn
149.0     --> libafl_qemu/src/emu/mod.rs:1237:43
149.0      |
149.0 1237 |                 gen, exec1, exec2, exec4, exec8, exec_n, data,
149.0      |                                           ^^^^^
149.0      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _)>`
149.0                 found enum `std::option::Option<extern "C" fn(_, _, _)>`
149.0 note: expected unsafe fn, found normal fn
149.0     --> libafl_qemu/src/emu/mod.rs:1237:50
149.0      |
149.0 1237 |                 gen, exec1, exec2, exec4, exec8, exec_n, data,
149.0      |                                                  ^^^^^^
149.0      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _, _)>`
149.0                 found enum `std::option::Option<extern "C" fn(_, _, _, _)>`
149.0 note: function defined here
149.0     --> /LibAFL/target/debug/build/libafl_qemu_sys-c915b0231f37eee6/out/bindings.rs:3:363741
149.0      |
149.0 3    | ...usize) > , data : u64) -> usize ; } extern "C" { pub fn libafl_add_write_hook (gen : :: std :: option :: Option < unsafe extern "C" fn...
149.0      |                                                            ^^^^^^^^^^^^^^^^^^^^^
149.0 
149.0 error[E0308]: arguments to this function are incorrect
149.0     --> libafl_qemu/src/emu/mod.rs:1260:23
149.0      |
149.0 1260 |             let num = libafl_qemu_sys::libafl_add_cmp_hook(gen, exec1, exec2, exec4, exec8, data);
149.0      |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
149.0      |
149.0 note: expected unsafe fn, found normal fn
149.0     --> libafl_qemu/src/emu/mod.rs:1260:60
149.0      |
149.0 1260 |             let num = libafl_qemu_sys::libafl_add_cmp_hook(gen, exec1, exec2, exec4, exec8, data);
149.0      |                                                            ^^^
149.0      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _) -> _>`
149.0                 found enum `std::option::Option<extern "C" fn(_, _, _) -> _>`
149.0 note: expected unsafe fn, found normal fn
149.0     --> libafl_qemu/src/emu/mod.rs:1260:65
149.0      |
149.0 1260 |             let num = libafl_qemu_sys::libafl_add_cmp_hook(gen, exec1, exec2, exec4, exec8, data);
149.0      |                                                                 ^^^^^
149.0      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _, _)>`
149.0                 found enum `std::option::Option<extern "C" fn(_, _, _, _)>`
149.0 note: expected unsafe fn, found normal fn
149.0     --> libafl_qemu/src/emu/mod.rs:1260:72
149.0      |
149.0 1260 |             let num = libafl_qemu_sys::libafl_add_cmp_hook(gen, exec1, exec2, exec4, exec8, data);
149.0      |                                                                        ^^^^^
149.0      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _, _)>`
149.0                 found enum `std::option::Option<extern "C" fn(_, _, _, _)>`
149.0 note: expected unsafe fn, found normal fn
149.0     --> libafl_qemu/src/emu/mod.rs:1260:79
149.0      |
149.0 1260 |             let num = libafl_qemu_sys::libafl_add_cmp_hook(gen, exec1, exec2, exec4, exec8, data);
149.0      |                                                                               ^^^^^
149.0      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _, _)>`
149.0                 found enum `std::option::Option<extern "C" fn(_, _, _, _)>`
149.0 note: expected unsafe fn, found normal fn
149.0     --> libafl_qemu/src/emu/mod.rs:1260:86
149.0      |
149.0 1260 |             let num = libafl_qemu_sys::libafl_add_cmp_hook(gen, exec1, exec2, exec4, exec8, data);
149.0      |                                                                                      ^^^^^
149.0      = note: expected enum `std::option::Option<unsafe extern "C" fn(_, _, _, _)>`
149.0                 found enum `std::option::Option<extern "C" fn(_, _, _, _)>`
149.0 note: function defined here
149.0     --> /LibAFL/target/debug/build/libafl_qemu_sys-c915b0231f37eee6/out/bindings.rs:3:364949
149.0      |
149.0 3    | ...: * mut TCGTemp , oi : MemOpIdx) ; } extern "C" { pub fn libafl_add_cmp_hook (gen : :: std :: option :: Option < unsafe extern "C" fn ...
149.0      |                                                             ^^^^^^^^^^^^^^^^^^^
149.0 
149.0 For more information about this error, try `rustc --explain E0308`.
149.0 The following warnings were emitted during compilation:
149.0 
149.0 warning: [email protected]: CROSS_CC is not set, default to cc (things can go wrong if the selected cpu target (x86_64) is not the host arch (x86_64))
149.0 
149.0 error: could not compile `libafl_qemu` (lib) due to 5 previous errors
------
Dockerfile:10
--------------------
   9 |         apt-get install -y git clang-18 libclang-18-dev libglib2.0-dev libpixman-1-dev libslirp-dev ninja-build pkg-config python3-venv
  10 | >>> RUN git clone https://github.com/AFLplusplus/LibAFL && \
  11 | >>>     cd LibAFL/libafl_qemu && \
  12 | >>>     git checkout 2f7c19e && \
  13 | >>>     cargo update && \
  14 | >>>     cargo build
--------------------
ERROR: failed to solve: process "/bin/sh -c git clone https://github.com/AFLplusplus/LibAFL &&     cd LibAFL/libafl_qemu &&     git checkout 2f7c19e &&     cargo update &&     cargo build" did not complete successfully: exit code: 101

samcowger avatar May 02 '24 20:05 samcowger

I was able to reproduce both of these failures locally on an arm64 mac, using docker. I used the LLVM 18 variant of @langston-barrett's dockerfile. The bindings generation error occurs when building the image as aarch64, and the E0308 error occurs when building as amd64.

twizmwazin avatar May 06 '24 23:05 twizmwazin

I was not able to reproduce the issue using an ubuntu base image. This was the dockerfile I used, apologies for the messiness:

FROM ubuntu:jammy
RUN apt-get update && \
    apt-get install -y gpg lsb-release wget software-properties-common curl && \
    echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" > /etc/apt/sources.list.d/apt.llvm.org.list && \
    wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key |  tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc && \
    apt update && \
    apt-get install -y llvm-18-dev llvm-18-tools && \
    apt-get update && \
    apt-get install -y git clang-18 libclang-18-dev libglib2.0-dev libpixman-1-dev libslirp-dev ninja-build pkg-config python3-venv
RUN apt-get install -y build-essential
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh
RUN sh rustup.sh -y
ENV PATH="/root/.cargo/bin:${PATH}"
RUN git clone https://github.com/twizmwazin/LibAFL && \
    cd LibAFL/libafl_qemu && \
    git checkout 81ae30b && \
    cargo update && \
    cargo build

This is using the commit in my previous PR as I run into the other error when building for aarch64.

twizmwazin avatar May 07 '24 20:05 twizmwazin

I've narrowed this issue down to the presence of rustfmt. The official rust docker image uses the minimal rustup profile which does not include rustfmt, but my installation uses the default profile. Here's a working dockerfile:

FROM rust:1.77
RUN apt-get update && \
    apt-get install -y gpg lsb-release wget software-properties-common && \
    echo "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-18 main" > /etc/apt/sources.list.d/apt.llvm.org.list && \
    wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key |  tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc && \
    apt update && \
    apt-get install -y llvm-18-dev llvm-18-tools && \
    apt-get update && \
    apt-get install -y git clang-18 libclang-18-dev libglib2.0-dev libpixman-1-dev libslirp-dev ninja-build pkg-config python3-venv
RUN rustup component add rustfmt
RUN git clone https://github.com/twizmwazin/LibAFL && \
    cd LibAFL/libafl_qemu && \
    git checkout 81ae30b && \
    cargo update && \
    cargo build

Using the same commit as before for the same reason. Remove the rustup component add rustfmt line and this will fail. I guess bindgen is generating all the function bindings as unsafe, and then for whatever reason rustfmt is removing some of them.

twizmwazin avatar May 07 '24 22:05 twizmwazin

interesting. but rustfmt does not include bindgen right? what happens if you install bindgen manually?

tokatoka avatar May 10 '24 09:05 tokatoka

Can confirm that adding rustup component add rustfmt to my CI build appears to have fixed this.

langston-barrett avatar May 10 '24 16:05 langston-barrett

found the issue, I can confirm it fixes the issue on my side. @langston-barrett do you mind checking if it also works for you by running the same dockerfile with the git hash b0acd2ccc8664373f6c5d99e3c70f55cc486b01b?

rmalmain avatar May 12 '24 13:05 rmalmain