mirror of
git://sourceware.org/git/libabigail.git
synced 2024-12-15 22:44:41 +00:00
c80f79271a
Thanks to the previous work done, changing the license is just a matter of changing the SPDX identifer from "LGPL-3.0-or-later" to "Apache-2.0 WITH LLVM-exception". Note that for the abigail.m4, tests/test-dot.cc and tests/test-svg.cc the change was from "GPL-3.0-or-later WITH GCC-exception-3.1" to "Apache-2.0 WITH LLVM-exception". include/abg-cxx-compat.h was changed from "LGPL-2.0-or-later" to "Apache-2.0 WITH LLVM-exception". Source code of programs (as opposed to source code of the library) where generally licensed under GPL-3.0-or-later; they are also now licensed "Apache-2.0 WITH LLVM-exception". This is what this patch does. * abigail.m4: Change the SPDX identifier from "GPL-3.0-or-later WITH GCC-exception-3.1" to "Apache-2.0 WITH LLVM-exception" * include/abg-cxx-compat.h: Change the SPDX identifier from "LGPL-2.0-or-later" to "Apache-2.0 WITH LLVM-exception". * .clang-format: Change the SPDX identifier from "LGPL-3.0-or-later" to "Apache-2.0 WITH LLVM-exception". * Makefile.am: Likewise. * bash-completion/Makefile.am: Likewise. * bash-completion/abicompat: Likewise. * bash-completion/abidiff: Likewise. * bash-completion/abidw: Likewise. * bash-completion/abilint: Likewise. * bash-completion/abinilint: Likewise. * bash-completion/abipkgdiff: Likewise. * bash-completion/abisym: Likewise. * bash-completion/fedabipkgdiff: Likewise. * configure.ac: Likewise. * default.abignore: Likewise. * doc/Makefile.am: Likewise. * doc/api/libabigail.doxy: Likewise. * doc/manuals/Makefile.am: Likewise. * doc/website/libabigail-website.doxy: Likewise. * include/Makefile.am: Likewise. * include/abg-comp-filter.h: Likewise. * include/abg-comparison.h: Likewise. * include/abg-config.h: Likewise. * include/abg-corpus.h: Likewise. * include/abg-diff-utils.h: Likewise. * include/abg-dwarf-reader.h: Likewise. * include/abg-fwd.h: Likewise. * include/abg-hash.h: Likewise. * include/abg-ini.h: Likewise. * include/abg-interned-str.h: Likewise. * include/abg-ir.h: Likewise. * include/abg-libxml-utils.h: Likewise. * include/abg-libzip-utils.h: Likewise. * include/abg-reader.h: Likewise. * include/abg-regex.h: Likewise. * include/abg-reporter.h: Likewise. * include/abg-sptr-utils.h: Likewise. * include/abg-suppression.h: Likewise. * include/abg-tools-utils.h: Likewise. * include/abg-traverse.h: Likewise. * include/abg-version.h.in: Likewise. * include/abg-viz-common.h: Likewise. * include/abg-viz-dot.h: Likewise. * include/abg-viz-svg.h: Likewise. * include/abg-workers.h: Likewise. * include/abg-writer.h: Likewise. * scripts/dot_to_png.sh: Likewise. * scripts/dot_to_svg.sh: Likewise. * scripts/make-verbose.sh: Likewise. * scripts/svg_to_plain_svg.sh: Likewise. * scripts/svg_to_png_and_pdf.sh: Likewise. * src/Makefile.am: Likewise. * src/abg-comp-filter.cc: Likewise. * src/abg-comparison-priv.h: Likewise. * src/abg-comparison.cc: Likewise. * src/abg-config.cc: Likewise. * src/abg-corpus-priv.h: Likewise. * src/abg-corpus.cc: Likewise. * src/abg-default-reporter.cc: Likewise. * src/abg-diff-utils.cc: Likewise. * src/abg-dwarf-reader.cc: Likewise. * src/abg-elf-helpers.cc: Likewise. * src/abg-elf-helpers.h: Likewise. * src/abg-hash.cc: Likewise. * src/abg-ini.cc: Likewise. * src/abg-internal.h: Likewise. * src/abg-ir-priv.h: Likewise. * src/abg-ir.cc: Likewise. * src/abg-leaf-reporter.cc: Likewise. * src/abg-libxml-utils.cc: Likewise. * src/abg-libzip-utils.cc: Likewise. * src/abg-reader.cc: Likewise. * src/abg-regex.cc: Likewise. * src/abg-reporter-priv.cc: Likewise. * src/abg-reporter-priv.h: Likewise. * src/abg-suppression-priv.h: Likewise. * src/abg-suppression.cc: Likewise. * src/abg-tools-utils.cc: Likewise. * src/abg-traverse.cc: Likewise. * src/abg-viz-common.cc: Likewise. * src/abg-viz-dot.cc: Likewise. * src/abg-viz-svg.cc: Likewise. * src/abg-workers.cc: Likewise. * src/abg-writer.cc: Likewise. * tests/Makefile.am: Likewise. * tests/data/Makefile.am: Likewise. * tests/lib/catch.cc: Likewise. * tests/mockfedabipkgdiff.in: Likewise. * tests/print-diff-tree.cc: Likewise. * tests/runtestcanonicalizetypes.sh.in: Likewise. * tests/runtestdefaultsupprs.py.in: Likewise. * tests/runtestdefaultsupprspy3.sh.in: Likewise. * tests/runtestfedabipkgdiff.py.in: Likewise. * tests/runtestfedabipkgdiffpy3.sh.in: Likewise. * tests/test-abicompat.cc: Likewise. * tests/test-abidiff-exit.cc: Likewise. * tests/test-abidiff.cc: Likewise. * tests/test-alt-dwarf-file.cc: Likewise. * tests/test-annotate.cc: Likewise. * tests/test-core-diff.cc: Likewise. * tests/test-cxx-compat.cc: Likewise. * tests/test-diff-dwarf-abixml.cc: Likewise. * tests/test-diff-dwarf.cc: Likewise. * tests/test-diff-filter.cc: Likewise. * tests/test-diff-pkg.cc: Likewise. * tests/test-diff-suppr.cc: Likewise. * tests/test-diff2.cc: Likewise. * tests/test-dot.cc: Change the SPDX identifier from "GPL-3.0-or-later WITH GCC-exception-3.1" to "Apache-2.0 WITH LLVM-exception" * tests/test-elf-helpers.cc: Change the SPDX identifier from "LGPL-3.0-or-later" to "Apache-2.0 WITH LLVM-exception" * tests/test-ini.cc: Likewise. * tests/test-ir-walker.cc: Likewise. * tests/test-kmi-whitelist.cc: Likewise. * tests/test-lookup-syms.cc: Likewise. * tests/test-read-dwarf.cc: Likewise. * tests/test-read-write.cc: Likewise. * tests/test-svg.cc: Change the SPDX identifier from "GPL-3.0-or-later WITH GCC-exception-3.1" to "Apache-2.0 WITH LLVM-exception". * tests/test-symtab.cc: Change the SPDX identifier from "LGPL-3.0-or-later" to "Apache-2.0 WITH LLVM-exception" * tests/test-tools-utils.cc: Likewise. * tests/test-types-stability.cc: Likewise. * tests/test-utils.cc: Likewise. * tests/test-utils.h: Likewise. * tests/test-write-read-archive.cc: Likewise. * tests/update-test-output.py: Likewise. * tools/Makefile.am: Likewise. * tools/abiar.cc: Likewise. * tools/abicompat.cc: Likewise. * tools/abidiff.cc: Likewise. * tools/abidw.cc: Likewise. * tools/abilint.cc: Likewise. * tools/abipkgdiff.cc: Likewise. * tools/abisym.cc: Likewise. * tools/binilint.cc: Likewise. * tools/fedabipkgdiff: Likewise. * tools/kmidiff.cc: Likewise. * update-copyright.sh: Likewise. Signed-off-by: Benjamin De Kosnik <bkoz@gnu.org> Signed-off-by: Ben Woodard <woodard@redhat.com> Signed-off-by: Chenxiong Qi <cqi@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Giuliano Procida <gprocida@google.com> Signed-off-by: Jan Engelhardt <jengelh@inai.de> Signed-off-by: Jessica Yu <jeyu@kernel.org> Signed-off-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Mark Wielaard <mark@klomp.org> Signed-off-by: Matthias Klose <doko@ubuntu.com> Signed-off-by: Matthias Maennich <maennich@google.com> Signed-off-by: Ondrej Oprala <ondrej.oprala@gmail.com> Signed-off-by: Roland McGrath <roland@hack.frob.com> Signed-off-by: Sinny Kumari <ksinny@gmail.com> Signed-off-by: Slava Barinov <v.barinov@samsung.com>
492 lines
14 KiB
C++
492 lines
14 KiB
C++
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
// -*- Mode: C++ -*-
|
|
//
|
|
// Copyright (C) 2013-2020 Red Hat, Inc.
|
|
//
|
|
// Author: Dodji Seketeli
|
|
|
|
/// @file
|
|
///
|
|
/// This is a program aimed at checking that a binary instrumentation
|
|
/// (bi) file is well formed and valid enough. It acts by loading an
|
|
/// input bi file and saving it back to a temporary file. It then
|
|
/// runs a diff on the two files and expects the result of the diff to
|
|
/// be empty.
|
|
|
|
#include <cstring>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <string>
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#include <vector>
|
|
#include "abg-cxx-compat.h"
|
|
#include "abg-config.h"
|
|
#include "abg-tools-utils.h"
|
|
#include "abg-ir.h"
|
|
#include "abg-corpus.h"
|
|
#include "abg-reader.h"
|
|
#include "abg-dwarf-reader.h"
|
|
#include "abg-writer.h"
|
|
#include "abg-suppression.h"
|
|
|
|
using std::string;
|
|
using std::cerr;
|
|
using std::cin;
|
|
using std::cout;
|
|
using std::ostream;
|
|
using std::ofstream;
|
|
using std::vector;
|
|
using abigail::tools_utils::emit_prefix;
|
|
using abigail::tools_utils::check_file;
|
|
using abigail::tools_utils::file_type;
|
|
using abigail::tools_utils::guess_file_type;
|
|
using abigail::suppr::suppression_sptr;
|
|
using abigail::suppr::suppressions_type;
|
|
using abigail::suppr::read_suppressions;
|
|
using abigail::corpus;
|
|
using abigail::corpus_sptr;
|
|
using abigail::xml_reader::read_translation_unit_from_file;
|
|
using abigail::xml_reader::read_translation_unit_from_istream;
|
|
using abigail::xml_reader::read_corpus_from_file;
|
|
using abigail::xml_reader::read_corpus_from_native_xml;
|
|
using abigail::xml_reader::read_corpus_from_native_xml_file;
|
|
using abigail::xml_reader::read_corpus_group_from_input;
|
|
using abigail::dwarf_reader::read_corpus_from_elf;
|
|
using abigail::xml_writer::write_translation_unit;
|
|
using abigail::xml_writer::write_context_sptr;
|
|
using abigail::xml_writer::create_write_context;
|
|
using abigail::xml_writer::write_corpus;
|
|
using abigail::xml_writer::write_corpus_to_archive;
|
|
|
|
struct options
|
|
{
|
|
string wrong_option;
|
|
string file_path;
|
|
bool display_version;
|
|
bool read_from_stdin;
|
|
bool read_tu;
|
|
bool diff;
|
|
bool noout;
|
|
abg_compat::shared_ptr<char> di_root_path;
|
|
vector<string> suppression_paths;
|
|
string headers_dir;
|
|
vector<string> header_files;
|
|
|
|
options()
|
|
: display_version(false),
|
|
read_from_stdin(false),
|
|
read_tu(false),
|
|
diff(false),
|
|
noout(false)
|
|
{}
|
|
};//end struct options;
|
|
|
|
static void
|
|
display_usage(const string& prog_name, ostream& out)
|
|
{
|
|
emit_prefix(prog_name, out)
|
|
<< "usage: " << prog_name << " [options] [<abi-file1>]\n"
|
|
<< " where options can be:\n"
|
|
<< " --help display this message\n"
|
|
<< " --version|-v display program version information and exit\n"
|
|
<< " --debug-info-dir <path> the path under which to look for "
|
|
<< " --headers-dir|--hd <patch> the path to headers of the elf file\n"
|
|
"debug info for the elf <abi-file>\n"
|
|
<< " --header-file|--hf <path> the path to one header of the elf file\n"
|
|
"debug info for the elf <abi-file>\n"
|
|
<< " --suppressions|--suppr <path> specify a suppression file\n"
|
|
<< " --diff for xml inputs, perform a text diff between "
|
|
"the input and the memory model saved back to disk\n"
|
|
<< " --noout do not display anything on stdout\n"
|
|
<< " --stdin|-- read abi-file content from stdin\n"
|
|
<< " --tu expect a single translation unit file\n";
|
|
}
|
|
|
|
bool
|
|
parse_command_line(int argc, char* argv[], options& opts)
|
|
{
|
|
if (argc < 2)
|
|
{
|
|
opts.read_from_stdin = true;
|
|
return true;
|
|
}
|
|
|
|
for (int i = 1; i < argc; ++i)
|
|
{
|
|
if (argv[i][0] != '-')
|
|
{
|
|
if (opts.file_path.empty())
|
|
opts.file_path = argv[i];
|
|
else
|
|
return false;
|
|
}
|
|
else if (!strcmp(argv[i], "--help"))
|
|
return false;
|
|
else if (!strcmp(argv[i], "--version")
|
|
|| !strcmp(argv[i], "-v"))
|
|
{
|
|
opts.display_version = true;
|
|
return true;
|
|
}
|
|
else if (!strcmp(argv[i], "--debug-info-dir"))
|
|
{
|
|
if (argc <= i + 1
|
|
|| argv[i + 1][0] == '-')
|
|
return false;
|
|
// elfutils wants the root path to the debug info to be
|
|
// absolute.
|
|
opts.di_root_path =
|
|
abigail::tools_utils::make_path_absolute(argv[i + 1]);
|
|
++i;
|
|
}
|
|
else if (!strcmp(argv[i], "--headers-dir")
|
|
|| !strcmp(argv[i], "--hd"))
|
|
{
|
|
int j = i + 1;
|
|
if (j >= argc)
|
|
return false;
|
|
opts.headers_dir = argv[j];
|
|
++i;
|
|
}
|
|
else if (!strcmp(argv[i], "--header-file")
|
|
|| !strcmp(argv[i], "--hf"))
|
|
{
|
|
int j = i + 1;
|
|
if (j >= argc)
|
|
return false;
|
|
opts.header_files.push_back(argv[j]);
|
|
++i;
|
|
}
|
|
else if (!strcmp(argv[i], "--suppressions")
|
|
|| !strcmp(argv[i], "--suppr"))
|
|
{
|
|
int j = i + 1;
|
|
if (j >= argc)
|
|
{
|
|
opts.wrong_option = argv[i];
|
|
return true;
|
|
}
|
|
opts.suppression_paths.push_back(argv[j]);
|
|
++i;
|
|
}
|
|
else if (!strcmp(argv[i], "--stdin"))
|
|
opts.read_from_stdin = true;
|
|
else if (!strcmp(argv[i], "--tu"))
|
|
opts.read_tu = true;
|
|
else if (!strcmp(argv[i], "--diff"))
|
|
opts.diff = true;
|
|
else if (!strcmp(argv[i], "--noout"))
|
|
opts.noout = true;
|
|
else
|
|
{
|
|
if (strlen(argv[i]) >= 2 && argv[i][0] == '-' && argv[i][1] == '-')
|
|
opts.wrong_option = argv[i];
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (opts.file_path.empty())
|
|
opts.read_from_stdin = true;
|
|
return true;
|
|
}
|
|
|
|
/// Check that the suppression specification files supplied are
|
|
/// present. If not, emit an error on stderr.
|
|
///
|
|
/// @param opts the options instance to use.
|
|
///
|
|
/// @return true if all suppression specification files are present,
|
|
/// false otherwise.
|
|
static bool
|
|
maybe_check_suppression_files(const options& opts)
|
|
{
|
|
for (vector<string>::const_iterator i = opts.suppression_paths.begin();
|
|
i != opts.suppression_paths.end();
|
|
++i)
|
|
if (!check_file(*i, cerr, "abidiff"))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
/// Set suppression specifications to the @p read_context used to load
|
|
/// the ABI corpus from the ELF/DWARF file.
|
|
///
|
|
/// These suppression specifications are going to be applied to drop
|
|
/// some ABI artifacts on the floor (while reading the ELF/DWARF file
|
|
/// or the native XML ABI file) and thus minimize the size of the
|
|
/// resulting ABI corpus.
|
|
///
|
|
/// @param read_ctxt the read context to apply the suppression
|
|
/// specifications to. Note that the type of this parameter is
|
|
/// generic (class template) because in practise, it can be either an
|
|
/// abigail::dwarf_reader::read_context type or an
|
|
/// abigail::xml_reader::read_context type.
|
|
///
|
|
/// @param opts the options where to get the suppression
|
|
/// specifications from.
|
|
template<class ReadContextType>
|
|
static void
|
|
set_suppressions(ReadContextType& read_ctxt, const options& opts)
|
|
{
|
|
suppressions_type supprs;
|
|
for (vector<string>::const_iterator i = opts.suppression_paths.begin();
|
|
i != opts.suppression_paths.end();
|
|
++i)
|
|
read_suppressions(*i, supprs);
|
|
|
|
suppression_sptr suppr =
|
|
abigail::tools_utils::gen_suppr_spec_from_headers(opts.headers_dir,
|
|
opts.header_files);
|
|
if (suppr)
|
|
supprs.push_back(suppr);
|
|
|
|
add_read_context_suppressions(read_ctxt, supprs);
|
|
}
|
|
|
|
/// Reads a bi (binary instrumentation) file, saves it back to a
|
|
/// temporary file and run a diff on the two versions.
|
|
int
|
|
main(int argc, char* argv[])
|
|
{
|
|
options opts;
|
|
if (!parse_command_line(argc, argv, opts))
|
|
{
|
|
if (!opts.wrong_option.empty())
|
|
emit_prefix(argv[0], cerr)
|
|
<< "unrecognized option: " << opts.wrong_option << "\n";
|
|
display_usage(argv[0], cerr);
|
|
return 1;
|
|
}
|
|
|
|
if (opts.display_version)
|
|
{
|
|
emit_prefix(argv[0], cout)
|
|
<< abigail::tools_utils::get_library_version_string();
|
|
return 0;
|
|
}
|
|
|
|
if (!maybe_check_suppression_files(opts))
|
|
return 1;
|
|
|
|
abigail::ir::environment_sptr env(new abigail::ir::environment);
|
|
if (opts.read_from_stdin)
|
|
{
|
|
if (!cin.good())
|
|
return 1;
|
|
|
|
if (opts.read_tu)
|
|
{
|
|
abigail::translation_unit_sptr tu =
|
|
read_translation_unit_from_istream(&cin, env.get());
|
|
|
|
if (!tu)
|
|
{
|
|
emit_prefix(argv[0], cerr)
|
|
<< "failed to read the ABI instrumentation from stdin\n";
|
|
return 1;
|
|
}
|
|
|
|
if (!opts.noout)
|
|
{
|
|
const write_context_sptr& ctxt
|
|
= create_write_context(tu->get_environment(), cout);
|
|
write_translation_unit(*ctxt, *tu, 0);
|
|
}
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
abigail::xml_reader::read_context_sptr ctxt =
|
|
abigail::xml_reader::create_native_xml_read_context(&cin,
|
|
env.get());
|
|
assert(ctxt);
|
|
set_suppressions(*ctxt, opts);
|
|
corpus_sptr corp = abigail::xml_reader::read_corpus_from_input(*ctxt);
|
|
if (!opts.noout)
|
|
{
|
|
const write_context_sptr& ctxt
|
|
= create_write_context(corp->get_environment(), cout);
|
|
write_corpus(*ctxt, corp, /*indent=*/0);
|
|
}
|
|
return 0;
|
|
}
|
|
}
|
|
else if (!opts.file_path.empty())
|
|
{
|
|
if (!check_file(opts.file_path, cerr, argv[0]))
|
|
return 1;
|
|
abigail::translation_unit_sptr tu;
|
|
abigail::corpus_sptr corp;
|
|
abigail::corpus_group_sptr group;
|
|
abigail::dwarf_reader::status s = abigail::dwarf_reader::STATUS_OK;
|
|
char* di_root_path = 0;
|
|
file_type type = guess_file_type(opts.file_path);
|
|
|
|
switch (type)
|
|
{
|
|
case abigail::tools_utils::FILE_TYPE_UNKNOWN:
|
|
emit_prefix(argv[0], cerr)
|
|
<< "Unknown file type given in input: " << opts.file_path;
|
|
return 1;
|
|
case abigail::tools_utils::FILE_TYPE_NATIVE_BI:
|
|
tu = read_translation_unit_from_file(opts.file_path, env.get());
|
|
break;
|
|
case abigail::tools_utils::FILE_TYPE_ELF:
|
|
case abigail::tools_utils::FILE_TYPE_AR:
|
|
{
|
|
di_root_path = opts.di_root_path.get();
|
|
vector<char**> di_roots;
|
|
di_roots.push_back(&di_root_path);
|
|
abigail::dwarf_reader::read_context_sptr ctxt =
|
|
abigail::dwarf_reader::create_read_context(opts.file_path,
|
|
di_roots, env.get(),
|
|
/*load_all_types=*/false);
|
|
assert(ctxt);
|
|
set_suppressions(*ctxt, opts);
|
|
corp = read_corpus_from_elf(*ctxt, s);
|
|
}
|
|
break;
|
|
case abigail::tools_utils::FILE_TYPE_XML_CORPUS:
|
|
{
|
|
abigail::xml_reader::read_context_sptr ctxt =
|
|
abigail::xml_reader::create_native_xml_read_context(opts.file_path,
|
|
env.get());
|
|
assert(ctxt);
|
|
set_suppressions(*ctxt, opts);
|
|
corp = read_corpus_from_input(*ctxt);
|
|
break;
|
|
}
|
|
case abigail::tools_utils::FILE_TYPE_XML_CORPUS_GROUP:
|
|
{
|
|
abigail::xml_reader::read_context_sptr ctxt =
|
|
abigail::xml_reader::create_native_xml_read_context(opts.file_path,
|
|
env.get());
|
|
assert(ctxt);
|
|
set_suppressions(*ctxt, opts);
|
|
group = read_corpus_group_from_input(*ctxt);
|
|
}
|
|
break;
|
|
case abigail::tools_utils::FILE_TYPE_ZIP_CORPUS:
|
|
#if WITH_ZIP_ARCHIVE
|
|
corp = read_corpus_from_file(opts.file_path);
|
|
#endif
|
|
break;
|
|
case abigail::tools_utils::FILE_TYPE_RPM:
|
|
break;
|
|
case abigail::tools_utils::FILE_TYPE_SRPM:
|
|
break;
|
|
case abigail::tools_utils::FILE_TYPE_DEB:
|
|
break;
|
|
case abigail::tools_utils::FILE_TYPE_DIR:
|
|
break;
|
|
case abigail::tools_utils::FILE_TYPE_TAR:
|
|
break;
|
|
}
|
|
|
|
if (!tu && !corp && !group)
|
|
{
|
|
emit_prefix(argv[0], cerr)
|
|
<< "failed to read " << opts.file_path << "\n";
|
|
if (!(s & abigail::dwarf_reader::STATUS_OK))
|
|
{
|
|
if (s & abigail::dwarf_reader::STATUS_DEBUG_INFO_NOT_FOUND)
|
|
{
|
|
cerr << "could not find the debug info";
|
|
if(di_root_path == 0)
|
|
emit_prefix(argv[0], cerr)
|
|
<< " Maybe you should consider using the "
|
|
"--debug-info-dir1 option to tell me about the "
|
|
"root directory of the debuginfo? "
|
|
"(e.g, --debug-info-dir1 /usr/lib/debug)\n";
|
|
else
|
|
emit_prefix(argv[0], cerr)
|
|
<< "Maybe the root path to the debug "
|
|
"information is wrong?\n";
|
|
}
|
|
if (s & abigail::dwarf_reader::STATUS_NO_SYMBOLS_FOUND)
|
|
emit_prefix(argv[0], cerr)
|
|
<< "could not find the ELF symbols in the file "
|
|
<< opts.file_path
|
|
<< "\n";
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
using abigail::tools_utils::temp_file;
|
|
using abigail::tools_utils::temp_file_sptr;
|
|
|
|
temp_file_sptr tmp_file = temp_file::create();
|
|
if (!tmp_file)
|
|
{
|
|
emit_prefix(argv[0], cerr) << "failed to create temporary file\n";
|
|
return 1;
|
|
}
|
|
|
|
std::ostream& of = opts.diff ? tmp_file->get_stream() : cout;
|
|
const abigail::ir::environment* env = 0;
|
|
if (tu)
|
|
env = tu->get_environment();
|
|
else if (corp)
|
|
env = corp->get_environment();
|
|
else if (group)
|
|
env = group->get_environment();
|
|
|
|
ABG_ASSERT(env);
|
|
const write_context_sptr ctxt = create_write_context(env, of);
|
|
|
|
bool is_ok = true;
|
|
|
|
if (tu)
|
|
{
|
|
if (!opts.noout)
|
|
is_ok = write_translation_unit(*ctxt, *tu, 0);
|
|
}
|
|
else
|
|
{
|
|
if (type == abigail::tools_utils::FILE_TYPE_XML_CORPUS
|
|
||type == abigail::tools_utils::FILE_TYPE_XML_CORPUS_GROUP
|
|
|| type == abigail::tools_utils::FILE_TYPE_ELF)
|
|
{
|
|
if (!opts.noout)
|
|
is_ok = write_corpus(*ctxt, corp, 0);
|
|
}
|
|
else if (type == abigail::tools_utils::FILE_TYPE_ZIP_CORPUS)
|
|
{
|
|
#ifdef WITH_ZIP_ARCHIVE
|
|
if (!opts.noout)
|
|
is_ok = write_corpus_to_archive(*corp, tmp_file->get_path());
|
|
#endif //WITH_ZIP_ARCHIVE
|
|
}
|
|
}
|
|
|
|
if (!is_ok)
|
|
{
|
|
string output =
|
|
(type == abigail::tools_utils::FILE_TYPE_NATIVE_BI)
|
|
? "translation unit"
|
|
: "ABI corpus";
|
|
emit_prefix(argv[0], cerr)
|
|
<< "failed to write the translation unit "
|
|
<< opts.file_path << " back\n";
|
|
}
|
|
|
|
if (is_ok
|
|
&& opts.diff
|
|
&& ((type == abigail::tools_utils::FILE_TYPE_XML_CORPUS)
|
|
||type == abigail::tools_utils::FILE_TYPE_XML_CORPUS_GROUP
|
|
|| type == abigail::tools_utils::FILE_TYPE_NATIVE_BI
|
|
|| type == abigail::tools_utils::FILE_TYPE_ZIP_CORPUS))
|
|
{
|
|
string cmd = "diff -u " + opts.file_path + " " + tmp_file->get_path();
|
|
if (system(cmd.c_str()))
|
|
is_ok = false;
|
|
}
|
|
|
|
return is_ok ? 0 : 1;
|
|
}
|
|
|
|
return 1;
|
|
}
|