<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi Andres,<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">There's still a smaller leak, unfortunately.</blockquote><div><br></div><div>Thanks very much for catching this!</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">but when using -fsanitize-leaks I see:<br>Direct leak of 9192 byte(s) in 383 object(s) allocated from:</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><snip/><br>which seems to suggest that somehow there's a reference too many?</blockquote><div><br></div><div>24bytes / object -- Looks like I managed module ownership correctly but leaked the ThreadSafeModule container. This should be fixed in 5044196b412f.</div><div><br></div><div>-- Lang.</div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 1, 2020 at 2:35 PM Andres Freund <<a href="mailto:andres@anarazel.de">andres@anarazel.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
On 2020-09-30 21:31:33 -0700, Lang Hames wrote:<br>
> I've taken a first shot at hooking RTDyldObjectLinkingLayer up to the<br>
> ResourceTracker API in 7436b2ab2428. Could you let me know whether that<br>
> fixes the leak you were seeing?<br>
<br>
It did improve the situation significantly, thanks!<br>
<br>
There's still a smaller leak, unfortunately. The function comments for<br>
modules say that:<br>
<br>
/**<br>
 * Create a ThreadSafeModule wrapper around the given LLVM module. This takes<br>
 * ownership of the M argument which should not be disposed of or referenced<br>
 * after this function returns.<br>
 *<br>
 * Ownership of the ThreadSafeModule is unique: If it is transferred to the JIT<br>
 * (e.g. by LLVMOrcLLJITAddLLVMIRModule), in which case the client is no longer<br>
 * responsible for it. If it is not transferred to the JIT then the client<br>
 * should call LLVMOrcDisposeThreadSafeModule to dispose of it.<br>
 */<br>
LLVMOrcThreadSafeModuleRef<br>
LLVMOrcCreateNewThreadSafeModule(LLVMModuleRef M,<br>
                                 LLVMOrcThreadSafeContextRef TSCtx);<br>
<br>
/**<br>
 * Dispose of a ThreadSafeModule. This should only be called if ownership has<br>
 * not been passed to LLJIT (e.g. because some error prevented the client from<br>
 * adding this to the JIT).<br>
 */<br>
void LLVMOrcDisposeThreadSafeModule(LLVMOrcThreadSafeModuleRef TSM);<br>
<br>
but when using -fsanitize-leaks I see:<br>
<br>
Direct leak of 9192 byte(s) in 383 object(s) allocated from:<br>
    #0 0x7fe249127670 in operator new(unsigned long) (/lib/x86_64-linux-gnu/liblsan.so.0+0xf670)<br>
    #1 0x7fe1bfc1cbc0 in LLVMOrcCreateNewThreadSafeModule (/home/andres/build/llvm-project/master/debug/install/lib/libLLVMOrcJIT.so.12git+0x38bbc0)<br>
    #2 0x7fe245f6ea6d in llvm_compile_module /home/andres/src/postgresql/src/backend/jit/llvm/llvmjit.c:606<br>
    #3 0x7fe245f6e0b0 in llvm_get_function /home/andres/src/postgresql/src/backend/jit/llvm/llvmjit.c:275<br>
    #4 0x7fe245f809f1 in ExecRunCompiledExpr /home/andres/src/postgresql/src/backend/jit/llvm/llvmjit_expr.c:2410<br>
    #5 0x5633fbb6c17f in ExecEvalExpr /home/andres/src/postgresql/src/include/executor/executor.h:294<br>
<br>
for modules which are passed to LLVMOrcLLJITAddLLVMIRModule:<br>
                ts_module = LLVMOrcCreateNewThreadSafeModule(context->module, llvm_ts_context);<br>
                rt = LLVMOrcJITDylibCreateResourceTracker(jd);<br>
                error = LLVMOrcLLJITAddLLVMIRModule(compile_orc, jd, ts_module, rt);<br>
<br>
which seems to suggest that somehow there's a reference too many?<br>
<br>
Greetings,<br>
<br>
Andres Freund<br>
</blockquote></div>