Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp455826lqr; Wed, 5 Jun 2024 10:39:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUqiPyqQZF+NcPkS7o6vZ6bxD0mrpKPCqB1RxEMio81s5MAvQfk9Z5RzcAb/SsWFDxHar25BtbrAGxk+SDNi0wi02F1KmhD/Cy2vSbVRQ== X-Google-Smtp-Source: AGHT+IFKVl03Mp6UUOaew9Z/rtXFJ15RQD2bA4hx9VPmO/g7jGsfK5mICuRlJ0iyZG6iGpCDWurH X-Received: by 2002:aca:1117:0:b0:3d1:fed9:a644 with SMTP id 5614622812f47-3d2043c77f9mr2851872b6e.15.1717609191875; Wed, 05 Jun 2024 10:39:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717609191; cv=pass; d=google.com; s=arc-20160816; b=m0qCzid20O4rgzDzjyAiV+xXCV0vVQUFXKekiS3cvRUuDpA3VOCuc1n/bSTltEp+LT eiYu2R31bJq67vF7WNg72zhZ/80d++bl+XKGU4NgFbMuLFhPxudx5AAnznLR8z3THoGv P/nSlh03w7Y8p74wVIMhsk+2TGcY/TYgwoCl0UWtkReiIvqHQiLW0U/QSVnx8rG8JbLU 9XNvDVgVF9fbzY8+HF+S67MR68GoRSeq1OuT5cA4V9/nBoQgRxUSUAjyEOQ4+/b2YbHR C2swRyi6RdiYoWY6cE4/QB4VF59Ef8rBi5cB6mioomoKS3Fi71TlZSzK5AS5wkz7nQUl XoSw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=pWUK0CGOC5S/1EFf+cBG2Xqhqya58dSKv4skQiG4JIo=; fh=0AWm5mhpzbil4P8GHYtKGhJg11za2hWncZVe2SFNBgs=; b=n7TY61rgY8Bzow0Ow/L6BHJxOc8/NeL05Nmitu5NI58oW/SJJh9Uv3uZGkTOhAYhcQ yHvA6caqPiTfrTapoJU1ePnwV0/XtSNZQbVBpMRjhGh0dD6yWWQpyGw9/ZAWoAzjbWHa 2o7Tkg+gwIAhQ5xV29j9Axi8pa2L0COtoKV8oAxi2rCcxkZCYzsNreXZEGbTBcoBhqVU 0QwH+F0MSf+4wMx6Km5/y9x+2DKd8rirYofQwewkdYomagRfosrMRojkvE7VwGzPDuVW tkjghEmh5cghzHmjCIDnZqudTJ31QlkDftX/wxmQLn6zyalWJ0WhVcUXLOXXDuN+cuX1 EZxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Xdnf64pj; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202981-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202981-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-7951593140asi380875185a.593.2024.06.05.10.39.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 10:39:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202981-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Xdnf64pj; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202981-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202981-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 7862D1C226AA for ; Wed, 5 Jun 2024 17:39:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 16BC213AA47; Wed, 5 Jun 2024 17:39:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Xdnf64pj" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3684013A27D; Wed, 5 Jun 2024 17:39:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717609184; cv=none; b=sgYVvvOXUbe4bUQTuUUbLg/wjmUqVlC0zQClVFhOcwfV3TTweNoWt5GlWaHHVyeiUvGOFKedlzJ3iNRLilcDDjnKwoeg2tlezG8cSJZcS4vUvVh6Flc7Z5NUAhpr18FK5yXMLaFC7Yp8km5EXhZ1q01K85fTRMs4vH2I0UJCH2k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717609184; c=relaxed/simple; bh=fuBA1Y0rsKEgp27r29OV1H/+ChmvQlgNMqku0b2LcDQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WOpF3ZaRVLJk4Sv3JYkysbgnHmJWXXpKHgVrm6hKc0t9Sl3Ta8IsP1NMhmXPW6jD6N7WmVCd+Yse1rDQQf/Y+7Kit58bfjLkeTc8tnZyJAyKZ0pfig47uNT2hTK6bRYBE+l57kFGC96bygUHucO8DBS8VmL2OmcTOYnGSw4bcnw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Xdnf64pj; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77CB1C2BD11; Wed, 5 Jun 2024 17:39:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717609183; bh=fuBA1Y0rsKEgp27r29OV1H/+ChmvQlgNMqku0b2LcDQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Xdnf64pjhxtSWNkb/vJK/QYT6Br0BKxQMIHffq53vbZ6mUpZ6fAP9O7+ofjSy3reT QY+0xr5D2SZTPWGy+10Myb9aMRzyQIwschEbybjv2BRIF0M4DSv4yL+0LRvTNhACPg 32k2FgKzDRDJM1l+NFzwffEeZhvxEofopeHZzATSXw4nKmAiiSjYfYegBDj7VIDuRQ EHcmjVChCQtuU7FIEvowvdt5NuIEag9rF42QJCshuTw07rFkL/c3uYzmGxux+a9/YM ZXxWiJllmRu8hUfyhUiGFzlQogF3b/ANXe7wHWkB8rnNfGiSbcL6+Ad/BmvpfGdQik GtXVjrsgtLICw== Date: Wed, 5 Jun 2024 10:39:41 -0700 From: Namhyung Kim To: "Steinar H. Gunderson" Cc: acme@kernel.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, irogers@google.com, Arnaldo Carvalho de Melo Subject: Re: [PATCH v8 1/3] perf report: Support LLVM for addr2line() Message-ID: References: <20240602204208.735793-1-sesse@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240602204208.735793-1-sesse@google.com> On Sun, Jun 02, 2024 at 10:42:06PM +0200, Steinar H. Gunderson wrote: > In addition to the existing support for libbfd and calling out to > an external addr2line command, add support for using libllvm directly. > This is both faster than libbfd, and can be enabled in distro builds > (the LLVM license has an explicit provision for GPLv2 compatibility). > Thus, it is set as the primary choice if available. > > As an example, running perf report on a medium-size profile with > DWARF-based backtraces took 58 seconds with LLVM, 78 seconds with > libbfd, 153 seconds with external llvm-addr2line, and I got tired > and aborted the test after waiting for 55 minutes with external > bfd addr2line (which is the default for perf as compiled by distributions > today). Evidently, for this case, the bfd addr2line process needs > 18 seconds (on a 5.2 GHz Zen 3) to load the .debug ELF in question, > hits the 1-second timeout and gets killed during initialization, > getting restarted anew every time. Having an in-process addr2line > makes this much more robust. > > As future extensions, libllvm can be used in many other places where > we currently use libbfd or other libraries: > > - Symbol enumeration (in particular, for PE binaries). > - Demangling (including non-Itanium demangling, e.g. Microsoft > or Rust). > - Disassembling (perf annotate). > > However, these are much less pressing; most people don't profile > PE binaries, and perf has non-bfd paths for ELF. The same with > demangling; the default _cxa_demangle path works fine for most > users, and while bfd objdump can be slow on large binaries, > it is possible to use --objdump=llvm-objdump to get the speed benefits. > (It appears LLVM-based demangling is very simple, should we want > that.) > > Tested with LLVM 14, 15, 16, 18 and 19. For some reason, LLVM 12 was not > correctly detected using feature_check, and thus was not tested. > > Signed-off-by: Steinar H. Gunderson > Tested-by: Arnaldo Carvalho de Melo > --- [SNIP] > +static int addr2line(const char *dso_name, u64 addr, > + char **file, unsigned int *line, struct dso *dso, > + bool unwind_inlines, struct inline_node *node, > + struct symbol *sym) > +{ > + struct llvm_a2l_frame *inline_frames = NULL; > + int num_frames = llvm_addr2line(dso_name, addr, file, line, > + node && unwind_inlines, &inline_frames); > + > + if (num_frames == 0 || !inline_frames) { > + /* Error, or we didn't want inlines. */ > + return num_frames; > + } > + > + for (int i = 0; i < num_frames; ++i) { > + struct symbol *inline_sym = > + new_inline_sym(dso, sym, inline_frames[i].funcname); > + char *srcline = NULL; > + > + if (inline_frames[i].filename) > + srcline = srcline_from_fileline( > + inline_frames[i].filename, > + inline_frames[i].line); Please fix the coding style. Also you may add a pair of brackets to multi-line code even if it's a single statement. Thanks, Namhyung > + if (inline_list__append(inline_sym, srcline, node) != 0) { > + free_llvm_inline_frames(inline_frames, num_frames); > + return 0; > + } > + } > + free_llvm_inline_frames(inline_frames, num_frames); > + > + return num_frames; > +} > + > +void dso__free_a2l(struct dso *) > +{ > + /* Nothing to free. */ > +} > + > +#elif defined(HAVE_LIBBFD_SUPPORT) > > /* > * Implement addr2line using libbfd. > -- > 2.45.1 >