[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
Sat Jan 7 22:31:13 PST 2017
> On Jan 7, 2017, at 9:34 PM, Simone Atzeni via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 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?
I don’t expect this, but there are possible subtleties: for instance who is calling the function? Is the call site in the dylib? Is it in the same translation unit as the definition? (It could have been inlined for instance). Is the library built with protected/hidden visibility? Which platform are you on?
Also, that’s not really directly related to LLVM or the fact that you add the symbol in a pass. You should be able to reproduce with two trivial files: main.c that defines main() and foo(), and lib.c that defines a weak foo() and is built as a library. Can you reproduce with such setup? Otherwise something else is going on in your build…
> 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.
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
More information about the llvm-dev