From patchwork Fri Mar 10 11:39:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18379 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 71936BE080 for ; Fri, 10 Mar 2023 11:39:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A408D626C5; Fri, 10 Mar 2023 12:39:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1678448352; bh=KVVx+zPzvlfOxsO8zlIx4Nr2HHOXITXdbjYKFMboXNs=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=cYKTIsdwjDZEK7TA2jq9AjUMbCn8SOnUV1IDLbA7Q9ver4HxmrNyxf5fATbZ+88hN RAKHVzJWinxO0r4DvN2FR7j7qbKdrkIRKSERFz+U7JjuYP5+DdV/7GawH8Z9jrkHKt hjG75ghXDc+vbu67pC8682KmSQxzP9qSi1jDRKS0m3pHCqlJIIOf3z5ULxnAvXJrUj tIzE3S1xv57ecSJocrUs1rc5R1Et+HC7kL3nU7BxeZCeJKKzm7GASfwPln02TY6F1w SOS3cMfqOlvKOia0z/in29/8CAgcweEFnTrJGyDk5Oc75/vveLKYoXSsJ7Xlk9kILG 9DGq/EBOvv3Xw== Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8BC45603B1 for ; Fri, 10 Mar 2023 12:39:10 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="tkEoCDSt"; dkim-atps=neutral Received: by mail-wm1-x329.google.com with SMTP id t25-20020a1c7719000000b003eb052cc5ccso5779957wmi.4 for ; Fri, 10 Mar 2023 03:39:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1678448350; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=9XQ6KhTL4PCbVABYwrsAcUl+kxKFDislxrgLWNXk3jQ=; b=tkEoCDStbYrvmfV9ZmEQpoeA+SFcwNjYiVHpcouoBdHbYIi/Eh+XDT/NRDCDnGo//e WlspoPwb8eetP8ACpHz93EZtb8qlE1AbJTJZ/Baj9o5p03lF4iau8c+El+AJLbox8SbT OPF0HFeuzvsIyAk3Unl+zI8ewUWaHpE4JQH4NsSDTHHBUnygpQ8aYcE9CUlODGNMsC9p N/z+lwPJJSUkSR1TgywrrS48RAWZ0943yoXY6bv40pvoUgLvNj3P/9ck9tr7H307U6Xs bPPRpJe5vGq6QOxTEe2v5lQ9l5C9RMEScAnLv5UdFYSv1WkU8Jye07CLexoxBPXw8NKk VjVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678448350; 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=9XQ6KhTL4PCbVABYwrsAcUl+kxKFDislxrgLWNXk3jQ=; b=aWSoT0RfL72dt8hKvZfACOxJntQt6CkEkSyTRy8NcYbGTRbwkD7i6Em9jGE159phC5 w468F+2XoyiTuOGveuhUBVOV/XYalrOqpoEYZ0Ru+RWydI4fjtn3PRg6OW13sufZJWFV LkAuZlNWRx53VLf8n1HCyH8jQuz7wssio7U7DUwtVxnxqjNUD5Kf+/VIEiosxFng+G2J ZuDevUFB7LAMi1tAZOAlXSDyMojwOeDAoKYRf+Z+35NUb34aYuyj9dPKvExqwG2yN/li PDHudfZEhjS14DF2x0w2z/WTeGL6Z2KR4W/gvrNHzgPYex5NAknQSpgVHlfcVA0OBYEM 8nJQ== X-Gm-Message-State: AO0yUKV1b0Qi6F4i51odlo2bDPPhFb3vjxOUN8rhB5MJvPsZkb5VaoEa A8B9dBOhaOlecUryrEd98hBdBcdVP2Ds3G2ZdItlDg== X-Google-Smtp-Source: AK7set924wU3pfCzfGRs75Y310TWN0Wjo3Z75iDzVCvVNMeduMx0u1/0IXRsjrJ/5s2pE4vOX8osgw== X-Received: by 2002:a05:600c:4453:b0:3eb:389d:156c with SMTP id v19-20020a05600c445300b003eb389d156cmr2366988wmn.37.1678448349783; Fri, 10 Mar 2023 03:39:09 -0800 (PST) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id 4-20020a05600c024400b003e2096da239sm2706389wmj.7.2023.03.10.03.39.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 03:39:09 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Fri, 10 Mar 2023 11:39:11 +0000 Message-Id: <20230310113911.30842-1-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] 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 Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/cam_helper.cpp | 14 +++++++++++--- src/ipa/raspberrypi/controller/algorithm.cpp | 15 ++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp index d90ac1deda47..ddd5e9a4fef2 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; } diff --git a/src/ipa/raspberrypi/controller/algorithm.cpp b/src/ipa/raspberrypi/controller/algorithm.cpp index 6d91ee292bd1..a957fde520c2 100644 --- a/src/ipa/raspberrypi/controller/algorithm.cpp +++ b/src/ipa/raspberrypi/controller/algorithm.cpp @@ -34,14 +34,23 @@ void Algorithm::process([[maybe_unused]] StatisticsPtr &stats, /* For registering algorithms with the system: */ -static std::map algorithms; -std::map const &RPiController::getAlgorithms() +namespace { + +std::map &algorithms() { + static std::map algorithms; return algorithms; } +} /* namespace */ + +std::map const &RPiController::getAlgorithms() +{ + return algorithms(); +} + RegisterAlgorithm::RegisterAlgorithm(char const *name, AlgoCreateFunc createFunc) { - algorithms[std::string(name)] = createFunc; + algorithms()[std::string(name)] = createFunc; }