Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp798218rwl; Fri, 31 Mar 2023 02:30:36 -0700 (PDT) X-Google-Smtp-Source: AKy350Y+WTzAF8AnHjfavLJD5V1l8Mg18Ko3REUU8NQtlRlwwR1fvLHBE6uZQIOCfupyKskQveXZ X-Received: by 2002:a17:903:685:b0:197:8e8e:f15 with SMTP id ki5-20020a170903068500b001978e8e0f15mr22435507plb.6.1680255036457; Fri, 31 Mar 2023 02:30:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680255036; cv=none; d=google.com; s=arc-20160816; b=ZyynodlHdkTPU6Z+SLf8EtaIgJ7StthRFOief7bJvjfjaE3dfa+1R8Ci+Rz9c3kYPJ reCgL9yFA1CdNoexcaJ0xZ6L0PvBqNvz1dF4+juxEOGHljDjRkTmqMeD81hThKum+TaM ysxZ6phAVJBVsZDX6/8s3c6jgnCdIFCCN/zqgg0IS2WCuZOU+hcdscsu77YfVLiFP1Ue 2b7c368ywj0O0k9OLVb5znXOSB5XOcFBcSrVVuL0ZsbDrdJj3m3xq1mLL7ahkf7t7r4v 2ae7e+nGg7ZCl17wJ0Klt46JhH2MVlXt/cCGXBeUQSgM2t+JSrBWnF1vhpfGaW4mL2aE cCgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=6hTMD0UMQi12y6mIS4pJY3b+4c57oAo5mVGZBWGnuAE=; b=P0BUlG9rUPReFlnznnXCD1lH4lo6ngmX7BLMenZHkSKNpL3C/+31JYs09LtJ6XsUto 4LxdNUbZQ37daaqTQMwnf6o9XMV8exwamP8jeQPjt620MVsUkK+2GYqbpeCjwqDFAg1Q N33Ff6Z1LOL19aLJqGPoeo/VWnKvy2EhgLD/zdurDJ5Bt04zb2cOxbEDMxdWFdWYDIzG /1X4DOEsK1C5EIyYRkwfTfXtwM6vSl3P8zRYPmshKThtUaQM3mwgAHXlNq/lFgY/qAXg zedRpwjpjK/BqaOXTPPqxHnqvow0YOLUf0ceCal81hDn/IbXMmT3yLhrei9EeZrGGWif CWkA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z17-20020a170903409100b001a18e0c66a9si1678662plc.249.2023.03.31.02.30.24; Fri, 31 Mar 2023 02:30:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232196AbjCaJ3H (ORCPT + 99 others); Fri, 31 Mar 2023 05:29:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231661AbjCaJ2q (ORCPT ); Fri, 31 Mar 2023 05:28:46 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A5E7D1FD2C; Fri, 31 Mar 2023 02:28:19 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9FE8E2F4; Fri, 31 Mar 2023 02:28:08 -0700 (PDT) Received: from [192.168.1.158] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7EC813F6C4; Fri, 31 Mar 2023 02:27:21 -0700 (PDT) Message-ID: <8daa6988-a0ec-bd92-5a7b-0dca39fbc3b0@arm.com> Date: Fri, 31 Mar 2023 10:27:12 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH v1 09/13] perf symbol: Add abi::__cxa_demangle C++ demangling support Content-Language: en-US To: Ian Rogers Cc: Arnaldo Carvalho de Melo , Stephane Eranian , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Nathan Chancellor , Nick Desaulniers , Tom Rix , Roberto Sassu , Quentin Monnet , Andres Freund , Tiezhu Yang , Pavithra Gurushankar , Yang Jihong , Adrian Hunter , Leo Yan , =?UTF-8?Q?Martin_Li=c5=a1ka?= , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, llvm@lists.linux.dev, Peter Zijlstra , Ingo Molnar References: <20230311065753.3012826-1-irogers@google.com> <20230311065753.3012826-10-irogers@google.com> From: James Clark In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 30/03/2023 20:03, Ian Rogers wrote: > On Thu, Mar 30, 2023 at 9:50 AM Ian Rogers wrote: >> >> On Thu, Mar 30, 2023 at 7:08 AM James Clark wrote: >>> >>> >>> >>> On 11/03/2023 06:57, Ian Rogers wrote: >>>> Refactor C++ demangling out of symbol-elf into its own files similar >>>> to other languages. Add abi::__cxa_demangle support. As the other >>>> demanglers are not shippable with distributions, this brings back C++ >>>> demangling in a common case. It isn't perfect as the support for >>>> optionally demangling arguments and modifiers isn't present. >>>> >>>> Signed-off-by: Ian Rogers >>>> --- >>>> tools/perf/Makefile.config | 29 +++++++++--------- >>>> tools/perf/util/Build | 1 + >>>> tools/perf/util/demangle-cxx.cpp | 50 ++++++++++++++++++++++++++++++++ >>>> tools/perf/util/demangle-cxx.h | 16 ++++++++++ >>>> tools/perf/util/symbol-elf.c | 37 +++++------------------ >>>> 5 files changed, 88 insertions(+), 45 deletions(-) >>>> create mode 100644 tools/perf/util/demangle-cxx.cpp >>>> create mode 100644 tools/perf/util/demangle-cxx.h >>>> >>>> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config >>>> index 5756498248e0..fdeca45cf15f 100644 >>>> --- a/tools/perf/Makefile.config >>>> +++ b/tools/perf/Makefile.config >>>> @@ -906,6 +906,7 @@ ifdef BUILD_NONDISTRO >>>> endif >>>> >>>> CFLAGS += -DHAVE_LIBBFD_SUPPORT >>>> + CXXFLAGS += -DHAVE_LIBBFD_SUPPORT >>>> ifeq ($(feature-libbfd-buildid), 1) >>>> CFLAGS += -DHAVE_LIBBFD_BUILDID_SUPPORT >>>> else >>>> @@ -913,26 +914,24 @@ ifdef BUILD_NONDISTRO >>>> endif >>>> endif >>>> >>>> -ifdef NO_DEMANGLE >>>> - CFLAGS += -DNO_DEMANGLE >>>> -else >>>> +ifndef NO_DEMANGLE >>>> + $(call feature_check,cxa-demangle) >>>> + ifeq ($(feature-cxa-demangle), 1) >>>> + EXTLIBS += -lstdc++ >>> >>> Hi Ian, >>> >>> I think cross compilation for arm on x86 isn't working after this change >>> (at least on Ubuntu). >>> >>> Even with all of the arm64 libstdc++ stuff installed, you can only link >>> to it using g++, but the perf build tries to link to it using gcc. Not >>> sure it's some quirk with the search paths on Ubuntu or something else: >>> >>> $ aarch64-linux-gnu-gcc -lstdc++ >>> >>> /usr/lib/gcc-cross/aarch64-linux-gnu/12/../../../../aarch64-linux- >>> gnu/bin/ld: cannot find -lstdc++: No such file or directory >>> collect2: error: ld returned 1 exit status >>> >>> g++ gets further: >>> >>> $ aarch64-linux-gnu-g++ -lstdc++ >>> >>> ... >>> (.text+0x20): undefined reference to `main' >>> collect2: error: ld returned 1 exit status >>> >>> At the end of the perf build it looks like something similar is >>> happening (with all the non interesting bits deleted): >>> >>> $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -C tools/perf >>> NO_BPF_SKEL=1 V=1 >>> >>> aarch64-linux-gnu-gcc ... -o perf >>> >>> /usr/lib/gcc-cross/aarch64-linux-gnu/12/../../../../aarch64-linux-gnu/bin/ld: >>> cannot find -lstdc++: No such file or directory >>> >>> If I build with NO_DEMANGLE=1 then the build works, but I think it would >>> at be best to autodetect rather than have to do this. Or maybe even link >>> at the end with g++ if we're going to use libstdc++? >> >> Hi James, >> >> sorry for the problems you are having, I'll see if I can get a repo. I >> did add a feature test with this change in the same set: >> https://lore.kernel.org/lkml/20230311065753.3012826-9-irogers@google.com/ >> So it should be feature testing and only enabling when >> HAVE_CXA_DEMANGLE_SUPPORT is present. Obviously something is up, so >> I'll have a think about it. >> >> Thanks, >> Ian > > Sorry to say I couldn't repro on Debian: > > $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -C tools/perf > NO_LIBELF=1 NO_LIBTRACEEVENT=1 If you have NO_LIBELF=1 it sets NO_DEMANGLE=1 automatically so it skips the c++ linking step. If you run with V=1 you can see that it doesn't have -lstdc++ on the last link line. But, having said that, I went to make a full reproducer in docker but it actually worked. Turns out that the issue was on my end. I'd used update-alternatives for a different compiler version and looks like I had half of one gcc and half of another g++. Completely my fault, sorry for the noise! James