Giter Club home page Giter Club logo

whole-program-llvm's Introduction

WLLVMWhole Program LLVM

License: MIT PyPI version Build Status PyPI Statistics

Introduction

This project, WLLVM, provides tools for building whole-program (or whole-library) LLVM bitcode files from an unmodified C or C++ source package. It currently runs on *nix platforms such as Linux, FreeBSD, and Mac OS X.

WLLVM provides python-based compiler wrappers that work in two steps. The wrappers first invoke the compiler as normal. Then, for each object file, they call a bitcode compiler to produce LLVM bitcode. The wrappers also store the location of the generated bitcode file in a dedicated section of the object file. When object files are linked together, the contents of the dedicated sections are concatenated (so we don't lose the locations of any of the constituent bitcode files). After the build completes, one can use a WLLVM utility to read the contents of the dedicated section and link all of the bitcode into a single whole-program bitcode file. This utility works for both executable and native libraries.

This two-phase build process is necessary to be a drop-in replacement for gcc or g++ in any build system. Using the LTO framework in gcc and the gold linker plugin works in many cases, but fails in the presence of static libraries in builds. WLLVM's approach has the distinct advantage of generating working binaries, in case some part of a build process requires that.

WLLVM works with either clang or the gcc dragonegg plugin. If you are not interested in dragonegg support, and speed is an issue for you, you may want to try out gllvm.

Installation

As of August 2016 WLLVM is now a pip package. You can just do:

pip install wllvm

or

sudo pip install wllvm

depending on your machine's permissions.

Tutorial

If you want to develop or use the development version:

git clone https://github.com/travitch/whole-program-llvm
cd whole-program-llvm

Now you need to install WLLVM. You can either install globally on your system in develop mode:

sudo pip install -e .

or install WLLVM into a virtual python environment in develop mode to avoid installing globally:

virtualenv venv
source venv/bin/activate
pip install -e .

Usage

WLLVM includes four python executables: wllvm for compiling C code and wllvm++ for compiling C++, an auxiliary tool extract-bc for extracting the bitcode from a build product (object file, executable, library or archive), and a sanity checker, wllvm-sanity-checker for detecting configuration oversights.

Three environment variables must be set to use these wrappers:

  • LLVM_COMPILER should be set to either dragonegg or clang.
  • LLVM_GCC_PREFIX should be set to the prefix for the version of gcc that should be used with dragonegg. This can be empty if there is no prefix. This variable is not used if $LLVM_COMPILER == clang.
  • LLVM_DRAGONEGG_PLUGIN should be the full path to the dragonegg plugin. This variable is not used if $LLVM_COMPILER == clang.

Once the environment is set up, just use wllvm and wllvm++ as your C and C++ compilers, respectively.

In addition to the above environment variables the following can be optionally used:

  • LLVM_CC_NAME can be set if your clang compiler is not called clang but something like clang-3.7. Similarly LLVM_CXX_NAME can be used to describe what the C++ compiler is called. Note that in these sorts of cases, the environment variable LLVM_COMPILER should still be set to clang not clang-3.7 etc. We also pay attention to the environment variables LLVM_LINK_NAME and LLVM_AR_NAME in an analagous way, since they too get adorned with suffixes in various Linux distributions.

  • LLVM_COMPILER_PATH can be set to the absolute path to the folder that contains the compiler and other LLVM tools such as llvm-link to be used. This prevents searching for the compiler in your PATH environment variable. This can be useful if you have different versions of clang on your system and you want to easily switch compilers without tinkering with your PATH variable. Example LLVM_COMPILER_PATH=/home/user/llvm_and_clang/Debug+Asserts/bin.

  • WLLVM_CONFIGURE_ONLY can be set to anything. If it is set, wllvm and wllvm++ behave like a normal C or C++ compiler. They do not produce bitcode. Setting WLLVM_CONFIGURE_ONLY may prevent configuration errors caused by the unexpected production of hidden bitcode files. It is sometimes required when configuring a build.

Building a bitcode module with clang

export LLVM_COMPILER=clang

tar xf pkg-config-0.26.tar.gz
cd pkg-config-0.26
CC=wllvm ./configure
make

This should produce the executable pkg-config. To extract the bitcode:

extract-bc pkg-config

which will produce the bitcode module pkg-config.bc.

Tutorials

A gentler set of instructions on building apache in a vagrant Ubuntu 14.04 can be found here, and for Ubuntu 16.04 here.

Building a bitcode module with dragonegg

export LLVM_COMPILER=dragonegg
export LLVM_GCC_PREFIX=llvm-
export LLVM_DRAGONEGG_PLUGIN=/unsup/llvm-2.9/lib/dragonegg.so

tar xf pkg-config-0.26.tar.gz
cd pkg-config-0.26
CC=wllvm ./configure
make

Again, this should produce the executable pkg-config. To extract the bitcode:

extract-bc pkg-config

which will produce the bitcode module pkg-config.bc.

Building bitcode archive

export LLVM_COMPILER=clang
tar -xvf bullet-2.81-rev2613.tgz
mkdir bullet-bin
cd bullet-bin
CC=wllvm CXX=wllvm++ cmake ../bullet-2.81-rev2613/
make

# Produces src/LinearMath/libLinearMath.bca
extract-bc src/LinearMath/libLinearMath.a

Note that by default extracting bitcode from an archive produces an archive of bitcode. You can also extract the bitcode directly into a module.

extract-bc -b src/LinearMath/libLinearMath.a

produces src/LinearMath/libLinearMath.a.bc.

Building an Operating System

To see how to build freeBSD 10.0 from scratch check out this guide.

Configuring without building bitcode

Sometimes it is necessary to disable the production of bitcode. Typically this is during configuration, where the production of unexpected files can confuse the configure script. For this we have a flag WLLVM_CONFIGURE_ONLY which can be used as follows:

WLLVM_CONFIGURE_ONLY=1 CC=wllvm ./configure
CC=wllvm make

Building a bitcode archive then extracting the bitcode

export LLVM_COMPILER=clang
tar xvfz jansson-2.7.tar.gz
cd jansson-2.7
CC=wllvm ./configure
make
mkdir bitcode
cp src/.libs/libjansson.a bitcode
cd bitcode
extract-bc libjansson.a
llvm-ar x libjansson.bca
ls -la

Preserving bitcode files in a store

Sometimes it can be useful to preserve the bitcode files produced in a build, either to prevent deletion or to retrieve it later. If the environment variable WLLVM_BC_STORE is set to the absolute path of an existing directory, then WLLVM will copy the produced bitcode file into that directory. The name of the copied bitcode file is the hash of the path to the original bitcode file. For convenience, when using both the manifest feature of extract-bc and the store, the manifest will contain both the original path, and the store path.

Cross-Compilation

To support cross-compilation WLLVM supports the -target triple used by clang. More information can be found here.

Additionally, WLLVM leverages objcopy for some of its heavy lifting. When cross-compiling you must ensure to use the appropriate objcopy for the target architecture. The BINUTILS_TARGET_PREFIX environment variable can be used to set the objcopy of choice, for example, arm-linux-gnueabihf.

LTO Support

In some situations it is desirable to pass certain flags to clang in the step that produces the bitcode. This can be fulfilled by setting the LLVM_BITCODE_GENERATION_FLAGS environment variable to the desired flags, for example "-flto -fwhole-program-vtables".

Debugging

The WLLVM tools can show various levels of output to aid with debugging. To show this output set the WLLVM_OUTPUT_LEVEL environment variable to one of the following levels:

  • ERROR
  • WARNING
  • INFO
  • DEBUG

For example:

    export WLLVM_OUTPUT_LEVEL=DEBUG

Output will be directed to the standard error stream, unless you specify the path of a logfile via the WLLVM_OUTPUT_FILE environment variable.

For example:

    export WLLVM_OUTPUT_FILE=/tmp/wllvm.log

Sanity Checking

Too many environment variables? Try doing a sanity check:

wllvm-sanity-checker

it might point out what is wrong.

License

WLLVM is released under the MIT license. See the file LICENSE for details.

whole-program-llvm's People

Contributors

bchurchill avatar benjaminschubert avatar brunodutertre avatar byshen avatar croemheld avatar delcypher avatar dtzwill avatar eric-blsgvt avatar fmag7 avatar ianamason avatar jcranmer avatar jryans avatar kalibera avatar liblit avatar lukasstadler avatar lzto avatar mayanez avatar mdimjasevic avatar szsam avatar travitch avatar woodruffw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

whole-program-llvm's Issues

clang-3.4: error: linker command failed with exit code 1 (use -v to see invocation)

Hello, when i compile pkg-config-0.18.1 the following problem comes up. It denotes something wrong with the linker command. Does anyone know the problem? Thank you very much.

/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: multiple definition of g_bit_storage' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: first defined here ./.libs/libglib.a(gtree.o): In functiong_bit_nth_lsf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: multiple definition of g_bit_nth_lsf' testgdate.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: first defined here ./.libs/libglib.a(gtree.o): In functiong_bit_nth_msf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: multiple definition of g_bit_nth_msf' testgdate.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: first defined here ./.libs/libglib.a(gtree.o): In functiong_bit_storage':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: multiple definition of g_bit_storage' testgdate.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: first defined here ./.libs/libglib.a(ghash.o): In functiong_bit_nth_lsf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: multiple definition of g_bit_nth_lsf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: first defined here ./.libs/libglib.a(ghash.o): In functiong_bit_nth_msf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: multiple definition of g_bit_nth_msf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: first defined here ./.libs/libglib.a(ghash.o): In functiong_bit_storage':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: multiple definition of g_bit_storage' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: first defined here ./.libs/libglib.a(garray.o): In functiong_bit_nth_lsf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: multiple definition of g_bit_nth_lsf' testgdate.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: first defined here ./.libs/libglib.a(garray.o): In functiong_bit_nth_msf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: multiple definition of g_bit_nth_msf' testgdate.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: first defined here ./.libs/libglib.a(garray.o): In functiong_bit_storage':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: multiple definition of g_bit_storage' testgdate.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: first defined here ./.libs/libglib.a(glist.o): In functiong_bit_nth_lsf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: multiple definition of g_bit_nth_lsf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: first defined here ./.libs/libglib.a(glist.o): In functiong_bit_nth_msf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: multiple definition of g_bit_nth_msf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: first defined here ./.libs/libglib.a(glist.o): In functiong_bit_storage':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: multiple definition of g_bit_storage' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: first defined here ./.libs/libglib.a(gslist.o): In functiong_bit_nth_lsf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: multiple definition of g_bit_nth_lsf' testgdate.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: first defined here ./.libs/libglib.a(gslist.o): In functiong_bit_nth_msf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: multiple definition of g_bit_nth_msf' testgdate.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: first defined here ./.libs/libglib.a(gslist.o): In functiong_bit_storage':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: multiple definition of g_bit_storage' testgdate.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: first defined here ./.libs/libglib.a(gmem.o): In functiong_bit_nth_lsf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: multiple definition of g_bit_nth_lsf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: first defined here ./.libs/libglib.a(gmem.o): In functiong_bit_nth_msf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: multiple definition of g_bit_nth_msf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: first defined here ./.libs/libglib.a(gmem.o): In functiong_bit_storage':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: multiple definition of g_bit_storage' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: first defined here ./.libs/libglib.a(gmessages.o): In functiong_bit_nth_lsf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: multiple definition of g_bit_nth_lsf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: first defined here ./.libs/libglib.a(gmessages.o): In functiong_bit_nth_msf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: multiple definition of g_bit_nth_msf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: first defined here ./.libs/libglib.a(gmessages.o): In functiong_bit_storage':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: multiple definition of g_bit_storage' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: first defined here ./.libs/libglib.a(gmutex.o): In functiong_bit_nth_lsf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: multiple definition of g_bit_nth_lsf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: first defined here ./.libs/libglib.a(gmutex.o): In functiong_bit_nth_msf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: multiple definition of g_bit_nth_msf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: first defined here ./.libs/libglib.a(gmutex.o): In functiong_bit_storage':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: multiple definition of g_bit_storage' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: first defined here ./.libs/libglib.a(gnode.o): In functiong_bit_nth_lsf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: multiple definition of g_bit_nth_lsf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: first defined here ./.libs/libglib.a(gnode.o): In functiong_bit_nth_msf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: multiple definition of g_bit_nth_msf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: first defined here ./.libs/libglib.a(gnode.o): In functiong_bit_storage':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: multiple definition of g_bit_storage' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: first defined here ./.libs/libglib.a(gprimes.o): In functiong_bit_nth_lsf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: multiple definition of g_bit_nth_lsf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: first defined here ./.libs/libglib.a(gprimes.o): In functiong_bit_nth_msf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: multiple definition of g_bit_nth_msf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: first defined here ./.libs/libglib.a(gprimes.o): In functiong_bit_storage':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: multiple definition of g_bit_storage' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: first defined here ./.libs/libglib.a(grel.o): In functiong_bit_nth_lsf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: multiple definition of g_bit_nth_lsf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: first defined here ./.libs/libglib.a(grel.o): In functiong_bit_nth_msf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: multiple definition of g_bit_nth_msf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: first defined here ./.libs/libglib.a(grel.o): In functiong_bit_storage':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: multiple definition of g_bit_storage' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: first defined here ./.libs/libglib.a(gslist.o): In functiong_bit_nth_lsf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: multiple definition of g_bit_nth_lsf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: first defined here ./.libs/libglib.a(gslist.o): In functiong_bit_nth_msf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: multiple definition of g_bit_nth_msf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: first defined here ./.libs/libglib.a(gslist.o): In functiong_bit_storage':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: multiple definition of g_bit_storage' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: first defined here ./.libs/libglib.a(gstrfuncs.o): In functiong_bit_nth_lsf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: multiple definition of g_bit_nth_lsf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: first defined here ./.libs/libglib.a(gstrfuncs.o): In functiong_bit_nth_msf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: multiple definition of g_bit_nth_msf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: first defined here ./.libs/libglib.a(gstrfuncs.o): In functiong_bit_storage':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: multiple definition of g_bit_storage' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: first defined here ./.libs/libglib.a(gstring.o): In functiong_bit_nth_lsf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: multiple definition of g_bit_nth_lsf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: first defined here ./.libs/libglib.a(gstring.o): In functiong_bit_nth_msf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: multiple definition of g_bit_nth_msf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: first defined here ./.libs/libglib.a(gstring.o): In functiong_bit_storage':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: multiple definition of g_bit_storage' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: first defined here ./.libs/libglib.a(gtimer.o): In functiong_bit_nth_lsf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: multiple definition of g_bit_nth_lsf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: first defined here ./.libs/libglib.a(gtimer.o): In functiong_bit_nth_msf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: multiple definition of g_bit_nth_msf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: first defined here ./.libs/libglib.a(gtimer.o): In functiong_bit_storage':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: multiple definition of g_bit_storage' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: first defined here ./.libs/libglib.a(gtree.o): In functiong_bit_nth_lsf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: multiple definition of g_bit_nth_lsf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: first defined here ./.libs/libglib.a(gtree.o): In functiong_bit_nth_msf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: multiple definition of g_bit_nth_msf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: first defined here ./.libs/libglib.a(gtree.o): In functiong_bit_storage':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: multiple definition of g_bit_storage' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: first defined here ./.libs/libglib.a(gutils.o): In functiong_bit_nth_lsf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: multiple definition of g_bit_nth_lsf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1563: first defined here ./.libs/libglib.a(gutils.o): In functiong_bit_nth_msf':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: multiple definition of g_bit_nth_msf' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1578: first defined here ./.libs/libglib.a(gutils.o): In functiong_bit_storage':
/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: multiple definition of g_bit_storage' testglib.o:/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8/./glib.h:1596: first defined here clang-3.4: error: linker command failed with exit code 1 (use -v to see invocation) make[4]: *** [testgdateparser] Error 1 make[4]: *** Waiting for unfinished jobs.... clang-3.4: error: linker command failed with exit code 1 (use -v to see invocation) make[4]: *** [testgdate] Error 1 clang-3.4: error: linker command failed with exit code 1 (use -v to see invocation) make[4]: *** [testglib] Error 1 make[4]: Leaving directory/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory /home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8' make[2]: *** [all] Error 2 make[2]: Leaving directory/home/mqk/Downloads/pkg-config-0.18.1/glib-1.2.8'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/mqk/Downloads/pkg-config-0.18.1'
make: *** [all] Error 2

wllvm fails with cmake

Hi,
Recently I've successfully built many packages with configure+make, but now I need to build a package that ships with a cmake build system. Here is the script I'm using (including the ftp site of the package itself):

#!/bin/bash
#########
# FILES #
#########
PACKAGE_NAME=openjpeg-2.3.0
PACKAGE_TAR_FILE=${PACKAGE_NAME}.tar.gz
PACKAGE_FTP_SITE=https://ftp.osuosl.org/pub/blfs/conglomeration/openjpeg

####################################
# REMOVE OLD STUFF JUST TO BE SURE #
####################################
rm -rf build
rm -rf ${PACKAGE_NAME}
rm -rf ${PACKAGE_TAR_FILE}

#####################################
# Get source code for buggy package #
#####################################
wget ${PACKAGE_FTP_SITE}/${PACKAGE_TAR_FILE}

######################
# Unpack it here ... #
######################
tar xf ${PACKAGE_TAR_FILE}

##########################################
# Prepare an out of tree build directory #
##########################################
mkdir build

##############################
# Get inside build directory #
##############################
cd build

#################
# Configure ... #
#################
CC=wllvm CXX=wllvm++ cmake -DBUILD_MJ2=On ../${PACKAGE_NAME}

###############
# Make it !!! #
###############
make -j

Here are the errors I get:

./myBuildingScripts/build-step0-openjpeg
--2018-03-08 10:53:27--  https://ftp.osuosl.org/pub/blfs/conglomeration/openjpeg/openjpeg-2.3.0.tar.gz
Resolving ftp.osuosl.org (ftp.osuosl.org)... 64.50.236.52, 140.211.166.134, 64.50.233.100, ...
Connecting to ftp.osuosl.org (ftp.osuosl.org)|64.50.236.52|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2207329 (2.1M) [application/x-gzip]
Saving to: โ€˜openjpeg-2.3.0.tar.gzโ€™

openjpeg-2.3.0.tar.gz                        100%

[======================>]   2.10M   351KB/s    in 6.5s    

2018-03-08 10:53:36 (329 KB/s) - โ€˜openjpeg-2.3.0.tar.gzโ€™ saved [2207329/2207329]

-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Check for working C compiler: /usr/local/bin/wllvm
-- Check for working C compiler: /usr/local/bin/wllvm -- broken
CMake Error at /usr/share/cmake-3.9/Modules/CMakeTestCCompiler.cmake:51 (message):
The C compiler "/usr/local/bin/wllvm" is not able to compile a simple test program.

It fails with the following output:

Change Dir: 
/home/oren/GIT/klee/str.klee/klee/benchmarks/openjpeg_bitcode/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_2e7d6/fast"

Any help is very much appreciated, thanks!

Generating bitcode for ARM (cross compile)

Is it possible to generate bitcode for a cross platform target using wllvm?
Perhaps something l like passing a CFLAGS argument specifying -march and -target and a path to ARM compatible LLVM tools?

Has anyone tried this?

"executable" in file path

The logic in FileType::getFileType does not work if certain keywords are in the file path. For example I have a directory named "executables" and therefore getFileType fails because it picks in "executable" from the path and not the file type information returned by file. A simple fix is to strip away the file path from the output. I have a one line fix here: https://github.com/missimer/whole-program-llvm/commit/1ac66595af31b1d5ab45f069e8bbfd6444c64122 that I can turn into a pull request or you can just copy the fix.

To reproduce bug:
Try to compile with wllvm in a directory called "executable"

extract-bc fail to execute, no idea why?

Hi,
I am following the KLEE tutorial to run example project at , tried to use wllvm to extract bitcode for GNU Coreutils. I work on KLEE's docker image. My step is as follow:

cd obj-llvm
CC=wllvm ../configure --disable-nls CFLAGS="-g -O1 -Xclang -disable-llvm-passes -D__NO_STRING_INLINES  -D_FORTIFY_SOURCE=0 -U__OPTIMIZE__"
... verify that configure worked ...
make
make -C src arch hostname
cd src
find . -executable -type f | xargs -I '{}' extract-bc '{}'

but i get the outputs like this:
ERROR:WLLVM Failed to execute: ['file', '/home/klee/coreutils-6.10/obj-llvm/src/chmod']
any idea why,thanks.

Failure in compiling 32 bit executables on 64 bit host

Hello,
I am using wllvm to compile various open source projects with LLVM bitcode embedded into the final executables.

I am currently working on a x86_64 machine and, whenever I target x86_64, wllvm works flawlessly. Now I am trying to output 32 bit binaries by using the standard -m32 flag but, unfortunately, I failed to get wllvm to work.

I have tried with the easiest example which is just a hello world program.
This is the command I used:

wllvm -m32 helloworld.c -o helloworld

The error I get back is the following:

/usr/bin/ld: i386 architecture of input file `.helloworld.o' is incompatible with i386:x86-64 output

It has to be noted that I am able to compile 32 bits executables with my system's clang with the same exact arguments.
This is the debug log with the environmental flag WLLVM_OUTPUT_LEVEL set to DEBUG:

wllvm -m32 helloworld.c -o helloworld -v

INFO::compilers.wcompile() at compilers.py:29 ::Entering CC [-m32 helloworld.c -o helloworld]
DEBUG::compilers.getBuilder() at compilers.py:252 ::WLLVM compiler using clang
DEBUG::compilers.buildObject() at compilers.py:274 ::buildObject rc = 0
DEBUG::compilers.buildAndAttachBitcode() at compilers.py:305 ::Not compile only case: helloworld.c
DEBUG::compilers.buildObjectFile() at compilers.py:359 ::buildObjectFile: ['clang', '-m32', 'helloworld.c', '-c', '-o', '.helloworld.o']
DEBUG::compilers.buildAndAttachBitcode() at compilers.py:315 ::building and attaching .helloworld.o.bc to .helloworld.o
DEBUG::compilers.buildBitcodeFile() at compilers.py:346 ::buildBitcodeFile: ['clang', '-emit-llvm', '-m32', '-c', 'helloworld.c', '-o', '.helloworld.o.bc']
DEBUG::compilers.attachBitcodePathToObject() at compilers.py:106 ::attachBitcodePathToObject: .helloworld.o.bc  ===> .helloworld.o [ext = .o]
DEBUG::compilers.attachBitcodePathToObject() at compilers.py:126 ::Wrote "/tmp/.helloworld.o.bc" to file "/tmp/tmpx86sst6v"
/usr/bin/ld: i386 architecture of input file `.helloworld.o' is incompatible with i386:x86-64 output
clang-8: error: linker command failed with exit code 1 (use -v to see invocation)
WARNING::compilers.linkFiles() at compilers.py:336 ::Failed to link "['clang', '.helloworld.o', '-o', 'helloworld']"

As a final note, I have tried to force the host target with the flag "-target i686-unknown-gnu-linux" but it seems that wllvm does not recognize the flag since I get back this warning when executing:

wllvm -m32 -target i686-unknown-linux-gnu helloworld.c -o helloworld

WARNING:Did not recognize the compiler flag "-target"
WARNING:Did not recognize the compiler flag "i686-unknown-linux-gnu"

The aforementioned command line works with my system's clang.

Any ideas?

Thank you very much!

extract-bc problems with shared objects

Hi,
I have the following script to build the libtiff package:

#!/bin/bash
#########
# FILES #
#########
PACKAGE_NAME=tiff-3.8.2
PACKAGE_TAR_FILE=${PACKAGE_NAME}.tar.gz
PACKAGE_FTP_SITE=http://libtiff.maptools.org/dl

####################################
# REMOVE OLD STUFF JUST TO BE SURE #
####################################
rm -rf build
rm -rf ${PACKAGE_NAME}
rm -rf ${PACKAGE_TAR_FILE}

#####################################
# Get source code for buggy package #
#####################################
wget ${PACKAGE_FTP_SITE}/${PACKAGE_TAR_FILE}

######################
# Unpack it here ... #
######################
tar xf ${PACKAGE_TAR_FILE}

##########################################
# Prepare an out of tree build directory #
##########################################
mkdir build

##############################
# Get inside build directory #
##############################
cd build

#################
# Configure ... #
#################
CC=wllvm
LLVM_COMPILER=clang
CFLAGS="-g -O0"
../${PACKAGE_NAME}/configure --disable-shared

###############
# Make it !!! #
###############
make -j

Everything works fine, but then I try to extract-bc like this:

extract-bc ./build/tools/tiffsplit

I fail with this message:

WARNING:Could not find ".llvm_bc" ELF section in "/home/oren/GIT/klee/str.klee/klee/benchmarks/libtiff_bitcode/build/tools/tiffsplit", so skipping this entry.

The result of:

file ./build/tools/tiffsplit

is:

./build/tools/tiffsplit: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, 
BuildID[sha1]=c7c57dd98623f41270e6042d3b4b8633e343ad21, with debug_info, not stripped

What's going on here? thanks!

Some unrecognized flags as of May 26, 2016

Here are a few flags I ran into that WLLVM didn't recognize:

WARNING:Did not recognize the compiler flag "-pedantic"
WARNING:Did not recognize the compiler flag "-print-prog-name=ld"
WARNING:Did not recognize the compiler flag "-pie"
WARNING:Did not recognize the compiler flag "--shared"
WARNING:Did not recognize the compiler flag "debian/libcolord2/usr/lib/x86_64-linux-gnu/libcolord.so.2"
WARNING:Did not recognize the compiler flag "debian/libcolord2/usr/lib/x86_64-linux-gnu/libcolordprivate.so.2"
WARNING:Did not recognize the compiler flag "debian/libcolorhug2/usr/lib/x86_64-linux-gnu/libcolorhug.so.2"

If you need more info for the "debian" flags, just let me know.

emit-llvm error for multiple source files

AFAIK, wllvm calles $LLVM_COMPILER to do regular compilation and the -emit-llvm compilation. But there are several source files and they are compiled and linked within one compiler(clang/gcc) command(actually the driver), then the build for bitcode version would fail. Here is an example:

The original command:

$(CC) main.c min.c -o min.out

The actual version:

clang main.c min.c -o min.out
clang -emit-llvm main.c min.c -c -o .min.out.bc  # error here

Compilation would fail for the 2nd line.

In this case, I suppose that the internal wrapper should be separated into 2 steps:

  1. the compilation from source code to object
  2. the llvm-link procedure

Error opening output file '/dev/.null.bc': Permission denied

Dear WLLVM devs,

I tried to use WLLVM to compile a Debian source package for musl to LLVM bitcode, but I get this error:

checking for C compiler... wllvm
checking whether C compiler works... no; compiler output follows:
error: unable to open output file '/dev/.null.bc': 'Error opening output file '/dev/.null.bc': Permission denied'

Do you have any clue why this is happening? If you are interested, I'm attaching a full build log file.
musl-build-cow.txt

Note I've been able to build about 1000 Debian source packages with WLLM so far.

This was with clang 3.4.2.

Rebuild executable from the extracted bitcode.

Hi,
I tried to use wllvm to extract bitcode for nodejs, and then rebuild executable from the extract bitcode. My step is as follow:

cd node-v10.16.0/
export LLVM_COMPILER=clang
CC=wllvm CXX=wllvm++ ./configure
CC=wllvm CXX=wllvm++ make -j
extract-bc node

Now I get the llvm bitcode node.bc. Then I try to rebuild this node.bc to executable:

llc node.bc --filetype=obj node.bc
gcc node.o -o node_from_bc

I can get a node.o but at the last step, one error accurs:

/usr/bin/ld: node.o: relocation R_X86_64_32S against symbol `_ZTVN4node9AsyncWrapE' can not be used when making a PIE object; recompile with -fPIC

I am confused when to add this flag -fPIC?

Pip?

Tristan,

Do you want me to push my pipification of wllvm upstream? The changes
are mostly structural, but rather pervasive, the dragonegg 'as' was the trickiest.
Take a look and let me know what you think.

https://github.com/SRI-CSL/whole-program-llvm

It is up to date otherwise, but may be a messy pull request due
to the structural changes.

Cheers, Ian.

configure: error: C compiler cannot create executables

I have recently build grep-2.18 bitcode from source code using wllvm, however failed in the configure step. The terminal says "configure: error: C compiler cannot create executables". Here is my build instructions and config.log hoping anyone can give some suggestions. Thank you.
instcution( I have already export LLVM_COMPILER as clang and the llvm clang version is 3.4):

CC=wllvm LLVM_LINK_NAME=llvm-link LLVM_AR_NAME=llvm-ar WLLVM_CONFIGURE_ONLY=1 ../configure --disable-nls CFLAGS="-g"

Here is the key error log:

-----------

Core tests.

-----------

configure:3374: checking for a BSD-compatible install
configure:3446: result: /usr/bin/install -c
configure:3457: checking whether build environment is sane
configure:3512: result: yes
configure:3671: checking for a thread-safe mkdir -p
configure:3714: result: /bin/mkdir -p
configure:3721: checking for gawk
configure:3755: result: no
configure:3721: checking for mawk
configure:3741: found /usr/bin/mawk
configure:3752: result: mawk
configure:3763: checking whether make sets $(MAKE)
configure:3785: result: yes
configure:3805: checking whether make supports nested variables
configure:3822: result: yes
configure:3953: checking whether make supports nested variables
configure:3970: result: yes
configure:3989: checking build system type
configure:4003: result: x86_64-unknown-linux-gnu
configure:4023: checking host system type
configure:4036: result: x86_64-unknown-linux-gnu
configure:4060: checking for gawk
configure:4091: result: mawk
configure:4155: checking for gcc
configure:4186: result: wllvm
configure:4431: checking for C compiler version
configure:4440: wllvm --version >&5
../configure: 1: eval: wllvm: not found
configure:4451: $? = 127
configure:4440: wllvm -v >&5
../configure: 1: eval: wllvm: not found
configure:4451: $? = 127
configure:4440: wllvm -V >&5
../configure: 1: eval: wllvm: not found
configure:4451: $? = 127
configure:4440: wllvm -qversion >&5
../configure: 1: eval: wllvm: not found
configure:4451: $? = 127
configure:4440: wllvm -version >&5
../configure: 1: eval: wllvm: not found
configure:4451: $? = 127
configure:4471: checking whether the C compiler works
configure:4493: wllvm -g conftest.c >&5
../configure: 1: eval: wllvm: not found
configure:4497: $? = 127
configure:4535: result: no
configure: failed program was:
| /* confdefs.h /
| #define PACKAGE_NAME "GNU grep"
| #define PACKAGE_TARNAME "grep"
| #define PACKAGE_VERSION "2.18"
| #define PACKAGE_STRING "GNU grep 2.18"
| #define PACKAGE_BUGREPORT "[email protected]"
| #define PACKAGE_URL "http://www.gnu.org/software/grep/"
| #define GREP 1
| #define PACKAGE "grep"
| #define VERSION "2.18"
| /
end confdefs.h. */
|
| int
| main (void)
| {
|
| ;
| return 0;
| }
configure:4540: error: in /home/mqk/grep-2.18/build': configure:4543: error: C compiler cannot create executables Seeconfig.log' for more details

wllvm error: C compiler cannot create executables

Hi,
I'm attaching a link to a SO question I've just posted regarding the fact that configure
complains wllvm can not create executables:

SO-question

What would be the best way to solve it? Thanks!
P.S.
There is no 'wllvm' label in SO, and it requires > 1500 votes to create one

Autotooled programs won't compile

When using a program built with autotool (such as Apache, or MySQL server), the configuration phase will not succeed, as the configure script creates conftest files, which it then removes with a "rm". As wllvm creates a hiddend directory in there, the configure script would fail.

However, using clang directly for the configure and then wllvm won't work, as the compiler is often hardcoded during the configure phase.

Would it be possible to have a toggle such as en environment variable on the wllvm and wllvm++ scripts, in which case these would only do the things a normal clang would do ?

extract-bc doesn't create .bc file

I compiled a program using wllvm.
Using extract-bc to create .bc file, but it doesn't work.
It doesn't show error message.

Any have idea this problem?

Add a license

The tool does not come with a license. I think that's it sufficiently useful that it should come with one.

@travitch You are the primary author of this tool so you should get the final say but I'd recommend a simple and very liberal license like

It would be kind of nice to have my name as well as yours in the copyright header too :)

fail to build binutils with wllvm

I attempted to build binutils (version 2.25) with wllvm, but got and configuration error.
wllvm gave a warning: Did not recognize the compiler flag "-print-prog-name=ld".
After disabling the output of this warning, it works.
I think we should modify defaultArgPatterns to match the compiler flag?

Pip maintainers.

We probably need a couple of backup pip maintainers. Definitely you @travitch should be one.
If you send me your pypi login name I can add you. Currently I push from the SRI fork, but I
suspect that is irrelevant.

Any others?

The pull request #21 has broken dragonegg

So I filed this as a comment to the closed pull request yesterday, but maybe that is a no-no.
So here it is again. @BenjaminSchubert.

I'm trying to configure httpd-2.4.12 on ubuntu 12.04 as part of a travis ci test script.
It configures just fine if I roll back to d066aae

But #21 breaks it:

configure:5285: checking whether the C compiler works
configure:5307: wllvm   -pthread   -DLINUX -D_REENTRANT -D_GNU_SOURCE   conftest.c  >&5
Traceback (most recent call last):
  File "/home/vagrant/whole-program-llvm/driver/as", line 15, in <module>
    from .utils import *
ValueError: Attempted relative import in non-package
WARNING:Failed to generate bitcode ".conftest.o.bc" for "conftest.c"
configure:5311: $? = 1
configure:5349: result: no

Apache httpd cannot load dynamic libraries after building from wllvm's extracted bc

I followed the apache build and rebuild from extracted bc tutorial (https://github.com/travitch/whole-program-llvm/blob/master/doc/tutorial-ubuntu-16.04.md). When I tried to start my rebuilt httpd they cannot load the dynamic libraries listed on the httpd.conf file. However, the original httpd binary (build with wllvm, but not from extracted bc) could load those modules. Is there any other way to rebuild the binary so that the binary can load these shared libraries?

extract_section_darwin failure

Hi,

I think there is a change with respect to byte-like objects and strings/regular expressions in Python 3. In particular, the regular expression match in extraction.py:180 throws an exception because line is a bytes-like object.

Moreover, otool output an extra line in plain english, which I needed to skip. My version of otool is:

llvm-otool(1): Apple Inc. version cctools-900
Apple LLVM version 9.0.0 (clang-900.0.39.2)

I don't know python well enough to offer a merge request, but I have fixed the problem with the following patch. I can create a merge request if it looks reasonable. It's possible that this requires more version checking.

--- extraction.py	2018-02-26 07:54:09.000000000 -0800
+++ /nix/store/qcym14s8kwlqmr8a5sv10xdp9kl0q9dm-wllvm-1.1.3/lib/python3.6/site-packages/wllvm/extraction.py	2018-02-26 07:57:33.000000000 -0800
@@ -8,6 +8,7 @@
 import tempfile
 import shutil
 import argparse
+import codecs
 
 from .popenwrapper import Popen
 
@@ -21,7 +22,7 @@
 
 from .logconfig import logConfig
 
-
+decode_hex = codecs.getdecoder("hex_codec")
 _logger = logConfig(__name__)
 
 
@@ -123,14 +124,14 @@
 
     try:
         octets = []
-        for line in lines:
-            m = otool_hexdata.match(line)
+        for line in lines[1:]:
+            m = otool_hexdata.match(line.decode())
             if not m:
                 _logger.debug('otool output:\n\t%s\nDID NOT match expectations.', line)
                 continue
             octetline = m.group(1)
             octets.extend(octetline.split())
-        retval = ''.join(octets).decode('hex').splitlines()
+        retval = decode_hex("".join(octets))[0].splitlines()
         if not retval:
             _logger.error('%s contained no %s segment', inputFile, darwinSegmentName)
     except Exception as e:

Finding mapping between llvm and native instructions

This may be a very stupid question. I guess it's not doable easily.

Is there a way to find mapping between llvm instructions (storing the corresponding native instruction in debug metadata in llvm IR) and native instructions by modifying current wllvm? Any pointer will be appreciated.

Build linux kernel 5.X to LLVM IR

For now, Linux kernel has been updated to 5.X. I want to compile whole 5.0 kernel to bitcode file. How could I achieve this by using WLLVM? Is there any advice? Thanks for your advice.

Cannot handle clang extensions *.c.o

When using clang object code produced has the extension compiledcode.c.o

However, this file extension is unknown to whole-program-llvm and it fails.

Didn't recognize link step

Below is the debug info for the link step of building the code. All prior steps created hidden .bc files for the object files, but this last step seems to have missed the fact that it should be linking the bitcode files associated with the object files into the final executable.

INFO::utils.getBuilder() at utils.py:601 ::WLLVM compiler using clang
INFO::utils.getBuilder() at utils.py:603 ::WLLVM compiler path prefix "/home/pag/Code/fslice/llvm/build/bin/"
DEBUG::popenwrapper.Popen() at popenwrapper.py:13 ::WLLVM Executing:
['/home/pag/Code/fslice/llvm/build/bin/clang',
 '-o',
 'testfs',
 '-g',
 '-Wall',
 '-DDISABLE_RECON',
 '-DDISABLE_PROMPT',
 '-DDISABLE_OSYNC',
 '-DDISABLE_PROLOG',
 'testfs.o',
 'bitmap.o',
 'block.o',
 'super.o',
 'inode.o',
 'dir.o',
 'file.o',
 'tx.o',
 'common.o',
 '-lpopt']
in: /home/pag/Code/testfs/no-recon
DEBUG::utils.**init**() at utils.py:263 ::Trying to match item -o
DEBUG::utils.**init**() at utils.py:263 ::Trying to match item -g
DEBUG::utils.**init**() at utils.py:263 ::Trying to match item -Wall
DEBUG::utils.**init**() at utils.py:263 ::Trying to match item -DDISABLE_RECON
DEBUG::utils.**init**() at utils.py:263 ::Trying to match item -DDISABLE_PROMPT
DEBUG::utils.**init**() at utils.py:263 ::Trying to match item -DDISABLE_OSYNC
DEBUG::utils.**init**() at utils.py:263 ::Trying to match item -DDISABLE_PROLOG
DEBUG::utils.**init**() at utils.py:263 ::Trying to match item testfs.o
DEBUG::utils.**init**() at utils.py:263 ::Trying to match item bitmap.o
DEBUG::utils.**init**() at utils.py:263 ::Trying to match item block.o
DEBUG::utils.**init**() at utils.py:263 ::Trying to match item super.o
DEBUG::utils.**init**() at utils.py:263 ::Trying to match item inode.o
DEBUG::utils.**init**() at utils.py:263 ::Trying to match item dir.o
DEBUG::utils.**init**() at utils.py:263 ::Trying to match item file.o
DEBUG::utils.**init**() at utils.py:263 ::Trying to match item tx.o
DEBUG::utils.**init**() at utils.py:263 ::Trying to match item common.o
DEBUG::utils.**init**() at utils.py:263 ::Trying to match item -lpopt
DEBUG::utils.buildAndAttachBitcode() at utils.py:637 ::No work to do
DEBUG::utils.buildAndAttachBitcode() at utils.py:638 ::{'isAssembleOnly': False, 'objectFiles': ['testfs.o', 'bitmap.o', 'block.o', 'super.o', 'inode.o', 'dir.o', 'file.o', 'tx.o', 'common.o'], 'isVerbose': False, 'isCompileOnly': False, '_inputArgs': deque([]), 'outputFilename': 'testfs', 'compileArgs': ['-g', '-Wall', '-DDISABLE_RECON', '-DDISABLE_PROMPT', '-DDISABLE_OSYNC', '-DDISABLE_PROLOG'], 'isDependencyOnly': False, 'isAssembly': False, 'linkArgs': ['-lpopt'], 'isPreprocessOnly': False, 'inputFiles': []}

How to get the bitcode file from a program that calls a library

I want to test a library with klee. I built the library using wllvm/wllvm++ and get the static link library libtest.a.
And then I write a test file to call the library. At last I compile the file against the library using command wllvm++ test.cc libtest.a. I get the bitcode file by executing extract-bc a.out.
However when running klee on this bitcode file, klee complained can't load a symbol.
I wonder is that the correct way to get the bitcode file or do I miss anything?

-emit-llvm

Hi,

I was trying to build android-6.0.1_r60 with wllvm and I ran into the following issues:

WARNING:Out of context experience: "['-Iframeworks/rs/scriptc', '-Iexternal/clang/lib/Headers', '-MD', '-DRS_VERSION=23', '-std=c99', '-c', '-O3', '-fno-builtin', '-emit-llvm', '-target', 'armv7-none-linux-gnueabi', '-fsigned-char', '-D__i386__', '-Iframeworks/rs/cpu_ref', '-DRS_DECLARE_EXPIRED_APIS', '-Xclang', '-fnative-half-type', '-Xclang', '-fallow-half-arguments-and-returns', '-Xclang', '-target-feature', '-Xclang', '+long64', 'frameworks/rs/driver/runtime/rs_allocation.c', '-o', 'out/target/product/generic_x86/obj/SHARED_LIBRARIES/libclcore.bc_intermediates/rs_allocation.bc']" "-emit-llvm"
I have found that if the argument list has -emit-llvm, wllvm calls abortUnaryCallback which actually issues this error message and exit from the build.

class ArgumentListFilter(object):
    ...
    #iam: if this happens, then we need to stop and think.
    '-emit-llvm' : (0, ArgumentListFilter.abortUnaryCallback),

Is there any fix for that?

bitcode compile filters out -load from -Xclang -load

Encountered a compilation command that includes the options:
-Xclang -load
The -load part gets filtered out by the call to isLinkOption in builAndAttachBitcode (as it filters out anything starting with -l). I think any -Xclang options should be left in the bitcode compilation for clang.

Failed to extract bitcode of Apache with APR

The tutorial by @ianamason for compiling Apache (from #30) just works for me. However, it assumes that Apache Portable Runtime (APR) is installed. Due to some reasons, I need to build Apache with the source of APR , but extract-bc fails in this scenario.

I followed the documentation of Apache by downloading the source code of APR and put it in ./srclib/ directory,

$ cd srclib/
$ wget http://ftp.tc.edu.tw/pub/Apache//apr/apr-1.6.2.tar.gz
$ wget http://ftp.tc.edu.tw/pub/Apache//apr/apr-util-1.6.0.tar.gz
$ tar zxvf apr-1.6.2.tar.gz
$ mv apr-1.6.2/ apr/
$ tar xzvf apr-util-1.6.0.tar.gz
$ mv apr-util-1.6.0/ apr-util/
$ cd ../
$ CC=wllvm ./configure --with-included-apr
$ make
$ extract-bc httpd
ERROR:File "/vagrant/evaluation/httpd-2.4.27/httpd" of type UNKNOWN cannot be used

P.S. the httpd binary is valid and is able to run.

Generating bitcode for Linux kernel

I am trying to generate LLVM bitcode for the linux kernel using wllvm. i understand there will be some extensions and some files (e.g assembly files such as kernel/bounds.s) that cannot be handled, and i'm fine to limp along with whatever bitcode that clang can work with. ideally i'll leave linux kernel sources as it is, without doing patching.

may i know how should i run the wllvm in this case, in such a way that it'll just gracefully ignore files that it can't work with?

how to extract bitcode for postgresql

Hi,

I tried to extract bitcode for httpd. I do "extract-bc httpd" after it is built, and it works perfectly.
Now I'm trying to extract bitcode for postgresql. But the problem is that I don't know what should I extract?

Any suggestions? Thank you.

configure: error: C compiler cannot create executables

Hi,

I just follow the example to compile pkg-config. I meet the following problem. How could I solve the problem? Thanks.

whole-program-llvm/test/pkg-config-0.29.1$ CC=wllvm ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking how to print strings... printf
checking for style of include used by make... GNU
checking for gcc... wllvm
checking whether the C compiler works... no
configure: error: in /home/sun/project/whole-program-llvm/test/pkg-config-0.29.1': configure: error: C compiler cannot create executables Seeconfig.log' for more details

httpd build executable file cannot be extracted as bitcode

After 'CC=wllvm ./configure' and 'make', the httpd project produced an executable file 'httpd'.
Then run 'extract-bc httpd' will get "ERROR:File "httpd" of type UNKNOWN cannot be used".

I found this is due to class FileType only takes file types with "ELF executable" or "_Mach-O_executable" as an executable file. Type of 'httpd' is "Bourne-Again shell script, ASCII text executable, with very long lines detected".

Not sure if whole-program-llvm can work on this kind of file.

Some issues need closing.

For example, this one, after

"emit-llvm error for multiple source files "

"Dragonegg driver not working (w/ python 2.6)"

and

"bitcode compile filters out -load from -Xclang -load"

are also closed. :-)

Issues in compiling 483.xalancbmk

My environment:
wllvm version 1.1.4 installed from pip
clang-3.8
SPECCPU2006 1.0 wllvm config file attached
linux64-amd64-wllvm.cfg.txt
SPEC build log attached
CPU2006.016.log.txt

After the build succeeds, I run
$ extract-bc Xalan && clang Xalan.bc -lstdc++ -lm

Expected output: a.out
Result: Undefined reference errors (attached log file)
undefined_reference_errors.txt

Additional info:
$ ldd Xalan
linux-vdso.so.1 => (0x00007ffc0a922000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fb54270f000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb542405000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fb5421ef000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb541e25000)
/lib64/ld-linux-x86-64.so.2 (0x000055d2615a8000)

It looks like some xerces library bitcode is missing from the final extracted bitcode.

Dragonegg driver not working (w/ python 2.6)

I had to make a couple of minor changes to get the dragonegg driver to work:

utils.py: python complains about not finding driver.popenwrapper. Solution:

-from driver.popenwrapper import Popen
+from popenwrapper import Popen

as: python complains about not finding subprocess.Popen. Solution:

-asmProc = subprocess.Popen(fakeAssembler)
+asmProc = Popen(fakeAssembler)

objcopy: src/steddNxf: failed to find link section for section 24

Hi,

Just wanted to check if anyone else has stumbled on this error with WLLVM? I get it when trying to build Coreutils 8.30 using LLVM 7.0 at rev 26b52aa of WLLVM.

Cheers,
Robin

$ wllvm --version
clang version 7.0.0 (tags/RELEASE_700/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
	cd coreutils-$(VER)
	export LLVM_COMPILER=clang
	CC=wllvm ./configure
	make
  CCLD     src/split
  CC       src/stat.o
objcopy: src/stkShpi9: failed to find link section for section 30
objcopy: src/stkShpi9: failed to find link section for section 30
  CCLD     src/stat
  CC       src/sum.o
objcopy: src/stuHRXtL: failed to find link section for section 24
objcopy: src/stuHRXtL: failed to find link section for section 24
  CCLD     src/sum
  CC       src/sync.o
objcopy: src/stzhYois: failed to find link section for section 23
objcopy: src/stzhYois: failed to find link section for section 23
  CCLD     src/sync
  CC       src/tac.o
objcopy: src/steddNxf: failed to find link section for section 24
objcopy: src/steddNxf: failed to find link section for section 24
  CCLD     src/tac
  CC       src/tail.o

configure error

I have a configure

the config.log is:
129 configure:3487: checking whether the C compiler works
130 configure:3509: wllvm conftest.c >&5
131 Failed to import the site module
132 Traceback (most recent call last):
133 File "/usr/lib/python3.6/site.py", line 570, in
134 main()
135 File "/usr/lib/python3.6/site.py", line 557, in main
136 known_paths = addsitepackages(known_paths)
137 File "/usr/lib/python3.6/site.py", line 345, in addsitepackages
138 addsitedir(sitedir, known_paths)
139 File "/usr/lib/python3.6/site.py", line 213, in addsitedir
140 addpackage(sitedir, name, known_paths)
141 File "/usr/lib/python3.6/site.py", line 169, in addpackage
142 for n, line in enumerate(f):
143 File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
144 return codecs.ascii_decode(input, self.errors)[0]
144 return codecs.ascii_decode(input, self.errors)[0]
145 UnicodeDecodeError: 'ascii' codec can't decode byte 0xeb in position 10: ordinal not in range(128)
146 configure:3513: $? = 1
147 configure:3551: result: no
148 configure: failed program was:
149 | /* confdefs.h /
150 | #define PACKAGE_NAME "Body Tracking Benchmark"
151 | #define PACKAGE_TARNAME "body-tracking-benchmark"
152 | #define PACKAGE_VERSION "1.0"
153 | #define PACKAGE_STRING "Body Tracking Benchmark 1.0"
154 | #define PACKAGE_BUGREPORT "[email protected]"
155 | #define PACKAGE_URL ""
156 | #define PACKAGE "body-tracking-benchmark"
157 | #define VERSION "1.0"
158 | /
end confdefs.h. */
159 |
160 | int
161 | main ()
162 | {
163 |
164 | ;
165 | return 0;
166 | }

My input is CC=wllvm CXX=wllvm++ ./configure .
I used "WLLVM_CONFIGURE_ONLY" but it does not work like above error.

clang: error: unknown argument: '-fstack-protector-strong'

Hello,

newer versions of Clang choke on '-fstack-protector-strong' argument which is nowadays in widespread use in Fedora distribution (I'm not sure about others).

Maybe wllvm could black-list this argument and strip it before passing command line to GCC and LLVM...

It would allow to easily re-compile many Fedora packages with simple CC=wllvm override - without chaning the original package.

Thank you for this project, it is very handy when it comes to KLEE and similar LLVM plug-ins!

some symbols undefined after extract-bc (llvmlinux)

I compiled llvmlinux(git://git.linuxfoundation.org/llvmlinux/kernel.git) successfully using wllvm, and extract-bc vmlinux.o to vmlinux.o.bc. However I found lots of symbols undefined in vmlinux.o.bc compared with vmlinux.o. for example,
llvm-nm vmlinux.o.bc | grep x86_platform_ipi: U x86_platform_ipi
llvm-nm vmlinux.o | grep x86_platform_ipi: 00000ff0 T x86_platform_ipi

Is this a bug in wllvm or extract-bc?

Same named object files get overwritten

I'm trying to compile ImageMagick with wllvm. Among others it has the following 3 source files:

../MagickCore/magick.c
../coders/magick.c
../utilities/magick.c

However the manifest for magic.o.bc objects looks like this:

utilities/.magick.o.bc
.magick.o.bc
.magick.o.bc

(notice the repeated .magic.o.bc) and the symbols defined in MagicCore/magick.c are undefined in the final binary.

So I'm pretty sure that wllvm puts the .bc files for both coders/magick.c and MagicCore/magick.c into the same .magic.o.bc file, so one of them get's overwritten.

I tried wllvm versions 1.2.2 and 1.2.7 and it seems to happen in both.

Any pointers as to how to fix this?

Request For Help with wllvm linking

Hi,
[1] I am trying to use KLEE to check the libosip package.
[2] For that, I compiled libosip successfully* with wllvm
(* after some effort, as documented by this (closed) issue)
[3] However, I need to change the libosip code, and add an external call to a
function (klee_make_symbolic) from KLEE's library.
[4] I've tried setting the LDFLAGS variable so it points to the location of
KLEE's libraries but with no success. Here is the script I tried:

wget https://ftp.gnu.org/gnu/osip/libosip2-4.1.0.tar.gz
tar xf libosip2-4.1.0.tar.gz

mkdir build
cd build
CC=wllvm LLVM_COMPILER=clang ../libosip2-4.1.0/configure --enable-test --disable-shared LDFLAGS="-L/home/oren/GIT/LatestKlee/klee/build/lib/"
LLVM_COMPILER=clang make -j

cd ./src/test
extract-bc ./torture_test
file ./torture_test.bc

[5] Here is the linker error I get when I run make:

/bin/bash ../../libtool --tag=CC   --mode=link wllvm -g   -pedantic -g -DENABLE_TRACE -g   -
L/home/oren/GIT/LatestKlee/klee/build/lib/ -o torture_test torture.o   
../../src/osipparser2/libosipparser2.la  
libtool: link: wllvm -g -pedantic -g -DENABLE_TRACE -g -o torture_test torture.o  -
L/home/oren/GIT/LatestKlee/klee/build/lib/ ../../src/osipparser2/.libs/libosipparser2.a
torture.o: In function `main':
/home/oren/GIT/LatestKlee/myBenchmarks/libosip_bitcode_2/build/src/test/../../../libosip2-
4.1.0/src/test/torture.c:142: undefined reference to `klee_make_symbolic'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

[6] Any help is very much appreciated, thanks!

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.