# Buggy code
def _get_module_for_linking(self):
    """
    Internal: get a LLVM module suitable for linking multiple times
    into another library.  Exported functions are made "linkonce_odr"
    to allow for multiple definitions, inlining, and removal of
    unused exports.

    See discussion in https://github.com/numba/numba/pull/890
    """
    if self._shared_module is not None:
        return self._shared_module
    mod = self._final_module
    to_fix = []
    nfuncs = 0
    for fn in mod.functions:
        nfuncs += 1
        if not fn.is_declaration and fn.linkage == ll.Linkage.external:
            to_fix.append(fn.name)
    if nfuncs == 0:
        # This is an issue which can occur if loading a module
        # from an object file and trying to link with it, so detect it
        # here to make debugging easier.
        raise RuntimeError(
            "library unfit for linking: no available functions in %s" % (self,)
        )
    if to_fix:
        mod = mod.clone()
        for name in to_fix:
            # NOTE: this will mark the symbol WEAK if serialized
            # to an ELF file
            mod.get_function(name).linkage = "linkonce_odr"
    self._shared_module = mod
    return mod


# Traceback (RuntimeError)
$ python app.py
Traceback (most recent call last):
File "app.py", line 21, in <module>
run(N)
File "app.py", line 15, in run
res = fcalc(x)
File "/Users/userx/anaconda/lib/python2.7/site-packages/numba/dispatcher.py", line 172, in _compile_for_args
return self.compile(sig)
File "/Users/userx/anaconda/lib/python2.7/site-packages/numba/dispatcher.py", line 350, in compile
flags=flags, locals=self.locals)
File "/Users/userx/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 644, in compile_extra
return pipeline.compile_extra(func)
File "/Users/userx/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 361, in compile_extra
return self.compile_bytecode(bc, func_attr=self.func_attr)
File "/Users/userx/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 370, in compile_bytecode
return self._compile_bytecode()
File "/Users/userx/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 631, in _compile_bytecode
return pm.run(self.status)
File "/Users/userx/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 251, in run
raise patched_exception
RuntimeError: Caused By:
Traceback (most recent call last):
File "/Users/userx/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 243, in run
res = stage()
File "/Users/userx/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 587, in stage_nopython_backend
return self._backend(lowerfn, objectmode=False)
File "/Users/userx/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 540, in _backend
lowered = lowerfn()
File "/Users/userx/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 527, in backend_nopython_mode
self.flags)
File "/Users/userx/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 786, in native_lowering_stage
cfunc = targetctx.get_executable(library, fndesc, env)
File "/Users/userx/anaconda/lib/python2.7/site-packages/numba/targets/cpu.py", line 147, in get_executable
baseptr = library.get_pointer_to_function(fndesc.llvm_func_name)
File "/Users/userx/anaconda/lib/python2.7/site-packages/numba/targets/codegen.py", line 377, in get_pointer_to_function
self._ensure_finalized()
File "/Users/userx/anaconda/lib/python2.7/site-packages/numba/targets/codegen.py", line 67, in _ensure_finalized
self.finalize()
File "/Users/userx/anaconda/lib/python2.7/site-packages/numba/targets/codegen.py", line 170, in finalize
library._get_module_for_linking(), preserve=True)
File "/Users/userx/anaconda/lib/python2.7/site-packages/numba/targets/codegen.py", line 113, in _get_module_for_linking
% (self,))
RuntimeError: library unfit for linking: no available functions in <Library 'func' at 0x10b73ef10>

Failed at nopython (nopython mode backend)
library unfit for linking: no available functions in <Library 'func' at 0x10b73ef10>

# Fixed code
def _get_module_for_linking(self):
    """
    Internal: get a LLVM module suitable for linking multiple times
    into another library.  Exported functions are made "linkonce_odr"
    to allow for multiple definitions, inlining, and removal of
    unused exports.

    See discussion in https://github.com/numba/numba/pull/890
    """
    self._ensure_finalized()
    if self._shared_module is not None:
        return self._shared_module
    mod = self._final_module
    to_fix = []
    nfuncs = 0
    for fn in mod.functions:
        nfuncs += 1
        if not fn.is_declaration and fn.linkage == ll.Linkage.external:
            to_fix.append(fn.name)
    if nfuncs == 0:
        # This is an issue which can occur if loading a module
        # from an object file and trying to link with it, so detect it
        # here to make debugging easier.
        raise RuntimeError(
            "library unfit for linking: no available functions in %s" % (self,)
        )
    if to_fix:
        mod = mod.clone()
        for name in to_fix:
            # NOTE: this will mark the symbol WEAK if serialized
            # to an ELF file
            mod.get_function(name).linkage = "linkonce_odr"
    self._shared_module = mod
    return mod