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

fixing linking issue on qemu build #990

Merged
merged 4 commits into from Jan 9, 2023

Conversation

elbiazo
Copy link
Contributor

@elbiazo elbiazo commented Jan 6, 2023

Trying to run qemu_systemmode example and qemu_arm example, i received linker error shown below. Odd thing is I tried it on 6 different machine and 3 of them worked while other 3 times it didnt.

Screenshot from 2023-01-06 10-09-45

@elbiazo
Copy link
Contributor Author

elbiazo commented Jan 6, 2023

seems like check fails for binding. problem we are having is because qemu checks if keyutils exists or not in system. if it exists it will build extra files. and this source code uses keyutils therefore when you link qemu in libafl_qemu_build, you have to link keyutils or it will not compile.

if you do not have keyutils everything will work fine.

i guess i have to either edit qemu to just always disable source code that use keyutils since it doesnt have --disable-keyutils option or check it from rust side that is like this meson script below

project('test')
keyutils = dependency('libkeyutils', required: false)
message(keyutils.found())

@AndrewFasano
Copy link

I was unable to build qemu_systemmode at commit 159e6ea (current HEAD) on an Ubuntu 22.04 machine with keyutils installed. The changes in this PR fixed my issue though, Thanks @elbiazo!

The errors I was seeing mostly overlap with the screenshot above:

andrew@panda194:~/panda_dev/LibAFL/fuzzers/qemu_systemmode$ NUM_JOBS=32 cargo build --release
   Compiling libafl_qemu_build v0.8.2 (/home/andrew/panda_dev/LibAFL/libafl_qemu/libafl_qemu_build)
   Compiling libafl_qemu_sys v0.8.2 (/home/andrew/panda_dev/LibAFL/libafl_qemu/libafl_qemu_sys)
   Compiling libafl_qemu v0.8.2 (/home/andrew/panda_dev/LibAFL/libafl_qemu)
   Compiling qemu_systemmode v0.8.2 (/home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode)
