From afc5ea57b496c633a1a16c67cf132df6c5ed9b46 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Fri, 10 Mar 2023 11:39:11 +0000 Subject: ipa: raspberrypi: Fix crash under LTO When compiled with LTO (the default on Ubuntu), the global static objects camHelpers and algorithms cause a crash in raspberrypi_ipa_proxy at runtime as they're not allocated by the time the registration routines execute. This is a fairly crude fix which just converts the global static objects into local static objects inside an equivalently named function. Signed-off-by: Dave Jones Signed-off-by: Naushir Patuck Tested-by: Naushir Patuck Reviewed-by: Laurent Pinchart Signed-off-by: Kieran Bingham --- src/ipa/raspberrypi/cam_helper.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/ipa/raspberrypi/cam_helper.cpp') diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp index d90ac1de..ddd5e9a4 100644 --- a/src/ipa/raspberrypi/cam_helper.cpp +++ b/src/ipa/raspberrypi/cam_helper.cpp @@ -25,7 +25,15 @@ namespace libcamera { LOG_DECLARE_CATEGORY(IPARPI) } -static std::map camHelpers; +namespace { + +std::map &camHelpers() +{ + static std::map helpers; + return helpers; +} + +} /* namespace */ CamHelper *CamHelper::create(std::string const &camName) { @@ -33,7 +41,7 @@ CamHelper *CamHelper::create(std::string const &camName) * CamHelpers get registered by static RegisterCamHelper * initialisers. */ - for (auto &p : camHelpers) { + for (auto &p : camHelpers()) { if (camName.find(p.first) != std::string::npos) return p.second(); } @@ -253,5 +261,5 @@ void CamHelper::populateMetadata([[maybe_unused]] const MdParser::RegisterMap &r RegisterCamHelper::RegisterCamHelper(char const *camName, CamHelperCreateFunc createFunc) { - camHelpers[std::string(camName)] = createFunc; + camHelpers()[std::string(camName)] = createFunc; } -- cgit v1.2.1