From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC1ED13AA5D for ; Mon, 20 Jan 2025 17:32:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737394346; cv=none; b=Y19/WAKtU5FGlERleUpxf0gTIJ0YvtIFgBpB0mYql6wTuhbNzsndpzytWoz2JIWVRoA5jXrcMWdPAcZH3FNLd7FPU3X2ihU9ZZJsn8gDDV/HF1poCGjNEBKgNeTAQs7kRlEPMkFgndZRg0tlxJJ1dd9DJeMtvaZvmCl71SSXV1I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737394346; c=relaxed/simple; bh=XoxEYV+VDCUQVGr/fXdELyMg5VnHtJqPGO/sRS5XXiA=; h=Date:Message-Id:Mime-Version:Subject:From:To:Content-Type; b=co7RpAX1JE2CO0OsHaAmgLMacRKKs68vWN4VxF9VULLdi0R0ubSN0MDMv/CAa1VLb+Y2uC5vOE6+JQ1GSpYGqA4uwkKDKVh1TpCd00WhPh2kgW4cPXm9w706D5CNliTRDGnPOE34ZP+uVolv6Q7QuAC/lFGNrcfUwGolrMRUowk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=EvzMPhr/; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="EvzMPhr/" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e3fea893dc5so13500590276.1 for ; Mon, 20 Jan 2025 09:32:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737394343; x=1737999143; darn=vger.kernel.org; h=to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=tkLT2dzsqbCe/JB8KOi2Tl3KKIFyxEh2X9A7KSrmrTY=; b=EvzMPhr/4fhd/ktYoOrl+d+diiXS7OXa6KVNaTvrWY4HAsFSXXP93g/VT0CW4YbN2k 1hTRmQfJvPXFM2b+UboI6f49jxNmS1T1UfcL/K0yI2Z1Oiv4GovzzaIGwTrD14YRknLM zZ5Z0MRX1yEgKT+cyP9sMCJEY1sBhNTxAN+DdZGE5au7iLKFirY2IppzMSGX0moXxxoN KrXAfa1UowjqQ+qp8KCflhitUM9V4PfjMwWlJVguLIIynvnbCRCA7PiQOohwDM0leXAd ZQNQU44ypyiHULAjIq/jD8i3QzkK344jcA8BGuwwlJDpKs9Rggb3+dPOKqkRc1AEwD+L 9aOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737394343; x=1737999143; h=to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=tkLT2dzsqbCe/JB8KOi2Tl3KKIFyxEh2X9A7KSrmrTY=; b=OYHLdJ7nvIPD4ztKc7CyGpLIHhpmKX62HepTEGH2icaQ+xizWlsaMWC+iKxcScjP+2 zyOIrLXtLjRKhSQzSffKU3iDie+XllLsjEntujKaxplMYnQDmJXRftsmGnky8HyNxtPu F9vVeqdqLOJouasBzl9LyOfYbfvpycGR1yCzQuntwzr+uN58CAYfCzL81kM6IwrgWBZz 39xdrs+x2IESIzTseNw42t/IKCN0fBh/T+khYoiPz1YqMoz4Z2jTmU3sRioNG28InUNR Uy5PBeJNdQbARMgBa79Qc8dnmtBPrnK0YA78pGxyq0YlkTXphv7NoDW5OZO8gHaSNP+1 6weg== X-Forwarded-Encrypted: i=1; AJvYcCV3GT5kQW/pn4fb5akKEugpv6OKEbM480OSEqV5JvoKtE7hojCwXZ731ytR4YpsRvoH0MW/6g+N87af9OU=@vger.kernel.org X-Gm-Message-State: AOJu0YyU/UOdFfeH9noh3+7uD4VMC1dT1kYxnUIec8Fmgi/AuRGVhE7q vJj1afnzXSb2cdXbvZk/QWYXsLB3tIJ4pQ8ELxzgKMmpGgSKCRm9Fq32wDsbi0s1ZdRdeXxkOUv hbILdQA== X-Google-Smtp-Source: AGHT+IGyt38/W4/BJDU9pXXSoXiIU1Y17e/2AaBaByDFhkf5NXiPNpYen3rqRmeKMY//v6VlvxwMbsh0wDML X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:fc95:312:c7ce:d18e]) (user=irogers job=sendgmr) by 2002:a25:d642:0:b0:e38:225a:c3be with SMTP id 3f1490d57ef6-e578a3e1d28mr61426276.5.1737394342834; Mon, 20 Jan 2025 09:32:22 -0800 (PST) Date: Mon, 20 Jan 2025 09:32:03 -0800 Message-Id: <20250120173208.344231-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog Subject: [PATCH v1 0/5] Support dynamic opening of capstone and libLLVM From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , "Steinar H. Gunderson" , Charlie Jenkins , Changbin Du , "Masami Hiramatsu (Google)" , James Clark , Kajol Jain , Athira Rajeev , Li Huafei , Dmitry Vyukov , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Linking against libcapstone and libLLVM can be a significant increase in dependencies and size of memory footprint. For something like `perf record` the disassembler and addr2line functionality won't be used. Support dynamically loading these libraries using dlopen and then calling the appropriate functions found using dlsym. The patch series: 1) moves the capstone and LLVM code to their own C files, 2) simplifies a little the capstone code, 3) adds perf_ variants of the functions that will either directly call the function or use dlsym to discover it. The addr2line LLVM functionality is written in C++. To avoid linking against libLLVM for this, a new LIBLLVM_DYNAMIC option is added where the C++ code with the libLLVM dependency will be built into a libperf-llvm.so and that dlsym-ed and called against. Ian Rogers (5): perf capstone: Move capstone functionality into its own file perf llvm: Move llvm functionality into its own file perf capstone: Remove open_capstone_handle perf capstone: Support for dlopen-ing libcapstone.so perf llvm: Support for dlopen-ing libLLVM.so tools/perf/Makefile.config | 13 + tools/perf/Makefile.perf | 23 +- tools/perf/builtin-script.c | 2 - tools/perf/tests/make | 2 + tools/perf/util/Build | 4 +- tools/perf/util/capstone.c | 723 +++++++++++++++++++++++++++++ tools/perf/util/capstone.h | 24 + tools/perf/util/disasm.c | 612 +----------------------- tools/perf/util/disasm.h | 2 + tools/perf/util/llvm-c-helpers.cpp | 113 ++++- tools/perf/util/llvm.c | 537 +++++++++++++++++++++ tools/perf/util/llvm.h | 24 + tools/perf/util/print_insn.c | 117 +---- tools/perf/util/srcline.c | 65 +-- tools/perf/util/srcline.h | 6 + 15 files changed, 1481 insertions(+), 786 deletions(-) create mode 100644 tools/perf/util/capstone.c create mode 100644 tools/perf/util/capstone.h create mode 100644 tools/perf/util/llvm.c create mode 100644 tools/perf/util/llvm.h -- 2.48.0.rc2.279.g1de40edade-goog