error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/andrew/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/andrew/.cargo/bin:/home/andrew/.opam/4.07.0/bin:/usr/local/go/bin:/usr/local/go/bin:/home/andrew/
perl5/bin:/home/andrew/.cargo/bin:/home/andrew/.opam/4.07.0/bin:/usr/local/go/bin:/usr/local/go/bin:/home/andrew/perl5/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/andrew/g
it/panda/build/i386-softmmu/:/home/andrew/git/panda/build/x86_64-softmmu/:/home/andrew/git/panda/build/arm-softmmu/:/home/andrew/git/panda/build/ppc-softmmu/:/home/andrew/git/panda/build/mips-softmmu/:/home/andrew/git/panda/build/mipsel
-softmmu/:/home/andrew/go/bin:/home/andrew/git/panda/build/i386-softmmu/:/home/andrew/git/panda/build/x86_64-softmmu/:/home/andrew/git/panda/build/arm-softmmu/:/home/andrew/git/panda/build/ppc-softmmu/:/home/andrew/git/panda/build/mips-
softmmu/:/home/andrew/git/panda/build/mipsel-softmmu/:/home/andrew/go/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustczlZvNB/symbols.o" "/home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/deps/qemu_systemmode-10abfab0ae86710
f.libafl_qemu.33wnarerakznirq9.rcgu.o.rcgu.o" "-Wl,--as-needed" "-L" "/home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/deps" "-L" "/home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/build/capstone-s
ys-7a8b81990e1f25dc/out" "-L" "/home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/build/libafl_qemu_sys-99483cb62f64ef77/out" "-L" "/home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/build/libafl_targ
ets-d7512e245f56bff3/out" "-L" "/home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/build/libafl_targets-d7512e245f56bff3/out" "-L" "/home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/build/libafl_targ
ets-d7512e245f56bff3/out" "-L" "/home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/build/libafl_targets-d7512e245f56bff3/out" "-L" "/home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/build/libafl_targ
ets-d7512e245f56bff3/out" "-L" "/home/andrew/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lcapstone" "-Wl,-Bstatic" "/tmp/rustczlZvNB/libcapstone_sys-02e8f60a6d439f70.rlib" "/tmp/rustcz
lZvNB/liblibafl_targets-b9206b7909d7ffd2.rlib" "/tmp/rustczlZvNB/liblibafl_qemu_sys-2538fdf1e7aad3e2.rlib" "/home/andrew/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-6
6b9c3ae5ff29c13.rlib" "-Wl,-Bdynamic" "-lrt" "-lgmodule-2.0" "-lglib-2.0" "-lstdc++" "-lz" "-lpixman-1" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/andrew/.rustup/toolcha
ins/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/deps/qemu_systemmode-10abfab0ae86710f" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-zn
ow" "-Wl,-O1" "-nodefaultlibs"
  = note: /usr/bin/ld: /tmp/rustczlZvNB/liblibafl_qemu_sys-2538fdf1e7aad3e2.rlib(libqemu-partially-linked.o): in function `cap_disas_start':
          /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../disas/capstone.c:70: undefined reference to `cs_open'
          /usr/bin/ld: /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../disas/capstone.c:76: undefined reference to `cs_option'
          /usr/bin/ld: /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../disas/capstone.c:80: undefined reference to `cs_option'
          /usr/bin/ld: /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../disas/capstone.c:96: undefined reference to `cs_malloc'
          /usr/bin/ld: /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../disas/capstone.c:98: undefined reference to `cs_close'
          /usr/bin/ld: /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../disas/capstone.c:90: undefined reference to `cs_option'
          /usr/bin/ld: /tmp/rustczlZvNB/liblibafl_qemu_sys-2538fdf1e7aad3e2.rlib(libqemu-partially-linked.o): in function `cap_disas_target':
          /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../disas/capstone.c:198: undefined reference to `cs_disasm_iter'
          /usr/bin/ld: /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../disas/capstone.c:233: undefined reference to `cs_close'
          /usr/bin/ld: /tmp/rustczlZvNB/liblibafl_qemu_sys-2538fdf1e7aad3e2.rlib(libqemu-partially-linked.o): in function `cap_disas_host':
          /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../disas/capstone.c:253: undefined reference to `cs_disasm_iter'
          /usr/bin/ld: /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../disas/capstone.c:262: undefined reference to `cs_close'
          /usr/bin/ld: /tmp/rustczlZvNB/liblibafl_qemu_sys-2538fdf1e7aad3e2.rlib(libqemu-partially-linked.o): in function `cap_disas_monitor':
          /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../disas/capstone.c:300: undefined reference to `cs_disasm_iter'
          /usr/bin/ld: /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../disas/capstone.c:314: undefined reference to `cs_close'
          /usr/bin/ld: /tmp/rustczlZvNB/liblibafl_qemu_sys-2538fdf1e7aad3e2.rlib(libqemu-partially-linked.o): in function `cap_disas_plugin':
          /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../disas/capstone.c:332: undefined reference to `cs_disasm_iter'
          /usr/bin/ld: /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../disas/capstone.c:337: undefined reference to `cs_close'
          /usr/bin/ld: /tmp/rustczlZvNB/liblibafl_qemu_sys-2538fdf1e7aad3e2.rlib(libqemu-partially-linked.o): in function `sndio_poll_wait':
          /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../audio/sndioaudio.c:155: undefined reference to `sio_pollfd'
          /usr/bin/ld: /tmp/rustczlZvNB/liblibafl_qemu_sys-2538fdf1e7aad3e2.rlib(libqemu-partially-linked.o): in function `sndio_poll_event':
          /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../audio/sndioaudio.c:193: undefined reference to `sio_revents'
          /usr/bin/ld: /tmp/rustczlZvNB/liblibafl_qemu_sys-2538fdf1e7aad3e2.rlib(libqemu-partially-linked.o): in function `sndio_read':
          /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../audio/sndioaudio.c:121: undefined reference to `sio_read'
          /usr/bin/ld: /tmp/rustczlZvNB/liblibafl_qemu_sys-2538fdf1e7aad3e2.rlib(libqemu-partially-linked.o): in function `sndio_write':
          /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../audio/sndioaudio.c:90: undefined reference to `sio_write'
          /usr/bin/ld: /tmp/rustczlZvNB/liblibafl_qemu_sys-2538fdf1e7aad3e2.rlib(libqemu-partially-linked.o): in function `sndio_init':
          /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../audio/sndioaudio.c:340: undefined reference to `sio_open'
          /usr/bin/ld: /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../audio/sndioaudio.c:348: undefined reference to `sio_initpar'
          /usr/bin/ld: /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../audio/sndioaudio.c:394: undefined reference to `sio_setpar'
          /usr/bin/ld: /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../audio/sndioaudio.c:399: undefined reference to `sio_getpar'
          /usr/bin/ld: /home/andrew/panda_dev/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../audio/sndioaudio.c:429: undefined reference to `sio_nfds'
          /usr/bin/ld: /tmp/rustczlZvNB/liblibafl_qemu_sys-2538fdf1e7aad3e2.rlib(libqemu-partially-linked.o): in function `sndio_fini':
		  /home/andrew/igloo_git/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../audio/sndioaudio.c:317: undefined reference to `sio_close'
          /usr/bin/ld: /home/andrew/igloo_git/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../audio/sndioaudio.c:317: undefined reference to `sio_close'
          /usr/bin/ld: /tmp/rustczlZvNB/liblibafl_qemu_sys-2538fdf1e7aad3e2.rlib(libqemu-partially-linked.o): in function `sndio_fini_in':
          /home/andrew/igloo_git/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../audio/sndioaudio.c:323: undefined reference to `sio_close'
          /usr/bin/ld: /tmp/rustczlZvNB/liblibafl_qemu_sys-2538fdf1e7aad3e2.rlib(libqemu-partially-linked.o): in function `sndio_enable_in':
          /home/andrew/igloo_git/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../audio/sndioaudio.c:323: undefined reference to `sio_start'
          /usr/bin/ld: /home/andrew/igloo_git/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../audio/sndioaudio.c:323: undefined reference to `sio_stop'
          /usr/bin/ld: /tmp/rustczlZvNB/liblibafl_qemu_sys-2538fdf1e7aad3e2.rlib(libqemu-partially-linked.o): in function `sndio_enable':
          /home/andrew/igloo_git/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../audio/sndioaudio.c:457: undefined reference to `sio_start'
          /usr/bin/ld: /home/andrew/igloo_git/LibAFL/fuzzers/qemu_systemmode/target/release/qemu-libafl-bridge/build/../audio/sndioaudio.c:463: undefined reference to `sio_stop'
          collect2: error: ld returned 1 exit status

  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `qemu_systemmode` due to previous error

@andreafioraldi andreafioraldi merged commit 3345727 into AFLplusplus:main Jan 9, 2023
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

Successfully merging this pull request may close these issues.

None yet

3 participants