Repository: numba/numba

Issue:
llvm local linkage requires default visibility failed.
Hi
Help to bypass the error

At the Ubuntu 16.04 Python 2.7 numba 0.29.0 llvm 3.8 compiles this code fine
But on Ubuntu 16.04 Python 3.5.2 (default, Sep 14 2017, 22:51:06)  [GCC 5.4.0 20160609] on linux
 llvm 3.9
numba 0.34  -35.0
if
ret[2, :, :] = aaa - excellent
and if just copy the string some times
ret[2, :, :] = aaa
ret[2, :, :] = aaa
ret[2, :, :] = aaa
get the error

python3: /opt/miniconda/conda-bld/llvmdev_1498055795382/work/llvm-4.0.0.src/include/llvm/IR/GlobalValue.h:227: void llvm::GlobalValue::setVisibility(llvm::GlobalValue::VisibilityTypes): Assertion `(!hasLocalLinkage() || V == DefaultVisibility) && "local linkage requires default visibility"' failed.

conda is not installed - just installed Python 3.5 and Python 2.7(system)

install numba was produced by the command
sudo pip3 install numba==0.34.0
or
sudo pip3 install numba

Thank you


Discussion:
same problem using conda installation
Can you post the output of running the `numba -s` command?
`numba -s` shows

```
System info:
--------------------------------------------------------------------------------
__Time Stamp__
2018-08-20 16:31:39.168452

__Hardware Information__
Machine                             : x86_64
CPU Name                            : ivybridge
CPU Features                        : 
aes avx cmov cx16 f16c fsgsbase mmx pclmul popcnt rdrnd sse sse2 sse3 sse4.1
sse4.2 ssse3 xsave xsaveopt

__OS Information__
Platform                            : Linux-4.4.0-116-generic-x86_64-with-debian-stretch-sid
Release                             : 4.4.0-116-generic
System Name                         : Linux
Version                             : #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018
OS specific info                    : debianstretch/sid
glibc info                          : glibc 2.9

__Python Information__
Python Compiler                     : GCC 7.2.0
Python Implementation               : CPython
Python Version                      : 3.6.6
Python Locale                       : en_US UTF-8

__LLVM information__
LLVM version                        : 6.0.0

__CUDA Information__
CUDA driver library cannot be found or no CUDA enabled devices are present.
Error class: <class 'numba.cuda.cudadrv.error.CudaSupportError'>

__SVML Information__
SVML state, config.USING_SVML       : False
SVML library found and loaded       : False
llvmlite using SVML patched LLVM    : True
SVML operational:                   : False

__Conda Information__
conda_build_version                 : 3.10.5
conda_env_version                   : 4.5.4
platform                            : linux-64
python_version                      : 3.6.5.final.0
root_writable                       : True

__Current Conda Env__
blas                      1.0                         mkl  
ca-certificates           2018.03.07                    0  
certifi                   2018.8.13                py36_0  
intel-openmp              2018.0.3                      0  
libedit                   3.1.20170329         h6b74fdf_2  
libffi                    3.2.1                hd88cf55_4  
libgcc-ng                 8.2.0                hdf63c60_1  
libgfortran-ng            7.2.0                hdf63c60_3  
libstdcxx-ng              8.2.0                hdf63c60_1  
llvmlite                  0.24.0           py36hdbcaa40_0  
mkl                       2018.0.3                      1  
mkl_fft                   1.0.4            py36h4414c95_1  
mkl_random                1.0.1            py36h4414c95_1  
ncurses                   6.1                  hf484d3e_0  
numba                     0.39.0           py36h04863e7_0  
numpy                     1.15.0           py36h1b885b7_0  
numpy-base                1.15.0           py36h3dfced4_0  
openssl                   1.0.2p               h14c3975_0  
pip                       10.0.1                   py36_0  
python                    3.6.6                hc3d631a_0  
readline                  7.0                  ha6073c6_4  
scipy                     1.1.0            py36hc49cb51_0  
setuptools                40.0.0                   py36_0  
sqlite                    3.24.0               h84994c4_0  
tk                        8.6.7                hc745277_3  
wheel                     0.31.1                   py36_0  
xz                        5.2.4                h14c3975_4  
zlib                      1.2.11               ha838bed_2  
--------------------------------------------------------------------------------
If requested, please copy and paste the information between
the dashed (----) lines, or from a given specific section as
appropriate.

