eurecom-s3 / symcc

SymCC: efficient compiler-based symbolic execution
http://www.s3.eurecom.fr/tools/symbolic_execution/symcc.html
GNU General Public License v3.0
771 stars 137 forks source link

SymCC fails to compile with -DTARGET_32BIT=ON #159

Open PwnVerse opened 4 months ago

PwnVerse commented 4 months ago

Here are the steps to reproduce the issue. Note that I have already built z3 separately.

git clone git@github.com:eurecom-s3/symcc.git
cd symcc 
git submodule init
git submodule update
mkdir build && cd build
cmake -G Ninja -DQSYM_BACKEND=ON -DTARGET_32BIT=ON -DZ3_TRUST_SYSTEM_VERSION=ON ..
ninja check

Fails with -

[9/22] Performing configure step for 'SymRuntime32'
FAILED: SymRuntime32-prefix/src/SymRuntime32-stamp/SymRuntime32-configure /home/ritvik/Desktop/Files/test/symcc/build/SymRuntime32-prefix/src/SymRuntime32-stamp/SymRuntime32-configure 
cd /home/ritvik/Desktop/Files/test/symcc/build/SymRuntime32-prefix/src/SymRuntime32-build && /usr/bin/cmake -DCMAKE_AR=/usr/bin/ar -DCMAKE_C_COMPILER=/usr/bin/cc -DCMAKE_C_FLAGS= "-DCMAKE_C_FLAGS_INIT=  " -DCMAKE_CXX_COMPILER=/usr/bin/c++ -DCMAKE_CXX_FLAGS= "-DCMAKE_CXX_FLAGS_INIT=  " -DCMAKE_EXE_LINKER_FLAGS= "-DCMAKE_EXE_LINKER_FLAGS_INIT=  " -DCMAKE_MAKE_PROGRAM=/home/ritvik/.local/bin/ninja -DCMAKE_MODULE_LINKER_FLAGS= "-DCMAKE_MODULE_LINKER_FLAGS_INIT=  " -DCMAKE_SHARED_LINKER_FLAGS= "-DCMAKE_SHARED_LINKER_FLAGS_INIT=  " -DCMAKE_MODULE_PATH=/home/ritvik/Desktop/Files/test/symcc/cmake -DCMAKE_SYSROOT= -DQSYM_BACKEND=ON -DCMAKE_BUILD_TYPE= -DZ3_TRUST_SYSTEM_VERSION=ON "-DCMAKE_C_FLAGS=\" -m32\"" "-DCMAKE_CXX_FLAGS=\" -m32\"" -DZ3_DIR= -DLLVM_DIR= -GNinja /home/ritvik/Desktop/Files/test/symcc/runtime && /usr/bin/cmake -E touch /home/ritvik/Desktop/Files/test/symcc/build/SymRuntime32-prefix/src/SymRuntime32-stamp/SymRuntime32-configure
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc - broken
CMake Error at /usr/share/cmake-3.22/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    "/usr/bin/cc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/ritvik/Desktop/Files/test/symcc/build/SymRuntime32-prefix/src/SymRuntime32-build/CMakeFiles/CMakeTmp

    Run Build Command(s):/home/ritvik/.local/bin/ninja cmTC_a5f77 && [1/2] Building C object CMakeFiles/cmTC_a5f77.dir/testCCompiler.c.o
    FAILED: CMakeFiles/cmTC_a5f77.dir/testCCompiler.c.o 
    /usr/bin/cc   " -m32" -o CMakeFiles/cmTC_a5f77.dir/testCCompiler.c.o -c /home/ritvik/Desktop/Files/test/symcc/build/SymRuntime32-prefix/src/SymRuntime32-build/CMakeFiles/CMakeTmp/testCCompiler.c
    cc: warning:  -m32: linker input file unused because linking not done
    cc: error:  -m32: linker input file not found: No such file or directory
    ninja: build stopped: subcommand failed.

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:17 (project)

-- Configuring incomplete, errors occurred!
See also "/home/ritvik/Desktop/Files/test/symcc/build/SymRuntime32-prefix/src/SymRuntime32-build/CMakeFiles/CMakeOutput.log".
See also "/home/ritvik/Desktop/Files/test/symcc/build/SymRuntime32-prefix/src/SymRuntime32-build/CMakeFiles/CMakeError.log".
[12/22] Performing configure step for 'SymRuntime'
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Could NOT find Z3 (missing: Z3_DIR)
-- Looking for C++ include filesystem
-- Looking for C++ include filesystem - found
-- Performing Test CXX_FILESYSTEM_NO_LINK_NEEDED
-- Performing Test CXX_FILESYSTEM_NO_LINK_NEEDED - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ritvik/Desktop/Files/test/symcc/build/SymRuntime-prefix/src/SymRuntime-build
[14/22] Building CXX object CMakeFiles/Symbolize.dir/compiler/Pass.cpp.o
ninja: build stopped: subcommand failed.

The reason I see is that it's trying to use the -m32 flag as " -m32" in it's arguments. Please let me know if I'm missing something trivial.

sebastianpoeplau commented 4 months ago

I think you're right, and apparently nobody noticed in more than two years :sweatsmile: We'll need to have a look at how to fix this properly in CMake. As a workaround, can you try to give CMake some dummy C and C++ flags, either via `-DCMAKE[C/CXX]_FLAGSor with theCFLAGS/CXXFLAGS` environment variables?

PwnVerse commented 4 months ago

I tried setting the c and cxxflags to -emit-llvm this time, build succeeded but it ended up building the 64 bit version.

~/Desktop/Files/test/symcc/build/SymRuntime32-prefix/src/SymRuntime32-build$ file libSymRuntime.so
libSymRuntime.so: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=c8d49090c208303ec72d7bb414fcc0df5a5265bd, not stripped
PwnVerse commented 3 months ago

@sebastianpoeplau I would like to investigate this further and either find a simple workaround or fix this issue for 32 bit builds. Is it possible for you to maybe hop on a quick call or give me some insight into how I can help in fixing this?

Dang-Khoa commented 2 months ago

Any updates on this bug? I'm also stuck on this.

Dang-Khoa commented 4 weeks ago

This error can be prevented by simply removing the leading space of the -m32 tags in the CMakeFile.txt.