[llvm-dev] GlobalValue::AvailableExternallyLinkage

Reid Kleckner via llvm-dev llvm-dev at lists.llvm.org
Mon Nov 21 10:14:01 PST 2016


On Sat, Nov 19, 2016 at 12:44 PM, Simone Atzeni via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Thanks Mehdi.
>
> My pass clones the functions within a module in order to have the original
> function and an exact copy of the same function but with a different name,
> i.e. sum() and sum_parallel().
> After my pass I will run ThreadSanitizer instrumentation pass only on the
> new copy of the functions, i.e. only the “_parallel” functions will be
> instrumented by tsan.
>
> In some programs that I am compiling, the functions such as atoi and atof
> get cloned but I want to avoid this, and I noticed that only those
> functions have GlobalValue::AvailableExternallyLinkage, so I was
> wondering if checking the  linkage is enough to avoid those library
> functions or there could be situations of functions with that linkage but
> that have the body implemented in the same module.
>

Checking for this linkage should be enough. If a function has
available_externally linkage, then some other module *must* provide an
equivalent, strong definition of that function, so you shouldn't need (or
want) to clone such functions.

The root of your problem is that you clone "atoi" into "atoi_parallel", but
you leave the linkage as available_externally, which means that you are
also promising that some other module out there provides the symbol
"atoi_parallel". Obviously, that isn't the case, so you get linker errors.

You could also resolve your problem by giving the parallel clones
'internal' linkage.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161121/a9f9faf3/attachment.html>


More information about the llvm-dev mailing list