[llvm] 296ccef - [WebAssembly] EmscriptenEHSjLj: Mark __invoke_ functions as imported

Mikael Holmén via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 4 02:04:54 PDT 2020


Hi,

On Fri, 2020-04-03 at 13:10 -0700, Sam Clegg wrote:
> Its hard to see how this change could have triggered a leak.  Are you
> sure it was this commit?

Yes I reran before your commit without complaints and then with
296ccef703 this started happening.

> If you are, I can try to make lsan build locally and reproduce.  I
> don't suppose you are able to symbolize that backtrace can you?

Here:

=================================================================
==23829==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x987410 in operator new(unsigned long)
(/local/repo/bbiswjenk/fem023-eiffel003/workspace/llvm/llvm-master-
sanitize-asan/llvm/build-sana/bin/llc+0x987410)
    #1 0xe08c09 in __allocate /usr/include/c++/v1/new:228:10
    #2 0xe08c09 in allocate /usr/include/c++/v1/memory:1793
    #3 0xe08c09 in allocate /usr/include/c++/v1/memory:1547
    #4 0xe08c09 in __init /usr/include/c++/v1/string:1591
    #5 0xe08c09 in basic_string /usr/include/c++/v1/string:1628
    #6 0xe08c09 in str /local/repo/bbiswjenk/fem023-
eiffel003/workspace/llvm/llvm-master-sanitize-asan/llvm/build-
sana/../include/llvm/ADT/StringRef.h:250
    #7 0xe08c09 in operator basic_string /local/repo/bbiswjenk/fem023-
eiffel003/workspace/llvm/llvm-master-sanitize-asan/llvm/build-
sana/../include/llvm/ADT/StringRef.h:275
    #8 0xe08c09 in llvm::MCSymbolWasm::setImportName(llvm::StringRef)
/local/repo/bbiswjenk/fem023-eiffel003/workspace/llvm/llvm-master-
sanitize-asan/llvm/build-sana/../include/llvm/MC/MCSymbolWasm.h:95
    #9 0x2daf3b2 in
llvm::WebAssemblyAsmPrinter::emitEndOfAsmFile(llvm::Module&)
/local/repo/bbiswjenk/fem023-eiffel003/workspace/llvm/llvm-master-
sanitize-asan/llvm/build-
sana/../lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp:132:14
    #10 0x41bf04a in llvm::AsmPrinter::doFinalization(llvm::Module&)
/local/repo/bbiswjenk/fem023-eiffel003/workspace/llvm/llvm-master-
sanitize-asan/llvm/build-
sana/../lib/CodeGen/AsmPrinter/AsmPrinter.cpp:1715:3
    #11 0x53969fd in llvm::FPPassManager::doFinalization(llvm::Module&)
/local/repo/bbiswjenk/fem023-eiffel003/workspace/llvm/llvm-master-
sanitize-asan/llvm/build-sana/../lib/IR/LegacyPassManager.cpp:1536:41
    #12 0x5397890 in runOnModule /local/repo/bbiswjenk/fem023-
eiffel003/workspace/llvm/llvm-master-sanitize-asan/llvm/build-
sana/../lib/IR/LegacyPassManager.cpp:1612:41
    #13 0x5397890 in llvm::legacy::PassManagerImpl::run(llvm::Module&)
/local/repo/bbiswjenk/fem023-eiffel003/workspace/llvm/llvm-master-
sanitize-asan/llvm/build-sana/../lib/IR/LegacyPassManager.cpp:1695
    #14 0x992e79 in compileModule(char**, llvm::LLVMContext&)
/local/repo/bbiswjenk/fem023-eiffel003/workspace/llvm/llvm-master-
sanitize-asan/llvm/build-sana/../tools/llc/llc.cpp:624:8
    #15 0x98d490 in main /local/repo/bbiswjenk/fem023-
eiffel003/workspace/llvm/llvm-master-sanitize-asan/llvm/build-
sana/../tools/llc/llc.cpp:360:22
    #16 0x7ff9852e7b96 in __libc_start_main /build/glibc-OTsEL5/glibc-
