<div dir="ltr">LGTM<div><br></div><div>While you're here, can you also fix compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc in the similar fashion?</div><div>Thanks!</div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Wed, Mar 26, 2014 at 6:57 PM, Kostya Serebryany <span dir="ltr"><<a href="mailto:kcc@google.com" target="_blank">kcc@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><div dir="ltr"><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Mar 26, 2014 at 6:48 PM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The interceptors have code that after macro expansion ends up looking like<br>
<br>
extern "C" void memalign()<br>
    __attribute__((weak, alias("__interceptor_memalign")));<br>
extern "C" void __interceptor_memalign() {}<br>
extern "C" void __interceptor___libc_memalign()<br>
    __attribute__((alias("memalign")));<br>
<br>
That is,<br>
* __interceptor_memalign is a function<br>
* memalign is a weak alias to __interceptor_memalign<br>
* __interceptor___libc_memalign is an alias to memalign<br>
<br>
Both gcc and clang produce assembly that look like<br>
<br>
__interceptor_memalign:<br>
...<br>
        .weak   memalign<br>
memalign = __interceptor_memalign<br>
        .globl  __interceptor___libc_memalign<br>
__interceptor___libc_memalign = memalign<br>
<br>
What it means in the end is that we have 3 symbols pointing to the<br>
same position in the file, one of which is weak:<br>
<br>
     8: 0000000000000000     1 FUNC    GLOBAL DEFAULT    1<br>
__interceptor_memalign<br>
     9: 0000000000000000     1 FUNC    WEAK   DEFAULT    1 memalign<br>
    10: 0000000000000000     1 FUNC    GLOBAL DEFAULT    1<br>
__interceptor___libc_memalign<br>
<br>
In particular, note that __interceptor___libc_memalign will always<br>
point to __interceptor_memalign, even if we do link in a strong symbol<br>
for memalign. In fact, the above code produces exactly the same binary<br>
as<br>
<br>
extern "C" void memalign()<br>
    __attribute__((weak, alias("__interceptor_memalign")));<br>
extern "C" void __interceptor_memalign() {}<br>
extern "C" void __interceptor___libc_memalign()<br>
    __attribute__((alias("__interceptor_memalign")));<br>
<br>
If nothing else, the attached patch makes it more obvious what is<br>
going on. I found this when I disallowed alias to weak aliases in the<br>
IR, since there is no way to properly represent them in object files.<br>
In now realize that I also have to change clang to produce a clear<br>
error message, but we should probably fix compiler-rt first.<br>
<br>
Cheers,<br>
Rafael<br>
</blockquote></div><br></div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Alexey Samsonov, MSK</div>
</div>