-
Notifications
You must be signed in to change notification settings - Fork 317
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 #986
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Building locally on Linux gives me:
$python setup.py develop
... output snipped ...
Traceback (most recent call last):
File "/home/gmarkall/numbadev/llvmlite/ffi/build.py", line 244, in <module>
main()
File "/home/gmarkall/numbadev/llvmlite/ffi/build.py", line 234, in main
main_posix('linux', '.so')
File "/home/gmarkall/numbadev/llvmlite/ffi/build.py", line 226, in main_posix
shutil.copy('libclang_rt.builtins.a', target_dir)
File "/home/gmarkall/mambaforge/envs/numbadev/lib/python3.10/shutil.py", line 417, in copy
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/home/gmarkall/mambaforge/envs/numbadev/lib/python3.10/shutil.py", line 254, in copyfile
with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: 'libclang_rt.builtins.a'
error: command '/home/gmarkall/mambaforge/envs/numbadev/bin/python' failed with exit code 1
If I apply:
diff --git a/ffi/build.py b/ffi/build.py
index a012bb5..4176630 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():
(which removes things I was confused about - I'm not saying they're not required, but I'm yet to understand their purpose) then the build completes, but I get an error running tests (so none of the binding tests run):
$ python runtests.py
E...................................................................................................................................................................................................
======================================================================
ERROR: llvmlite.tests.test_binding (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: llvmlite.tests.test_binding
Traceback (most recent call last):
File "/home/gmarkall/numbadev/llvmlite/llvmlite/binding/ffi.py", line 136, in __getattr__
return self._fntab[name]
KeyError: 'LLVMPY_AddSymbol'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/gmarkall/numbadev/llvmlite/llvmlite/binding/ffi.py", line 119, in _load_lib
_ = self._lib_handle.__gnu_f2h_ieee()
File "/home/gmarkall/mambaforge/envs/numbadev/lib/python3.10/ctypes/__init__.py", line 387, in __getattr__
func = self.__getitem__(name)
File "/home/gmarkall/mambaforge/envs/numbadev/lib/python3.10/ctypes/__init__.py", line 392, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: /home/gmarkall/numbadev/llvmlite/llvmlite/binding/libllvmlite.so: undefined symbol: _lib_wrapper__gnu_f2h_ieee
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/gmarkall/mambaforge/envs/numbadev/lib/python3.10/unittest/loader.py", line 436, in _find_test_path
module = self._get_module_from_name(name)
File "/home/gmarkall/mambaforge/envs/numbadev/lib/python3.10/unittest/loader.py", line 377, in _get_module_from_name
__import__(name)
File "/home/gmarkall/numbadev/llvmlite/llvmlite/tests/test_binding.py", line 17, in <module>
from llvmlite import binding as llvm
File "/home/gmarkall/numbadev/llvmlite/llvmlite/binding/__init__.py", line 4, in <module>
from .dylib import *
File "/home/gmarkall/numbadev/llvmlite/llvmlite/binding/dylib.py", line 36, in <module>
ffi.lib.LLVMPY_AddSymbol.argtypes = [
File "/home/gmarkall/numbadev/llvmlite/llvmlite/binding/ffi.py", line 139, in __getattr__
cfn = getattr(self._lib, name)
File "/home/gmarkall/numbadev/llvmlite/llvmlite/binding/ffi.py", line 131, in _lib
self._load_lib()
File "/home/gmarkall/numbadev/llvmlite/llvmlite/binding/ffi.py", line 125, in _load_lib
raise OSError("Could not find/load shared object file") from e
OSError: Could not find/load shared object file
----------------------------------------------------------------------
Ran 196 tests in 0.046s
FAILED (errors=1)
Maybe this is because the code I removed is needed, but had some other issue? Or maybe the issue is elsewhere?
@gmarkall found the problem with the test...the issue is related to cdll loading logic, left a comment in the code: https://github.com/numba/llvmlite/pull/986/files#diff-a23ac0d3c4c6d8093d709eb3c5d28fc4dadae4e58e648ba306485a7f4eddd776R119 |
…out fp16 registers
After more investigation... I reverted the build change for macOS & Windows, and added a test for Linux. Issues for macOS:
However, linker complains the
Issues for WindowsI'm mainly struggling with dev tooling to figure out what is missing, applied the following diff (
However, when I dump the symbols of the generated
Shall we fix the Linux version first? |
Additional debugging for macOS, got some help from llvm discourse: https://discourse.llvm.org/t/lld-automatically-hide-symbols-with-prefix/73192,
|
After checking out the compiler-rt source, It seems we need to turn off
After the change:
|
@esc It's waiting on me - I've been struggling to find the time to get back to progressing with it. |
(It's waiting for #979, which is also waiting for me) |
@gmarkall ok, thank you for the info. I have updated the labels accordingly. |
The symbols in the compiler-rt builtins library are private external by default on MacOS. We need them to be visible so we can link against them (e.g. when building libllvmlite.so). This patch makes the symbols visible when the CMake option `COMPILER_RT_BUILTINS_HIDE_SYMBOLS` is off. Note that this is an existing option for the compiler-rt build, and the flags requiring modification in this patch appear to be an oversight. References: - https://discourse.llvm.org/t/lld-automatically-hide-symbols-with-prefix/73192 - numba#986 (comment)
Testing in #1072. |
This PR addesses issues in #834 and tinygrad/tinygrad#1367, in which libllvmlite.so fails to resolve symbols in libclang_rt.builtin.a since compiler rt is not linked. This PR statically links the compiler_rt library.
(address the comments from #976)