Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statically link compiler-rt #976

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
*.pyd
*.o
*.so
*.a
*.dylib
*.dll
*.lib
build/
dist/
*.egg-info
Expand Down
2 changes: 1 addition & 1 deletion buildscripts/azure/azure-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
call conda remove --all -q -y -n %CONDA_ENV%
call conda create -n %CONDA_ENV% -q -y python=%PYTHON% cmake
call activate %CONDA_ENV%
call conda install -y -q -c numba/label/dev llvmdev="14.*" libxml2
call conda install -y -q --override-channels -c mcollison llvmdev="14.*"
displayName: 'Before Install'

- script: |
Expand Down
5 changes: 4 additions & 1 deletion buildscripts/incremental/setup_conda_environment.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ if %errorlevel% neq 0 exit /b %errorlevel%
call activate %CONDA_ENV%
if %errorlevel% neq 0 exit /b %errorlevel%

@rem Temporarily point to mcollison llvmdev
%CONDA_INSTALL% -c mcollison llvmdev="14.*"

@rem Install llvmdev
%CONDA_INSTALL% -c numba/label/dev llvmdev="14.*"
@%CONDA_INSTALL% -c numba/label/dev llvmdev="14.*"
if %errorlevel% neq 0 exit /b %errorlevel%
12 changes: 11 additions & 1 deletion buildscripts/incremental/setup_conda_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,18 @@ set +v
source activate $CONDA_ENV
set -v

#Install llvmdev from mcollison channel
#until it can be upload to Anaconda
if [ "$(uname -sm)" = "Linux aarch64" ]; then
$CONDA_INSTALL -c mcollison llvmdev="11.*"
else
$CONDA_INSTALL -c mcollison llvmdev="14.*"
fi

# Install llvmdev (separate channel, for now)
$CONDA_INSTALL -c numba/label/dev llvmdev="14.*"
# NOTE: Commented out until llvmdev with compiler-rt
# available
#$CONDA_INSTALL -c numba/label/dev llvmdev="14.*"

# Install the compiler toolchain, for osx, bootstrapping needed
# which happens in build.sh
Expand Down
54 changes: 53 additions & 1 deletion conda-recipes/llvmdev/bld.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ FOR /D %%d IN (llvm-*.src) DO (MKLINK /J llvm %%d
if !errorlevel! neq 0 exit /b %errorlevel%)
FOR /D %%d IN (lld-*.src) DO (MKLINK /J lld %%d
if !errorlevel! neq 0 exit /b %errorlevel%)
FOR /D %%d IN (rt\compiler-rt-*.src) DO (MKLINK /J compiler-rt %%d
if !errorlevel! neq 0 exit /b %errorlevel%)
FOR /D %%d IN (unwind\libunwind-*.src) DO (MKLINK /J libunwind %%d
if !errorlevel! neq 0 exit /b %errorlevel%)

Expand Down Expand Up @@ -34,13 +36,16 @@ REM the 64bit linker anyway. This must be passed in to certain generators as
REM '-Thost x64'.
set PreferredToolArchitecture=x64

set MAX_INDEX_CMAKE_GENERATOR=0
set MAX_INDEX_CMAKE_GENERATOR=1

set "CMAKE_GENERATOR[0]=Visual Studio 16 2019"
set "CMAKE_GENERATOR[1]=Visual Studio 17 2022"

set "CMAKE_GENERATOR_ARCHITECTURE[0]=%GEN_ARCH%"
set "CMAKE_GENERATOR_ARCHITECTURE[1]=%GEN_ARCH%"

set "CMAKE_GENERATOR_TOOLSET[0]=v142"
set "CMAKE_GENERATOR_TOOLSET[1]=v142"

REM Reduce build times and package size by removing unused stuff
REM BENCHMARKS (new for llvm8) don't build under Visual Studio 14 2015
Expand All @@ -54,6 +59,8 @@ set CMAKE_CUSTOM=-DLLVM_TARGETS_TO_BUILD="%LLVM_TARGETS_TO_BUILD%" ^
-DLLVM_USE_INTEL_JITEVENTS=ON ^
-DLLVM_INCLUDE_BENCHMARKS=OFF ^
-DLLVM_ENABLE_DIA_SDK=OFF ^
-DLLVM_ENABLE_LIBXML2:BOOL=OFF ^
-DCLANG_ENABLE_LIBXML=OFF ^
-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly

REM try all compatible visual studio toolsets to find one that is installed
Expand Down Expand Up @@ -93,3 +100,48 @@ REM enhanced unix-like shell which has functions like `grep` available.
REM cd ..\test
REM "%PYTHON%" "..\build\%BUILD_CONFIG%\bin\llvm-lit.py" -vv Transforms ExecutionEngine Analysis CodeGen/X86
REM if errorlevel 1 exit 1


REM Build compiler-rt separately, because it fails on Windows with LLVM 14.0.6
REM if built as an LLVM project.
REM See also: https://stackoverflow.com/questions/46108390/building-llvm-with-cmake-and-visual-stuidio-fails-to-install

cd "%SRC_DIR%\compiler-rt"
mkdir build
cd build

set CMAKE_CUSTOM=-DCOMPILER_RT_BUILD_BUILTINS:BOOL=ON ^
-DCOMPILER_RT_BUILD_LIBFUZZER:BOOL=OFF ^
-DCOMPILER_RT_BUILD_CRT:BOOL=OFF ^
-DCOMPILER_RT_BUILD_MEMPROF:BOOL=OFF ^
-DCOMPILER_RT_BUILD_PROFILE:BOOL=OFF ^
-DCOMPILER_RT_BUILD_SANITIZERS:BOOL=OFF ^
-DCOMPILER_RT_BUILD_XRAY:BOOL=OFF ^
-DCOMPILER_RT_BUILD_GWP_ASAN:BOOL=OFF ^
-DCOMPILER_RT_BUILD_ORC:BOOL=OFF ^
-DCOMPILER_RT_INCLUDE_TESTS:BOOL=OFF ^
-DLLVM_CONFIG_PATH="%SRC_DIR%\build\%BUILD_CONFIG%\bin\llvm-config.exe"

REM try all compatible visual studio toolsets to find one that is installed
setlocal enabledelayedexpansion
for /l %%n in (0,1,%MAX_INDEX_CMAKE_GENERATOR%) do (
cmake -G "!CMAKE_GENERATOR[%%n]!" ^
-A "!CMAKE_GENERATOR_ARCHITECTURE[%%n]!" ^
-T "!CMAKE_GENERATOR_TOOLSET[%%n]!" ^
-DCMAKE_BUILD_TYPE="%BUILD_CONFIG%" ^
-DCMAKE_PREFIX_PATH="%LIBRARY_PREFIX%" ^
-DCMAKE_INSTALL_PREFIX:PATH="%LIBRARY_PREFIX%" ^
%CMAKE_CUSTOM% ..
if not errorlevel 1 goto crt_configuration_successful
del CMakeCache.txt
)
if errorlevel 1 exit 1

:crt_configuration_successful
endlocal

cmake --build . --config "%BUILD_CONFIG%"
if errorlevel 1 exit 1

cmake --build . --config "%BUILD_CONFIG%" --target install
if errorlevel 1 exit 1
13 changes: 12 additions & 1 deletion conda-recipes/llvmdev/build.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ fi

mv llvm-*.src llvm
mv lld-*.src lld
mv rt/compiler-rt-*.src compiler-rt
mv unwind/libunwind-*.src libunwind

declare -a _cmake_config
_cmake_config+=(-DCMAKE_INSTALL_PREFIX:PATH=${PREFIX})
_cmake_config+=(-DCMAKE_BUILD_TYPE:STRING=Release)
_cmake_config+=(-DLLVM_ENABLE_PROJECTS:STRING="lld")
_cmake_config+=(-DLLVM_ENABLE_PROJECTS:STRING="lld;compiler-rt")
# The bootstrap clang I use was built with a static libLLVMObject.a and I trying to get the same here
# _cmake_config+=(-DBUILD_SHARED_LIBS:BOOL=ON)
_cmake_config+=(-DLLVM_ENABLE_ASSERTIONS:BOOL=ON)
Expand All @@ -44,6 +45,16 @@ _cmake_config+=(-DLLVM_ENABLE_RTTI=OFF)
_cmake_config+=(-DLLVM_TARGETS_TO_BUILD=${LLVM_TARGETS_TO_BUILD})
_cmake_config+=(-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly)
_cmake_config+=(-DLLVM_INCLUDE_UTILS=ON) # for llvm-lit
_cmake_config+=(-DCOMPILER_RT_BUILD_BUILTINS:BOOL=ON)
_cmake_config+=(-DCOMPILER_RT_BUILD_LIBFUZZER:BOOL=OFF)
_cmake_config+=(-DCOMPILER_RT_BUILD_CRT:BOOL=OFF)
_cmake_config+=(-DCOMPILER_RT_BUILD_MEMPROF:BOOL=OFF)
_cmake_config+=(-DCOMPILER_RT_BUILD_PROFILE:BOOL=OFF)
_cmake_config+=(-DCOMPILER_RT_BUILD_SANITIZERS:BOOL=OFF)
_cmake_config+=(-DCOMPILER_RT_BUILD_XRAY:BOOL=OFF)
_cmake_config+=(-DCOMPILER_RT_BUILD_GWP_ASAN:BOOL=OFF)
_cmake_config+=(-DCOMPILER_RT_BUILD_ORC:BOOL=OFF)
_cmake_config+=(-DCOMPILER_RT_INCLUDE_TESTS:BOOL=OFF)
_cmake_config+=(-DLLVM_INCLUDE_BENCHMARKS:BOOL=OFF) # doesn't build without the rest of LLVM project
# TODO :: It would be nice if we had a cross-ecosystem 'BUILD_TIME_LIMITED' env var we could use to
# disable these unnecessary but useful things.
Expand Down
6 changes: 6 additions & 0 deletions conda-recipes/llvmdev/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% set sha256_llvm = "050922ecaaca5781fdf6631ea92bc715183f202f9d2f15147226f023414f619a" %}
{% set sha256_lld = "0c28ce0496934d37d20fec96591032dd66af8d10178a45762e0e75e85cf95ad3" %}
{% set sha256_libunwind = "3bbe9c23c73259fe39c045dc87d0b283236ba6e00750a226b2c2aeac4a51d86b" %}
{% set sha256_compiler_rt = "88df303840ca8fbff944e15e61c141226fe79f5d2b8e89fb024264d77841a02e" %}
{% set build_number = "3" %}

package:
Expand All @@ -17,6 +18,7 @@ source:
- ../llvm14-clear-gotoffsetmap.patch
- ../llvm14-remove-use-of-clonefile.patch
- ../llvm14-svml.patch

- url: https://github.com/llvm/llvm-project/releases/download/llvmorg-{{ version }}/lld-{{ version }}.src.tar.xz
fn: lld-{{ version }}.src.tar.xz
sha256: {{ sha256_lld }}
Expand All @@ -26,6 +28,10 @@ source:
sha256: {{ sha256_libunwind }}
folder: unwind

- url: https://github.com/llvm/llvm-project/releases/download/llvmorg-{{ version }}/compiler-rt-{{ version }}.src.tar.xz
fn: compiler-rt-{{ version }}.src.tar.xz
sha256: {{ sha256_compiler_rt }}
folder: rt
build:
number: {{ build_number }}
script_env:
Expand Down
45 changes: 43 additions & 2 deletions conda-recipes/llvmdev_manylinux2014/build.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ fi
# _cmake_config+=(--trace-expand)
# CPU_COUNT=1

mkdir build
cd build
mkdir llvm/build
cd llvm/build

cmake -G'Unix Makefiles' \
"${_cmake_config[@]}" \
Expand All @@ -94,3 +94,44 @@ make check-llvm-unit || exit $?

# From: https://github.com/conda-forge/llvmdev-feedstock/pull/53
make install || exit $?