=============================================================
IMPORTANT: Please ensure that you are happy with sharing the
contents of the information present, any information that you
wish to keep private you should remove before sharing.
=============================================================
```

and the code is 

```python
#!/usr/bin/env python3
import numpy as np
from numba.pycc import CC
from numba import njit
from numpy.linalg import norm as l21_norm

cc = CC('math_utils')
cc.verbose = True

@cc.export('welsch_func', 'f8[:](f8[:], f8)')
@njit
def welsch_func(x, epsilon):

    result = (1 - np.exp(- epsilon * x ** 2)) / epsilon

    return result

@cc.export('E', 'f8(f8[:,:],f8[:,:],f8[:,:],f8,f8)')
@njit
def E(U, V, X, gamma, epsilon):

    N, C, ndim = len(X), len(V), len(X[0])  # noqa

    W = np.empty(shape=(N, C), dtype=np.float64)
    for i in range(N):
        xi = X[i, :]
        for k in range(C):
            W[i, k] = welsch_func(l21_norm(xi - V[k, :]), epsilon)

    return np.sum(U * W) + gamma * l21_norm(U)**2

if __name__ == '__main__':
    cc.compile()
```

I've tried downgrading numba to 0.38 and it works. Seemingly it's a bug in 0.39.

Resolving patch:
diff --git a/numba/targets/listobj.py b/numba/targets/listobj.py
--- a/numba/targets/listobj.py
+++ b/numba/targets/listobj.py
@@ -279,7 +279,7 @@ def define_dtor(self):
         if not fn.is_declaration:
             # End early if the dtor is already defined
             return fn
-        fn.linkage = 'internal'
+        fn.linkage = 'linkonce_odr'
         # Populate the dtor
         builder = ir.IRBuilder(fn.append_basic_block())
         base_ptr = fn.args[0]  # void*


Test patch:
diff --git a/numba/tests/compile_with_pycc.py b/numba/tests/compile_with_pycc.py
--- a/numba/tests/compile_with_pycc.py
+++ b/numba/tests/compile_with_pycc.py
@@ -90,6 +90,10 @@ def vector_dot(n):
 def zeros(n):
     return np.zeros(n)
 
+# requires list dtor, #issue3535
+@cc_nrt.export('np_argsort', 'intp[:](float64[:])')
+def np_argsort(arr):
+    return np.argsort(arr)
 
 #
 # Legacy API
diff --git a/numba/tests/test_pycc.py b/numba/tests/test_pycc.py
--- a/numba/tests/test_pycc.py
+++ b/numba/tests/test_pycc.py
@@ -278,8 +278,15 @@ def test_compile_nrt(self):
             if has_blas:
                 res = lib.vector_dot(4)
                 self.assertPreciseEqual(res, 30.0)
+            # test argsort
+            val = np.float64([2., 5., 1., 3., 4.])
+            res = lib.np_argsort(val)
+            expected = np.argsort(val)
+            self.assertPreciseEqual(res, expected)
 
             code = """if 1:
+                from numpy.testing import assert_equal
+                from numpy import float64, argsort
                 res = lib.zero_scalar(1)
                 assert res == 0.0
                 res = lib.zeros(3)
@@ -287,6 +294,10 @@ def test_compile_nrt(self):
                 if %(has_blas)s:
                     res = lib.vector_dot(4)
                     assert res == 30.0
+                val = float64([2., 5., 1., 3., 4.])
+                res = lib.np_argsort(val)
+                expected = argsort(val)
+                assert_equal(res, expected)
                 """ % dict(has_blas=has_blas)
             self.check_cc_compiled_in_subprocess(lib, code)