LLVM¶
The LLVM project has multiple components. The core of the project is itself called "LLVM". This contains all of the tools, libraries, and header files needed to process intermediate representations and convert them into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer. It also contains basic regression tests.
C-like languages use the Clang frontend. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.
Other components include: the libc++ C++ standard library, the LLD linker, and more.
**Requirements Compiling LLVM requires that you have several software packages installed. The table below lists those required packages. The Package column is the usual name for the software package that LLVM depends on. The Version column provides “known to work” versions of the package. The Notes column describes how LLVM uses the package and provides other details.
Package | Version |
---|---|
Cmakte | >=3.13.4 |
GCC | >=7.1.0 |
Python | >= 3.6 |
BINUTILS | newer is better |
Download¶
# tar xvf llvm-project-llvmorg-14.0.5.tar.gz
# cd llvm-project-llvmorg-14.0.5
# rm -r llvm-14
git clone --branch release/14.x https://github.com/llvm/llvm-project.git llvm-14x
cd llvm-14x
git pull origin release/14.x
mkdir build && cd build
Tachyon - Centos 6.9¶
LLVM 14¶
use GCC¶
Note
- May need GCC >= 9.
- Use
-DCMAKE_CXX_STANDARD=17
to avoid no digit exponent. - use
CMAKE_C_FLAGS="-flax-vector-conversions"
avoid 128i convert error. - consider -DLLVM_TARGETS_TO_BUILD="AArch64".
- must use
-DGCC_INSTALL_PREFIX -DCMAKE_CXX_LINK_FLAGS="-Wl,-rpath,${myCOMPILER}/lib64 -L${myCOMPILER}/lib64"
to have right link to libc. - Dont use -DLLVM_ENABLE_RUNTIMES="compiler-rt;libc;libcxx;libcxxabi;libunwind". Instead, use DLLVM_ENABLE_RUNTIMES="compiler-rt;libc;libcxx;libcxxabi;libunwind" see.
- These modules may cause errors: compiler-rt;libunwind;libc
- Use Release/Debug
- See more https://llvm.org/docs/CMake.html
- LLDB require SWIG > 3.0
- LLVM require python >= 3.6, and python 3.6 require zlib>1.2.11 require GLIBC_2.14 (libgcc-ng=9). And zlib=1.2.11 will cause hidden libs by conda, so should update zlib>1.2.11 to hidden error. Or should use static-link (libs*.a) or use absolute path to dynamic libs (.so) in cmake to avoid this error. Note, link a dynamic lib (.so) to a static lib (.a) may cause " Dyanmic reloc overflow runtime" error, so best way is use absolute path to dynamic libs (.so).
source activate py37Lammps
conda install -c conda-forge libgcc-ng=9 libstdcxx-ng=9 libstdcxx-ng=9 libgomp=9 zlib=1.2.11 python=3.7
**Install LLVM
git pull origin release/14.x
mkdir build && cd build
module load tool_dev/cmake-3.24
module load conda/py37Lammps
module load tool_dev/binutils-2.37
module load compiler/gcc-12.2
export myGCC=/home1/p001cao/local/app/compiler/gcc-12.2
export PATH=$PATH:${myGCC}/bin # :/usr/bin
export CC=gcc export CXX=g++
export LDFLAGS="-fuse-ld=gold -lrt"
export myZLIB=/home1/p001cao/local/app/tool_dev/zlib-1.2.12 # avoid zlib hidden by conda
export CPPFLAGS="-gdwarf-4 -gstrict-dwarf" # avoid dwarf5 error
cmake ../llvm -DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;libclc;lld;openmp;polly;flang;pstl;mlir;libcxx;libcxxabi" \
-DGCC_INSTALL_PREFIX=${myGCC} \
-DCMAKE_CXX_LINK_FLAGS="-Wl,-rpath,${myGCC}/lib64 -L${myGCC}/lib64" \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_C_FLAGS="-flax-vector-conversions" -DCMAKE_C_FLAGS_RELEASE="-flax-vector-conversions" \
-DZLIB_INCLUDE_DIR=${myZLIB} -DZLIB_LIBRARY=${myZLIB}/lib/libz.so.1.2.12 \
-DCMAKE_INSTALL_PREFIX=/home1/p001cao/local/app/compiler/llvm-14
make -j 16 && make install
check:
Options:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${myCOMPILER}/lib
-DLLVM_ENABLE_RUNTIMES="libunwind;libcxx"
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;flang;libclc;lld;openmp;polly;pstl;mlir" \ # "clang;flang;lld;openmp"
-DCMAKE_CXX_LINK_FLAGS="-Wl,-rpath,${myCOMPILER}/lib64 -L${myCOMPILER}/lib64" \
Ref
[1] https://stackoverflow.com/questions/69683755/libpng-apngerror-o-requires-dynamic-r-x86-64-pc32-reloc-against-stderr [2] Dynamic relocs, runtime overflows and -fPIC: https://tinyurl.com/2bw9jo5q
Module file¶
at directory: /home1/p001cao/local/1myModfiles/compiler → create file "llvm-14"
# for Tcl script use only
set topdir /home1/p001cao/local/app/compiler/llvm-14
set version clang-14.0
prepend-path PATH $topdir/bin
prepend-path LD_LIBRARY_PATH $topdir/lib
prepend-path LD_LIBRARY_PATH $topdir/libexec
prepend-path INCLUDE $topdir/include
# prepend-path INCLUDE $topdir/include/c++/v1
How to Use Clang without GCC on Linux¶
export LIBS="-nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc_s -lgcc"
export CXX=clang++
export CC=clang
cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
-DCMAKE_EXE_LINKER_FLAGS="-nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc_s -lgcc"
http://tolik1967.azurewebsites.net/clang_no_gcc.html
use GCC-conda¶
use conda can install: gcc, cmake,... and other libs. But note install LLVM, since new GLIBC is required,
**Install Conda (Since LLVM require python >= 3.6)
conda create -n py37gcc12 python=3.7
source activate py37gcc12
conda install -c conda-forge libgcc-ng=12 libstdcxx-ng=12 libgomp=12 cmake=3 binutils
**Install LLVM
git clone -b release/14.x https://github.com/llvm/llvm-project.git llvm-14
cd llvm-14
mkdir build_conda && cd build_conda
module load conda/py37gcc12
export myCOMPILER=/home1/p001cao/local/app/miniconda3/envs/py37gcc12
export PATH=${myCOMPILER}/bin:$PATH # :/usr/bin
export CC=gcc export CXX=g++
export LDFLAGS="-fuse-ld=gold -lrt"
export CFLAGS="-gdwarf-4 -gstrict-dwarf -flax-vector-conversions"
cmake ../llvm -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_STANDARD=17 \
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;libclc;lld;openmp;polly;pstl;mlir;flang;libcxx;libcxxabi" \
-DGCC_INSTALL_PREFIX=${myCOMPILER} \
-DCMAKE_CXX_LINK_FLAGS="-Wl,-rpath,${myCOMPILER}/lib64 -L${myCOMPILER}/lib64" \
-DCMAKE_INSTALL_PREFIX=/home1/p001cao/local/app/compiler/llvm-14-conda
make -j 16 && make install
LLVM 17¶
Note
- do not use GCC-13, since some source codes can not recognize compiler version
- projects with errors: PROJECTS="mlir;flang;clang-tools-extra;libclc" RUNTIMES="libc;libcxx;libcxxabi". Try with few projects, then increasing.
- LLVM 16 cause error:
'aligned_alloc' was not declared in this scope
(mlir) →aligned_alloc
should availabe with#include <stdlib.h>
, but if system does not support it, then define it in thenamespace
of the file where error comes see this - to disable "mlir", we must disable "flang", since Enabling MLIR as a dependency to flang
- error
‘PTRACE_SEIZE’ was not declared
→ add following lines in the file where error comes - must update newer
binutils
, to avoid zip error - Use GCC-11.4
conda install gcc_linux-64=11.2 zlib=1.2.11 libzlib-1.2.11
cd /home1/p001cao/0SourceCode
# git clone -b release/17.x https://github.com/llvm/llvm-project.git llvm-17x
cd llvm-17x
git pull origin release/17.x
# git reset --hard origin/main
# git pull origin main
rm -rf build && mkdir build && cd build
module load tooldev/cmake-3.27
module load tooldev/binutils-2.40
module load conda/py9link_lammps
module load compiler/gcc-11
myGCC=/home1/p001cao/app/compiler/gcc-11
export PATH=${myGCC}/bin:$PATH # :/usr/bin
export CC=gcc CXX=g++ FC=clang-new
export LDFLAGS="-fuse-ld=gold -lrt"
export CXXFLAGS="-std=c++17"
myZLIB=/home1/p001cao/app/tooldev/zlib-1.2.12 # avoid zlib hidden by conda
myFREFIX=/home1/p001cao/app/compiler/llvm-17
cmake ../llvm -DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="clang;lld;openmp;polly;flang" \
-DLLVM_ENABLE_RUNTIMES="pstl" \
-DGCC_INSTALL_PREFIX=${myGCC} \
-DCMAKE_CXX_LINK_FLAGS="-Wl,-rpath,${myGCC}/lib64 -L${myGCC}/lib64" \
-DCMAKE_CXX_STANDARD_REQUIRED=ON -DLLVM_ENABLE_ZLIB=ON \
-DCMAKE_C_FLAGS="-flax-vector-conversions" -DCMAKE_C_FLAGS_RELEASE="-flax-vector-conversions" \
-DZLIB_INCLUDE_DIR=${myZLIB}/include -DZLIB_LIBRARY=${myZLIB}/lib/libz.so.1.2.12 \
-DCMAKE_INSTALL_PREFIX=${myFREFIX}
make -j 16 && make install
Quote
ReleaseNotes: https://releases.llvm.org/15.0.0/docs/ReleaseNotes.html
options: