From 2b6e1e7094895b51613652b0679f4ef11de070fe Mon Sep 17 00:00:00 2001 From: oliverhu Date: Sun, 20 Aug 2023 21:53:37 -0700 Subject: [PATCH 01/14] Statically link compiler-rt --- .gitignore | 2 ++ buildscripts/azure/azure-windows.yml | 2 +- .../incremental/setup_conda_environment.cmd | 3 +- .../incremental/setup_conda_environment.sh | 4 ++- ffi/CMakeLists.txt | 33 +++++++++++++++++-- ffi/Makefile.freebsd | 14 ++++++-- ffi/Makefile.linux | 16 ++++++--- ffi/Makefile.osx | 11 +++++-- ffi/build.py | 18 +++++++++- llvmlite/utils.py | 8 ++++- setup.py | 3 +- 11 files changed, 96 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index dd191b234..0e2331945 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +*.a +*.lib *.pyc *.pyd *.o diff --git a/buildscripts/azure/azure-windows.yml b/buildscripts/azure/azure-windows.yml index 56c1edcaa..e65373875 100644 --- a/buildscripts/azure/azure-windows.yml +++ b/buildscripts/azure/azure-windows.yml @@ -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 gmarkall llvmdev="14.*" libxml2 displayName: 'Before Install' - script: | diff --git a/buildscripts/incremental/setup_conda_environment.cmd b/buildscripts/incremental/setup_conda_environment.cmd index e3b66574e..94289ac1a 100644 --- a/buildscripts/incremental/setup_conda_environment.cmd +++ b/buildscripts/incremental/setup_conda_environment.cmd @@ -20,5 +20,6 @@ call activate %CONDA_ENV% if %errorlevel% neq 0 exit /b %errorlevel% @rem Install llvmdev -%CONDA_INSTALL% -c numba/label/dev llvmdev="14.*" +%CONDA_INSTALL% -c gmarkall llvmdev="14.*" +@REM %CONDA_INSTALL% -c numba/label/dev llvmdev="14.*" if %errorlevel% neq 0 exit /b %errorlevel% diff --git a/buildscripts/incremental/setup_conda_environment.sh b/buildscripts/incremental/setup_conda_environment.sh index 20008b264..df73f36cf 100755 --- a/buildscripts/incremental/setup_conda_environment.sh +++ b/buildscripts/incremental/setup_conda_environment.sh @@ -26,8 +26,10 @@ set +v source activate $CONDA_ENV set -v +# TEMPORARY +$CONDA_INSTALL -c gmarkall llvmdev="14.*" # Install llvmdev (separate channel, for now) -$CONDA_INSTALL -c numba/label/dev llvmdev="14.*" +# $CONDA_INSTALL -c numba/label/dev llvmdev="14.*" # Install the compiler toolchain, for osx, bootstrapping needed # which happens in build.sh diff --git a/ffi/CMakeLists.txt b/ffi/CMakeLists.txt index e4ce2c12c..21d70aa00 100755 --- a/ffi/CMakeLists.txt +++ b/ffi/CMakeLists.txt @@ -7,8 +7,8 @@ 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) @@ -16,6 +16,29 @@ 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") + set(COMPILER_RT_LOCATION ${LLVM_LIBRARY_DIR}/windows/clang_rt.builtins-${ARCH}.lib) +else() + if (EXISTS "$(LLVM_LIBDIR)/clang") + set(COMPILER_RT_LOCATION ${LLVM_LIBRARY_DIR}/linux/libclang_rt.builtins-${ARCH}.a) + else() + set(COMPILER_RT_LOCATION ${LLVM_LIBRARY_DIR}/clang/${LLVM_PACKAGE_VERSION}/lib/linux/libclang_rt.builtins-${ARCH}.a) + 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 @@ -42,6 +65,10 @@ 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) +# Link compiler-rt whole archive +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 @@ -63,7 +90,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") diff --git a/ffi/Makefile.freebsd b/ffi/Makefile.freebsd index 7b869e876..437c37569 100644 --- a/ffi/Makefile.freebsd +++ b/ffi/Makefile.freebsd @@ -3,8 +3,9 @@ CXX = clang++ -stdlib=libc++ # -flto and --exclude-libs allow us to remove those parts of LLVM we don't use CXX_FLTO_FLAGS ?= -flto -LD_FLTO_FLAGS ?= -flto -Wl,--exclude-libs=ALL +LD_FLTO_FLAGS ?= -flto -Wl,--exclude-libs=$(LLVM_EXCLUDE_LIB) +ARCH := `uname -m` CXXFLAGS := $(CPPFLAGS) $(CXXFLAGS) $(LLVM_CXXFLAGS) $(CXX_FLTO_FLAGS) LDFLAGS := $(LDFLAGS) $(LLVM_LDFLAGS) $(LD_FLTO_FLAGS) LIBS = $(LLVM_LIBS) @@ -14,10 +15,17 @@ SRC = assembly.cpp bitcode.cpp core.cpp initfini.cpp module.cpp value.cpp \ linker.cpp object_file.cpp OUTPUT = libllvmlite.so +ifneq ("$(wildcard $(LLVM_LIBDIR)/clang)","") + BUILTINS_ARCHIVE := $(LLVM_LIBDIR)/clang/*/lib/freebsd/libclang_rt.builtins-${ARCH}.a +else + BUILTINS_ARCHIVE := $(LLVM_LIBDIR)/freebsd/libclang_rt.builtins-$(ARCH).a +endif + all: $(OUTPUT) $(OUTPUT): $(SRC) $(INCLUDE) - $(CXX) -shared $(CXXFLAGS) $(SRC) -o $(OUTPUT) $(LDFLAGS) $(LIBS) + $(CXX) -shared $(CXXFLAGS) $(SRC) -o $(OUTPUT) $(LDFLAGS) $(LIBS) \ + -Wl,--whole-archive ${BUILTINS_ARCHIVE} -Wl,--no-whole-archive clean: - rm -rf test + rm -rf test $(OUTPUT) $(OBJ) diff --git a/ffi/Makefile.linux b/ffi/Makefile.linux index c1df42dbb..1a844013f 100644 --- a/ffi/Makefile.linux +++ b/ffi/Makefile.linux @@ -3,10 +3,11 @@ CXX ?= g++ # -flto and --exclude-libs allow us to remove those parts of LLVM we don't use CXX_FLTO_FLAGS ?= -flto -LD_FLTO_FLAGS ?= -flto -Wl,--exclude-libs=ALL +LD_FLTO_FLAGS ?= -flto=auto -flto -Wl,--exclude-libs=$(LLVM_EXCLUDE_LIB) # -fPIC is required when compiling objects for a shared library CXX_FPIC_FLAGS ?= -fPIC +ARCH = `uname -m` CXXFLAGS := $(CPPFLAGS) $(CXXFLAGS) $(LLVM_CXXFLAGS) $(CXX_FLTO_FLAGS) $(CXX_FPIC_FLAGS) LDFLAGS := $(LDFLAGS) $(LLVM_LDFLAGS) $(LD_FLTO_FLAGS) LIBS = $(LLVM_LIBS) @@ -16,6 +17,12 @@ OBJ = assembly.o bitcode.o core.o initfini.o module.o value.o \ linker.o object_file.o custom_passes.o orcjit.o OUTPUT = libllvmlite.so +ifneq ("$(wildcard $(LLVM_LIBDIR)/clang)","") + BUILTINS_ARCHIVE := $(LLVM_LIBDIR)/clang/*/lib/linux/libclang_rt.builtins-${ARCH}.a +else + BUILTINS_ARCHIVE := $(LLVM_LIBDIR)/linux/libclang_rt.builtins-$(ARCH).a +endif + all: $(OUTPUT) .cpp.o: $(INCLUDE) @@ -23,8 +30,9 @@ all: $(OUTPUT) $(OUTPUT): $(OBJ) # static-libstdc++ avoids runtime dependencies on a - # particular libstdc++ version. - $(CXX) $(CXX_STATIC_LINK) -shared $(CXXFLAGS) $(OBJ) -o $(OUTPUT) $(LDFLAGS) $(LIBS) + # particular libstdc++ version.' + $(CXX) $(CXX_STATIC_LINK) -shared $(CXXFLAGS) $(OBJ) -o $(OUTPUT) $(LDFLAGS) $(LIBS) \ + -Wl,--whole-archive $(BUILTINS_ARCHIVE) -Wl,--no-whole-archive clean: - rm -rf test $(OUTPUT) $(OBJ) + rm -rf test $(OUTPUT) $(OBJ) \ No newline at end of file diff --git a/ffi/Makefile.osx b/ffi/Makefile.osx index a0d06db4f..11707da59 100644 --- a/ffi/Makefile.osx +++ b/ffi/Makefile.osx @@ -10,10 +10,17 @@ SRC = assembly.cpp bitcode.cpp core.cpp initfini.cpp module.cpp value.cpp \ executionengine.cpp transforms.cpp passmanagers.cpp targets.cpp dylib.cpp \ linker.cpp object_file.cpp custom_passes.cpp orcjit.cpp OUTPUT = libllvmlite.dylib + +ifneq ("$(wildcard $(LLVM_LIBDIR)/clang)","") + BUILTINS_ARCHIVE := $(LLVM_LIBDIR)/clang/*/lib/darwin/libclang_rt.builtins-${ARCH}.a +else + BUILTINS_ARCHIVE := $(LLVM_LIBDIR)/darwin/libclang_rt.builtins-$(ARCH).a +endif + MACOSX_DEPLOYMENT_TARGET ?= 10.9 all: $(SRC) $(INCLUDE) - MACOSX_DEPLOYMENT_TARGET=$(MACOSX_DEPLOYMENT_TARGET) $(CXX) -dynamiclib $(CXXFLAGS) $(SRC) -o $(OUTPUT) $(LDFLAGS) $(LIBS) + MACOSX_DEPLOYMENT_TARGET=$(MACOSX_DEPLOYMENT_TARGET) $(CXX) -dynamiclib $(CXXFLAGS) $(SRC) -o $(OUTPUT) $(LDFLAGS) $(LIBS) -Wl,--whole-archive ${BUILTINS_ARCHIVE} -Wl,--no-whole-archive clean: - rm -rf test + rm -rf test $(BUILTINS_ARCHIVE) diff --git a/ffi/build.py b/ffi/build.py index f4f8c69fa..a012bb5f2 100755 --- a/ffi/build.py +++ b/ffi/build.py @@ -6,6 +6,7 @@ from __future__ import print_function from ctypes.util import find_library +from glob import glob import re import multiprocessing import os @@ -100,7 +101,15 @@ def main_windows(): # Run configuration step try_cmake(here_dir, build_dir, *generator) subprocess.check_call(['cmake', '--build', build_dir, '--config', config]) - shutil.copy(os.path.join(build_dir, config, 'llvmlite.dll'), target_dir) + try: + shutil.copy(os.path.join(build_dir, config, 'llvmlite.dll'), target_dir) + except shutil.SameFileError: + pass + + try: + shutil.copy(os.path.join(build_dir, 'clang_rt.builtins.lib'), target_dir) + except shutil.SameFileError: + pass def main_posix_cmake(kind, library_ext): @@ -177,6 +186,12 @@ def main_posix(kind, library_ext): libs = run_llvm_config(llvm_config, "--system-libs --libs all".split()) # Normalize whitespace (trim newlines) os.environ['LLVM_LIBS'] = ' '.join(libs.split()) + # Get LLVM information for building + llvm_libdir = run_llvm_config(llvm_config, ["--libdir"]).strip() + os.environ['LLVM_LIBDIR'] = llvm_libdir + + exclude_file = glob(llvm_libdir + '/*LLVM*.a') + os.environ['LLVM_EXCLUDE_LIB'] = (',').join(exclude_file) cxxflags = run_llvm_config(llvm_config, ["--cxxflags"]) # on OSX cxxflags has null bytes at the end of the string, remove them @@ -208,6 +223,7 @@ def main_posix(kind, library_ext): makeopts = os.environ.get('LLVMLITE_MAKEOPTS', default_makeopts).split() subprocess.check_call(['make', '-f', makefile] + makeopts) shutil.copy('libllvmlite' + library_ext, target_dir) + shutil.copy('libclang_rt.builtins.a', target_dir) def main(): diff --git a/llvmlite/utils.py b/llvmlite/utils.py index e07ecd370..73dafb6a9 100644 --- a/llvmlite/utils.py +++ b/llvmlite/utils.py @@ -19,11 +19,17 @@ def get_library_name(): return 'llvmlite.dll' +def get_builtins_archive_name(): + if os.name == 'nt': + return 'clang_rt.builtins.lib' + return 'libclang_rt.builtins.a' + + def get_library_files(): """ Return the names of shared library files needed for this platform. """ - files = [get_library_name()] + files = [get_library_name(), get_builtins_archive_name()] if os.name == 'nt': files.extend(['msvcr120.dll', 'msvcp120.dll']) return files diff --git a/setup.py b/setup.py index 75150ea4b..bbeaf30d1 100644 --- a/setup.py +++ b/setup.py @@ -139,7 +139,8 @@ def _rm_walk(self): else: for fname in files: if (fname.endswith('.pyc') or fname.endswith('.so') - or fname.endswith('.o')): + or fname.endswith('.o') or fname.endswith('.a') + or fname.endswith('.dll') or fname.endswith('.lib')): fpath = os.path.join(path, fname) os.remove(fpath) log.info("removing '%s'", fpath) From d52ef02bb7f74a549b3c42d35e21038fb2d76b04 Mon Sep 17 00:00:00 2001 From: oliverhu Date: Thu, 24 Aug 2023 15:02:02 -0700 Subject: [PATCH 02/14] Add check to make sure compiler rt archive is loaded --- llvmlite/binding/ffi.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/llvmlite/binding/ffi.py b/llvmlite/binding/ffi.py index 58ab4efbc..eaa64deb4 100644 --- a/llvmlite/binding/ffi.py +++ b/llvmlite/binding/ffi.py @@ -115,6 +115,8 @@ def _load_lib(self): self._lib_handle = ctypes.CDLL(str(lib_path)) # Check that we can look up expected symbols. _ = self._lib_handle.LLVMPY_GetVersionInfo() + # Make sure we can look up symbols from compiler-rt. + _ = self._lib_handle.__gnu_f2h_ieee() except (OSError, AttributeError) as e: # OSError may be raised if the file cannot be opened, or is not # a shared library. From b354fe1dec79f9a99d1cfa1025d5c800e5b8aa36 Mon Sep 17 00:00:00 2001 From: oliverhu Date: Fri, 25 Aug 2023 14:53:44 -0700 Subject: [PATCH 03/14] Add documentation --- docs/source/admin-guide/install.rst | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/source/admin-guide/install.rst b/docs/source/admin-guide/install.rst index 7bf5eea18..1c38d685c 100644 --- a/docs/source/admin-guide/install.rst +++ b/docs/source/admin-guide/install.rst @@ -41,9 +41,13 @@ maintainers do *not* use any LLVM shared libraries that may be present on the system, and/or in the Conda environment. The parts of LLVM required by llvmlite are statically linked at build time. As a result, installing llvmlite from a binary package from the Numba channel does not also require the end user to -install LLVM. (For more -details on the reasoning behind this, see: :ref:`faq_why_static`). Note however -also that llvmlite packages compiled by other parties, e.g. conda-forge may +install LLVM. (For more details on the reasoning behind this, see: +:ref:`faq_why_static`). From version 0.42, `compiler-rt `_ +builtin is also statically linked at build time to provide an implementation of the +low-level target-specific hooks required by code generation and other runtime +components. You can find a a list of supported IR from the builtin `here `_. + +Note also that llvmlite packages compiled by other parties, e.g. conda-forge may split this into and ``llvmlite`` and ``llvm`` package and link dynamically. Conda packages: From b16adc422cabf9d26d4357bffe886c54def78fcb Mon Sep 17 00:00:00 2001 From: oliverhu Date: Fri, 25 Aug 2023 15:12:03 -0700 Subject: [PATCH 04/14] Address feedback from Graham --- buildscripts/azure/azure-windows.yml | 2 +- buildscripts/incremental/setup_conda_environment.cmd | 2 +- buildscripts/incremental/setup_conda_environment.sh | 2 +- ffi/CMakeLists.txt | 1 - ffi/build.py | 11 +---------- 5 files changed, 4 insertions(+), 14 deletions(-) diff --git a/buildscripts/azure/azure-windows.yml b/buildscripts/azure/azure-windows.yml index e65373875..2593489c2 100644 --- a/buildscripts/azure/azure-windows.yml +++ b/buildscripts/azure/azure-windows.yml @@ -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 --override-channels -c gmarkall llvmdev="14.*" libxml2 + call conda install -y -q gmarkall::llvmdev libxml2 displayName: 'Before Install' - script: | diff --git a/buildscripts/incremental/setup_conda_environment.cmd b/buildscripts/incremental/setup_conda_environment.cmd index 94289ac1a..a36f8b2fe 100644 --- a/buildscripts/incremental/setup_conda_environment.cmd +++ b/buildscripts/incremental/setup_conda_environment.cmd @@ -20,6 +20,6 @@ call activate %CONDA_ENV% if %errorlevel% neq 0 exit /b %errorlevel% @rem Install llvmdev -%CONDA_INSTALL% -c gmarkall llvmdev="14.*" +%CONDA_INSTALL% gmarkall::llvmdev @REM %CONDA_INSTALL% -c numba/label/dev llvmdev="14.*" if %errorlevel% neq 0 exit /b %errorlevel% diff --git a/buildscripts/incremental/setup_conda_environment.sh b/buildscripts/incremental/setup_conda_environment.sh index df73f36cf..63d15ea7e 100755 --- a/buildscripts/incremental/setup_conda_environment.sh +++ b/buildscripts/incremental/setup_conda_environment.sh @@ -27,7 +27,7 @@ source activate $CONDA_ENV set -v # TEMPORARY -$CONDA_INSTALL -c gmarkall llvmdev="14.*" +$CONDA_INSTALL gmarkall::llvmdev # Install llvmdev (separate channel, for now) # $CONDA_INSTALL -c numba/label/dev llvmdev="14.*" diff --git a/ffi/CMakeLists.txt b/ffi/CMakeLists.txt index 21d70aa00..07ab5ec15 100755 --- a/ffi/CMakeLists.txt +++ b/ffi/CMakeLists.txt @@ -16,7 +16,6 @@ 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() diff --git a/ffi/build.py b/ffi/build.py index a012bb5f2..4176630f9 100755 --- a/ffi/build.py +++ b/ffi/build.py @@ -101,15 +101,7 @@ def main_windows(): # Run configuration step try_cmake(here_dir, build_dir, *generator) subprocess.check_call(['cmake', '--build', build_dir, '--config', config]) - try: - shutil.copy(os.path.join(build_dir, config, 'llvmlite.dll'), target_dir) - except shutil.SameFileError: - pass - - try: - shutil.copy(os.path.join(build_dir, 'clang_rt.builtins.lib'), target_dir) - except shutil.SameFileError: - pass + shutil.copy(os.path.join(build_dir, config, 'llvmlite.dll'), target_dir) def main_posix_cmake(kind, library_ext): @@ -223,7 +215,6 @@ def main_posix(kind, library_ext): makeopts = os.environ.get('LLVMLITE_MAKEOPTS', default_makeopts).split() subprocess.check_call(['make', '-f', makefile] + makeopts) shutil.copy('libllvmlite' + library_ext, target_dir) - shutil.copy('libclang_rt.builtins.a', target_dir) def main(): From 7fcd175f6469eeb2a8d8060c3a60c41f0734d0d7 Mon Sep 17 00:00:00 2001 From: oliverhu Date: Fri, 25 Aug 2023 22:59:13 -0700 Subject: [PATCH 05/14] fix symbol validation logic --- llvmlite/binding/ffi.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/llvmlite/binding/ffi.py b/llvmlite/binding/ffi.py index eaa64deb4..10dbfd7c2 100644 --- a/llvmlite/binding/ffi.py +++ b/llvmlite/binding/ffi.py @@ -116,7 +116,9 @@ def _load_lib(self): # Check that we can look up expected symbols. _ = self._lib_handle.LLVMPY_GetVersionInfo() # Make sure we can look up symbols from compiler-rt. - _ = self._lib_handle.__gnu_f2h_ieee() + # Since __getattr__ will override symbol with '__' prefix + # with class name, we directly invoke '__getitem__' to validate + _ = self._lib_handle['__gnu_f2h_ieee']() except (OSError, AttributeError) as e: # OSError may be raised if the file cannot be opened, or is not # a shared library. From 2a166e05ca7a3f13470ede801ae439445c7ab2f9 Mon Sep 17 00:00:00 2001 From: oliverhu Date: Sat, 26 Aug 2023 07:54:00 -0700 Subject: [PATCH 06/14] remove adding builtin to binding folder since it is already statically linked --- llvmlite/utils.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/llvmlite/utils.py b/llvmlite/utils.py index 73dafb6a9..e07ecd370 100644 --- a/llvmlite/utils.py +++ b/llvmlite/utils.py @@ -19,17 +19,11 @@ def get_library_name(): return 'llvmlite.dll' -def get_builtins_archive_name(): - if os.name == 'nt': - return 'clang_rt.builtins.lib' - return 'libclang_rt.builtins.a' - - def get_library_files(): """ Return the names of shared library files needed for this platform. """ - files = [get_library_name(), get_builtins_archive_name()] + files = [get_library_name()] if os.name == 'nt': files.extend(['msvcr120.dll', 'msvcp120.dll']) return files From f93933ae72fe4c0d4d50c421650592c35522c96f Mon Sep 17 00:00:00 2001 From: oliverhu Date: Sat, 26 Aug 2023 14:20:47 -0700 Subject: [PATCH 07/14] test ci --- buildscripts/incremental/setup_conda_environment.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildscripts/incremental/setup_conda_environment.sh b/buildscripts/incremental/setup_conda_environment.sh index 63d15ea7e..9c6b7b333 100755 --- a/buildscripts/incremental/setup_conda_environment.sh +++ b/buildscripts/incremental/setup_conda_environment.sh @@ -27,7 +27,7 @@ source activate $CONDA_ENV set -v # TEMPORARY -$CONDA_INSTALL gmarkall::llvmdev +$CONDA_INSTALL ohu::llvmdev # Install llvmdev (separate channel, for now) # $CONDA_INSTALL -c numba/label/dev llvmdev="14.*" From eece4c38e3c1e45bfd293bfc29db2d2ce21a6559 Mon Sep 17 00:00:00 2001 From: oliverhu Date: Sat, 26 Aug 2023 15:06:04 -0700 Subject: [PATCH 08/14] test ci for windows & macOS arm --- buildscripts/azure/azure-windows.yml | 2 +- buildscripts/incremental/setup_conda_environment.cmd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/buildscripts/azure/azure-windows.yml b/buildscripts/azure/azure-windows.yml index 2593489c2..008fc5913 100644 --- a/buildscripts/azure/azure-windows.yml +++ b/buildscripts/azure/azure-windows.yml @@ -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 gmarkall::llvmdev libxml2 + call conda install -y -q ohu::llvmdev libxml2 displayName: 'Before Install' - script: | diff --git a/buildscripts/incremental/setup_conda_environment.cmd b/buildscripts/incremental/setup_conda_environment.cmd index a36f8b2fe..f87948f1e 100644 --- a/buildscripts/incremental/setup_conda_environment.cmd +++ b/buildscripts/incremental/setup_conda_environment.cmd @@ -20,6 +20,6 @@ call activate %CONDA_ENV% if %errorlevel% neq 0 exit /b %errorlevel% @rem Install llvmdev -%CONDA_INSTALL% gmarkall::llvmdev +%CONDA_INSTALL% ohu::llvmdev @REM %CONDA_INSTALL% -c numba/label/dev llvmdev="14.*" if %errorlevel% neq 0 exit /b %errorlevel% From 07c5e588a9b75ea30714692a898b9b2340be798c Mon Sep 17 00:00:00 2001 From: oliverhu Date: Sun, 27 Aug 2023 11:15:29 -0700 Subject: [PATCH 09/14] only link compiler-rt for linux, add a test --- .gitignore | 1 + ffi/CMakeLists.txt | 22 ++++++++++------------ llvmlite/binding/ffi.py | 4 ---- llvmlite/tests/test_binding.py | 7 +++++++ 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 0e2331945..968f9e7c2 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ MANIFEST docs/_build/ docs/gh-pages/ .*.swp +.vscode/ \ No newline at end of file diff --git a/ffi/CMakeLists.txt b/ffi/CMakeLists.txt index 07ab5ec15..a16b55f4f 100755 --- a/ffi/CMakeLists.txt +++ b/ffi/CMakeLists.txt @@ -22,16 +22,6 @@ else() set(ARCH ${CMAKE_SYSTEM_PROCESSOR}) endif() -if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") - set(COMPILER_RT_LOCATION ${LLVM_LIBRARY_DIR}/windows/clang_rt.builtins-${ARCH}.lib) -else() - if (EXISTS "$(LLVM_LIBDIR)/clang") - set(COMPILER_RT_LOCATION ${LLVM_LIBRARY_DIR}/linux/libclang_rt.builtins-${ARCH}.a) - else() - set(COMPILER_RT_LOCATION ${LLVM_LIBRARY_DIR}/clang/${LLVM_PACKAGE_VERSION}/lib/linux/libclang_rt.builtins-${ARCH}.a) - endif() -endif() - file(GLOB LLVM_EXCLUDE_LIB "${LLVM_LIBRARY_DIR}/*LLVM*.a" ) @@ -65,8 +55,16 @@ add_library(llvmlite SHARED assembly.cpp bitcode.cpp core.cpp initfini.cpp custom_passes.cpp orcjit.cpp) # Link compiler-rt whole archive -set_target_properties(llvmlite PROPERTIES - LINK_FLAGS "-Lfoobar -Wl,--whole-archive,${COMPILER_RT_LOCATION},--no-whole-archive ") +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") + if (EXISTS "$(LLVM_LIBDIR)/clang") + set(COMPILER_RT_LOCATION ${LLVM_LIBRARY_DIR}/linux/libclang_rt.builtins-${ARCH}.a) + else() + set(COMPILER_RT_LOCATION ${LLVM_LIBRARY_DIR}/clang/${LLVM_PACKAGE_VERSION}/lib/linux/libclang_rt.builtins-${ARCH}.a) + endif() + set_target_properties(llvmlite PROPERTIES + LINK_FLAGS "-Wl,--whole-archive,${COMPILER_RT_LOCATION},--no-whole-archive ") +endif() + # Find the libraries that correspond to the LLVM components # that we wish to use. diff --git a/llvmlite/binding/ffi.py b/llvmlite/binding/ffi.py index 10dbfd7c2..58ab4efbc 100644 --- a/llvmlite/binding/ffi.py +++ b/llvmlite/binding/ffi.py @@ -115,10 +115,6 @@ def _load_lib(self): self._lib_handle = ctypes.CDLL(str(lib_path)) # Check that we can look up expected symbols. _ = self._lib_handle.LLVMPY_GetVersionInfo() - # Make sure we can look up symbols from compiler-rt. - # Since __getattr__ will override symbol with '__' prefix - # with class name, we directly invoke '__getitem__' to validate - _ = self._lib_handle['__gnu_f2h_ieee']() except (OSError, AttributeError) as e: # OSError may be raised if the file cannot be opened, or is not # a shared library. diff --git a/llvmlite/tests/test_binding.py b/llvmlite/tests/test_binding.py index d0955508d..5c377f2d8 100644 --- a/llvmlite/tests/test_binding.py +++ b/llvmlite/tests/test_binding.py @@ -2120,6 +2120,13 @@ def test_libm(self): llvm.load_library_permanently(libm) +class TestArchive(BaseTest): + @unittest.skipUnless(platform.system() in ["Linux"], + "test only works on Linux") + def test_libm(self): + ffi.lib._lib_handle['__gnu_f2h_ieee']() + + class TestAnalysis(BaseTest): def build_ir_module(self): m = ir.Module() From 4ee18122843f547b51bde73e89d4218dd7f74d8c Mon Sep 17 00:00:00 2001 From: oliverhu Date: Sun, 27 Aug 2023 11:17:41 -0700 Subject: [PATCH 10/14] fix test naming --- llvmlite/tests/test_binding.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvmlite/tests/test_binding.py b/llvmlite/tests/test_binding.py index 5c377f2d8..eaf5312a6 100644 --- a/llvmlite/tests/test_binding.py +++ b/llvmlite/tests/test_binding.py @@ -2123,7 +2123,7 @@ def test_libm(self): class TestArchive(BaseTest): @unittest.skipUnless(platform.system() in ["Linux"], "test only works on Linux") - def test_libm(self): + def test_compiler_rt(self): ffi.lib._lib_handle['__gnu_f2h_ieee']() From db1b10702e759786b53aef62f0885188fbcac5bf Mon Sep 17 00:00:00 2001 From: oliverhu Date: Sun, 27 Aug 2023 11:27:47 -0700 Subject: [PATCH 11/14] clean up ci env setup --- .../incremental/setup_conda_environment.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/buildscripts/incremental/setup_conda_environment.sh b/buildscripts/incremental/setup_conda_environment.sh index 9c6b7b333..682f9b16a 100755 --- a/buildscripts/incremental/setup_conda_environment.sh +++ b/buildscripts/incremental/setup_conda_environment.sh @@ -26,15 +26,15 @@ set +v source activate $CONDA_ENV set -v -# TEMPORARY -$CONDA_INSTALL ohu::llvmdev -# Install llvmdev (separate channel, for now) -# $CONDA_INSTALL -c numba/label/dev llvmdev="14.*" - -# Install the compiler toolchain, for osx, bootstrapping needed -# which happens in build.sh if [[ $(uname) == Linux ]]; then -$CONDA_INSTALL gcc_linux-64 gxx_linux-64 + # Install the compiler toolchain, for osx, bootstrapping needed + # which happens in build.sh + $CONDA_INSTALL gcc_linux-64 gxx_linux-64 + # Install llvmdev (separate channel, for now) + $CONDA_INSTALL ohu::llvmdev + # $CONDA_INSTALL -c numba/label/dev llvmdev="14.*" +else + $CONDA_INSTALL -c numba/label/dev llvmdev="14.*" fi # Install dependencies for code coverage (codecov.io) From 8e5a1bafb3c695de47586e0e2a02f55531b7d1c0 Mon Sep 17 00:00:00 2001 From: oliverhu Date: Sun, 27 Aug 2023 11:42:27 -0700 Subject: [PATCH 12/14] reset changes for macos --- ffi/Makefile.osx | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/ffi/Makefile.osx b/ffi/Makefile.osx index 11707da59..a0d06db4f 100644 --- a/ffi/Makefile.osx +++ b/ffi/Makefile.osx @@ -10,17 +10,10 @@ SRC = assembly.cpp bitcode.cpp core.cpp initfini.cpp module.cpp value.cpp \ executionengine.cpp transforms.cpp passmanagers.cpp targets.cpp dylib.cpp \ linker.cpp object_file.cpp custom_passes.cpp orcjit.cpp OUTPUT = libllvmlite.dylib - -ifneq ("$(wildcard $(LLVM_LIBDIR)/clang)","") - BUILTINS_ARCHIVE := $(LLVM_LIBDIR)/clang/*/lib/darwin/libclang_rt.builtins-${ARCH}.a -else - BUILTINS_ARCHIVE := $(LLVM_LIBDIR)/darwin/libclang_rt.builtins-$(ARCH).a -endif - MACOSX_DEPLOYMENT_TARGET ?= 10.9 all: $(SRC) $(INCLUDE) - MACOSX_DEPLOYMENT_TARGET=$(MACOSX_DEPLOYMENT_TARGET) $(CXX) -dynamiclib $(CXXFLAGS) $(SRC) -o $(OUTPUT) $(LDFLAGS) $(LIBS) -Wl,--whole-archive ${BUILTINS_ARCHIVE} -Wl,--no-whole-archive + MACOSX_DEPLOYMENT_TARGET=$(MACOSX_DEPLOYMENT_TARGET) $(CXX) -dynamiclib $(CXXFLAGS) $(SRC) -o $(OUTPUT) $(LDFLAGS) $(LIBS) clean: - rm -rf test $(BUILTINS_ARCHIVE) + rm -rf test From 32207ca366e8628336707d6d3bef251380728e03 Mon Sep 17 00:00:00 2001 From: oliverhu Date: Sun, 27 Aug 2023 11:48:36 -0700 Subject: [PATCH 13/14] reset windows changes --- buildscripts/azure/azure-windows.yml | 2 +- buildscripts/incremental/setup_conda_environment.cmd | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/buildscripts/azure/azure-windows.yml b/buildscripts/azure/azure-windows.yml index 008fc5913..56c1edcaa 100644 --- a/buildscripts/azure/azure-windows.yml +++ b/buildscripts/azure/azure-windows.yml @@ -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 ohu::llvmdev libxml2 + call conda install -y -q -c numba/label/dev llvmdev="14.*" libxml2 displayName: 'Before Install' - script: | diff --git a/buildscripts/incremental/setup_conda_environment.cmd b/buildscripts/incremental/setup_conda_environment.cmd index f87948f1e..e3b66574e 100644 --- a/buildscripts/incremental/setup_conda_environment.cmd +++ b/buildscripts/incremental/setup_conda_environment.cmd @@ -20,6 +20,5 @@ call activate %CONDA_ENV% if %errorlevel% neq 0 exit /b %errorlevel% @rem Install llvmdev -%CONDA_INSTALL% ohu::llvmdev -@REM %CONDA_INSTALL% -c numba/label/dev llvmdev="14.*" +%CONDA_INSTALL% -c numba/label/dev llvmdev="14.*" if %errorlevel% neq 0 exit /b %errorlevel% From 586dcd65267ac4612642fbdfaf61bc98f1c59166 Mon Sep 17 00:00:00 2001 From: oliverhu Date: Sun, 27 Aug 2023 12:00:32 -0700 Subject: [PATCH 14/14] change test to __ashldi3 as __gnu_f2h_ieee is only for platforms without fp16 registers --- llvmlite/tests/test_binding.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvmlite/tests/test_binding.py b/llvmlite/tests/test_binding.py index eaf5312a6..967a96e5c 100644 --- a/llvmlite/tests/test_binding.py +++ b/llvmlite/tests/test_binding.py @@ -2124,7 +2124,7 @@ class TestArchive(BaseTest): @unittest.skipUnless(platform.system() in ["Linux"], "test only works on Linux") def test_compiler_rt(self): - ffi.lib._lib_handle['__gnu_f2h_ieee']() + ffi.lib._lib_handle['__ashldi3']() class TestAnalysis(BaseTest):