What's the status of asan support in pytorch?

syheliel: <p>Hi guys, I’ve built pytorch with asan, and I find that simply <code>import torch</code> then exit will trigger the asan’s fault. Is it expected? Here is my build script:</p>
<pre><code class="lang-auto">export DEBUG=1
export USE_CUDA=1
export DEBUG_CUDA=1
export CXXFLAGS="-fsanitize=address"
export CC="gcc"
export CXX="g++"
export USE_OPENMP=0
export USE_MKLDNN=0
export CUDA_HOME="~/micromamba/envs/cuda_env" # this is from conda environment
python ./setup.py develop
</code></pre>
<p>My start script:</p>
<pre><code class="lang-auto">export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.6
export ASAN_OPTIONS="detect_odr_violation=0"
python ./1.py # 1.py just contain `import torch`
</code></pre>
<p>error message:</p>
<pre><code class="lang-auto">Indirect leak of 1 byte(s) in 1 object(s) allocated from:
    #0 0x7f2d5aa5b9a7 in __interceptor_strdup ../../../../src/libsanitizer/asan/asan_interceptors.cpp:454
    #1 0x7f2d4faf464e in pybind11::cpp_function::strdup_guard::operator()(char const*) /home/zhangzihan/pytorch/third_party/pybind11/include/pybind11/pybind11.h:374
    #2 0x7f2d4faf4c37 in pybind11::cpp_function::initialize_generic(std::unique_ptr&lt;pybind11::detail::function_record, pybind11::cpp_function::InitializingFunctionRecordDeleter&gt;&amp;&amp;, char const*, std::type_info const* const*, unsigned long) /home/zhangzihan/pytorch/third_party/pybind11/include/pybind11/pybind11.h:404
    #3 0x7f2d50686f9f in void pybind11::cpp_function::initialize&lt;pybind11::enum_&lt;at::Tag&gt;::enum_&lt;&gt;(pybind11::handle const&amp;, char const*)::{lambda(at::Tag)#2} const&amp;, int, at::Tag&gt;(pybind11::enum_&lt;at::Tag&gt;::enum_&lt;&gt;(pybind11::handle const&amp;, char const*)::{lambda(at::Tag)#2} const&amp;, int (*)(at::Tag)) (/home/zhangzihan/pytorch/torch/lib/libtorch_python.so+0x2c86f9f)
    #4 0x7f2d5067e9a3 in pybind11::cpp_function::cpp_function&lt;pybind11::enum_&lt;at::Tag&gt;::enum_&lt;&gt;(pybind11::handle const&amp;, char const*)::{lambda(at::Tag)#2} const&amp;, , void&gt;(pybind11::enum_&lt;at::Tag&gt;::enum_&lt;&gt;(pybind11::handle const&amp;, char const*)::{lambda(at::Tag)#2} const&amp;) (/home/zhangzihan/pytorch/torch/lib/libtorch_python.so+0x2c7e9a3)
    #5 0x7f2d506772a4 in pybind11::class_&lt;at::Tag&gt;&amp; pybind11::class_&lt;at::Tag&gt;::def_property_readonly&lt;pybind11::enum_&lt;at::Tag&gt;::enum_&lt;&gt;(pybind11::handle const&amp;, char const*)::{lambda(at::Tag)#2}&gt;(char const*, pybind11::enum_&lt;at::Tag&gt;::enum_&lt;&gt;(pybind11::handle const&amp;, char const*)::{lambda(at::Tag)#2} const&amp;) (/home/zhangzihan/pytorch/torch/lib/libtorch_python.so+0x2c772a4)
    #6 0x7f2d506629d9 in pybind11::enum_&lt;at::Tag&gt;::enum_&lt;&gt;(pybind11::handle const&amp;, char const*) /home/zhangzihan/pytorch/third_party/pybind11/include/pybind11/pybind11.h:2251
    #7 0x7f2d50643552 in torch::autograd::initEnumTag(_object*) /home/zhangzihan/pytorch/torch/csrc/autograd/generated/python_enum_tag.cpp:11
    #8 0x7f2d5076b71c in initModule /home/zhangzihan/pytorch/torch/csrc/Module.cpp:1620
    #9 0x7f2d570c5125 in PyInit__C torch/csrc/stub.c:14
    #10 0x5592ee764f1e in _PyImport_LoadDynamicModuleWithSpec /usr/local/src/conda/python-3.10.14/Python/importdl.c:167
    #11 0x5592ee764f1e in _imp_create_dynamic_impl /usr/local/src/conda/python-3.10.14/Python/import.c:2050
    #12 0x5592ee764f1e in _imp_create_dynamic /usr/local/src/conda/python-3.10.14/Python/clinic/import.c.h:330