# run the tests, skip some on linux-32
cd ../test
if [[ $ARCH == 'i686' ]]; then
../build/bin/llvm-lit -vv Transforms Analysis CodeGen/X86
else
../build/bin/llvm-lit -vv Transforms ExecutionEngine Analysis CodeGen/X86
fi

# Next, build compiler-rt

declare -a _compiler_rt_cmake_config
_compiler_rt_cmake_config+=(-DCMAKE_INSTALL_PREFIX:PATH=${PREFIX})
_compiler_rt_cmake_config+=(-DCMAKE_BUILD_TYPE:STRING=Release)
_compiler_rt_cmake_config+=(-DCOMPILER_RT_BUILD_BUILTINS:BOOL=ON)
_compiler_rt_cmake_config+=(-DCOMPILER_RT_BUILD_LIBFUZZER:BOOL=OFF)
_compiler_rt_cmake_config+=(-DCOMPILER_RT_BUILD_CRT:BOOL=OFF)
_compiler_rt_cmake_config+=(-DCOMPILER_RT_BUILD_MEMPROF:BOOL=OFF)
_compiler_rt_cmake_config+=(-DCOMPILER_RT_BUILD_PROFILE:BOOL=OFF)
_compiler_rt_cmake_config+=(-DCOMPILER_RT_BUILD_SANITIZERS:BOOL=OFF)
_compiler_rt_cmake_config+=(-DCOMPILER_RT_BUILD_XRAY:BOOL=OFF)
_compiler_rt_cmake_config+=(-DCOMPILER_RT_BUILD_GWP_ASAN:BOOL=OFF)
_compiler_rt_cmake_config+=(-DCOMPILER_RT_BUILD_ORC:BOOL=OFF)
_compiler_rt_cmake_config+=(-DCOMPILER_RT_INCLUDE_TESTS:BOOL=OFF)
_compiler_rt_cmake_config+=(-DLLVM_CONFIG_PATH=../../llvm/build/bin/llvm-config)

cd ../../compiler-rt
mkdir build
cd build

cmake -G'Unix Makefiles' \
"${_compiler_rt_cmake_config[@]}" \
..

if [ $ARCH == 'armv7l' ]; then # RPi need thread count throttling
make -j2 VERBOSE=1
else
make -j${CPU_COUNT} VERBOSE=1
fi

make install
11 changes: 10 additions & 1 deletion conda-recipes/llvmdev_manylinux2014/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
{% set sha256_llvm = "050922ecaaca5781fdf6631ea92bc715183f202f9d2f15147226f023414f619a" %}
{% set sha256_lld = "0c28ce0496934d37d20fec96591032dd66af8d10178a45762e0e75e85cf95ad3" %}
{% set sha256_libunwind = "3bbe9c23c73259fe39c045dc87d0b283236ba6e00750a226b2c2aeac4a51d86b" %}
{% set build_number = "1" %}
{% set sha256_compiler_rt = "88df303840ca8fbff944e15e61c141226fe79f5d2b8e89fb024264d77841a02e" %}
{% set build_number = "2" %}

package:
name: llvmdev
Expand All @@ -13,19 +14,27 @@ source:
- url: https://github.com/llvm/llvm-project/releases/download/llvmorg-{{ version }}/llvm-{{ version }}.src.tar.xz
fn: llvm-{{ version }}.src.tar.xz
sha256: {{ sha256_llvm }}
folder: llvm
patches:
- ../llvm14-clear-gotoffsetmap.patch
- ../llvm14-remove-use-of-clonefile.patch
- ../llvm14-svml.patch

- url: https://github.com/llvm/llvm-project/releases/download/llvmorg-{{ version }}/lld-{{ version }}.src.tar.xz
fn: lld-{{ version }}.src.tar.xz
sha256: {{ sha256_lld }}
folder: llvm/tools/lld

- url: https://github.com/llvm/llvm-project/releases/download/llvmorg-{{ version }}/libunwind-{{ version }}.src.tar.xz
fn: libunwind-{{ version }}.src.tar.xz
sha256: {{ sha256_libunwind }}
folder: unwind

- url: https://github.com/llvm/llvm-project/releases/download/llvmorg-{{ version }}/compiler-rt-{{ version }}.src.tar.xz
fn: compiler-rt-{{ version }}.src.tar.xz
sha256: {{ sha256_compiler_rt }}
folder: compiler-rt

build:
number: {{ build_number }}
string: "manylinux2014h{{ PKG_HASH }}"
Expand Down
1 change: 0 additions & 1 deletion conda-recipes/llvmlite/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ requirements:
- vs2015_runtime # [win]
# llvmdev is built with libz compression support
- zlib # [unix and not (armv6l or armv7l)]
# requires libxml2
- libxml2 # [win]
run:
- python >=3.8,<3.10
Expand Down
45 changes: 42 additions & 3 deletions ffi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,51 @@ project(llvmlite_ffi)
include(CheckIncludeFiles)

if(NOT MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -g")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -g $ENV{CXX_STATIC_LINK}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -g $ENV{CXX_STATIC_LINK}")
endif()


find_package(LLVM REQUIRED CONFIG)

message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

# Copy builtins archive
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64") # for desktop
set(ARCH "x86_64")
else()
set(ARCH ${CMAKE_SYSTEM_PROCESSOR})
endif()

if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
file(COPY ${LLVM_LIBRARY_DIR}/windows/clang_rt.builtins-${ARCH}.lib
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
set(COMPILER_RT_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/clang_rt.builtins.lib)
file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/clang_rt.builtins-${ARCH}.lib
${COMPILER_RT_LOCATION})
else()
if (EXISTS "$(LLVM_LIBDIR)/clang")
file(COPY ${LLVM_LIBRARY_DIR}/linux/libclang_rt.builtins-${ARCH}.a
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/libclang_rt.builtins-${ARCH}.a
${CMAKE_CURRENT_BINARY_DIR}/libclang_rt.builtins.a)
else()
file(COPY ${LLVM_LIBRARY_DIR}/clang/${LLVM_PACKAGE_VERSION}/lib/linux/libclang_rt.builtins-${ARCH}.a
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
set(COMPILER_RT_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/libclang_rt.builtins.a)
file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/libclang_rt.builtins-${ARCH}.a
${COMPILER_RT_LOCATION})
endif()
endif()

file(GLOB LLVM_EXCLUDE_LIB
"${LLVM_LIBRARY_DIR}/*LLVM*.a"
)

STRING(REPLACE ";" "," LLVM_EXCLUDE_LIB "${LLVM_EXCLUDE_LIB}")


# Set your project compile flags.
# E.g. if using the C++ header files
# you will need to enable C++11 support
Expand All @@ -42,6 +78,9 @@ add_library(llvmlite SHARED assembly.cpp bitcode.cpp core.cpp initfini.cpp
passmanagers.cpp targets.cpp dylib.cpp linker.cpp object_file.cpp
custom_passes.cpp orcjit.cpp)

set_target_properties(llvmlite PROPERTIES
LINK_FLAGS "-Lfoobar -Wl,--whole-archive,${COMPILER_RT_LOCATION},--no-whole-archive ")

# Find the libraries that correspond to the LLVM components
# that we wish to use.
# The following line is broken with LLVM 10.0.0 due to a potential bug in
Expand All @@ -63,7 +102,7 @@ list(REMOVE_ITEM llvm_libs "OptRemarks")
target_link_libraries(llvmlite ${llvm_libs})
# -flto and --exclude-libs allow us to remove those parts of LLVM we don't use
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
set_property(TARGET llvmlite APPEND_STRING PROPERTY LINK_FLAGS "-flto -Wl,--exclude-libs,ALL")
set_property(TARGET llvmlite APPEND_STRING PROPERTY LINK_FLAGS "-flto -Wl,--exclude-libs,${LLVM_EXCLUDE_LIB}")
# On Darwin we only include the LLVMPY symbols we require and exclude
# everything else.
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Expand Down
Loading