[llvm-dev] Weak symbol function in shared library and strong symbol function in main problem

Reid Kleckner via llvm-dev llvm-dev at lists.llvm.org
Sun Jan 8 10:57:10 PST 2017

ELF dynamic loaders generally do not distinguish between weak and strong
symbols. They only look at the visibility, which can be internal, hidden,
default, or protected.

If you're trying to allow the main program to customize some aspect of your
LD_PRELOAD'ed tool, you probably want to use an extern weak symbol. I
forget the details on how to do this, but it looks something like this:

extern void __attribute__((weak)) myhook(void);
  if (&myhook) {

On Sat, Jan 7, 2017 at 9:34 PM, Simone Atzeni via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hi,
> I have a pass that add a function in the module where the “main” is. Then,
> I have the same function declared as weak symbol in a shared library that I
> load at runtime with LD_PRELOAD.
> When I run a program the weak symbol function gets called over the
> function was added by the pass.
> Is it a correct behavior? Is there a way to call the strong symbol
> function when it’s present in the module?
> In other words, when I don’t apply the pass I want the program to call the
> weak symbol function, otherwise when I apply the pass I want the program to
> call the function added by the pass.
> Thanks!
> Best,
> Simone
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170108/db8dcea3/attachment.html>

More information about the llvm-dev mailing list