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

Mehdi Amini via llvm-dev llvm-dev at lists.llvm.org
Sun Jan 8 12:10:11 PST 2017


DiOn Jan 8, 2017, at 10:57 AM, Reid Kleckner via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> 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.

Was it always the case?

The only thing I find in the doc is the description of the environment variable: LD_DYNAMIC_WEAK "(glibc since 2.1.91) Allow weak symbols to be overridden (reverting to old glibc behaviour)."


Just curious…

—
Mehdi


> 
> 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) {
>    myhook();
>   }
> 
> On Sat, Jan 7, 2017 at 9:34 PM, Simone Atzeni via llvm-dev <llvm-dev at lists.llvm.org <mailto: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 <mailto:llvm-dev at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev>
> 
> _______________________________________________
> 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/544b23b1/attachment.html>


More information about the llvm-dev mailing list