<div dir="ltr"><div><div>Thank you for the test files. For convenience, I copy the contents here.</div><div><br></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div><font face="monospace, monospace">$ cat main.c</font></div></div><div><div><font face="monospace, monospace">void test();</font></div></div><div><div><font face="monospace, monospace">int main() { test(); return 0; }</font></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">$ cat test.c</font></div><div><div><font face="monospace, monospace">int foo() { return 1; }</font></div></div><div><div><font face="monospace, monospace">int __wrap_foo() { return 0; }</font></div></div><div><div><font face="monospace, monospace">void test() { foo(); __wrap_foo(); }</font></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">$ cat run-test</font></div><div><div><font face="monospace, monospace">#! /bin/bash</font></div></div><div><div><font face="monospace, monospace">set -x</font></div></div><div><div><font face="monospace, monospace">set -e</font></div></div><div><div><font face="monospace, monospace">clang -fuse-ld=lld -Wl,--wrap=strstr -glldb -Wl,--wrap=foo -shared -o test.so -fpic test.c</font></div></div><div><div><font face="monospace, monospace">clang -fuse-ld=lld -Wl,--wrap=strstr -glldb -Wl,--wrap=foo -dynamic -o main -fpic main.c ./test.so</font></div></div><div><div><font face="monospace, monospace">./main</font></div></div></blockquote><div><br></div><div>I'm not still very happy about this, but it seems like this is indeed the only thing we can do with the current architecture. LGTM with some nits. Thank you for finding and fixing this one!</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Jul 2, 2018 at 2:10 PM Matthew Koontz via Phabricator <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">matthew.koontz added a comment.<br>
<br>
I've attached a basic program that will crash. It looks like this only happens when creating a shared object file, otherwise it gets a direct call like you describe. The problem is the `applySymbolWrap` duplicates `__wrap_sym`, and then sets the `IsUsedInRegularObj` in one of them to false. From then on, these get treated as two separate symbols. I think the cause of the runtime crash is setting the `IsUsedInRegularObj` prevents adding an entry in the dynamic symbol table, so the lookup fails. Also, the former code creates two PLT entries for `__wrap_sym`, when they should share a PLT entry since they really are the same symbol.<br>
<br>
Ideally, we wouldn't do this memcpy and somehow have all of the references to `sym` to now point to `__wrap_sym`, but I can't think of a good way of doing that with the current code.<br>
<br>
F6562635: lld-test.tar.bz2 <<a href="https://reviews.llvm.org/F6562635" rel="noreferrer" target="_blank">https://reviews.llvm.org/F6562635</a>><br>
<br>
<br>
Repository:<br>
  rLLD LLVM Linker<br>
<br>
<a href="https://reviews.llvm.org/D48502" rel="noreferrer" target="_blank">https://reviews.llvm.org/D48502</a><br>
<br>
<br>
<br>
</blockquote></div>