llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.24k stars 12.07k forks source link

[MLIR][JIT] memory leak found in mlir JitRunner #114018

Open wr-web opened 3 weeks ago

wr-web commented 3 weeks ago

git version: c104d79ec6b278fcc0d2df18c7b5452fb7e7e5d3 system:

LSB Version:    core-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.6 LTS
Release:        20.04
Codename:       focal

reproduce:

mlir-opt ~/llvm-project/mlir/test/Integration/Dialect/MemRef/print-memref.mlir  -one-shot-bufferize="bufferize-function-boundaries" --canonicalize    -finalize-memref-to-llvm   -convert-func-to-llvm -reconcile-unrealized-casts | ~/llvm-project/build/bin/mlir-cpu-runner   -e entry -entry-point-result=void    -shared-libs=$HOME/llvm-project/build/lib/libmlir_c_runner_utils.so,$HOME/llvm-project/build/lib/libmlir_runner_utils.so

bug report by LeakSanitizer:

=================================================================
==1097093==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 208 byte(s) in 1 object(s) allocated from:
    #0 0x556ae47a098e in malloc (/home/wangrui/llvm-project/build/bin/mlir-cpu-runner+0x10498e) (BuildId: 7f789079801dace4)
    #1 0x7fc20526c584  (<unknown module>)
    #2 0x7fc252d92d06 in compileAndExecuteVoidFunction((anonymous namespace)::Options&, mlir::Operation*, llvm::StringRef, (anonymous namespace)::CompileAndExecuteConfig, std::unique_ptr<llvm::TargetMachine, std::default_delete<llvm::TargetMachine>>) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:234:10
    #3 0x7fc252d8c7d6 in mlir::JitRunnerMain(int, char**, mlir::DialectRegistry const&, mlir::JitRunnerConfig) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:391:23
    #4 0x556ae47dfa6f in main /home/wangrui/llvm-project/mlir/tools/mlir-cpu-runner/mlir-cpu-runner.cpp:33:10
    #5 0x7fc23910d082 in __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:308:16

Direct leak of 136 byte(s) in 1 object(s) allocated from:
    #0 0x556ae47a098e in malloc (/home/wangrui/llvm-project/build/bin/mlir-cpu-runner+0x10498e) (BuildId: 7f789079801dace4)
    #1 0x7fc20526c335  (<unknown module>)
    #2 0x7fc252d92d06 in compileAndExecuteVoidFunction((anonymous namespace)::Options&, mlir::Operation*, llvm::StringRef, (anonymous namespace)::CompileAndExecuteConfig, std::unique_ptr<llvm::TargetMachine, std::default_delete<llvm::TargetMachine>>) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:234:10
    #3 0x7fc252d8c7d6 in mlir::JitRunnerMain(int, char**, mlir::DialectRegistry const&, mlir::JitRunnerConfig) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:391:23
    #4 0x556ae47dfa6f in main /home/wangrui/llvm-project/mlir/tools/mlir-cpu-runner/mlir-cpu-runner.cpp:33:10
    #5 0x7fc23910d082 in __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:308:16

Direct leak of 136 byte(s) in 1 object(s) allocated from:
    #0 0x556ae47a098e in malloc (/home/wangrui/llvm-project/build/bin/mlir-cpu-runner+0x10498e) (BuildId: 7f789079801dace4)
    #1 0x7fc20526c612  (<unknown module>)
    #2 0x7fc252d92d06 in compileAndExecuteVoidFunction((anonymous namespace)::Options&, mlir::Operation*, llvm::StringRef, (anonymous namespace)::CompileAndExecuteConfig, std::unique_ptr<llvm::TargetMachine, std::default_delete<llvm::TargetMachine>>) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:234:10
    #3 0x7fc252d8c7d6 in mlir::JitRunnerMain(int, char**, mlir::DialectRegistry const&, mlir::JitRunnerConfig) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:391:23
    #4 0x556ae47dfa6f in main /home/wangrui/llvm-project/mlir/tools/mlir-cpu-runner/mlir-cpu-runner.cpp:33:10
    #5 0x7fc23910d082 in __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:308:16

