From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0C0FEA051C; Fri, 26 Jun 2020 17:00:26 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8C6BE1C1C0; Fri, 26 Jun 2020 17:00:25 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id A03AF1C1BE for ; Fri, 26 Jun 2020 17:00:24 +0200 (CEST) IronPort-SDR: q+qPKiHgnUK/Advwto1qLcaBjSoN7W+XpWYig7aVSnqabbmBSOdwdR8wDV22IfWkIyoTjqU13x Btk/cLGq7LcA== X-IronPort-AV: E=McAfee;i="6000,8403,9663"; a="144439124" X-IronPort-AV: E=Sophos;i="5.75,284,1589266800"; d="scan'208";a="144439124" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2020 08:00:07 -0700 IronPort-SDR: tJDD7NvCsbpiChBtr6+ca1+vB6Y1QY0v3ZxEBsmx7iV12F0C2UIpfKU/27M4qRewC7Xbl7A7pZ 1oPTyxPEd8zg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,284,1589266800"; d="scan'208";a="479849858" Received: from silpixa00399126.ir.intel.com ([10.237.222.84]) by fmsmga006.fm.intel.com with ESMTP; 26 Jun 2020 08:00:08 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson Date: Fri, 26 Jun 2020 15:59:57 +0100 Message-Id: <20200626145957.722089-1-bruce.richardson@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] eal: don't use default library path for static binaries X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" When using statically linked DPDK binaries, the EAL checks the default PMD path and tries to load any drivers there, despite the fact that all drivers are normally linked into the binary. This behaviour can cause issues if the PMD path and lib dir is configured to a non-standard location which is not in the ld.so.conf paths, e.g. a build with prefix set to a home directory location. In a case such as this, EAL will try and (unnecessarily) load the .so driver files but that load will fail as their dependent libraries, such as ethdev, for example, will not be found. Because of this, it is better if statically linked DPDK apps do not load drivers from the standard paths automatically. The user can always have this behaviour by explicitly specifying the path using -d flag, if so desired. Not loading the libraries automatically can also prevent potential issues with a user building and running a statically-linked DPDK binary based off a private copy of DPDK, while there exists on the same machine a system-wide installation of DPDK in the default locations. Without this change, the system-installed drivers will be loaded to the binary alongside the statically-linked drivers, which is not what the user would have intended. To detect whether we are in a statically or dynamically linked binary, we can have EAL try to get a dlopen handle to its own shared library, by calling dlopen with the RTLD_NOLOAD flag. This will return NULL if there is no such shared lib loaded i.e. the code is executing from a static library, or a handle to the lib if it is loaded. Signed-off-by: Bruce Richardson --- lib/librte_eal/common/eal_common_options.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 0901b493c..1d958d11e 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -447,8 +447,15 @@ eal_plugins_init(void) struct shared_driver *solib = NULL; struct stat sb; - if (*default_solib_dir != '\0' && stat(default_solib_dir, &sb) == 0 && - S_ISDIR(sb.st_mode)) + /* if we are not statically linked, add default driver loading + * path if it exists as a directory. + * (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", RTLD_LAZY | RTLD_NOLOAD) != NULL && + *default_solib_dir != '\0' && + stat(default_solib_dir, &sb) == 0 && + S_ISDIR(sb.st_mode)) eal_plugin_add(default_solib_dir); TAILQ_FOREACH(solib, &solib_list, next) { -- 2.25.1