From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A27CBA0548 for ; Mon, 8 Feb 2021 17:33:31 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9488D1606FE; Mon, 8 Feb 2021 17:33:31 +0100 (CET) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id 93CAC1606F1; Mon, 8 Feb 2021 17:33:28 +0100 (CET) IronPort-SDR: oxHdzPX3fLJt4/tvwltDY4ET26uBysig6wgBLtgKNOKhwRnU6ZYcgyAGEPCvFzczOpGzsT7BSK 0hfRuaQqIG3g== X-IronPort-AV: E=McAfee;i="6000,8403,9889"; a="180962449" X-IronPort-AV: E=Sophos;i="5.81,162,1610438400"; d="scan'208";a="180962449" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2021 08:33:26 -0800 IronPort-SDR: cPW/7SKSNeggg9caAQ8eK6BUfZBTRXfslgm8PmlX0NcBQKcyXfDIhKrpHmHaEwMzwI6u/CN61j 4JVwtyIT6DwQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,162,1610438400"; d="scan'208";a="418850699" Received: from silpixa00399126.ir.intel.com ([10.237.222.4]) by fmsmga002.fm.intel.com with ESMTP; 08 Feb 2021 08:33:24 -0800 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson , tredaelli@redhat.com, stable@dpdk.org, Maxime Coquelin , David Marchand Date: Mon, 8 Feb 2021 16:33:19 +0000 Message-Id: <20210208163319.507567-1-bruce.richardson@intel.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] [PATCH] eal: fix detection of static or shared DPDK builds X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" When checking the loading of EAL shared lib to see if we have a shared DPDK build, we only want to include part of the ABI version in the check rather than the whole thing. For example, with ABI version 21.1 for DPDK release 21.02, the linker links the binary against librte_eal.so.21, without the ".1". To avoid any further brittleness in this area, we can check for multiple versions when doing the check, since just about any version of EAL implies a shared build. Therefore we check for presence of librte_eal.so with full ABI_VERSION extension, and then repeatedly remove the end part of the filename after the last dot, checking each time. For example (debug log output for static build): EAL: Checking presence of .so 'librte_eal.so.21.1' EAL: Checking presence of .so 'librte_eal.so.21' EAL: Checking presence of .so 'librte_eal.so' EAL: Detected static linkage of DPDK Fixes: 7781950f4d38 ("eal: fix shared lib mode detection") Cc: tredaelli@redhat.com Cc: stable@dpdk.org Signed-off-by: Bruce Richardson --- lib/librte_eal/common/eal_common_options.c | 35 +++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 6b3707725f..94029bf7f1 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -494,6 +494,39 @@ eal_dlopen(const char *pathname) return retval; } +static int +is_shared_build(void) +{ +#define EAL_SO "librte_eal.so" + char soname[32]; + size_t len, minlen = strlen(EAL_SO); + + len = strlcpy(soname, EAL_SO"."ABI_VERSION, sizeof(soname)); + if (len > sizeof(soname)) { + RTE_LOG(ERR, EAL, "Shared lib name too long in shared build check\n"); + len = sizeof(soname) - 1; + } + + while (len >= minlen) { + /* check if we have this .so loaded, if so - shared build */ + RTE_LOG(DEBUG, EAL, "Checking presence of .so '%s'\n", soname); + if (dlopen(soname, RTLD_LAZY | RTLD_NOLOAD) != NULL) { + RTE_LOG(INFO, EAL, "Detected shared linkage of DPDK\n"); + return 1; + } + + /* remove any version numbers off the end to retry */ + while (len-- > 0) + if (soname[len] == '.') { + soname[len] = '\0'; + break; + } + } + + RTE_LOG(INFO, EAL, "Detected static linkage of DPDK\n"); + return 0; +} + int eal_plugins_init(void) { @@ -505,7 +538,7 @@ eal_plugins_init(void) * (Using dlopen with NOLOAD flag on EAL, will return NULL if the EAL * shared library is not already loaded i.e. it's statically linked.) */ - if (dlopen("librte_eal.so."ABI_VERSION, RTLD_LAZY | RTLD_NOLOAD) != NULL && + if (is_shared_build() && *default_solib_dir != '\0' && stat(default_solib_dir, &sb) == 0 && S_ISDIR(sb.st_mode)) -- 2.27.0