Direct leak of 136 byte(s) in 1 object(s) allocated from:
    #0 0x556ae47a098e in malloc (/home/wangrui/llvm-project/build/bin/mlir-cpu-runner+0x10498e) (BuildId: 7f789079801dace4)
    #1 0x7fc20526c4a6  (<unknown module>)
    #2 0x7fc252d92d06 in compileAndExecuteVoidFunction((anonymous namespace)::Options&, mlir::Operation*, llvm::StringRef, (anonymous namespace)::CompileAndExecuteConfig, std::unique_ptr<llvm::TargetMachine, std::default_delete<llvm::TargetMachine>>) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:234:10
    #3 0x7fc252d8c7d6 in mlir::JitRunnerMain(int, char**, mlir::DialectRegistry const&, mlir::JitRunnerConfig) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:391:23
    #4 0x556ae47dfa6f in main /home/wangrui/llvm-project/mlir/tools/mlir-cpu-runner/mlir-cpu-runner.cpp:33:10
    #5 0x7fc23910d082 in __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:308:16

Direct leak of 136 byte(s) in 1 object(s) allocated from:
    #0 0x556ae47a098e in malloc (/home/wangrui/llvm-project/build/bin/mlir-cpu-runner+0x10498e) (BuildId: 7f789079801dace4)
    #1 0x7fc20526c515  (<unknown module>)
    #2 0x7fc252d92d06 in compileAndExecuteVoidFunction((anonymous namespace)::Options&, mlir::Operation*, llvm::StringRef, (anonymous namespace)::CompileAndExecuteConfig, std::unique_ptr<llvm::TargetMachine, std::default_delete<llvm::TargetMachine>>) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:234:10
    #3 0x7fc252d8c7d6 in mlir::JitRunnerMain(int, char**, mlir::DialectRegistry const&, mlir::JitRunnerConfig) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:391:23
    #4 0x556ae47dfa6f in main /home/wangrui/llvm-project/mlir/tools/mlir-cpu-runner/mlir-cpu-runner.cpp:33:10
    #5 0x7fc23910d082 in __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:308:16

Direct leak of 100 byte(s) in 1 object(s) allocated from:
    #0 0x556ae47a098e in malloc (/home/wangrui/llvm-project/build/bin/mlir-cpu-runner+0x10498e) (BuildId: 7f789079801dace4)
    #1 0x7fc20526c451  (<unknown module>)
    #2 0x7fc252d92d06 in compileAndExecuteVoidFunction((anonymous namespace)::Options&, mlir::Operation*, llvm::StringRef, (anonymous namespace)::CompileAndExecuteConfig, std::unique_ptr<llvm::TargetMachine, std::default_delete<llvm::TargetMachine>>) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:234:10
    #3 0x7fc252d8c7d6 in mlir::JitRunnerMain(int, char**, mlir::DialectRegistry const&, mlir::JitRunnerConfig) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:391:23
    #4 0x556ae47dfa6f in main /home/wangrui/llvm-project/mlir/tools/mlir-cpu-runner/mlir-cpu-runner.cpp:33:10
    #5 0x7fc23910d082 in __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:308:16

Direct leak of 100 byte(s) in 1 object(s) allocated from:
    #0 0x556ae47a098e in malloc (/home/wangrui/llvm-project/build/bin/mlir-cpu-runner+0x10498e) (BuildId: 7f789079801dace4)
    #1 0x7fc20526c2e0  (<unknown module>)
    #2 0x7fc252d92d06 in compileAndExecuteVoidFunction((anonymous namespace)::Options&, mlir::Operation*, llvm::StringRef, (anonymous namespace)::CompileAndExecuteConfig, std::unique_ptr<llvm::TargetMachine, std::default_delete<llvm::TargetMachine>>) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:234:10
    #3 0x7fc252d8c7d6 in mlir::JitRunnerMain(int, char**, mlir::DialectRegistry const&, mlir::JitRunnerConfig) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:391:23
    #4 0x556ae47dfa6f in main /home/wangrui/llvm-project/mlir/tools/mlir-cpu-runner/mlir-cpu-runner.cpp:33:10
    #5 0x7fc23910d082 in __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:308:16

