From patchwork Wed Feb 5 13:04:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 2771 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 03C8760444 for ; Wed, 5 Feb 2020 14:04:26 +0100 (CET) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9507352F; Wed, 5 Feb 2020 14:04:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1580907865; bh=t9cqojs86Tp/WE1nUKpMnhO2V9ifQ5SLP+hE2LbOlfU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gy7dV5aPaxu6M6pwlewS4gAGaN4yy+mzKZb7KtnholQHqhoNWe4RdpaN5GBRqPXMj lJxgQBoLAUuLOSyXrLDLoUXw/JkJsK2gZMtbIGfwbInRJh4xHZUKaTco/B/+/7xqGC BpOUcq4guWm4mpmy/yntlMp3dI/R1qnVeiz31fFM= From: Kieran Bingham To: LibCamera Devel Date: Wed, 5 Feb 2020 13:04:16 +0000 Message-Id: <20200205130420.8736-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200205130420.8736-1-kieran.bingham@ideasonboard.com> References: <20200205130420.8736-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/5] libcamera: utils: Provide helper to get dynamic library runpath 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-List-Received-Date: Wed, 05 Feb 2020 13:04:26 -0000 Provide a helper that will identify the DT_RUNPATH string from the ELF dynamic library string table entries. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/libcamera/include/utils.h | 1 + src/libcamera/utils.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h index e467eb21c518..069b327bb436 100644 --- a/src/libcamera/include/utils.h +++ b/src/libcamera/include/utils.h @@ -33,6 +33,7 @@ namespace utils { const char *basename(const char *path); char *secure_getenv(const char *name); +const char *get_runpath(); template unsigned int set_overlap(InputIt1 first1, InputIt1 last1, diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp index 4beffdab5eb6..e48cf2b6a48e 100644 --- a/src/libcamera/utils.cpp +++ b/src/libcamera/utils.cpp @@ -7,7 +7,9 @@ #include "utils.h" +#include #include +#include #include #include #include @@ -70,6 +72,30 @@ char *secure_getenv(const char *name) #endif } +/** + * \brief Obtain the runpath string from the dynamic symbol table + * \returns a const char pointer to the runpath entry in the elf string table + * or NULL if it is not found. + */ +const char *get_runpath() +{ + const ElfW(Dyn) *dyn = _DYNAMIC; + const ElfW(Dyn) *runpath = NULL; + const char *strtab = NULL; + + for (; dyn->d_tag != DT_NULL; ++dyn) { + if (dyn->d_tag == DT_STRTAB) + strtab = reinterpret_cast(dyn->d_un.d_val); + else if (dyn->d_tag == DT_RUNPATH) + runpath = dyn; + } + + if (strtab && runpath) + return strtab + runpath->d_un.d_val; + + return NULL; +} + /** * \fn libcamera::utils::set_overlap(InputIt1 first1, InputIt1 last1, * InputIt2 first2, InputIt2 last2)