Code Monkey home page Code Monkey logo

crux-bitcode's Introduction

crux-bitcode

crux-bitcode is a CRUX Linux Docker image to make generating LLVM bitcode from (some) open-source software easy by using CRUX's ports system and GLLVM. build-bitcode.sh can build software in the official ports tree (with some caveats) into bitcode.

LLVM/Clang version: 12.0.0.

Requirements

Docker. The first run may be slow as the (large) image is downloaded.

Usage

  1. Create a list of desired ports in a file pkgs.txt (modify included file). (The full list of possibilities can be seen by running ls ports/*/.)
  2. Run ./build-bitcode.sh.
  3. unzip the generated bitcode-XYZ.zip.

An info.txt file is provided alongside the bitcode files containing (an estimate of) the lines of C/C++ code used to generate each bitcode file. This is calculated by counting the lines of code in the files mentioned in the debug information. info.txt also includes the user-defined CFLAGS and CXXFLAGS.

Customisation

  • build-bitcode.sh copies ports into the container, so ports can be modified, and new ports can be created or copied from elsewhere.
  • build-bitcode.sh copies pkgmk.conf into the container (run the image and man pkgmk.conf for more information).

Caveats

Some ports may not respect CFLAGS/CXXFLAGS nor CC/CXX. The image attempts to resolve this by intercepting calls to the compiler (see image/cc.lua, image/cxx.lua). Some ports may need to have their Pkgfile modified, or a patch added, if problems arise.

Packages that cannot be built

These packages have some known problem building bitcode or building bitcode according to user parameters. They can still be used as dependencies though.

  • nss: can produce bitcode, but not with user-defined CFLAGS.
  • firefox: appears to fail at the last step; needs investigation.
  • qt5: does not produce bitcode for some/all binaries; needs investigation
    • Can be used as a dependency
  • qownnotes: same problem as qt5
  • bc: will not build on Apple Silicon
    • ARM build may be worthwhile

LLVM/Clang version

If LLVM or Clang (or their runtime dependencies) are included in pkgs.txt, then version 10 is used. The ports directory is "frozen" (modulo required fixes) whereas the image/ports directory is not. LLVM and Clang (and dependencies) in image/ports are updated as necessary.

Thus there is a tension where LLVM/Clang ports, when building bitcode, are of different versions to the included LLVM/Clang. If LLVM (or Clang) is built, explicitly or as a dependency, the container will use the newly built LLVM (or Clang) and not the one included in the image. This can be an older version.

TODO

  • Ability to run build-bitcode.sh from anywhere.
  • Command line options for build-bitcode.sh and build-bitcode.lua.
  • Reduce image size.
  • Test more ports.
  • Remove more non-C/C++ ports.
  • Nicer error handling.
  • Would be nice if sources are archived to "freeze" the port tree.
  • Always use included LLVM/Clang, never a version built by the user.

crux-bitcode's People

Contributors

jumormt avatar mbarbar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

crux-bitcode's Issues

Issue on compiling the gcc 8.4.0

There is an issue when compiling the gcc 8.4.0. Many of the ports need the GCC 8.4.0 but after the GCC 8.4.0 is downloaded, when the configure script is running, it will get stuck at the step "checking whether compiler driver understands Ada...", and the memory will be run out. I am not sure is it caused by the clang 12, maybe it is a bug of the clang 12. (you can test with the ports: openblas / coin-or-osi)

configure output

2022-07-01 05:15:34 (546 KB/s) - '/usr/ports/contrib/gcc-fortran/gcc-8.4.0.tar.xz.partial' saved [63713440]

=======> Building '/usr/ports/contrib/gcc-fortran/gcc-fortran#8.4.0-1.pkg.tar.gz'.
bsdtar -p -o -C /usr/ports/contrib/gcc-fortran/work/src -xf /usr/ports/contrib/gcc-fortran/gcc-8.4.0.tar.xz
cp gcc-nocheck-fixincludes.patch /usr/ports/contrib/gcc-fortran/work/src
cp gcc-4.7.3-multilib-dirs.patch /usr/ports/contrib/gcc-fortran/work/src
+ build
+ patch -d gcc-8.4.0 -p 1 -i /usr/ports/contrib/gcc-fortran/work/src/gcc-nocheck-fixincludes.patch
patching file fixincludes/Makefile.in
+ patch -d gcc-8.4.0 -p 1 -i /usr/ports/contrib/gcc-fortran/work/src/gcc-4.7.3-multilib-dirs.patch
patching file gcc/config/i386/linux64.h
Hunk #1 succeeded at 27 with fuzz 2 (offset -1 lines).
patching file gcc/config/i386/t-linux64
Hunk #1 succeeded at 33 (offset -1 lines).
+ sed -i -e 's|\./fixinc\.sh|-c true|' gcc-8.4.0/gcc/Makefile.in
+ install -d build
+ cd build
+ ../gcc-8.4.0/configure --prefix=/usr --libexecdir=/usr/lib --enable-languages=fortran --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-shared --disable-nls --with-x=no --with-system-zlib --enable-multilib --disable-sjlj-exceptions --with-pkgversion=CRUX-x86_64-multilib
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln works... yes
checking whether ln -s works... yes
checking for a sed that does not truncate output... /bin/sed
checking for gawk... gawk
checking for libatomic support... yes
checking for libitm support... yes
checking for libsanitizer support... yes
checking for libvtv support... yes
checking for libmpx support... yes
checking for libhsail-rt support... yes
checking for gcc... gclang
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gclang accepts -g... yes
checking for gclang option to accept ISO C89... none needed
checking whether we are using the GNU C++ compiler... yes
checking whether gclang++ accepts -g... yes
checking whether g++ accepts -static-libstdc++ -static-libgcc... no
checking for gnatbind... no
checking for gnatmake... no
checking whether compiler driver understands Ada...

<<< get stuck here

thounsands of processes on the server

root      102070  0.0  0.0 704128  3612 ?        Sl   20:22   0:00 /bin/gclang -c -m64 -o conftest.o -x ada conftest.adb -O0 -g -fno-discard-value-names -fno-lto
root      102075  0.0  0.0 172164 59228 ?        S    20:22   0:00 clang -c -m64 -o conftest.o -x ada conftest.adb -O0 -g -fno-discard-value-names -fno-lto
root      102076  0.0  0.0  15032  1408 ?        S    20:22   0:00 lua5.3 /usr/bin/gcc -c -m64 -o conftest.o -x ada conftest.adb
root      102077  0.0  0.0 704128  3612 ?        Sl   20:22   0:00 /bin/gclang -c -m64 -o conftest.o -x ada conftest.adb -O0 -g -fno-discard-value-names -fno-lto
root      102082  0.0  0.0 172164 58828 ?        S    20:22   0:00 clang -c -m64 -o conftest.o -x ada conftest.adb -O0 -g -fno-discard-value-names -fno-lto
root      102083  0.0  0.0  15032  1320 ?        S    20:22   0:00 lua5.3 /usr/bin/gcc -c -m64 -o conftest.o -x ada conftest.adb
root      102084  0.0  0.0 704128  3616 ?        Sl   20:22   0:00 /bin/gclang -c -m64 -o conftest.o -x ada conftest.adb -O0 -g -fno-discard-value-names -fno-lto
root      102089  0.0  0.0 172164 59236 ?        S    20:22   0:00 clang -c -m64 -o conftest.o -x ada conftest.adb -O0 -g -fno-discard-value-names -fno-lto
root      102090  0.0  0.0  15032  1424 ?        S    20:22   0:00 lua5.3 /usr/bin/gcc -c -m64 -o conftest.o -x ada conftest.adb
root      102091  0.0  0.0 705536  3612 ?        Sl   20:22   0:00 /bin/gclang -c -m64 -o conftest.o -x ada conftest.adb -O0 -g -fno-discard-value-names -fno-lto

Building bitcode in opaque ptr mode

Hello Mohamad,

SVF is now offering support for opaque pointers. To effectively test this feature, we need some open-source programs that are compiled in opaque pointer mode. Could you please advise me how to modify crux-bitcode to be able to build bitcodes in opaque pointer mode?

Best regards,
Xiao Cheng

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.