Direct leak of 82 byte(s) in 1 object(s) allocated from:
    #0 0x556ae47a098e in malloc (/home/wangrui/llvm-project/build/bin/mlir-cpu-runner+0x10498e) (BuildId: 7f789079801dace4)
    #1 0x7fc20526c39e  (<unknown module>)
    #2 0x7fc252d92d06 in compileAndExecuteVoidFunction((anonymous namespace)::Options&, mlir::Operation*, llvm::StringRef, (anonymous namespace)::CompileAndExecuteConfig, std::unique_ptr<llvm::TargetMachine, std::default_delete<llvm::TargetMachine>>) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:234:10
    #3 0x7fc252d8c7d6 in mlir::JitRunnerMain(int, char**, mlir::DialectRegistry const&, mlir::JitRunnerConfig) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:391:23
    #4 0x556ae47dfa6f in main /home/wangrui/llvm-project/mlir/tools/mlir-cpu-runner/mlir-cpu-runner.cpp:33:10
    #5 0x7fc23910d082 in __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:308:16

Direct leak of 82 byte(s) in 1 object(s) allocated from:
    #0 0x556ae47a098e in malloc (/home/wangrui/llvm-project/build/bin/mlir-cpu-runner+0x10498e) (BuildId: 7f789079801dace4)
    #1 0x7fc20526c3f2  (<unknown module>)
    #2 0x7fc252d92d06 in compileAndExecuteVoidFunction((anonymous namespace)::Options&, mlir::Operation*, llvm::StringRef, (anonymous namespace)::CompileAndExecuteConfig, std::unique_ptr<llvm::TargetMachine, std::default_delete<llvm::TargetMachine>>) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:234:10
    #3 0x7fc252d8c7d6 in mlir::JitRunnerMain(int, char**, mlir::DialectRegistry const&, mlir::JitRunnerConfig) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:391:23
    #4 0x556ae47dfa6f in main /home/wangrui/llvm-project/mlir/tools/mlir-cpu-runner/mlir-cpu-runner.cpp:33:10
    #5 0x7fc23910d082 in __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:308:16

Direct leak of 82 byte(s) in 1 object(s) allocated from:
    #0 0x556ae47a098e in malloc (/home/wangrui/llvm-project/build/bin/mlir-cpu-runner+0x10498e) (BuildId: 7f789079801dace4)
    #1 0x7fc20526c27e  (<unknown module>)
    #2 0x7fc252d92d06 in compileAndExecuteVoidFunction((anonymous namespace)::Options&, mlir::Operation*, llvm::StringRef, (anonymous namespace)::CompileAndExecuteConfig, std::unique_ptr<llvm::TargetMachine, std::default_delete<llvm::TargetMachine>>) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:234:10
    #3 0x7fc252d8c7d6 in mlir::JitRunnerMain(int, char**, mlir::DialectRegistry const&, mlir::JitRunnerConfig) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:391:23
    #4 0x556ae47dfa6f in main /home/wangrui/llvm-project/mlir/tools/mlir-cpu-runner/mlir-cpu-runner.cpp:33:10
    #5 0x7fc23910d082 in __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:308:16

Direct leak of 73 byte(s) in 1 object(s) allocated from:
    #0 0x556ae47a098e in malloc (/home/wangrui/llvm-project/build/bin/mlir-cpu-runner+0x10498e) (BuildId: 7f789079801dace4)
    #1 0x7fc20526c228  (<unknown module>)
    #2 0x7fc252d92d06 in compileAndExecuteVoidFunction((anonymous namespace)::Options&, mlir::Operation*, llvm::StringRef, (anonymous namespace)::CompileAndExecuteConfig, std::unique_ptr<llvm::TargetMachine, std::default_delete<llvm::TargetMachine>>) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:234:10
    #3 0x7fc252d8c7d6 in mlir::JitRunnerMain(int, char**, mlir::DialectRegistry const&, mlir::JitRunnerConfig) /home/wangrui/llvm-project/mlir/lib/ExecutionEngine/JitRunner.cpp:391:23
    #4 0x556ae47dfa6f in main /home/wangrui/llvm-project/mlir/tools/mlir-cpu-runner/mlir-cpu-runner.cpp:33:10
    #5 0x7fc23910d082 in __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:308:16

SUMMARY: AddressSanitizer: 1271 byte(s) leaked in 11 allocation(s).
wr-web commented 3 weeks ago

I found it leak at https://github.com/llvm/llvm-project/blob/8d38fbf2f027c72332c8ba03ff0ff0f83b4dcf02/mlir/lib/ExecutionEngine/JitRunner.cpp#L214-L215 But it's difficult for me to find out the root cause.