Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2115706ybv; Sun, 23 Feb 2020 23:05:25 -0800 (PST) X-Google-Smtp-Source: APXvYqz4kKuTI5GTAcyhtfqNRiT2Ds2ccNZ+uSvV4PNqr260kuwF3UCCVFXxeI3wgoGNZpGGOWrp X-Received: by 2002:aca:52d0:: with SMTP id g199mr10920724oib.153.1582527925312; Sun, 23 Feb 2020 23:05:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582527925; cv=none; d=google.com; s=arc-20160816; b=03sP3X8vZzT61JTlBZk8dPZmzHy+Yw0e+dzswQdhGPLY/cBcl2zDBJtvsLEMnU+GDV z+gm2L/TdFPy4wyVCCCKPuCC4GJoy5cNl3+jv4Q/JckLc0BROW1AoPh5wTOudcDDpE3z RMvWUGnvDo/1b+D+L1B1dfm3jWQ2chX1rvL/HW0+QP1U7IVwxue1rQo9MyaYxOolPc76 1EIRQjOqIngvN/0zBxrwItw2dCPpdEniWyKpsEZecVFHIiibA6ZXOc0wHoiHIOezVogs 6FKzypi31ZypBiZXCDSRFUKuDe4NF9rYEuieXjxKF7YfKfJ12Qm7qBC/Um9vqcMEu1ry OmJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=2QkVcjWwb41VfZR9OaQrqSLBc/jsDuHXMIExrl6QBnk=; b=pnAmgjj/Ht5AMEJxIlXc2TV8VXPo/H6omUPO26BxzRJL/PCgU1R8MyDXZdBwq5FeP6 JLE2MFiw8dyIw2/qXbT4UYo4vVW9rHG11FFEBC6FppDY9kwvPYnYYpMNk3AqRm+m0Q3h 8LyYOLe6baniyOTHTFVSnqxhmS5au84bXz4wiJ1/1DD865FtvNHUV+eM2SxLlbDdV2qu 0biGW7xtoMOwf8J5xrx/zLUucZa3GEyUC/1D28Emqp+Ksro/lyORSRwVDuGLPsL+UTY4 0wJTbo2NWKJPrSdvSjZQGhm55ihkHgb4BRb9tFIzz7ZaknbxRTDH98D9WPgToz/7Ll75 aOmw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q6si5784001oth.26.2020.02.23.23.05.06; Sun, 23 Feb 2020 23:05:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727115AbgBXHDK (ORCPT + 99 others); Mon, 24 Feb 2020 02:03:10 -0500 Received: from mail5.windriver.com ([192.103.53.11]:53568 "EHLO mail5.wrs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726509AbgBXHDJ (ORCPT ); Mon, 24 Feb 2020 02:03:09 -0500 Received: from ALA-HCA.corp.ad.wrs.com (ala-hca.corp.ad.wrs.com [147.11.189.40]) by mail5.wrs.com (8.15.2/8.15.2) with ESMTPS id 01O70LVi011567 (version=TLSv1 cipher=AES256-SHA bits=256 verify=FAIL); Sun, 23 Feb 2020 23:00:31 -0800 Received: from [128.224.162.175] (128.224.162.175) by ALA-HCA.corp.ad.wrs.com (147.11.189.50) with Microsoft SMTP Server (TLS) id 14.3.468.0; Sun, 23 Feb 2020 23:00:11 -0800 Subject: Re: [PATCH] perf: Support Python 3.8+ in Makefile To: Sam Lunt CC: , , , , , , Jiri Olsa , , References: <20200131181123.tmamivhq4b7uqasr@gmail.com> <30752f2a-fe0b-4150-c32d-07690fb43b82@windriver.com> From: He Zhe Message-ID: <3f59e138-6f19-5419-2397-fc7d2e5f9df9@windriver.com> Date: Mon, 24 Feb 2020 15:00:05 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Content-Language: en-US X-Originating-IP: [128.224.162.175] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/23/20 12:38 AM, Sam Lunt wrote: > On Sun, Feb 16, 2020 at 8:24 PM He Zhe wrote: >> On 2/1/20 2:11 AM, Sam Lunt wrote: >>> Python 3.8 changed the output of 'python-config --ldflags' to no longer >>> include the '-lpythonX.Y' flag (this apparently fixed an issue loading >>> modules with a statically linked Python executable). The libpython >>> feature check in linux/build/feature fails if the Python library is not >>> included in FEATURE_CHECK_LDFLAGS-libpython variable. >>> >>> This adds a check in the Makefile to determine if PYTHON_CONFIG accepts >>> the '--embed' flag and passes that flag alongside '--ldflags' if so. >>> >>> tools/perf is the only place the libpython feature check is used. >>> >>> Signed-off-by: Sam Lunt >>> --- >>> tools/perf/Makefile.config | 11 ++++++++++- >>> 1 file changed, 10 insertions(+), 1 deletion(-) >>> >>> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config >>> index c90f4146e5a2..ccf99351f058 100644 >>> --- a/tools/perf/Makefile.config >>> +++ b/tools/perf/Makefile.config >>> @@ -228,8 +228,17 @@ strip-libs = $(filter-out -l%,$(1)) >>> >>> PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG)) >>> >>> +# Python 3.8 changed the output of `python-config --ldflags` to not include the >>> +# '-lpythonX.Y' flag unless '--embed' is also passed. The feature check for >>> +# libpython fails if that flag is not included in LDFLAGS >>> +ifeq ($(shell $(PYTHON_CONFIG_SQ) --ldflags --embed 2>&1 1>/dev/null; echo $$?), 0) >>> + PYTHON_CONFIG_LDFLAGS := --ldflags --embed >>> +else >>> + PYTHON_CONFIG_LDFLAGS := --ldflags >>> +endif >>> + >>> ifdef PYTHON_CONFIG >>> - PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null) >>> + PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) $(PYTHON_CONFIG_LDFLAGS) 2>/dev/null) >> I met the same problem. Would the following change be more simple and clear? >> >> - PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null) >> + PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags --embed 2>/dev/null || $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null) > That change is nearly equivalent to the change I'd suggested, just > squashed into one line. I think it's certainly more terse, but I'm not > sure it's any clearer. > > It's also making the implicit assumption that PYTHON_CONFIG_SQ does > not print anything to stdout when it exits with a non-zero return > code. I think that's probably a safe assumption, but it seems more > robust not to make that assumption at all. That said, such assumption was also made in the "else" case of your change and in the original line. If we wanted that robustness, we'd better give a stricter condition and a warning like below. +ifeq ($(shell $(PYTHON_CONFIG_SQ) --ldflags --embed 2>&1 1>/dev/null; echo $$?), 0) +  PYTHON_CONFIG_LDFLAGS := --ldflags --embed +else ifeq ($(shell $(PYTHON_CONFIG_SQ) --ldflags 2>&1 1>/dev/null; echo $$?), 0) +  PYTHON_CONFIG_LDFLAGS := --ldflags +else +  $(warning Failed to get python ldflags.) +endif Given that such kind of assumptions spread across kernel makefiles, the one-liner might be good enough. Regards, Zhe > > Best, > Sam