Skip to content

Instantly share code, notes, and snippets.

@tomilov
Created August 19, 2016 12:24
Show Gist options
  • Save tomilov/4a210ba0fd9cb0aaad6c318e0c652288 to your computer and use it in GitHub Desktop.
Save tomilov/4a210ba0fd9cb0aaad6c318e0c652288 to your computer and use it in GitHub Desktop.
// http://wiki.musl-libc.org/wiki/BuildingLLVM
// build libunwind and all other libraries in -m32 and -m64 versions
// export CFLAGS="-march=native -mavx"
// export CXXFLAGS="-march=native -mavx"
// CMAKE_C_FLAGS and CMAKE_CXX_FLAGS += -fPIC for libs
// build last cmake version from https://cmake.org/files/
wget https://cmake.org/files/v3.6/cmake-3.6.1.zip
unzip cmake-3.6.1.zip
// build cmake using cmake-gui+cmake or ./bootstrap
// build libunwind
git clone --depth=1 --single-branch --branch=master git://github.com/pathscale/libunwind.git
// CMAKE_C_FLAGS=-m64 or -m32 -march=native -mavx
cp -a src/libunwind.* /lib/
// or build libunwind as part of llvm source tree (from svn co http://llvm.org/svn/llvm-project/libunwind/trunk libunwind)
// build ld.gold and other utilities against gcc/g++ or clang/clang++
// requires texinfo (makeinfo utility)
git clone --single-branch --branch=master --depth=1 https://github.com/bminor/binutils-gdb.git binutils
mkdir binutils-build
cd binutils-build
CC=clang CXX=clang++ ../binutils/configure --enable-gold --enable-ld --enable-lto --enable-vtable-verify --enable-plugins --disable-werror --enable-compressed-debug-sections=all
make -j5
sudo make install
// build dtrace
git clone --single-branch --depth=1 "https://github.com/dtrace4linux/linux.git" dtrace
cd dtrace
tools/get-deps.pl
make all
sudo make install
sudo make load
#/usr/include/x86_64-linux-gnu/ffi.h
#/usr/lib/x86_64-linux-gnu/libffi.so
#build llvm/clang/compiler-rt/libunwind (in-tree) against libgcc/libstdc++
#LLVM_BUILD_EXAMPLES/TESTS:BOOL=OFF
#LLVM_INCLUDE_EXAMPLES/TESTS:BOOL=OFF
#LLVM_TARGETS_TO_BUILD:STRING=host
make -j5
sudo make install
// build libcxxrt -m32 and -m64
// This library will be replaced later with libcxxabi which performs the same function, but requires libc++ to build which we don't have yet.
// llvm works better with libcxxabi when using libc++, but libcxxrt is enough to build libc++ the first time around.
git clone --single-branch --depth=1 git://github.com/pathscale/libcxxrt.git
mkdir libcxxrt-build
cd libcxxrt-build
#cmake
make
//sudo cp -av lib/libcxxrt.* /usr/local/lib
// build libcxx against libcxxrt -m32 and -m64:
// LIBCXX_CXX_ABI=libcxxrt
// LIBCXX_CXX_ABI_INCLUDE_PATHS
// LIBCXX_LIBCXXRT_INCLUDE_PATHS=../libcxxrt/src
// LIBCXX_CXX_ABI_LIBRARY_PATH=/lib
svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
mkdir libcxx-build
cd libcxx-build
#cmake
make
sudo make install
// build libcxxabi -m32 and -m64
// fix libcxxabi/CMakeLists.txt: about line 63
// /usr/local/lib/cmake/llvm/AddLLVM.cmake
// /usr/local/lib/cmake/llvm/HandleLLVMOptions.cmake
// and set(LLVM_CMAKE_PATH "/home/user/llvm/cmake")
// LIBCXXABI_USE_COMPILER_RT=ON
// add entry CMAKE_MODULE_PATH:PATH=/usr/local/lib/cmake/llvm;/usr/local/lib/cmake/clang
// LIBCXXABI_LIBCXX=/home/user/llvm/projects/libcxx
// LIBCXXABI_USE_LLVM_UNWINDER=1
svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi
#cmake
make
sudo make install
// !OR (for both -m32 and -m64)
cd llvm/projects/libcxxabi
set -vex
EXTRA_FLAGS="-std=gnu++1z -stdlib=libc++ -fstrict-aliasing -Wstrict-aliasing=2 \
-Wsign-conversion -Wshadow -Wconversion -Wunused-variable \
-Wmissing-field-initializers -Wchar-subscripts -Wmismatched-tags \
-Wmissing-braces -Wshorten-64-to-32 -Wsign-compare \
-Wstrict-aliasing=2 -Wstrict-overflow=4 -Wunused-parameter \
-Wnewline-eof"
for FILE in src/*.cpp
do
clang++ -c -g -O3 -march=native -mavx -fPIC $EXTRA_FLAGS -Iinclude/ $OPTIONS $FILE
done
# instead of -lstdc++: -lc++ (and maybe -lunwind)
LDSHARED_FLAGS="-o libc++abi.so.1.0 \
-shared -nodefaultlibs -Wl,-soname,libc++abi.so.1 \
-lpthread -lc -lc++"
# in next line: all *.o except cxa_noexception.cpp
shopt -s extglob
clang !(cxa_noexception).o -fPIC $LDSHARED_FLAGS $EXTRA_FLAGS
ar rc libc++abi.a *.o
rm -v *.o
ln -sf libc++abi.so.1.0 libc++abi.so.1
ln -sf libc++abi.so.1 libc++abi.so
sudo mv -v libc++abi.* /usr/local/lib
// build libcxx against libcxxabi for -m32 and -m64 (and for libcxxabi of corresponding versions)
// LIBCXX_CXX_ABI=libcxxabi
// LIBCXX_CXX_ABI_INCLUDE_PATHS=/home/user/libcxxabi/include
// LIBCXX_CXX_ABI_LIBRARY_PATH=/usr/local/lib/
// or against ~/libcxxabi/{lib,include}
#cmake into separate directory
make -j5
sudo make install
// cd lib/CMakeFiles/cxx.dir/__/src/
// ar rc libc++.a *.o
// sudo mv libc++.a /usr/local/lib
// rebuild llvm+clang against libcxx/libcxxabi
// CLANG_DEFAULT_CXX_STDLIB=libc++
// CLANG_DEFAULT_RTLIB=compiler-rt
// LLVM_TARGETS_TO_BUILD=host
// LIBCXXABI_USE_COMPILER_RT=ON
// LLVM_ENABLE_LIBCXX=ON + CMAKE_CXX_LINK_FLAGS += -lc++abi
=============================================================================================
// completely rebuild (w/o EH and RTTI)
// CLANG_DEFAULT_CXX_STDLIB=libc++
// GCC_INSTALL_PREFIX=/usr/local
// CMAKE_MODULE_LINKER_FLAGS
// CMAKE_EXE_LINKER_FLAGS
// CMAKE_SHARED_LINKER_FLAGS
// CMAKE_CXX_LINK_FLAGS=-L/usr/local/lib -L/usr/local/lib32 -Wl,-rpath,-L/usr/local/lib -Wl,-rpath,-L/usr/local/lib32
cd
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
cd llvm/tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk clang/tools/extra
svn co http://llvm.org/svn/llvm-project/lldb/trunk lldb
svn co http://llvm.org/svn/llvm-project/lld/trunk lld
svn co http://llvm.org/svn/llvm-project/polly/trunk polly
cd ../projects/
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
svn co http://llvm.org/svn/llvm-project/libunwind/trunk libunwind
svn co http://llvm.org/svn/llvm-project/openmp/trunk openmp
svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi
svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
=============================================================================================
// for test-suite:
// sudo apt-get install python-setuptools
svn co http://llvm.org/svn/llvm-project/test-suite/trunk test-suite
cd llvm/utils/lit
sudo python setup.py install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment