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

Test #986 on CI #1072

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.a
*.lib
*.pyc
*.pyd
*.o
Expand All @@ -15,3 +17,4 @@ MANIFEST
docs/_build/
docs/gh-pages/
.*.swp
.vscode/
10 changes: 7 additions & 3 deletions docs/source/admin-guide/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://compiler-rt.llvm.org/>`_
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 <https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/builtins/README.txt>`_.

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:
Expand Down
30 changes: 27 additions & 3 deletions ffi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

set(CMAKE_CXX_STANDARD 17)
Expand All @@ -22,6 +22,18 @@ find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64") # for desktop
set(ARCH "x86_64")
else()
set(ARCH ${CMAKE_SYSTEM_PROCESSOR})
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 @@ -48,6 +60,18 @@ 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 memorymanager.cpp newpassmanagers.cpp)

# Link compiler-rt 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.
# The following line is broken with LLVM 10.0.0 due to a potential bug in
Expand All @@ -69,7 +93,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
14 changes: 11 additions & 3 deletions ffi/Makefile.freebsd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -15,10 +16,17 @@ SRC = assembly.cpp bitcode.cpp core.cpp initfini.cpp module.cpp value.cpp \
memorymanager.cpp newpassmanagers.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)
16 changes: 12 additions & 4 deletions ffi/Makefile.linux
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -16,15 +17,22 @@ OBJ = assembly.o bitcode.o core.o initfini.o module.o value.o \
linker.o object_file.o custom_passes.o orcjit.o memorymanager.o newpassmanagers.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)
$(CXX) -c $(CXXFLAGS) $< -o $@

$(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)
7 changes: 7 additions & 0 deletions ffi/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -184,6 +185,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
Expand Down
7 changes: 7 additions & 0 deletions llvmlite/tests/test_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -2601,6 +2601,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_compiler_rt(self):
ffi.lib._lib_handle['__ashldi3']()


class TestAnalysis(BaseTest):
def build_ir_module(self):
m = ir.Module()
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,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)
Expand Down
Loading