Re: [klee-dev] Error while using C++ STL, libcxx
On 26/05/2020 13:32, Namrata Jain wrote: I also want to know about klee version-2.1-pre, is it the same as version 2.0? This is because I have made some changes in my klee source (2.1-pre) for a project and now I will be using version-2.1. 2.1-pre is the version string reported by the mainline between releases 2.0 and 2.1. Cristian ___ klee-dev mailing list klee-dev@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/klee-dev
Re: [klee-dev] Error while using C++ STL, libcxx
Thankyou Felix. -- Namrata Jain On 26.05.2020 22:02, Felix Rath wrote: Hey, As suggested, I ran "make check" from klee-build-directory and found that 47 unexpected tests were failing. That definitely sounds like something might have been broken there. What this error is about? I also found this as an open issue on klee github page. I sadly cannot help with this, as I don't use KLEE's build scripts, and am not really familiar with how they work at all. So I don't know what the correct options, usage, etc. for building KLEE with libcxx support are. As you mentioned that libcxx support was not required for the example I stated, I built klee (version 2.1) without enabling libcxx and was able to see the output "12" with no errors. Nice :) Then I would assume that LLVM 9 or 10 should definitely help with running with `--libcxx`. Are these due to not linking libcxx? KLEE: WARNING: undefined reference to function: _ZSt9terminatev KLEE: WARNING: undefined reference to function: __cxa_begin_catch KLEE: WARNING: undefined reference to function: __gxx_personality_v0 I think these are from not linking libcxxabi, which can be part of libcxx depending on how you build it. 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: llvm.dbg.label KLEE: WARNING: undefined reference to function: open KLEE: WARNING: undefined reference to function: write KLEE: WARNING: undefined reference to function: kill (UNSAFE)! Some of these actually are provided by --posix-runtime (like `open`, `ioctl` and maybe more), so that might help here. Others might not be modeled for KLEE (yet), but they don't seem to be from libcxx, as libcxx usually contains C++-mangled names (but they might appear in the program because you #include'd and ). I also want to know about klee version-2.1-pre, is it the same as version 2.0? This is because I have made some changes in my klee source (2.1-pre) for a project and now I will be using version-2.1. Can't really help with this, not really familiar with KLEE's release process. Best, Felix From: Namrata Jain Sent: Tuesday, May 26, 2020 2:32 PM To: Felix Rath Cc: klee-dev@imperial.ac.uk Subject: Re: [klee-dev] Error while using C++ STL, libcxx Hello Felix, Thankyou for the reply. As suggested, I ran "make check" from klee-build-directory and found that 47 unexpected tests were failing. So, I installed llvm-10, but while installing libcxx from klee-source-directory using the command: LLVM_VERSION=10 SANITIZER_BUILD= BASE= ./scripts/build/build.sh libcxx it generated output: Detected OS: linux OS=linux Detected distribution: ubuntu DISTRIBUTION=ubuntu Detected version: 18.04 DISTRIBUTION_VER=18.04 Component sanitizer not found. Component sanitizer not found. ENABLE_OPTIMIZED Required but unset What this error is about? I also found this as an open issue on klee github page. As you mentioned that libcxx support was not required for the example I stated, I built klee (version 2.1) without enabling libcxx and was able to see the output "12" with no errors. (using the command: klee --libc=uclibc /experiment.bc) Warnings that were generated: KLEE: WARNING: undefined reference to function: _ZSt9terminatev KLEE: WARNING: undefined reference to function: __cxa_begin_catch KLEE: WARNING: undefined reference to function: __gxx_personality_v0 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: llvm.dbg.label 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, 94590150907232) at libc/termios/tcgetattr.c:43 12 KLEE: WARNING ONCE: calling __user_main with extra arguments. Are these due to not linking libcxx? I also want to know about klee version-2.1-pre, is it the same as version 2.0? This is because I have made some changes in my klee source (2.1-pre) for a project and now I will be using version-2.1. Thankyou. -- Namrata Jain On 25.05.2020 17:21, Felix Rath wrote: Hello Namrata, I worked a lot on the current C++ support in KLEE (the recent C++ support PRs to KLEE were by me), so I hope I can help. I think the main problem is that llvm 6.0 is quite old, and your example should pretty much work as-is if you switch to a recent llvm version (the most recent being 10, which should work). I tried your example locally with llvm (and libc++) 10 and it produced the
Re: [klee-dev] Error while using C++ STL, libcxx
Hello Felix, Thankyou for the reply. As suggested, I ran "make check" from klee-build-directory and found that 47 unexpected tests were failing. So, I installed llvm-10, but while installing libcxx from klee-source-directory using the command: LLVM_VERSION=10 SANITIZER_BUILD= BASE= ./scripts/build/build.sh libcxx it generated output: Detected OS: linux OS=linux Detected distribution: ubuntu DISTRIBUTION=ubuntu Detected version: 18.04 DISTRIBUTION_VER=18.04 Component sanitizer not found. Component sanitizer not found. ENABLE_OPTIMIZED Required but unset What this error is about? I also found this as an open issue on klee github page. As you mentioned that libcxx support was not required for the example I stated, I built klee (version 2.1) without enabling libcxx and was able to see the output "12" with no errors. (using the command: klee --libc=uclibc /experiment.bc) Warnings that were generated: KLEE: WARNING: undefined reference to function: _ZSt9terminatev KLEE: WARNING: undefined reference to function: __cxa_begin_catch KLEE: WARNING: undefined reference to function: __gxx_personality_v0 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: llvm.dbg.label 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, 94590150907232) at libc/termios/tcgetattr.c:43 12 KLEE: WARNING ONCE: calling __user_main with extra arguments. Are these due to not linking libcxx? I also want to know about klee version-2.1-pre, is it the same as version 2.0? This is because I have made some changes in my klee source (2.1-pre) for a project and now I will be using version-2.1. Thankyou. -- Namrata Jain On 25.05.2020 17:21, Felix Rath wrote: Hello Namrata, I worked a lot on the current C++ support in KLEE (the recent C++ support PRs to KLEE were by me), so I hope I can help. I think the main problem is that llvm 6.0 is quite old, and your example should pretty much work as-is if you switch to a recent llvm version (the most recent being 10, which should work). I tried your example locally with llvm (and libc++) 10 and it produced the expected output ("12"). You can also run KLEE's testsuite to see if your build works (or whether some tests already fail); To do so, go to the directory you built KLEE in and run "make check". This will run KLEE's unit- and integrationtests, which also test the C++ support. If this issue is simply due to llvm 6.0 being too old, I would expect some tests to fail (unless the tests relevant to your case aren't executed for older llvm versions). As building the bitcode file with the right flags can also be non-trivial, here are the flags I use to build (up to large) C++ projects for execution with KLEE (I've been wondering about a good way to share them anyway, so I guess they might also be helpful in general). Let's go over your flags first: clang++ -emit-llvm -c experiment.cpp -o experiment.bc What this will do: Use your system clang++ (unless you have another clang++ in your PATH before that) and use that to compile your program and output bitcode. clang++ will by default (at least on Linux) use your g++'s C++ standard library implementation for compiling and linking. As and are both header only (at least for the functionality in your example), your example doesn't require linking against a bitcode-version of libcxx to run in KLEE. Using the command you give to build the bitcode file (but using llvm 10's clang++), I was able to run your program using `klee --libcxx --libc=uclibc main.bc` as well as just `klee --libc=uclibc main.bc`, so without explicitly linking libcxx. For many programs, especially small examples, this is often the case. However, as soon as your program makes use of functionality that requires actually linking against a libcxx (so running KLEE with `--libcxx`), this might cause weird things to happen, or simply not work at all, as you are now mixing g++'s (through `#include`s) and llvm's (through `--libcxx`) standard library implementations. Therefore, my general recommendation would be to always build against the libcxx version you also give to KLEE's CMake invocation (the -DKLEE_LIBCXX_DIR parameter). clang++-6.0 -emit-llvm -c -std=c++11 -I"/home/namrata/libc++-install-60/include/c++/v1/" -nostdinc++ experiment.cpp This should properly cause your example to include and from your libcxx version (at least for recent llvm/clang++ version, i.e., 9 or 10). Running KLEE with `--libcxx` should then also link the corresponding libcxx-library version into your program. However, compiling your programs to a working binary this way might be a problem, or
Re: [klee-dev] Error while using C++ STL, libcxx
Hey, > As suggested, I ran "make check" from klee-build-directory and found > that 47 unexpected tests were failing. That definitely sounds like something might have been broken there. > What this error is about? I also found this as an open issue on klee > github page. I sadly cannot help with this, as I don't use KLEE's build scripts, and am not really familiar with how they work at all. So I don't know what the correct options, usage, etc. for building KLEE with libcxx support are. > As you mentioned that libcxx support was not required for the example I > stated, I built klee (version 2.1) without enabling libcxx and was able > to see the output "12" with no errors. Nice :) Then I would assume that LLVM 9 or 10 should definitely help with running with `--libcxx`. > Are these due to not linking libcxx? > KLEE: WARNING: undefined reference to function: _ZSt9terminatev > KLEE: WARNING: undefined reference to function: __cxa_begin_catch > KLEE: WARNING: undefined reference to function: __gxx_personality_v0 I think these are from not linking libcxxabi, which can be part of libcxx depending on how you build it. > 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: llvm.dbg.label > KLEE: WARNING: undefined reference to function: open > KLEE: WARNING: undefined reference to function: write > KLEE: WARNING: undefined reference to function: kill (UNSAFE)! Some of these actually are provided by --posix-runtime (like `open`, `ioctl` and maybe more), so that might help here. Others might not be modeled for KLEE (yet), but they don't seem to be from libcxx, as libcxx usually contains C++-mangled names (but they might appear in the program because you #include'd and ). > I also want to know about klee version-2.1-pre, is it the same as > version 2.0? This is because I have made some changes in my klee source > (2.1-pre) for a project and now I will be using version-2.1. Can't really help with this, not really familiar with KLEE's release process. Best, Felix From: Namrata Jain Sent: Tuesday, May 26, 2020 2:32 PM To: Felix Rath Cc: klee-dev@imperial.ac.uk Subject: Re: [klee-dev] Error while using C++ STL, libcxx Hello Felix, Thankyou for the reply. As suggested, I ran "make check" from klee-build-directory and found that 47 unexpected tests were failing. So, I installed llvm-10, but while installing libcxx from klee-source-directory using the command: LLVM_VERSION=10 SANITIZER_BUILD= BASE= ./scripts/build/build.sh libcxx it generated output: Detected OS: linux OS=linux Detected distribution: ubuntu DISTRIBUTION=ubuntu Detected version: 18.04 DISTRIBUTION_VER=18.04 Component sanitizer not found. Component sanitizer not found. ENABLE_OPTIMIZED Required but unset What this error is about? I also found this as an open issue on klee github page. As you mentioned that libcxx support was not required for the example I stated, I built klee (version 2.1) without enabling libcxx and was able to see the output "12" with no errors. (using the command: klee --libc=uclibc /experiment.bc) Warnings that were generated: KLEE: WARNING: undefined reference to function: _ZSt9terminatev KLEE: WARNING: undefined reference to function: __cxa_begin_catch KLEE: WARNING: undefined reference to function: __gxx_personality_v0 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: llvm.dbg.label 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, 94590150907232) at libc/termios/tcgetattr.c:43 12 KLEE: WARNING ONCE: calling __user_main with extra arguments. Are these due to not linking libcxx? I also want to know about klee version-2.1-pre, is it the same as version 2.0? This is because I have made some changes in my klee source (2.1-pre) for a project and now I will be using version-2.1. Thankyou. -- Namrata Jain On 25.05.2020 17:21, Felix Rath wrote: > Hello Namrata, > > I worked a lot on the current C++ support in KLEE (the recent C++ > support PRs to KLEE were by me), so I hope I can help. I think the > main problem is that llvm 6.0 is quite old, and your example should > pretty much work as-is if you switch to a recent llvm version (the > most recent being 10, which should work). I tried your example loc
Re: [klee-dev] Error while using C++ STL, libcxx
Hello Namrata, I worked a lot on the current C++ support in KLEE (the recent C++ support PRs to KLEE were by me), so I hope I can help. I think the main problem is that llvm 6.0 is quite old, and your example should pretty much work as-is if you switch to a recent llvm version (the most recent being 10, which should work). I tried your example locally with llvm (and libc++) 10 and it produced the expected output ("12"). You can also run KLEE's testsuite to see if your build works (or whether some tests already fail); To do so, go to the directory you built KLEE in and run "make check". This will run KLEE's unit- and integrationtests, which also test the C++ support. If this issue is simply due to llvm 6.0 being too old, I would expect some tests to fail (unless the tests relevant to your case aren't executed for older llvm versions). As building the bitcode file with the right flags can also be non-trivial, here are the flags I use to build (up to large) C++ projects for execution with KLEE (I've been wondering about a good way to share them anyway, so I guess they might also be helpful in general). Let's go over your flags first: > clang++ -emit-llvm -c experiment.cpp -o experiment.bc What this will do: Use your system clang++ (unless you have another clang++ in your PATH before that) and use that to compile your program and output bitcode. clang++ will by default (at least on Linux) use your g++'s C++ standard library implementation for compiling and linking. As and are both header only (at least for the functionality in your example), your example doesn't require linking against a bitcode-version of libcxx to run in KLEE. Using the command you give to build the bitcode file (but using llvm 10's clang++), I was able to run your program using `klee --libcxx --libc=uclibc main.bc` as well as just `klee --libc=uclibc main.bc`, so without explicitly linking libcxx. For many programs, especially small examples, this is often the case. However, as soon as your program makes use of functionality that requires actually linking against a libcxx (so running KLEE with `--libcxx`), this might cause weird things to happen, or simply not work at all, as you are now mixing g++'s (through `#include`s) and llvm's (through `--libcxx`) standard library implementations. Therefore, my general recommendation would be to always build against the libcxx version you also give to KLEE's CMake invocation (the -DKLEE_LIBCXX_DIR parameter). > clang++-6.0 -emit-llvm -c -std=c++11 > -I"/home/namrata/libc++-install-60/include/c++/v1/" -nostdinc++ experiment.cpp This should properly cause your example to include and from your libcxx version (at least for recent llvm/clang++ version, i.e., 9 or 10). Running KLEE with `--libcxx` should then also link the corresponding libcxx-library version into your program. However, compiling your programs to a working binary this way might be a problem, or might still mix up llvm and g++ versions of the standard library (as I'm not sure what this uses for linking, or whether it reports an error). This might especially be the case when you build larger real-word projects using wllvm++. Here are the flags I generally use to build C++ programs for running with KLEE: LIBCXX_LIB_DIR="//lib" LIBCXXABI_LIB_DIR="//lib" MY_CXX_FLAGS="-nostdinc++ -stdlib=libc++ -lc++ -lc++abi \ -I//libcxx/include \ -I//libcxxabi/include \ -Wl,-L$LIBCXX_LIB_DIR -Wl,-L$LIBCXXABI_LIB_DIR \ -Wl,-rpath=$LIBCXX_LIB_DIR -Wl,-rpath=$LIBCXXABI_LIB_DIR" And then build a file main.cpp using: clang++ $MY_CXX_FLAGS -emit-llvm -c main.cpp Or, when building a project that uses cmake (plus setup for clang++/wllvm++): cmake -DCMAKE_CXX_FLAGS="$MY_CXX_FLAGS" Depending on how you build libcxx and libcxxabi (I build them without checking out the rest of llvm's source, which I think leads to a slightly different setup), you might need only some of these. E.g., if your build process outputs a `libc++.bca` that already contains a linked version of `libc++abi`, the linker directives (those beginning with -Wl) for libcxxabi should not be needed (but those for libcxx are still required). Additionally, I usually use a version of KLEE that supports C++ exceptions (exactly this PR: https://github.com/klee/klee/pull/966), which is why the libcxxabi/libc++abi setup is required, but you might be able to avoid specifying those if you use one of the released KLEE versions or KLEE's current master. Some more explanations: `-nostdinc++` makes the compiler not set default paths for including standard library headers, which you also used in your example. `-stdlib=libc++` makes clang++ use llvm's libc++ implementation instead of g++'s. I sometimes get warnings that this flag is ignored by the compiler, which I think is due to the fact that the next flags, `-lc++` and `-lc++abi`, already cause linking against libc++ and libc++abi. The two `-I` directives then set up include-paths for standard