From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <3f7zRYAgKCkwu352qwrou22uzs.q20zwpopwuowz6285qsAo5s.25u@flex--gprocida.bounces.google.com> Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by sourceware.org (Postfix) with ESMTPS id 5BF3B3889800 for ; Tue, 22 Jun 2021 10:33:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5BF3B3889800 Received: by mail-qt1-x84a.google.com with SMTP id c29-20020ac86e9d0000b0290247b267c8e4so15459579qtv.22 for ; Tue, 22 Jun 2021 03:33:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=kPkuAykLKvk++TUWpcyEKK8XLB5YMC7Ez4REcJVYw7Y=; b=TM7vFcNw4RIrPqiw5B2VZwyKtxzJkGmWnc8dYzM5JJc/WyiRSG9uElx5NjG6ey7GAp 25QYp6NaS+52LoEnXUaoEJohlrXLMs4TNexUXQZVoDP4yUFByAm/cjnVHKe4T56bVHNE 1Zv3oC3x8uK8Yb09gS75oVzkBz3lnpzr8JHllkxBp5NcMxOGHQTq93vFzdYcrIOuCF1i wAcoN9GZeXEBtOmYzWt9GikwW5N79hwcx+9TXeKRhwlGS2JnibxIdiqysMoxVmfqscNh hwBifmqvCOK8h4vlKcnfLIAjtFkoJt6f6euynIVkaN3e/SHMZfNgGvM9IRTUTj5jYAWU KW2Q== X-Gm-Message-State: AOAM530LNt/Yc64nn5Q8YFCIBVhaOrscwfCT72Pu2jX5aLjdJUTD4KIR JPdCDplG9MGtrntTi1SeFRvn66BSTI+FncPeAG+KKWMcEDxptXH+cQfXUaZ1JfejH0J2b8t0UsG OR/kYhnGEe+OANUwYMJAPpQajd8lZzTQb4PJadNr7wLaaOG+KkwLv3zIMcCFei1z5Ym4l34k= X-Google-Smtp-Source: ABdhPJwaGj1aQSObRPCdMJuIIAmQ/VxRSP8+Dzo/bGdf3u4QuJf4dws5UIcdv4mwTPVLm1tDGqMtcxycqjEERQ== X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:210:b7d7:a6fe:d167:7a5d]) (user=gprocida job=sendgmr) by 2002:a0c:f0c5:: with SMTP id d5mr15931057qvl.2.1624358015913; Tue, 22 Jun 2021 03:33:35 -0700 (PDT) Date: Tue, 22 Jun 2021 11:33:17 +0100 In-Reply-To: <20210622103318.478914-1-gprocida@google.com> Message-Id: <20210622103318.478914-6-gprocida@google.com> Mime-Version: 1.0 References: <20210611153319.778996-1-gprocida@google.com> <20210622103318.478914-1-gprocida@google.com> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog Subject: [PATCH v2 5/6] BTF: add btfinfo and btfdiff tools From: Giuliano Procida To: libabigail@sourceware.org Cc: dodji@seketeli.org, kernel-team@android.com, gprocida@google.com, maennich@google.com, Maria Teguiani Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-22.2 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Jun 2021 10:33:37 -0000 This commit adds BTF command line tools. They are fairly thin wrappers around the core BTF functionality. The files are almost a straight copy of the originals. Changes: - Files renamed and #includes updated. * tools/Makefile.am: Compile BTF tools, conditional on C++17 and . * tools/btfdiff.cc: New utility that compares BTF information. * tools/btfinfo.cc: New utility that dumps BTF information. Co-authored-by: Maria Teguiani Signed-off-by: Giuliano Procida --- tools/Makefile.am | 14 ++++++++++ tools/btfdiff.cc | 68 +++++++++++++++++++++++++++++++++++++++++++++++ tools/btfinfo.cc | 19 +++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 tools/btfdiff.cc create mode 100644 tools/btfinfo.cc diff --git a/tools/Makefile.am b/tools/Makefile.am index 648a71b5..bd310c18 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -9,6 +9,12 @@ else noinst_SCRIPTS = fedabipkgdiff endif +if ENABLE_CXX17 +if HAVE_BTF + bin_PROGRAMS += btfinfo btfdiff +endif +endif + noinst_PROGRAMS = abisym abinilint abidiff_SOURCES = abidiff.cc @@ -45,6 +51,14 @@ kmidiffdir = $(bindir) kmidiff_LDADD = $(abs_top_builddir)/src/libabigail.la kmidiff_LDFLAGS = -pthread +btfinfo_SOURCES = btfinfo.cc +btfinfodir = $(bindir) +btfinfo_LDADD = ../src/libabigail.la + +btfdiff_SOURCES = btfdiff.cc +btfdiffdir = $(bindir) +btfdiff_LDADD = ../src/libabigail.la + AM_CXXFLAGS = \ $(VISIBILITY_FLAGS) -I$(abs_top_srcdir)/include \ -I$(abs_top_srcdir)/tools -fPIC diff --git a/tools/btfdiff.cc b/tools/btfdiff.cc new file mode 100644 index 00000000..0649821d --- /dev/null +++ b/tools/btfdiff.cc @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// -*- mode: C++ -*- +// +// Copyright (C) 2020-2021 Google, Inc. +// +// Author: Maria Teguiani +// Author: Giuliano Procida + +#include + +#include +#include +#include + +#include "abg-btf.h" + +const int kAbiChange = 4; + +int main(int argc, char *argv[]) { + bool use_elf_symbols = true; + static option opts[] = { + { "symbols", required_argument, nullptr, 's' }, + { nullptr, 0, nullptr, 0 }, + }; + auto usage = [&]() { + std::cerr << "usage: " << argv[0] + << " [-s|--symbols type] file1 file2\n" + << " where type is elf (the default) or btf\n"; + return 1; + }; + auto bad_arg = [&](int ix) { + std::cerr << argv[0] << ": option '--" << opts[ix].name + << "' unrecognized argument '" << optarg << "'\n"; + return usage(); + }; + while (true) { + int ix; + int c = getopt_long(argc, argv, "s:", opts, &ix); + if (c == -1) + break; + switch (c) { + case 's': + if (!strcmp(optarg, "btf")) + use_elf_symbols = false; + else if (!strcmp(optarg, "elf")) + use_elf_symbols = true; + else + return bad_arg(ix); + break; + default: + return usage(); + } + } + if (optind + 2 != argc) + return usage(); + + const auto structs1 = abigail::btf::ReadFile(argv[optind++]); + const auto structs2 = abigail::btf::ReadFile(argv[optind++]); + const auto &map1 = structs1.GetSymbols(use_elf_symbols); + const auto &map2 = structs2.GetSymbols(use_elf_symbols); + abigail::btf::Outcomes outcomes; + auto result = abigail::btf::Type::CompareSymbols(map1, map2, outcomes); + abigail::btf::NameCache names; + abigail::btf::Seen seen; + abigail::btf::Print(result.details_, outcomes, seen, names, std::cout); + + return result.equals_ ? 0 : kAbiChange; +} diff --git a/tools/btfinfo.cc b/tools/btfinfo.cc new file mode 100644 index 00000000..dbda7945 --- /dev/null +++ b/tools/btfinfo.cc @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// -*- mode: C++ -*- +// +// Copyright (C) 2020 Google, Inc. +// +// Author: Maria Teguiani + +#include "abg-btf.h" + +int main(int argc, const char *argv[]) { + if (argc != 2) { + std::cerr << "Please specify the path to a BTF file."; + return 1; + } + + (void) abigail::btf::ReadFile(argv[1], /* verbose = */ true); + + return 0; +} -- 2.32.0.288.g62a8d224e6-goog