From: Giuliano Procida <gprocida@google.com>
To: libabigail@sourceware.org
Cc: dodji@seketeli.org, kernel-team@android.com, gprocida@google.com,
maennich@google.com, teguiani@android.com,
Maria Teguiani <teguiani@google.com>
Subject: [PATCH 5/6] BTF: add btfinfo and btfdiff tools
Date: Fri, 11 Jun 2021 16:33:18 +0100 [thread overview]
Message-ID: <20210611153319.778996-6-gprocida@google.com> (raw)
In-Reply-To: <20210611153319.778996-1-gprocida@google.com>
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 <linux/btf.h>.
* tools/btfdiff.cc: New utility that compares BTF information.
* tools/btfinfo.cc: New utility that dumps BTF information.
Co-authored-by: Maria Teguiani <teguiani@google.com>
Signed-off-by: Giuliano Procida <gprocida@google.com>
---
tools/Makefile.am | 14 ++++++++++
tools/btfdiff.cc | 67 +++++++++++++++++++++++++++++++++++++++++++++++
tools/btfinfo.cc | 19 ++++++++++++++
3 files changed, 100 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..58c40e42
--- /dev/null
+++ b/tools/btfdiff.cc
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+// -*- mode: C++ -*-
+//
+// Copyright (C) 2020-2021 Google, Inc.
+//
+// Author: Maria Teguiani
+// Author: Giuliano Procida
+
+#include <getopt.h>
+#include <string.h>
+
+#include <iomanip>
+#include <iostream>
+
+#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.272.g935e593368-goog
next prev parent reply other threads:[~2021-06-11 15:34 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-11 15:33 [PATCH 0/6] BTF ABI Giuliano Procida
2021-06-11 15:33 ` [PATCH 1/6] Tweak clang-format Giuliano Procida
2021-06-11 15:33 ` [PATCH 2/6] Allow C++17 code to be compiled Giuliano Procida
2021-06-11 15:33 ` [PATCH 3/6] BTF: add SCC finder and test Giuliano Procida
2021-06-11 15:33 ` [PATCH 4/6] BTF: add core functionality Giuliano Procida
2021-06-11 15:33 ` Giuliano Procida [this message]
2021-06-11 15:33 ` [PATCH 6/6] BTF: clang-format all the new source files Giuliano Procida
2021-06-22 10:33 ` [PATCH v2 0/6] BTF ABI Giuliano Procida
2021-06-22 10:33 ` [PATCH v2 1/6] Allow C++17 code to be compiled Giuliano Procida
2021-06-22 10:33 ` [PATCH v2 2/6] Tweak clang-format Giuliano Procida
2021-06-22 10:33 ` [PATCH v2 3/6] BTF: add SCC finder and test Giuliano Procida
2021-06-22 10:33 ` [PATCH v2 4/6] BTF: add core functionality Giuliano Procida
2021-06-22 10:33 ` [PATCH v2 5/6] BTF: add btfinfo and btfdiff tools Giuliano Procida
2021-06-22 10:33 ` [PATCH v2 6/6] BTF: clang-format all the new source files Giuliano Procida
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210611153319.778996-6-gprocida@google.com \
--to=gprocida@google.com \
--cc=dodji@seketeli.org \
--cc=kernel-team@android.com \
--cc=libabigail@sourceware.org \
--cc=maennich@google.com \
--cc=teguiani@android.com \
--cc=teguiani@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).