SAFECode Install Guide
Welcome to the SAFECode compiler! This manual provides instructions for
downloading and compiling SAFECode. It also provides information on software
that you must have in order to install SAFECode.
SAFECode depends upon several other pieces of software. SAFECode is built
using the LLVM Compiler Infrastructure, so you
must have LLVM. SAFECode also uses libraries from the
Automatic Pool Allocation project. Directions on how to download these will be
provided with the directions on downloading SAFECode.
SAFECode comes pre-compiled for some architectures, but the best way to get it
is as as source code. If building from source, you will need the proper tools
(namely GCC and GNU make) to compile it. The necessary requirements are those
needed by LLVM and are listed
here.
SAFECode is currently supported on Linux and Mac OS X running on x86
processors.
There are two ways to get SAFECode: downloading the tar archive or downloading
it from the public Subversion repository.
Complete source TAR archives of SAFECode can be found
here. These
archives include LLVM as well as the Automatic Pool Allocation and SAFECode
projects located within the llvm/projects directory. You will need
GNU Zip (gunzip) and the tar utility (tar) to unpack the
archive (these are available on practically all Unix systems today).
SAFECode, the Automatic Pool Allocation project, and LLVM are all stored in
the public Subversion repository at llvm.org. You can retrieve the source code
for these projects using a standard Subversion client as described below.
By default, you should put Automatic Pool Allocation and SAFECode into the
projects subdirectory of the LLVM source distribution. The following commands
should download all of the source code into the appropriate places (note that,
in this example, we are grabbing the version of SAFECode from the release_32
branch which works with LLVM 3.2):
- cd where-you-want-llvm-to-live
- svn co http://llvm.org/svn/llvm-project/llvm/branches/release_32 llvm
- cd llvm/projects
-
svn co http://llvm.org/svn/llvm-project/poolalloc/branches/release_32 poolalloc
-
svn co http://llvm.org/svn/llvm-project/safecode/branches/release_32 safecode
You may optionally want to get the LLVM Test Suite (test-suite) source code:
- cd llvm/projects
-
svn co http://llvm.org/svn/llvm-project/test-suite/branches/release_32 test-suite
If you use the LLVM Test Suite, you will also need the LLVM GCC front-end, and
you will need to configure LLVM so that it knows where to find llvm-gcc and
llvm-g++. Directions for downloading and installing the front-end can be found
in the
LLVM Getting Started Guide
.
Once you have the source code checked out, you should be able to configure
LLVM, the poolalloc project, and the SAFECode project using just the top level
LLVM configure script (the LLVM configure script configures the
poolalloc and safecode projects automatically if they're present in the
projects subdirectory). Simply configure LLVM as you normally would
(e.g., run ./configure in the LLVM source tree), and SAFECode will be
configured automatically for you.
If you have any problems configuring SAFECode (or you're doing something
unconventional), you can try adding the following options to the command line
when running configure:
-
--with-llvmsrc=directory:
Specifies the location of the LLVM source directory. This option is used by
the Automatic Pool Allocation and SAFECode build systems to find the LLVM
source tree; it is ignored by the LLVM configure script but passed to the
Automatic Pool Allocation configure script. This option is not needed if
building in the source tree (i.e., SRCDIR == OBJDIR) and the project
(poolalloc or safecode) is in the LLVM projects subdirectory.
-
--with-llvmobj=directory:
Specifies the location of the LLVM object directory. This option is used by
the Automatic Pool Allocation and SAFECode build systems to find the LLVM
object tree; it is ignored by the LLVM configure script but passed to the
Automatic Pool Allocation configure script. This option is not needed if
building in the source tree (i.e., SRCDIR == OBJDIR) and the project
(poolalloc or safecode) is in the LLVM projects subdirectory.
Additional options for the SAFECode configure script include:
- --with-poolalloc-srcdir:
Specifies the location of the source code for Automatic Pool Allocation.
This should only be necessary if the either the poolalloc source tree or
safecode source tree is not within llvm/projects.
- --with-poolalloc-objdir:
Specifies the location of the object code for Automatic Pool Allocation.
This should only be necessary if the either the poolalloc object tree or
safecode object tree is not within the projects subdirectory of the
LLVM object tree.
The overall process will look like the following if you are building Automatic
Pool Allocation and SAFECode in the the projects subdirectory of the LLVM
object tree:
- cd LLVM-object-directory
- LLVM-source-directory/configure [options]
To build SAFECode, first compile the LLVM tools and then SAFECode itself:
- cd LLVM-object-directory
- make tools-only
- cd projects/poolalloc
- make
- cd ../safecode
- make
SAFECode will, by default, perform the same type of build that LLVM does. For
example, if LLVM is configured to do a Release build by default, SAFECode will
do a Release build by default as well.
There are three types of builds:
-
Debug:
The SAFECode libraries and tools are placed in Debug/lib and
Debug/bin in the SAFECode object tree. The libraries and programs
are compiled with debug symbols enabled. The tools may operate more slowly
due to the extra debug information.
-
Release:
The SAFECode libraries and tools are placed in Release/lib and
Release/bin in the SAFECode object tree. The libraries and programs
are compiled at a higher optimization level and debug symbols are stripped
from executables, making the SAFECode tools faster.
-
Profile:
The SAFECode libraries and tools are placed in Profile/lib and
Profile/bin in the SAFECode object tree. The libraries and programs
are compiled to generate profiling information which can be used to find
performance bottlenecks.
If you only want to use SAFECode, use a Release build. If you are doing
development work on SAFECode, use the Debug or Profile builds as appropriate.
Once SAFECode has been built, you can install it using the following commands:
- cd LLVM-object-directory
- make install
- cd projects/poolalloc
- make install
- cd ../safecode
- make install
Like LLVM, installing SAFECode is not necessary for using it; however,
performing the installation may place the SAFECode binaries and libraries into
directories that are more convenient. By default, clang and clang++ are
installed into /usr/local/bin, and the libraries are installed in
/usr/local/lib; however, these locations can be changed by using the
--prefix option to the LLVM configure script.
SAFECode uses a set of whole program analysis techniques to make its run-time
checks more stringent and to optimize away unneeded run-time checks. To
perform whole-program analysis, SAFECode provides a replacement libLTO plugin
for the linker that performs these analyses and transformations.
Installing SAFECode's libLTO plugin is not necessary for using SAFECode, but it
will make SAFECode's run-time checks more thorough, so you will want to
install it if you can.
The install instructions differ based on platform:
Mac OS X:
For Mac OS X, you simply need to backup the original LTO plugin
(
/usr/lib/libLTO.dylib) and replace it with the one from the SAFECode
build (this will, sadly, require root access). To do that, do the following:
- cd SAFECode-object-directory
- sudo
- cp /usr/lib/libLTO.dylib /usr/lib/orig.libLTO.dylib
- cp Debug/lib/libLTO.dylib /usr/lib
Linux:
For Linux, you will need to install new, LTO-compatible versions of the ld, nm,
and ar utilities. You will then need to configure, compile, and install LLVM
and SAFECode. More specifically, you will need to do the following:
-
Select a directory into which all the tools will be installed
It will be much easier to use libLTO if you install all the software into a
directory. Call this directory $PREFIX.
-
Build LTO-compatible versions of ld, nm, and ar
The directions to build LTO-compatible versions of ld, nm, and ar are found
in the LLVM Gold Plugin document at
http://llvm.org/docs/GoldPlugin.html.
However, you will want to install all of binutils into $PREFIX; to do that,
make sure to add a --prefix=$PREFIX option to the configure command
line and use "make install" instead of "make all-gold." In other words, you
will want to do the following:
- mkdir binutils
- cd binutils
- cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src login
- {enter "anoncvs" as the password}
- cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src co binutils
- mkdir build
- cd build
- ../src/configure --prefix=$PREFIX --enable-gold --enable-plugins
- make
- make install
-
Configure, Build, and Install LLVM and SAFECode
You will need to tell LLVM where to find the Binutils header files, and you
will need to configure it to install into the same directory as Binutils:
- cd LLVM-object-directory
- LLVM-source-directory/configure --prefix=$PREFIX
--with-binutils-include=/path/to/binutils/src/include [additional options]
- make install
- cd projects/poolalloc
- make install
- cd ../safecode
- make install
-
Switch the Linker to the Gold Linker
By default, Binutils will create three files: $PREFIX/bin/ld,
$PREFIX/bin/ld.bfd, and $PREFIX/bin/ld.gold. You need to change
$PREFIX/bin/ld so that it is a hard link to $PREFIX/bin/ld.bfd:
- rm $PREFIX/bin/ld
- ln $PREFIX/bin/ld.gold $PREFIX/bin/ld
-
Change your $PATH so that $PREFIX/bin is first
Now that everything is installed, change your $PATH environment variable so
that $PREFIX/bin is the first directory that is searched. This will make
SAFECode's clang and SAFECode's libLTO the default ones that are used.
With all of that done, you should now have a working SAFECode with libLTO
installation on your system.