From patchwork Fri Mar 10 09:51:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18378 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 7D8D8BE080 for ; Fri, 10 Mar 2023 09:51:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DD143626A2; Fri, 10 Mar 2023 10:51:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1678441890; bh=zlQETCuFOucjX0qe6NOT3NOLu4uolzRRmXxqZ+0Tmtg=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=dkelUFXnUYPMfV0VCjJQuGQrMefQUwRpzGMsNBfy4aerCu5toz5mHUSpyHFcKojGh W439IsdQibsjqb/Xrnd0ABcCK7QMMZ4+MnqJF3PA99eVe9FrkIW7QGHbIA33T0OK2w 2AaPiLreGkxw9Q8GPtO7i1D3+Ie74cixnIVEhQ3NKLvXoOoCIjJydx8VSTL+ZKUW9M PctEvGSa7lnbUnvWsAX1Qm/tzPrtiF8uxs4vG6ZycrsGA/s2DjXM9m+7iTvkAzbnqP texAAtbper86SXYlASaq4n4xDnl3EGG5lQh8cHD69ZWmWUP2zlT4dV5u1aNRKuEIXa BxWCr0SItXiAg== Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7A7E862661 for ; Fri, 10 Mar 2023 10:51:28 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="IGFUKW1F"; dkim-atps=neutral Received: by mail-wr1-x435.google.com with SMTP id r18so4488115wrx.1 for ; Fri, 10 Mar 2023 01:51:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1678441887; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=AFMMmMHsBE+gdnQZvIacaFiKKRakqOT4N4CLzRR9FN4=; b=IGFUKW1Fezm4xcTFRbnH1F779aBWCj/GQd/TZNXT7ex6NtKdV44yw7r9e71AhHNpeh /TIf86sx1q+ZC3dDY4VjCxeOQofps+LEzHbUhXL7meW5jpLllKETxuUCKIzNqrddiLQX dJ6G4oR6mah9XUUb5Y4uRa/odIaJZD+ykcGEvURHtuMWWixn3QezWeH1IgxlOfKc00ge RjZ6ThX2xJ2R2HWa1dXta7ZzOCCeu1aJykNfulqa0Ge0TfPTrfuDDM0rUgLL3YWbrvqY iHzSGxNnw49mkErfz1qZnAlM1XPgMgOU4Py2NvcEb0N+PpVP+0mnGYRhOX08bxV8l6Nt Xsrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678441887; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AFMMmMHsBE+gdnQZvIacaFiKKRakqOT4N4CLzRR9FN4=; b=37gc+C4VOBWfXEtYRI9fS/rPLTjhFM1C51lq8HaPhCoEhfpFFBfkt0nlN/t7SescZS Aj1crbEcQ4xUNYxJnKMPCpHQ2gFgWzXQYmgEFtb/qBXpFp2IGK8qDSRczy9CH+o1aLqm hM4PsI8VH2clJUrWeKo9zFV8gXHPfPLoXR6VPCMtUNQ8Jawj+13LgYgj3Ht2R0vU3XNn bWtPU9MfotorkkFH63bJK2Gtp+Ox4Ngjg7yACUEU1uPQ6xplhQ1n2Q8K3JtZI0coJHHP 0Ygq7vVR/SUUsDnDynGWN+oXfVbX2b2YRTmgUOiPyc6tARk+uxMR/TR0nJ29buvZ0l5D Ecdg== X-Gm-Message-State: AO0yUKXl0YIyostFHrGE1xWm8D2xWR7lHewXJ5NIw+C0zdXpBZXm3E57 31KGwHfHE8192EAkS9KW9gdxClj39ek0S58DkjehTg== X-Google-Smtp-Source: AK7set/2I+twGfuO5J24SyhEqUYgG506MfhUSeC2Fve/ONcRGZDPkbp7lmH6v0yDLO6cQSKTPfQWZQ== X-Received: by 2002:a5d:6acd:0:b0:2cd:e0a8:f2de with SMTP id u13-20020a5d6acd000000b002cde0a8f2demr15428357wrw.12.1678441887620; Fri, 10 Mar 2023 01:51:27 -0800 (PST) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id s11-20020a5d4ecb000000b002c55efa9cbesm1686058wrv.39.2023.03.10.01.51.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 01:51:26 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Fri, 10 Mar 2023 09:51:26 +0000 Message-Id: <20230310095126.27236-1-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] ipa: raspberrypi: Fix crash under LTO X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Dave Jones Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Dave Jones 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 --- src/ipa/raspberrypi/cam_helper.cpp | 16 +++++++++++++--- src/ipa/raspberrypi/controller/algorithm.cpp | 19 +++++++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp index d90ac1deda47..efe453dc6135 100644 --- a/src/ipa/raspberrypi/cam_helper.cpp +++ b/src/ipa/raspberrypi/cam_helper.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include "libcamera/internal/v4l2_videodevice.h" @@ -25,7 +26,16 @@ namespace libcamera { LOG_DECLARE_CATEGORY(IPARPI) } -static std::map camHelpers; +namespace { + +std::map &camHelpers() +{ + static std::unique_ptr> obj = + std::make_unique>(); + return *obj; +} + +} /* namespace */ CamHelper *CamHelper::create(std::string const &camName) { @@ -33,7 +43,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 +263,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; } diff --git a/src/ipa/raspberrypi/controller/algorithm.cpp b/src/ipa/raspberrypi/controller/algorithm.cpp index 6d91ee292bd1..2650f98bee5b 100644 --- a/src/ipa/raspberrypi/controller/algorithm.cpp +++ b/src/ipa/raspberrypi/controller/algorithm.cpp @@ -4,9 +4,10 @@ * * algorithm.cpp - ISP control algorithms */ - #include "algorithm.h" +#include + using namespace RPiController; int Algorithm::read([[maybe_unused]] const libcamera::YamlObject ¶ms) @@ -34,14 +35,24 @@ void Algorithm::process([[maybe_unused]] StatisticsPtr &stats, /* For registering algorithms with the system: */ -static std::map algorithms; +namespace { + +static std::map &algorithms() +{ + static std::unique_ptr> obj = + std::make_unique>(); + return *obj; +} + +} /* namespace */ + std::map const &RPiController::getAlgorithms() { - return algorithms; + return algorithms(); } RegisterAlgorithm::RegisterAlgorithm(char const *name, AlgoCreateFunc createFunc) { - algorithms[std::string(name)] = createFunc; + algorithms()[std::string(name)] = createFunc; }