2.27/csu/../csu/libc-start.c:310

SUMMARY: AddressSanitizer: 32 byte(s) leaked in 1 allocation(s).

/Mikael

> 
> On Fri, Apr 3, 2020 at 2:49 AM Mikael Holmén <
> mikael.holmen at ericsson.com> wrote:
> > Hi,
> > 
> > I noticed on one of my organization's build bots that runs with
> > sanatizers that we got a warning about a leak with this commit. So
> > when
> > running the testcase
> >  test/CodeGen/WebAssembly/irreducible-cfg-exceptions.ll
> > 
> > build-sana/bin/llc < test/CodeGen/WebAssembly/irreducible-cfg-
> > exceptions.ll -asm-verbose=false -verify-machineinstrs -disable-
> > block-
> > placement -wasm-disable-explicit-locals -wasm-keep-registers
> > -enable-
> > emscripten-cxx-exceptions | build-sana/bin/FileCheck
> > test/CodeGen/WebAssembly/irreducible-cfg-exceptions.ll
> > 
> > I get
> > 
> > =================================================================
> > ==5081==ERROR: LeakSanitizer: detected memory leaks
> > 
> > Direct leak of 32 byte(s) in 1 object(s) allocated from:
> >     #0 0x421d520  (/data/repo/master/llvm/build-
> > sana/bin/llc+0x421d520)
> >     #1 0x46a9ec9  (/data/repo/master/llvm/build-
> > sana/bin/llc+0x46a9ec9)
> >     #2 0x676cc32  (/data/repo/master/llvm/build-
> > sana/bin/llc+0x676cc32)
> >     #3 0x7bbf0ca  (/data/repo/master/llvm/build-
> > sana/bin/llc+0x7bbf0ca)
> >     #4 0x8e2374d  (/data/repo/master/llvm/build-
> > sana/bin/llc+0x8e2374d)
> >     #5 0x8e245e0  (/data/repo/master/llvm/build-
> > sana/bin/llc+0x8e245e0)
> >     #6 0x4228f89  (/data/repo/master/llvm/build-
> > sana/bin/llc+0x4228f89)
> >     #7 0x42235a0  (/data/repo/master/llvm/build-
> > sana/bin/llc+0x42235a0)
> >     #8 0x7f50ee2f4b96  (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
> > 
> > SUMMARY: AddressSanitizer: 32 byte(s) leaked in 1 allocation(s).
> > 
> > /Mikael
> > 
> > On Wed, 2020-04-01 at 16:33 -0700, Sam Clegg via llvm-commits
> > wrote:
> > > Author: Sam Clegg
> > > Date: 2020-04-01T16:33:33-07:00
> > > New Revision: 296ccef70363df9195bc678ad5501dd44de7f8fb
> > > 
> > > URL: 
> > > 
> > https://protect2.fireeye.com/v1/url?k=6f7ff692-33f65951-6f7fb609-0cc47ad93d36-d092eb1748b9557d&q=1&e=1ca40782-7747-4f20-89e4-55dbb09d830d&u=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fcommit%2F296ccef70363df9195bc678ad5501dd44de7f8fb
> > > DIFF: 
> > > 
> > https://protect2.fireeye.com/v1/url?k=4a3efd3f-16b752fc-4a3ebda4-0cc47ad93d36-ac161843750d844e&q=1&e=1ca40782-7747-4f20-89e4-55dbb09d830d&u=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fcommit%2F296ccef70363df9195bc678ad5501dd44de7f8fb.diff
> > > 
> > > LOG: [WebAssembly] EmscriptenEHSjLj: Mark __invoke_ functions as
> > > imported
> > > 
> > > This means the linker will be expect them be undefined at link
> > time
> > > an
> > > will generate imports from the `env` module rather than reporting
> > > undefined externals.
> > > 
> > > Differential Revision: https://reviews.llvm.org/D77192
> > > 
> > > Added: 
> > >     
> > > 
> > > Modified: 
> > >   
> >  llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
> > >     llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
> > > 
> > > Removed: 
> > >     
> > > 
> > > 
> > >
> > ###################################################################
> > ##
> > > ###########
> > > diff  --git
> > >
> > a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
> > >
> > b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
> > > index 89265a3a9520..c8878a48b243 100644
> > > ---
> > >
> > a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
> > > +++
> > >
> > b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
> > > @@ -344,6 +344,21 @@ static std::string getSignature(FunctionType
> > > *FTy) {
> > >    return Sig;
> > >  }
> > >  
> > > +static void markAsImported(Function *F) {
> > > +  // Tell the linker that this function is expected to be
> > imported
> > > from the
> > > +  // 'env' module.
> > > +  if (!F->hasFnAttribute("wasm-import-module")) {
> > > +    llvm::AttrBuilder B;
> > > +    B.addAttribute("wasm-import-module", "env");
> > > +    F->addAttributes(llvm::AttributeList::FunctionIndex, B);
> > > +  }
> > > +  if (!F->hasFnAttribute("wasm-import-name")) {
> > > +    llvm::AttrBuilder B;
> > > +    B.addAttribute("wasm-import-name", F->getName());
> > > +    F->addAttributes(llvm::AttributeList::FunctionIndex, B);
> > > +  }
> > > +}
> > > +
> > >  // Returns __cxa_find_matching_catch_N function, where N =
> > > NumClauses + 2.
> > >  // This is because a landingpad instruction contains two more
> > > arguments, a
> > >  // personality function and a cleanup bit, and
> > > __cxa_find_matching_catch_N
> > > @@ -360,6 +375,7 @@
> > > WebAssemblyLowerEmscriptenEHSjLj::getFindMatchingCatch(Module &M,
> > >    Function *F = Function::Create(
> > >        FTy, GlobalValue::ExternalLinkage,
> > >        "__cxa_find_matching_catch_" + Twine(NumClauses + 2), &M);
> > > +  markAsImported(F);
> > >    FindMatchingCatches[NumClauses] = F;
> > >    return F;
> > >  }
> > > @@ -469,6 +485,7 @@ Function
> > > *WebAssemblyLowerEmscriptenEHSjLj::getInvokeWrapper(CallOrInvoke
> > *CI)
> > > {
> > >                                          CalleeFTy->isVarArg());
> > >    Function *F =
> > >        Function::Create(FTy, GlobalValue::ExternalLinkage,
> > > "__invoke_" + Sig, M);
> > > +  markAsImported(F);
> > >    InvokeWrappers[Sig] = F;
> > >    return F;
> > >  }
> > > 
> > > diff  --git a/llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
> > > b/llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
> > > index cad6c4ac855b..ad42cc5f8615 100644
> > > --- a/llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
> > > +++ b/llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
> > > @@ -308,6 +308,10 @@ attributes #0 = { returns_twice }
> > >  attributes #1 = { noreturn }
> > >  attributes #2 = { nounwind }
> > >  attributes #3 = { allocsize(0) }
> > > +; CHECK: attributes #{{[0-9]+}} = { "wasm-import-module"="env"
> > > "wasm-import-name"="__invoke_void" }
> > > +; CHECK: attributes #{{[0-9]+}} = { "wasm-import-module"="env"
> > > "wasm-import-name"="__cxa_find_matching_catch_3" }
> > > +; CHECK: attributes #{{[0-9]+}} = { "wasm-import-module"="env"
> > > "wasm-import-name"="__invoke_i8*_i32_%struct.__jmp_buf_tag*" }
> > > +; CHECK: attributes #{{[0-9]+}} = { "wasm-import-module"="env"
> > > "wasm-import-name"="__invoke_void_%struct.__jmp_buf_tag*_i32" }
> > >  ; CHECK: attributes #[[ALLOCSIZE_ATTR]] = { allocsize(1) }
> > >  
> > >  !llvm.dbg.cu = !{!2}
> > > 
> > > 
> > >         
> > > _______________________________________________
> > > llvm-commits mailing list
> > > llvm-commits at lists.llvm.org
> > > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list