Indirect leak of 1 byte(s) in 1 object(s) allocated from:
    #0 0x7f2d5aa5b9a7 in __interceptor_strdup ../../../../src/libsanitizer/asan/asan_interceptors.cpp:454
    #1 0x7f2d4faf464e in pybind11::cpp_function::strdup_guard::operator()(char const*) /home/zhangzihan/pytorch/third_party/pybind11/include/pybind11/pybind11.h:374
    #2 0x7f2d4faf4c37 in pybind11::cpp_function::initialize_generic(std::unique_ptr&lt;pybind11::detail::function_record, pybind11::cpp_function::InitializingFunctionRecordDeleter&gt;&amp;&amp;, char const*, std::type_info const* const*, unsigned long) /home/zhangzihan/pytorch/third_party/pybind11/include/pybind11/pybind11.h:404
    #3 0x7f2d51d99461 in void pybind11::cpp_function::initialize&lt;pybind11::enum_&lt;torch::onnx::OperatorExportTypes&gt;::enum_&lt;&gt;(pybind11::handle const&amp;, char const*)::{lambda(torch::onnx::OperatorExportTypes)#2} const&amp;, int, torch::onnx::OperatorExportTypes&gt;(pybind11::enum_&lt;torch::onnx::OperatorExportTypes&gt;::enum_&lt;&gt;(pybind11::handle const&amp;, char const*)::{lambda(torch::onnx::OperatorExportTypes)#2} const&amp;, int (*)(torch::onnx::OperatorExportTypes)) /home/zhangzihan/pytorch/third_party/pybind11/include/pybind11/pybind11.h:346
    #4 0x7f2d51d8f617 in pybind11::cpp_function::cpp_function&lt;pybind11::enum_&lt;torch::onnx::OperatorExportTypes&gt;::enum_&lt;&gt;(pybind11::handle const&amp;, char const*)::{lambda(torch::onnx::OperatorExportTypes)#2} const&amp;, , void&gt;(pybind11::enum_&lt;torch::onnx::OperatorExportTypes&gt;::enum_&lt;&gt;(pybind11::handle const&amp;, char const*)::{lambda(torch::onnx::OperatorExportTypes)#2} const&amp;) /home/zhangzihan/pytorch/third_party/pybind11/include/pybind11/pybind11.h:145
    #5 0x7f2d51d806ac in pybind11::class_&lt;torch::onnx::OperatorExportTypes&gt;&amp; pybind11::class_&lt;torch::onnx::OperatorExportTypes&gt;::def_property_readonly&lt;pybind11::enum_&lt;torch::onnx::OperatorExportTypes&gt;::enum_&lt;&gt;(pybind11::handle const&amp;, char const*)::{lambda(torch::onnx::OperatorExportTypes)#2}&gt;(char const*, pybind11::enum_&lt;torch::onnx::OperatorExportTypes&gt;::enum_&lt;&gt;(pybind11::handle const&amp;, char const*)::{lambda(torch::onnx::OperatorExportTypes)#2} const&amp;) /home/zhangzihan/pytorch/third_party/pybind11/include/pybind11/pybind11.h:1766
    #6 0x7f2d51d7caff in pybind11::enum_&lt;torch::onnx::OperatorExportTypes&gt;::enum_&lt;&gt;(pybind11::handle const&amp;, char const*) /home/zhangzihan/pytorch/third_party/pybind11/include/pybind11/pybind11.h:2251
    #7 0x7f2d51d5c5d4 in torch::onnx::initONNXBindings(_object*) /home/zhangzihan/pytorch/torch/csrc/onnx/init.cpp:283
    #8 0x7f2d5076b70a in initModule /home/zhangzihan/pytorch/torch/csrc/Module.cpp:1619
    #9 0x7f2d570c5125 in PyInit__C torch/csrc/stub.c:14
    #10 0x5592ee764f1e in _PyImport_LoadDynamicModuleWithSpec /usr/local/src/conda/python-3.10.14/Python/importdl.c:167
    #11 0x5592ee764f1e in _imp_create_dynamic_impl /usr/local/src/conda/python-3.10.14/Python/import.c:2050
    #12 0x5592ee764f1e in _imp_create_dynamic /usr/local/src/conda/python-3.10.14/Python/clinic/import.c.h:330

Indirect leak of 1 byte(s) in 1 object(s) allocated from:
    #0 0x7f2d5aa5b9a7 in __interceptor_strdup ../../../../src/libsanitizer/asan/asan_interceptors.cpp:454
    #1 0x7f2d4faf464e in pybind11::cpp_function::strdup_guard::operator()(char const*) /home/zhangzihan/pytorch/third_party/pybind11/include/pybind11/pybind11.h:374
    #2 0x7f2d4faf4c37 in pybind11::cpp_function::initialize_generic(std::unique_ptr&lt;pybind11::detail::function_record, pybind11::cpp_function::InitializingFunctionRecordDeleter&gt;&amp;&amp;, char const*, std::type_info const* const*, unsigned long) /home/zhangzihan/pytorch/third_party/pybind11/include/pybind11/pybind11.h:404
    #3 0x7f2d51d96d63 in void pybind11::cpp_function::initialize&lt;pybind11::enum_&lt;onnx_torch::TensorProto_DataType&gt;::enum_&lt;&gt;(pybind11::handle const&amp;, char const*)::{lambda(onnx_torch::TensorProto_DataType)#2} const&amp;, int, onnx_torch::TensorProto_DataType&gt;(pybind11::enum_&lt;onnx_torch::TensorProto_DataType&gt;::enum_&lt;&gt;(pybind11::handle const&amp;, char const*)::{lambda(onnx_torch::TensorProto_DataType)#2} const&amp;, int (*)(onnx_torch::TensorProto_DataType)) /home/zhangzihan/pytorch/third_party/pybind11/include/pybind11/pybind11.h:346
    #4 0x7f2d51d8dd47 in pybind11::cpp_function::cpp_function&lt;pybind11::enum_&lt;onnx_torch::TensorProto_DataType&gt;::enum_&lt;&gt;(pybind11::handle const&amp;, char const*)::{lambda(onnx_torch::TensorProto_DataType)#2} const&amp;, , void&gt;(pybind11::enum_&lt;onnx_torch::TensorProto_DataType&gt;::enum_&lt;&gt;(pybind11::handle const&amp;, char const*)::{lambda(onnx_torch::TensorProto_DataType)#2} const&amp;) /home/zhangzihan/pytorch/third_party/pybind11/include/pybind11/pybind11.h:145
    #5 0x7f2d51d7f488 in pybind11::class_&lt;onnx_torch::TensorProto_DataType&gt;&amp; pybind11::class_&lt;onnx_torch::TensorProto_DataType&gt;::def_property_readonly&lt;pybind11::enum_&lt;onnx_torch::TensorProto_DataType&gt;::enum_&lt;&gt;(pybind11::handle const&amp;, char const*)::{lambda(onnx_torch::TensorProto_DataType)#2}&gt;(char const*, pybind11::enum_&lt;onnx_torch::TensorProto_DataType&gt;::enum_&lt;&gt;(pybind11::handle const&amp;, char const*)::{lambda(onnx_torch::TensorProto_DataType)#2} const&amp;) /home/zhangzihan/pytorch/third_party/pybind11/include/pybind11/pybind11.h:1766
    #6 0x7f2d51d7bf25 in pybind11::enum_&lt;onnx_torch::TensorProto_DataType&gt;::enum_&lt;&gt;(pybind11::handle const&amp;, char const*) /home/zhangzihan/pytorch/third_party/pybind11/include/pybind11/pybind11.h:2251
    #7 0x7f2d51d5c321 in torch::onnx::initONNXBindings(_object*) /home/zhangzihan/pytorch/torch/csrc/onnx/init.cpp:258
    #8 0x7f2d5076b70a in initModule /home/zhangzihan/pytorch/torch/csrc/Module.cpp:1619
    #9 0x7f2d570c5125 in PyInit__C torch/csrc/stub.c:14
    #10 0x5592ee764f1e in _PyImport_LoadDynamicModuleWithSpec /usr/local/src/conda/python-3.10.14/Python/importdl.c:167
    #11 0x5592ee764f1e in _imp_create_dynamic_impl /usr/local/src/conda/python-3.10.14/Python/import.c:2050
    #12 0x5592ee764f1e in _imp_create_dynamic /usr/local/src/conda/python-3.10.14/Python/clinic/import.c.h:330

SUMMARY: AddressSanitizer: 10486203 byte(s) leaked in 44776 allocation(s).
</code></pre>