Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: LSAN reports leaks in ONNX frontend #24632

Open
3 tasks done
vient opened this issue May 22, 2024 · 1 comment
Open
3 tasks done

[Bug]: LSAN reports leaks in ONNX frontend #24632

vient opened this issue May 22, 2024 · 1 comment
Assignees
Labels
bug Something isn't working support_request

Comments

@vient
Copy link

vient commented May 22, 2024

OpenVINO Version

2024.0.0

Operating System

Ubuntu 20.04 (LTS)

Device used for inference

CPU

Framework

None

Model used

No response

Issue description

ONNX frontend uses protobuf library which allocates some memory on startup and expects user to call google::protobuf::ShutdownProtobufLibrary() on exit. OpenVINO does it here https://github.com/openvinotoolkit/openvino/blob/releases/2024/0/src/frontends/common/shutdown_protobuf/shutdown_protobuf.cpp#L27-L30 but, at least in my builds, this function does not get called, it is not even present in final libopenvino_onnx_frontend.so.2024.0.0.

I've checked that it is there in libopenvino_protobuf_shutdown.a, and the issue seems to be that __attribute__((destructor)) does nothing, library_unload is not actually registered as destructor. Adding -Wl,--whole-archive to libopenvino_protobuf_shutdown.a linkage does not help - library_unload is present in final .so after this but is not called anywhere.

I've fixed this for myself by replacing this function with

struct ProtobufsPleaseShutdown {
    ~ProtobufsPleaseShutdown() {
        google::protobuf::ShutdownProtobufLibrary();
    }
} protobuf_killer;

Step-by-step reproduction

No response

Relevant log output

No response

Issue submission checklist

  • I'm reporting an issue. It's not a question.
  • I checked the problem with the documentation, FAQ, open issues, Stack Overflow, etc., and have not found a solution.
  • There is reproducer code and related data files such as images, videos, models, etc.
@vient vient added bug Something isn't working support_request labels May 22, 2024
@vient
Copy link
Author

vient commented May 22, 2024

Correction: I also changed openvino::protobuf_shutdown to "$<LINK_LIBRARY:WHOLE_ARCHIVE,openvino::protobuf_shutdown>" here https://github.com/openvinotoolkit/openvino/blob/releases/2024/0/cmake/developer_package/frontends/frontends.cmake#L204. Without it linker throws away protobuf_killer object. Maybe it is enough to declare it as extern "C" or explicitly set visibility instead, did not try it.

LINK_LIBRARY:WHOLE_ARCHIVE is pretty fresh, don't know what cmake version you target. It it is too new, it is possible to create a proxy library instead which has explicit -Wl,--whole-archive in its link options.

Note that whole-archive does not help by itself, I still needed to replace destructor function with global object.

My toolchain is LLVM 18, GCC 14 (stdlib provider), cmake 3.29, ninja 1.11 on Ubuntu 20.04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working support_request
Projects
None yet
Development

No branches or pull requests

2 participants