klee icon indicating copy to clipboard operation
klee copied to clipboard

"warning: Linking two modules of different target triples" when using KLEE via Docker with the `--libc=uclibc` option

Open YikeZhou opened this issue 2 years ago • 4 comments

Description

I'm using KLEE 3.0 via Docker. I came across lots of unexpected warning messages like this:

warning: Linking two modules of different target triples: 'get_sign.bc' is 'x86_64-unknown-linux-gnu' whereas '__uClibc_main.os' is 'x86_64-pc-linux-gnu'

Manually specifying the target triple may solve this problem. I wonder if this could be fixed globally in the construction of a Docker image.

Steps to reproduce

First, pull the docker image down and start a fresh container.

$ docker pull klee/klee:3.0
$ docker run --rm -ti --ulimit='stack=-1:-1' klee/klee:3.0

Then we need to find some input for KLEE. The program doesn't matter here. So I choose get_sign.c as an example.

$ cd ~/klee_src/examples/get_sign/
$ clang -I ../../include -emit-llvm -c -g -O0 -Xclang -disable-O0-optnone get_sign.c

Now we have the .bc file. We can invoke KLEE with the following command-line.

$ klee --libc=uclibc get_sign.bc

Note: I'm aware that the --libc=uclibc option is unnecessary here. It is only used to illustrate the warnings caused by this option.

KLEE complains about the mismatching targets.

KLEE: NOTE: Using klee-uclibc : /tmp/klee_build130stp_z3/runtime/lib/klee-uclibc.bca
KLEE: output directory is "/home/klee/klee_src/examples/get_sign/klee-out-0"
KLEE: Using STP solver backend
KLEE: SAT solver: MiniSat
warning: Linking two modules of different target triples: 'get_sign.bc' is 'x86_64-unknown-linux-gnu' whereas '__uClibc_main.os' is 'x86_64-pc-linux-gnu'

warning: Linking two modules of different target triples: 'klee_overshift_check64_Debug+Asserts.bc' is 'x86_64-unknown-linux-gnu' whereas '__uClibc_main.os' is 'x86_64-pc-linux-gnu'

KLEE: WARNING: undefined reference to function: __syscall_rt_sigaction
KLEE: WARNING: undefined reference to function: fcntl
KLEE: WARNING: undefined reference to function: fstat
KLEE: WARNING: undefined reference to function: ioctl
KLEE: WARNING: undefined reference to function: open
KLEE: WARNING: undefined reference to function: write
KLEE: WARNING: undefined reference to function: kill (UNSAFE)!
KLEE: WARNING ONCE: calling external: ioctl(0, 21505, 94527241372272) at libc/termios/tcgetattr.c:43 12
KLEE: WARNING ONCE: calling __user_main with extra arguments.

KLEE: done: total instructions = 11973
KLEE: done: completed paths = 3
KLEE: done: partially completed paths = 0
KLEE: done: generated tests = 3

Platform

I'm running Docker (with the WSL 2 backend) on a Windows PC.

YikeZhou avatar Jun 21 '23 06:06 YikeZhou

This is unfortunately a result of building uclibc (building with wllvm) differently than KLEE's bitcode files (building with clang directly). As a result, the target triplets are slightly different: 'x86_64-unknown-linux-gnu' vs. 'x86_64-pc-linux-gnu' In this case, they are compatible.

But it becomes a problem if bitcode files of different platforms/architectures are mixed that's why KLEE is warning about it.

@YikeZhou I'll close this issue but feel free to re-open it with related follow-up questions.

MartinNowack avatar Jun 22 '23 05:06 MartinNowack

I think it would be an improvement in terms of usability to remove such warnings when they don't matter, but this is something that LLVM rather than KLEE warns about.

ccadar avatar Jun 22 '23 09:06 ccadar

I think you might get a fitting target triple when building klee-uclibc with:

$ make -j2 KLEE_CFLAGS="--target=x86_64-unknown-linux-gnu" 

251 avatar Jun 22 '23 10:06 251

That would be nice to try. Let's reopen this until we try.

ccadar avatar Jun 22 '23 10:06 ccadar