Repository: numba/numba

Issue:
-pthread link flag missing in setup.py for linux-ppc64le
As part of https://github.com/numba/numba/pull/8052 the `-pthread` was injected for the linux-ppc64le platform. However, this was only done for the conda recipe and as setting for AOT complation. What is missing is adding this injection into `setup.py` so that the regular build process succeeds on that platform too. Here is a reproducer:

```
(debug_gamma) ci@atx-power8-01:~/ci/numba$ python setup.py build_ext -i && python setup.py develop --no-deps
...
(debug_gamma) ci@atx-power8-01:~/ci/numba$ python -m numba.runtests -m 4 numba.tests.test_np_randomgen
Traceback (most recent call last):
  File "/home/ci/miniconda3/envs/debug_gamma/lib/python3.9/runpy.py", line 188, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/home/ci/miniconda3/envs/debug_gamma/lib/python3.9/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/home/ci/ci/numba/numba/__init__.py", line 38, in <module>
    from numba.core.decorators import (cfunc, generated_jit, jit, njit, stencil,
  File "/home/ci/ci/numba/numba/core/decorators.py", line 12, in <module>
    from numba.stencils.stencil import stencil
  File "/home/ci/ci/numba/numba/stencils/stencil.py", line 11, in <module>
    from numba.core import types, typing, utils, ir, config, ir_utils, registry
  File "/home/ci/ci/numba/numba/core/ir_utils.py", line 13, in <module>
    from numba.core.extending import _Intrinsic
  File "/home/ci/ci/numba/numba/core/extending.py", line 19, in <module>
    from numba.core.pythonapi import box, unbox, reflect, Nativeciue  # noqa: F401
  File "/home/ci/ci/numba/numba/core/pythonapi.py", line 11, in <module>
    from numba import _helperlib
ImportError: /home/ci/ci/numba/numba/_helperlib.cpython-39-powerpc64le-linux-gnu.so: undefined symbol: pthread_atfork
```

<!--

Thanks for opening an issue! To help the Numba team handle your information
efficiently, please first ensure that there is no other issue present that
already describes the issue you have
(search at https://github.com/numba/numba/issues?&q=is%3Aissue).

-->

## Reporting a bug

<!--

Before submitting a bug report please ensure that you can check off these boxes:

-->

- [x] I have tried using the latest released version of Numba (most recent is
 visible in the change log (https://github.com/numba/numba/blob/main/CHANGE_LOG).
- [x] I have included a self contained code sample to reproduce the problem.
  i.e. it's possible to run as 'python bug.py'.

<!--

Please include details of the bug here, including, if applicable, what you
expected to happen!

-->



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -66,9 +66,12 @@ def run(self):
 cmdclass = versioneer.get_cmdclass()
 cmdclass['build_doc'] = build_doc
 
+extra_link_args = []
 install_name_tool_fixer = []
 if sys.platform == 'darwin':
     install_name_tool_fixer += ['-headerpad_max_install_names']
+if platform.machine() == 'ppc64le':
+    extra_link_args += ['-pthread']
 
 build_ext = cmdclass.get('build_ext', build_ext)
 
@@ -172,7 +175,9 @@ def get_ext_modules():
                                        "numba/cext/dictobject.c",
                                        "numba/cext/listobject.c",
                                        ],
-                              extra_link_args=install_name_tool_fixer,
+                              # numba/_random.c needs pthreads
+                              extra_link_args=install_name_tool_fixer +
+                              extra_link_args,
                               depends=["numba/_pymodule.h",
                                        "numba/_helperlib.c",
                                        "numba/_lapack.c",
@@ -278,6 +283,7 @@ def check_file_at_path(path2file):
                 depends=['numba/np/ufunc/workqueue.h'],
                 include_dirs=[os.path.join(tbb_root, 'include')],
                 extra_compile_args=cpp11flags,
+                extra_link_args=extra_link_args,
                 libraries=['tbb'],  # TODO: if --debug or -g, use 'tbb_debug'
                 library_dirs=[
                     # for Linux
@@ -319,7 +325,8 @@ def check_file_at_path(path2file):
         name='numba.np.ufunc.workqueue',
         sources=['numba/np/ufunc/workqueue.c',
                  'numba/np/ufunc/gufunc_scheduler.cpp'],
-        depends=['numba/np/ufunc/workqueue.h'])
+        depends=['numba/np/ufunc/workqueue.h'],
+        extra_link_args=extra_link_args)
     ext_np_ufunc_backends.append(ext_np_ufunc_workqueue_backend)
 
     ext_mviewbuf = Extension(name='numba.mviewbuf',


Test patch: