<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On 26 May 2016 at 16:46, Mehdi Amini <span dir="ltr"><<a href="mailto:mehdi.amini@apple.com" target="_blank">mehdi.amini@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class=""><br>
> On May 25, 2016, at 6:05 AM, Pierre Gagelin via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
> Hi everyone,<br>
><br>
> I am having troubles but this shouldn't be hard to solve for many people here. I am beginning a runtime feature for the BoundsChecking pass and I want to replace the libc malloc&free. I followed the design of AddressSanitizer (Asan) and tried to use the INTERCEPTOR macro from the interception.h file of compiler-rt library.<br>
><br>
> Here is the problem. The file I modify (BoundsCheking.cpp) is in lib/Transforms/Instrumentation/ and I can't include properly interception.h (which is in projects/compiler-rt/lib/interception/).<br>
<br>
</span>Something does not make sense to me here: lib/Transforms/... is about stuff that will transform/generate code, it does not contain code that will be part of the final binary. So this transform may generates calls to your runtime, but should not need the runtime to operate.<br>
<span class=""><font color="#888888"><br></font></span></blockquote><div><br></div><div>Yes I know this does not make sense. That's why I asked for some help to clear the design (in my head and also in the code).<br><br></div><div>As I said further in the message, when I analyzed ASan I found the runtime could be called by instrumented code through the function __asan_init() but I haven't managed to reproduce the mechanism. Though I haven't spend much time on it as I thought maybe another solution existed or someone could explain it to me easily.<br><br></div><div>But as you said it could be the regular way to do it I looked a bit deeper and it appears to be this pattern:<br></div><div>  - the doInitialization of the FunctionPass (which as more access than the runOnFunction) calls ModuleUtils createSanitizerCtorAndInitFunctions function to get two pointers (constructor_func, init_func)<br></div><div>  - stores it in the FunctionPass structure<br></div><div>  - runOnFunction may then call init_func via the IRBuilder when needed.<br></div><div>Am I right? I'll try to use it the same way.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class=""><font color="#888888">
--<br>
Mehdi<br></font></span></blockquote><div><br></div><div>Thank you Mehdi!<br></div><div>Pierre <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class=""><font color="#888888">
</font></span><span class="im"><br>
<br>
<br>
> I looked at the CMakeLists.txt and how other files included interception.h but they are all from compiler-rt lib directory.<br>
><br>
> I assume this is normal as runtime project should be developped under the correct directory but I don't see how this should be designed in order that the code optimized by BoundsCheking Pass uses my own malloc&free functions.<br>
><br>
> I spent quite some time on Asan runtime code and found that runtime could be initialized with a call to __asan_init() (function defined in asan_rtl.cc) from the instrumented code directly but I don't know if it's the only way to do it or how to reproduce it...<br>
><br>
> So to resume, I want to make my own malloc and free function to be called by the code I instrument with BoundsChecking. Any suggestion is welcome =)<br>
><br>
> Thanks,<br>
> Pierre<br>
</span><div class=""><div class="h5">> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br>
</div></div></blockquote></div><br></div></div>