1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- Mode: C++ -*-
//
// Copyright (C) 2013-2025 Red Hat, Inc.
//
// Author: Dodji Seketeli
/// @file
#include "config.h"
#include <cstring>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <set>
#include "abg-config.h"
#include "abg-comp-filter.h"
#include "abg-suppression.h"
#include "abg-tools-utils.h"
#include "abg-reader.h"
#include "abg-dwarf-reader.h"
#ifdef WITH_CTF
#include "abg-ctf-reader.h"
#endif
#ifdef WITH_BTF
#include "abg-btf-reader.h"
#endif
using std::vector;
using std::set;
using std::string;
using std::ostream;
using std::cout;
using std::cerr;
using std::shared_ptr;
using abg_compat::optional;
using namespace abigail;
using abigail::ir::environment;
using abigail::ir::environment_sptr;
using abigail::translation_unit;
using abigail::translation_unit_sptr;
using abigail::corpus_sptr;
using abigail::corpus_group_sptr;
using abigail::comparison::translation_unit_diff_sptr;
using abigail::comparison::corpus_diff;
using abigail::comparison::corpus_diff_sptr;
using abigail::comparison::compute_diff;
using abigail::comparison::get_default_harmless_categories_bitmap;
using abigail::comparison::get_default_harmful_categories_bitmap;
using abigail::suppr::suppression_sptr;
using abigail::suppr::suppressions_type;
using abigail::suppr::read_suppressions;
using abigail::tools_utils::emit_prefix;
using abigail::tools_utils::check_file;
using abigail::tools_utils::guess_file_type;
using abigail::tools_utils::gen_suppr_spec_from_headers;
using abigail::tools_utils::gen_suppr_spec_from_kernel_abi_whitelists;
using abigail::tools_utils::load_default_system_suppressions;
using abigail::tools_utils::load_default_user_suppressions;
using abigail::tools_utils::abidiff_status;
using abigail::tools_utils::create_best_elf_based_reader;
using abigail::tools_utils::stick_corpus_and_dependencies_into_corpus_group;
using abigail::tools_utils::stick_corpus_and_binaries_into_corpus_group;
using abigail::tools_utils::add_dependencies_into_corpus_group;
using abigail::tools_utils::get_dependencies;
using namespace abigail;
struct options
{
bool display_usage;
bool display_version;
bool missing_operand;
string wrong_option;
string file1;
string file2;
vector<string> suppression_paths;
vector<string> kernel_abi_whitelist_paths;
vector<string> drop_fn_regex_patterns;
vector<string> drop_var_regex_patterns;
vector<string> keep_fn_regex_patterns;
vector<string> keep_var_regex_patterns;
vector<string> headers_dirs1;
vector<string> header_files1;
vector<string> headers_dirs2;
vector<string> header_files2;
bool drop_private_types;
optional<bool> exported_interfaces_only;
bool linux_kernel_mode;
bool no_default_supprs;
bool no_arch;
bool no_corpus;
bool ignore_soname;
bool leaf_changes_only;
bool fail_no_debug_info;
bool show_hexadecimal_values;
bool show_offsets_sizes_in_bits;
bool show_relative_offset_changes;
bool show_stats_only;
bool show_symtabs;
bool show_deleted_fns;
bool show_changed_fns;
bool show_added_fns;
bool show_added_syms;
bool show_all_fns;
bool show_deleted_vars;
bool show_changed_vars;
bool show_added_vars;
bool show_all_vars;
bool show_all_types;
bool show_linkage_names;
bool show_locs;
bool show_harmful_changes;
bool show_harmless_changes;
bool show_redundant_changes;
bool show_symbols_not_referenced_by_debug_info;
bool show_impacted_interfaces;
bool assume_odr_for_cplusplus;
bool leverage_dwarf_factorization;
bool perform_change_categorization;
bool follow_dependencies;
bool list_dependencies;
bool dump_diff_tree;
bool show_stats;
bool do_log;
#ifdef WITH_DEBUG_SELF_COMPARISON
bool do_debug_self_comparison;
#endif
#ifdef WITH_DEBUG_TYPE_CANONICALIZATION
bool do_debug_type_canonicalization;
#endif
#ifdef WITH_CTF
bool use_ctf;
#endif
#ifdef WITH_BTF
bool use_btf;
#endif
vector<string> di_root_paths1;
vector<string> di_root_paths2;
vector<string> added_bins_dirs1;
vector<string> added_bins_dirs2;
vector<string> added_bins1;
vector<string> added_bins2;
options()
: display_usage(),
display_version(),
missing_operand(),
drop_private_types(false),
linux_kernel_mode(true),
no_default_supprs(),
no_arch(),
no_corpus(),
ignore_soname(false),
leaf_changes_only(),
fail_no_debug_info(),
show_hexadecimal_values(),
show_offsets_sizes_in_bits(true),
show_relative_offset_changes(true),
show_stats_only(),
show_symtabs(),
show_deleted_fns(),
show_changed_fns(),
show_added_fns(),
show_added_syms(true),
show_all_fns(true),
show_deleted_vars(),
show_changed_vars(),
show_added_vars(),
show_all_vars(true),
show_all_types(false),
show_linkage_names(true),
show_locs(true),
show_harmful_changes(true),
show_harmless_changes(),
show_redundant_changes(),
show_symbols_not_referenced_by_debug_info(true),
show_impacted_interfaces(),
assume_odr_for_cplusplus(true),
leverage_dwarf_factorization(true),
perform_change_categorization(true),
follow_dependencies(),
list_dependencies(),
dump_diff_tree(),
show_stats(),
do_log()
#ifdef WITH_DEBUG_SELF_COMPARISON
,
do_debug_self_comparison()
#endif
#ifdef WITH_DEBUG_TYPE_CANONICALIZATION
,
do_debug_type_canonicalization()
#endif
#ifdef WITH_CTF
,
use_ctf()
#endif
#ifdef WITH_BTF
,
use_btf()
#endif
{}
~options()
{
}
};//end struct options;
static void
display_usage(const string& prog_name, ostream& out)
{
emit_prefix(prog_name, out)
<< "usage: " << prog_name << " [options] [<file1> <file2>]\n"
<< " where options can be:\n"
<< " --help|-h display this message\n "
<< " --version|-v display program version information and exit\n"
<< " --debug-info-dir1|--d1 <path> the root for the debug info of file1\n"
<< " --debug-info-dir2|--d2 <path> the root for the debug info of file2\n"
<< " --headers-dir1|--hd1 <path> the path to headers of file1\n"
<< " --header-file1|--hf1 <path> the path to one header of file1\n"
<< " --headers-dir2|--hd2 <path> the path to headers of file2\n"
<< " --header-file2|--hf2 <path> the path to one header of file2\n"
<< " --added-binaries-dir1 the path to the dependencies of file1\n"
<< " --added-binaries-dir2 the path to the dependencies of file2\n"
<< " --add-binaries1 <bin1,bin2,.>. build corpus groups with "
"extra binaries added to the first one and compare them\n"
<< " --add-binaries2 <bin1,bin2,..> build corpus groups with "
"extra binaries added to the second one and compare them\n"
<< " --follow-dependencies|--fdeps build corpus groups with the "
"dependencies of the input files\n"
<< " --list-dependencies|--ldeps show the dependencies of the input files\n"
<< " --drop-private-types drop private types from "
"internal representation\n"
<< " --exported-interfaces-only analyze exported interfaces only\n"
<< " --allow-non-exported-interfaces analyze interfaces that "
"might not be exported\n"
<< " --no-linux-kernel-mode don't consider the input binaries as "
"linux kernel binaries\n"
<< " --kmi-whitelist|-w path to a "
"linux kernel abi whitelist\n"
<< " --stat only display the diff stats\n"
<< " --symtabs only display the symbol tables of the corpora\n"
<< " --no-default-suppression don't load any "
"default suppression specification\n"
<< " --no-architecture do not take architecture in account\n"
<< " --no-corpus-path do not take the path to the corpora into account\n"
<< " --ignore-soname do not take the SONAMEs into account\n"
<< " --fail-no-debug-info bail out if no debug info was found\n"
<< " --leaf-changes-only|-l only show leaf changes, "
"so no change impact analysis (implies --redundant)\n"
<< " --deleted-fns display deleted public functions\n"
<< " --changed-fns display changed public functions\n"
<< " --added-fns display added public functions\n"
<< " --deleted-vars display deleted global public variables\n"
<< " --changed-vars display changed global public variables\n"
<< " --added-vars display added global public variables\n"
<< " --non-reachable-types|-t consider types non reachable"
" from public interfaces\n"
<< " --no-added-syms do not display added functions or variables\n"
<< " --no-linkage-name do not display linkage names of "
"added/removed/changed\n"
<< " --no-unreferenced-symbols do not display changes "
"about symbols not referenced by debug info\n"
<< " --no-show-locs do now show location information\n"
<< " --show-bytes show size and offsets in bytes\n"
<< " --show-bits show size and offsets in bits\n"
<< " --show-hex show size and offset in hexadecimal\n"
<< " --show-dec show size and offset in decimal\n"
<< " --no-show-relative-offset-changes do not show relative"
" offset changes\n"
<< " --suppressions|--suppr <path> specify a suppression file\n"
<< " --drop <regex> drop functions and variables matching a regexp\n"
<< " --drop-fn <regex> drop functions matching a regexp\n"
<< " --drop-var <regex> drop variables matching a regexp\n"
<< " --keep <regex> keep only functions and variables matching a regex\n"
<< " --keep-fn <regex> keep only functions matching a regex\n"
<< " --keep-var <regex> keep only variables matching a regex\n"
<< " --harmless display the harmless changes\n"
<< " --no-harmful do not display the harmful changes\n"
<< " --redundant display redundant changes\n"
<< " --no-redundant do not display redundant changes "
"(this is the default)\n"
<< " --impacted-interfaces display interfaces impacted by leaf changes\n"
<< " --no-leverage-dwarf-factorization do not use DWZ optimisations to "
"speed-up the analysis of the binary\n"
<< " --no-change-categorization | -x don't perform categorization "
"of changes, for speed purposes\n"
<< " --no-assume-odr-for-cplusplus do not assume the ODR to speed-up the "
"analysis of the binary\n"
<< " --dump-diff-tree emit a debug dump of the internal diff tree to "
"the error output stream\n"
<< " --stats show statistics about various internal stuff\n"
#ifdef WITH_CTF
<< " --ctf use CTF instead of DWARF in ELF files\n"
#endif
#ifdef WITH_BTF
<< " --btf use BTF instead of DWARF in ELF files\n"
#endif
#ifdef WITH_DEBUG_SELF_COMPARISON
<< " --debug-self-comparison debug the process of comparing "
"an ABI corpus against itself"
#endif
#ifdef WITH_DEBUG_TYPE_CANONICALIZATION
<< " --debug-tc debug the type canonicalization process"
#endif
<< " --verbose show verbose messages about internal stuff\n";
}
/// Parse the command line and set the options accordingly.
///
/// @param argc the number of words on the command line
///
/// @param argv the command line, which is an array of words.
///
/// @param opts the options data structure. This is set by the
/// function iff it returns true.
///
/// @return true if the command line could be parsed and opts filed,
/// false otherwise.
bool
parse_command_line(int argc, char* argv[], options& opts)
{
if (argc < 2)
return false;
for (int i = 1; i < argc; ++i)
{
if (argv[i][0] != '-')
{
if (opts.file1.empty())
opts.file1 = argv[i];
else if (opts.file2.empty())
opts.file2 = argv[i];
else
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-dir1")
|| !strcmp(argv[i], "--d1"))
{
int j = i + 1;
if (j >= argc)
{
opts.missing_operand = true;
opts.wrong_option = argv[i];
return true;
}
// elfutils wants the root path to the debug info to be
// absolute.
opts.di_root_paths1.push_back
(abigail::tools_utils::make_path_absolute(string(argv[j])));
++i;
}
else if (!strcmp(argv[i], "--debug-info-dir2")
|| !strcmp(argv[i], "--d2"))
{
int j = i + 1;
if (j >= argc)
{
opts.missing_operand = true;
opts.wrong_option = argv[i];
return true;
}
// elfutils wants the root path to the debug info to be
// absolute.
opts.di_root_paths2.push_back
(abigail::tools_utils::make_path_absolute(string(argv[j])));
++i;
}
else if (!strcmp(argv[i], "--headers-dir1")
|| !strcmp(argv[i], "--hd1"))
{
int j = i + 1;
if (j >= argc)
{
opts.missing_operand = true;
opts.wrong_option = argv[i];
return true;
}
// The user can specify several header files directories for
// the first binary.
opts.headers_dirs1.push_back(argv[j]);
++i;
}
else if (!strcmp(argv[i], "--header-file1")
|| !strcmp(argv[i], "--hf1"))
{
int j = i + 1;
if (j >= argc)
{
opts.missing_operand = true;
opts.wrong_option = argv[i];
return true;
}
opts.header_files1.push_back(argv[j]);
++i;
}
else if (!strcmp(argv[i], "--headers-dir2")
|| !strcmp(argv[i], "--hd2"))
{
int j = i + 1;
if (j >= argc)
{
opts.missing_operand = true;
opts.wrong_option = argv[i];
return true;
}
// The user can specify several header files directories for
// the first binary.
opts.headers_dirs2.push_back(argv[j]);
++i;
}
else if (!strcmp(argv[i], "--header-file2")
|| !strcmp(argv[i], "--hf2"))
{
int j = i + 1;
if (j >= argc)
{
opts.missing_operand = true;
opts.wrong_option = argv[i];
return true;
}
opts.header_files2.push_back(argv[j]);
++i;
}
else if (!strcmp(argv[i], "--follow-dependencies")
|| !strcmp(argv[i], "--fdeps"))
opts.follow_dependencies = true;
else if (!strcmp(argv[i], "--list-dependencies")
|| !strcmp(argv[i], "--ldeps"))
opts.list_dependencies = true;
else if (!strcmp(argv[i], "--added-binaries-dir1")
|| !strcmp(argv[i], "--abd1"))
{
int j = i + 1;
if (j >= argc)
{
opts.missing_operand = true;
opts.wrong_option = argv[i];
return true;
}
opts.added_bins_dirs1.push_back(argv[j]);
++i;
}
else if (!strcmp(argv[i], "--added-binaries-dir2")
|| !strcmp(argv[i], "--abd2"))
{
int j = i + 1;
if (j >= argc)
{
opts.missing_operand = true;
opts.wrong_option = argv[i];
return true;
}
opts.added_bins_dirs2.push_back(argv[j]);
++i;
}
else if (!strncmp(argv[i], "--add-binaries1=",
strlen("--add-binaries1=")))
tools_utils::get_comma_separated_args_of_option(argv[i],
"--add-binaries1=",
opts.added_bins1);
else if (!strcmp(argv[i], "--add-binaries1"))
{
int j = i + 1;
if (j >= argc)
{
opts.missing_operand = true;
opts.wrong_option = argv[i];
return true;
}
string s = argv[j];
if (s.find(','))
tools_utils::split_string(s, ",", opts.added_bins1);
else
opts.added_bins1.push_back(s);
++i;
}
else if (!strncmp(argv[i], "--add-binaries2=",
strlen("--add-binaries2=")))
tools_utils::get_comma_separated_args_of_option(argv[i],
"--add-binaries2=",
opts.added_bins2);
else if (!strcmp(argv[i], "--add-binaries2"))
{
int j = i + 1;
if (j >= argc)
{
opts.missing_operand = true;
opts.wrong_option = argv[i];
return true;
}
string s = argv[j];
if (s.find(','))
tools_utils::split_string(s, ",", opts.added_bins2);
else
opts.added_bins2.push_back(s);
++i;
}
else if (!strcmp(argv[i], "--kmi-whitelist")
|| !strcmp(argv[i], "-w"))
{
int j = i + 1;
if (j >= argc)
{
opts.missing_operand = true;
opts.wrong_option = argv[i];
return true;
}
opts.kernel_abi_whitelist_paths.push_back(argv[j]);
++i;
}
else if (!strcmp(argv[i], "--stat"))
opts.show_stats_only = true;
else if (!strcmp(argv[i], "--symtabs"))
opts.show_symtabs = true;
else if (!strcmp(argv[i], "--help")
|| !strcmp(argv[i], "-h"))
{
opts.display_usage = true;
return true;
}
else if (!strcmp(argv[i], "--drop-private-types"))
opts.drop_private_types = true;
else if (!strcmp(argv[i], "--exported-interfaces-only"))
opts.exported_interfaces_only = true;
else if (!strcmp(argv[i], "--allow-non-exported-interfaces"))
opts.exported_interfaces_only = false;
else if (!strcmp(argv[i], "--no-linux-kernel-mode"))
opts.linux_kernel_mode = false;
else if (!strcmp(argv[i], "--no-default-suppression"))
opts.no_default_supprs = true;
else if (!strcmp(argv[i], "--no-architecture"))
opts.no_arch = true;
else if (!strcmp(argv[i], "--no-corpus-path"))
opts.no_corpus = true;
else if (!strcmp(argv[i], "--ignore-soname"))
opts.ignore_soname = true;
else if (!strcmp(argv[i], "--fail-no-debug-info"))
opts.fail_no_debug_info = true;
else if (!strcmp(argv[i], "--leaf-changes-only")
||!strcmp(argv[i], "-l"))
opts.leaf_changes_only = true;
else if (!strcmp(argv[i], "--deleted-fns"))
{
opts.show_deleted_fns = true;
opts.show_all_fns = false;
opts.show_all_vars = false;
}
else if (!strcmp(argv[i], "--changed-fns"))
{
opts.show_changed_fns = true;
opts.show_all_fns = false;
opts.show_all_vars = false;
}
else if (!strcmp(argv[i], "--added-fns"))
{
opts.show_added_fns = true;
opts.show_all_fns = false;
opts.show_all_vars = false;
}
else if (!strcmp(argv[i], "--deleted-vars"))
{
opts.show_deleted_vars = true;
opts.show_all_fns = false;
opts.show_all_vars = false;
}
else if (!strcmp(argv[i], "--changed-vars"))
{
opts.show_changed_vars = true;
opts.show_all_fns = false;
opts.show_all_vars = false;
}
else if (!strcmp(argv[i], "--added-vars"))
{
opts.show_added_vars = true;
opts.show_all_fns = false;
opts.show_all_vars = false;
}
else if (!strcmp(argv[i], "--non-reachable-types")
|| !strcmp(argv[i], "-t"))
opts.show_all_types = true;
else if (!strcmp(argv[i], "--no-added-syms"))
{
opts.show_added_syms = false;
opts.show_added_vars = false;
opts.show_added_fns = false;
// If any of the {changed,deleted}_{vars,fns} is already
// specified, --no-added-syms has no further effect. If it
// is the only option specified (as of the time of parsing
// it), it shall mean "show everything, except added vars,
// fns and unreferenced symbols.
if (!(opts.show_changed_fns
|| opts.show_changed_vars
|| opts.show_deleted_fns
|| opts.show_deleted_vars))
{
opts.show_changed_fns = true;
opts.show_changed_vars = true;
opts.show_deleted_vars = true;
opts.show_deleted_fns = true;
}
opts.show_all_fns = false;
opts.show_all_vars = false;
}
else if (!strcmp(argv[i], "--no-linkage-name"))
opts.show_linkage_names = false;
else if (!strcmp(argv[i], "--no-unreferenced-symbols"))
opts.show_symbols_not_referenced_by_debug_info = false;
else if (!strcmp(argv[i], "--no-show-locs"))
opts.show_locs = false;
else if (!strcmp(argv[i], "--show-bytes"))
opts.show_offsets_sizes_in_bits = false;
else if (!strcmp(argv[i], "--show-bits"))
opts.show_offsets_sizes_in_bits = true;
else if (!strcmp(argv[i], "--show-hex"))
opts.show_hexadecimal_values = true;
else if (!strcmp(argv[i], "--show-dec"))
opts.show_hexadecimal_values = false;
else if (!strcmp(argv[i], "--no-show-relative-offset-changes"))
opts.show_relative_offset_changes = false;
else if (!strcmp(argv[i], "--suppressions")
|| !strcmp(argv[i], "--suppr"))
{
int j = i + 1;
if (j >= argc)
{
opts.missing_operand = true;
opts.wrong_option = argv[i];
return true;
}
opts.suppression_paths.push_back(argv[j]);
++i;
}
else if (!strcmp(argv[i], "--drop"))
{
int j = i + 1;
if (j >= argc)
{
opts.missing_operand = true;
opts.wrong_option = argv[i];
return true;
}
opts.drop_fn_regex_patterns.push_back(argv[j]);
opts.drop_var_regex_patterns.push_back(argv[j]);
++i;
}
else if (!strcmp(argv[i], "--drop-fn"))
{
int j = i + 1;
if (j >= argc)
{
opts.missing_operand = true;
opts.wrong_option = argv[i];
return true;
}
opts.drop_fn_regex_patterns.push_back(argv[j]);
++i;
}
else if (!strcmp(argv[i], "--drop-var"))
{
int j = i + 1;
if (j >= argc)
{
opts.missing_operand = true;
opts.wrong_option = argv[i];
return true;
}
opts.drop_var_regex_patterns.push_back(argv[j]);
++i;
}
else if (!strcmp(argv[i], "--keep"))
{
int j = i + 1;
if (j >= argc)
{
opts.missing_operand = true;
opts.wrong_option = argv[i];
return true;
}
opts.keep_fn_regex_patterns.push_back(argv[j]);
opts.keep_var_regex_patterns.push_back(argv[j]);
++i;
}
else if (!strcmp(argv[i], "--keep-fn"))
{
int j = i + 1;
if (j >= argc)
{
opts.missing_operand = true;
opts.wrong_option = argv[i];
return true;
}
opts.keep_fn_regex_patterns.push_back(argv[j]);
}
else if (!strcmp(argv[i], "--keep-var"))
{
int j = i + 1;
if (j >= argc)
{
opts.missing_operand = true;
opts.wrong_option = argv[i];
return true;
}
opts.keep_var_regex_patterns.push_back(argv[j]);
}
else if (!strcmp(argv[i], "--harmless"))
opts.show_harmless_changes = true;
else if (!strcmp(argv[i], "--no-harmful"))
opts.show_harmful_changes = false;
else if (!strcmp(argv[i], "--redundant"))
opts.show_redundant_changes = true;
else if (!strcmp(argv[i], "--no-redundant"))
opts.show_redundant_changes = false;
else if (!strcmp(argv[i], "--impacted-interfaces"))
opts.show_impacted_interfaces = true;
else if (!strcmp(argv[i], "--no-leverage-dwarf-factorization"))
opts.leverage_dwarf_factorization = false;
else if (!strcmp(argv[i], "--no-change-categorization")
|| !strcmp(argv[i], "-x"))
opts.perform_change_categorization = false;
else if (!strcmp(argv[i], "--no-assume-odr-for-cplusplus"))
opts.leverage_dwarf_factorization = false;
else if (!strcmp(argv[i], "--dump-diff-tree"))
opts.dump_diff_tree = true;
else if (!strcmp(argv[i], "--stats"))
opts.show_stats = true;
else if (!strcmp(argv[i], "--verbose"))
opts.do_log = true;
#ifdef WITH_CTF
else if (!strcmp(argv[i], "--ctf"))
opts.use_ctf = true;
#endif
#ifdef WITH_BTF
else if (!strcmp(argv[i], "--btf"))
opts.use_btf = true;
#endif
#ifdef WITH_DEBUG_SELF_COMPARISON
else if (!strcmp(argv[i], "--debug-self-comparison"))
opts.do_debug_self_comparison = true;
#endif
#ifdef WITH_DEBUG_TYPE_CANONICALIZATION
else if (!strcmp(argv[i], "--debug-tc"))
opts.do_debug_type_canonicalization = true;
#endif
else
{
if (strlen(argv[i]) >= 2 && argv[i][0] == '-' && argv[i][1] == '-')
opts.wrong_option = argv[i];
return false;
}
}
return true;
}
/// Display the function symbol tables for the two corpora.
///
/// @param c1 the first corpus to display the symbol table for.
///
/// @param c2 the second corpus to display the symbol table for.
///
/// @param o the output stream to emit the symbol tables to.
static void
display_symtabs(const corpus_sptr c1, const corpus_sptr c2, ostream& o)
{
o << "size of the functions symtabs: "
<< c1->get_functions().size()
<< " and "
<< c2->get_functions().size()
<< "\n\n";
if (c1->get_functions().size())
o << "First functions symbol table\n\n";
for (abigail::corpus::functions::const_iterator i =
c1->get_functions().begin();
i != c1->get_functions().end();
++i)
o << (*i)->get_pretty_representation() << std::endl;
if (c1->get_functions().size() != 0)
o << "\n";
if (c2->get_functions().size())
o << "Second functions symbol table\n\n";
for (abigail::corpus::functions::const_iterator i =
c2->get_functions().begin();
i != c2->get_functions().end();
++i)
o << (*i)->get_pretty_representation() << std::endl;
}
using abigail::comparison::diff_context_sptr;
using abigail::comparison::diff_context;
/// 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;
for (vector<string>::const_iterator i =
opts.kernel_abi_whitelist_paths.begin();
i != opts.kernel_abi_whitelist_paths.end();
++i)
if (!check_file(*i, cerr, "abidiff"))
return false;
return true;
}
/// Update the diff context from the @ref options data structure.
///
/// @param ctxt the diff context to update.
///
/// @param opts the instance of @ref options to consider.
static void
set_diff_context_from_opts(diff_context_sptr ctxt,
options& opts)
{
ctxt->default_output_stream(&cout);
ctxt->error_output_stream(&cerr);
ctxt->perform_change_categorization(opts.perform_change_categorization);
ctxt->show_leaf_changes_only(opts.leaf_changes_only);
ctxt->show_hex_values(opts.show_hexadecimal_values);
ctxt->show_offsets_sizes_in_bits(opts.show_offsets_sizes_in_bits);
ctxt->show_relative_offset_changes(opts.show_relative_offset_changes);
ctxt->show_stats_only(opts.show_stats_only);
ctxt->show_deleted_fns(opts.show_all_fns || opts.show_deleted_fns);
ctxt->show_changed_fns(opts.show_all_fns || opts.show_changed_fns);
ctxt->show_added_fns(opts.show_all_fns || opts.show_added_fns);
ctxt->show_deleted_vars(opts.show_all_vars || opts.show_deleted_vars);
ctxt->show_changed_vars(opts.show_all_vars || opts.show_changed_vars);
ctxt->show_added_vars(opts.show_all_vars || opts.show_added_vars);
ctxt->show_linkage_names(opts.show_linkage_names);
ctxt->show_locs(opts.show_locs);
// Intentional logic flip of ignore_soname
ctxt->show_soname_change(!opts.ignore_soname);
// So when we are showing only leaf changes, we want to show
// redundant changes because of this: Suppose several functions have
// their return type changed from void* to int*. We want them all
// to be reported. In that case the change is not redundant. As
// far as user-defined type changes (like struct/class) they are
// already put inside a map which makes them be non-redundant, so we
// don't have to worry about that case.
//
// TODO: maybe that in this case we should avoid firing the
// redundancy analysis pass altogether. That could help save a
// couple of CPU cycle here and there!
ctxt->show_redundant_changes(opts.show_redundant_changes
|| opts.leaf_changes_only);
ctxt->show_symbols_unreferenced_by_debug_info
(opts.show_symbols_not_referenced_by_debug_info);
ctxt->show_added_symbols_unreferenced_by_debug_info
(opts.show_symbols_not_referenced_by_debug_info && opts.show_added_syms);
ctxt->show_unreachable_types(opts.show_all_types);
ctxt->show_impacted_interfaces(opts.show_impacted_interfaces);
if (!opts.show_harmless_changes)
ctxt->switch_categories_off(get_default_harmless_categories_bitmap());
if (!opts.show_harmful_changes)
ctxt->switch_categories_off(get_default_harmful_categories_bitmap());
suppressions_type supprs;
for (vector<string>::const_iterator i = opts.suppression_paths.begin();
i != opts.suppression_paths.end();
++i)
read_suppressions(*i, supprs);
ctxt->add_suppressions(supprs);
if (!opts.no_default_supprs && opts.suppression_paths.empty())
{
// Load the default system and user suppressions.
suppressions_type& supprs = ctxt->suppressions();
load_default_system_suppressions(supprs);
load_default_user_suppressions(supprs);
}
if (!opts.headers_dirs1.empty() || !opts.header_files1.empty())
{
// Generate suppression specification to avoid showing ABI
// changes on types that are not defined in public headers.
suppression_sptr suppr =
gen_suppr_spec_from_headers(opts.headers_dirs1, opts.header_files1);
if (suppr)
ctxt->add_suppression(suppr);
}
if (!opts.headers_dirs2.empty() || !opts.header_files2.empty())
{
// Generate suppression specification to avoid showing ABI
// changes on types that are not defined in public headers.
suppression_sptr suppr =
gen_suppr_spec_from_headers(opts.headers_dirs2, opts.header_files2);
if (suppr)
ctxt->add_suppression(suppr);
}
ctxt->dump_diff_tree(opts.dump_diff_tree);
ctxt->do_log(opts.do_log);
}
/// Set a bunch of tunable buttons on the ELF-based reader from the
/// command-line options.
///
/// @param rdr the reader to tune.
///
/// @param opts the command line options.
static void
set_generic_options(abigail::elf_based_reader& rdr, options& opts)
{
rdr.options().show_stats = opts.show_stats;
rdr.options().do_log = opts.do_log;
rdr.options().leverage_dwarf_factorization =
opts.leverage_dwarf_factorization;
rdr.options().assume_odr_for_cplusplus =
opts.assume_odr_for_cplusplus;
}
/// 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
/// dwarf::read_context type or an
/// abigail::abiabixml_reader::reader type.
///
/// @param opts the options where to get the suppression
/// specifications from.
static void
set_suppressions(abigail::fe_iface& reader, 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);
if (reader.corpus_path() == opts.file1
&& (!opts.headers_dirs1.empty() || !opts.header_files1.empty()))
{
// Generate suppression specification to avoid showing ABI
// changes on types that are not defined in public headers for
// the first binary.
//
// As these suppression specifications are applied during the
// corpus loading, they are going to be dropped from the
// internal representation altogether.
suppression_sptr suppr =
gen_suppr_spec_from_headers(opts.headers_dirs1, opts.header_files1);
if (suppr)
{
if (opts.drop_private_types)
suppr->set_drops_artifact_from_ir(true);
supprs.push_back(suppr);
}
}
if (reader.corpus_path() == opts.file2
&& (!opts.headers_dirs2.empty() || !opts.header_files2.empty()))
{
// Generate suppression specification to avoid showing ABI
// changes on types that are not defined in public headers for
// the second binary.
//
// As these suppression specifications are applied during the
// corpus loading, they are going to be dropped from the
// internal representation altogether.
suppression_sptr suppr =
gen_suppr_spec_from_headers(opts.headers_dirs2, opts.header_files2);
if (suppr)
{
if (opts.drop_private_types)
suppr->set_drops_artifact_from_ir(true);
supprs.push_back(suppr);
}
}
const suppressions_type& wl_suppr =
gen_suppr_spec_from_kernel_abi_whitelists(
opts.kernel_abi_whitelist_paths);
supprs.insert(supprs.end(), wl_suppr.begin(), wl_suppr.end());
reader.add_suppressions(supprs);
}
/// Configure the abigail::xml_reacher::read_context based on the
/// relevant command-line options.
///
/// @param ctxt the read context to configure.
///
/// @param opts the command-line options to configure @p ctxt from.
static void
set_native_xml_reader_options(abigail::fe_iface& rdr,
const options& opts)
{
abixml::consider_types_not_reachable_from_public_interfaces(rdr,
opts.show_all_types);
rdr.options().do_log = opts.do_log;
}
/// Set the regex patterns describing the functions to drop from the
/// symbol table of a given corpus.
///
/// @param opts the options to the regex patterns from.
///
/// @param c the corpus to set the regex patterns into.
static void
set_corpus_keep_drop_regex_patterns(options& opts, corpus_sptr c)
{
if (!opts.drop_fn_regex_patterns.empty())
{
vector<string>& v = opts.drop_fn_regex_patterns;
vector<string>& p = c->get_regex_patterns_of_fns_to_suppress();
p.assign(v.begin(), v.end());
}
if (!opts.keep_fn_regex_patterns.empty())
{
vector<string>& v = opts.keep_fn_regex_patterns;
vector<string>& p = c->get_regex_patterns_of_fns_to_keep();
p.assign(v.begin(), v.end());
}
if (!opts.drop_var_regex_patterns.empty())
{
vector<string>& v = opts.drop_var_regex_patterns;
vector<string>& p = c->get_regex_patterns_of_vars_to_suppress();
p.assign(v.begin(), v.end());
}
if (!opts.keep_var_regex_patterns.empty())
{
vector<string>& v = opts.keep_var_regex_patterns;
vector<string>& p = c->get_regex_patterns_of_vars_to_keep();
p.assign(v.begin(), v.end());
}
}
/// This function sets diff context options that are specific to
/// kernel module interface comparison.
///
/// @param ctxt the diff context to consider.
static void
adjust_diff_context_for_kmidiff(diff_context &ctxt)
{
ctxt.show_linkage_names(false);
}
/// Emit an appropriate error message if necessary, given an error
/// code.
///
/// To emit the appropriate error message the function might need to
/// access the context in which the (ELF) input file was being loaded,
/// if it's present.
///
/// @param status_code the status code returned after trying to load
/// the input file.
///
/// @param ctxt the context used to load the ELF file, if we still
/// have it. If this is nil, then it's ignored.
///
/// @param prog_name the name of the current program. This is
/// important as it's used in the error message.
///
/// @param input_file_name the name of the input file that we are
/// tryin to load.
///
/// @param debug_info_dir1 if non nil, then this points to the path of
/// the root debug info directory of the first binary that we are
/// trying to load.. If nil, then it's ignored.
///
/// @param debug_info_dir2 if non nil, then this points to the path of
/// the root debug info directory of the second binary that we are
/// trying to load.. If nil, then it's ignored.
///
/// @return abigail::tools_utils::ABIDIFF_ERROR if an error was
/// detected, abigail::tools_utils::ABIDIFF_OK otherwise.
static abigail::tools_utils::abidiff_status
handle_error(abigail::fe_iface::status status_code,
const abigail::elf_based_reader* rdr,
const string& prog_name,
const options& opts)
{
if (!(status_code & abigail::fe_iface::STATUS_OK)
|| status_code & abigail::fe_iface::STATUS_DEBUG_INFO_NOT_FOUND
|| status_code & abigail::fe_iface::STATUS_ALT_DEBUG_INFO_NOT_FOUND)
{
emit_prefix(prog_name, cerr)
<< "failed to read input file " << opts.file1 << "\n";
if (status_code & abigail::fe_iface::STATUS_DEBUG_INFO_NOT_FOUND)
{
emit_prefix(prog_name, cerr) <<
"could not find the debug info\n";
{
if (opts.di_root_paths1.empty() == 0)
emit_prefix(prog_name, 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(prog_name, cerr)
<< "Maybe the root path to the debug information '";
for (vector<string>::const_iterator i
= opts.di_root_paths1.begin();
i != opts.di_root_paths1.end();
++i)
{
if (i != opts.di_root_paths1.end())
cerr << ", ";
cerr << *i;
}
cerr << "' is wrong?\n";
}
}
{
if (opts.di_root_paths2.empty())
emit_prefix(prog_name, cerr)
<< "Maybe you should consider using the "
"--debug-info-dir2 option to tell me about the "
"root directory of the debuginfo? "
"(e.g, --debug-info-dir2 /usr/lib/debug)\n";
else
{
emit_prefix(prog_name, cerr)
<< "Maybe the root path to the debug information '";
for (vector<string>::const_iterator i
= opts.di_root_paths2.begin();
i != opts.di_root_paths2.end();
++i)
{
if (i != opts.di_root_paths2.end())
cerr << ", ";
cerr << *i;
}
cerr << "' is wrong?\n";
}
}
}
if (status_code & abigail::fe_iface::STATUS_ALT_DEBUG_INFO_NOT_FOUND)
{
emit_prefix(prog_name, cerr)
<< "could not find the alternate debug info file";
if (!rdr->alternate_dwarf_debug_info_path().empty())
cerr << " at: "
<< rdr->alternate_dwarf_debug_info_path();
cerr << "\n";
}
if (status_code & abigail::fe_iface::STATUS_NO_SYMBOLS_FOUND)
emit_prefix(prog_name, cerr)
<< "could not find the ELF symbols in the file '"
<< opts.file1
<< "'\n";
return abigail::tools_utils::ABIDIFF_ERROR;
}
return abigail::tools_utils::ABIDIFF_OK;
}
/// Emit an error message saying that the two files have incompatible
/// format versions.
///
/// @param file_path1 the first file path to consider.
///
/// @param version1 the second version to consider.
///
/// @param file_path2 the second file path to consider.
///
/// @param version2 the second version to consider.
///
/// @param prog_name the name of the current program.
static void
emit_incompatible_format_version_error_message(const string& file_path1,
const string& version1,
const string& file_path2,
const string& version2,
const string& prog_name)
{
emit_prefix(prog_name, cerr)
<< "incompatible format version between the two input files:\n"
<< "'" << file_path1 << "' (" << version1 << ")\n"
<< "and\n"
<< "'" << file_path2 << "' (" << version2 << ")\n";
}
/// Display the dependencies of two corpora.
///
/// @param prog_name the name of the current abidiff program.
///
/// @param corp1 the first corpus to consider.
///
/// @param corp2 the second corpus to consider.
///
/// @param deps1 the dependencies to display.
///
/// @param deps2 the dependencies to display.
static void
display_dependencies(const string& prog_name,
const corpus_sptr& corp1,
const corpus_sptr& corp2,
const set<string>& deps1,
const set<string>& deps2)
{
if (deps1.empty())
emit_prefix(prog_name, cout)
<< "No dependencies found for '" << corp1->get_path() << "':\n";
else
{
emit_prefix(prog_name, cout)
<< "dependencies of '" << corp1->get_path() << "':\n\t";
int n = 0;
for (const auto& dep : deps1)
{
if (n)
cout << ", ";
cout << dep;
++n;
}
cout << "\n";
}
if (deps2.empty())
emit_prefix(prog_name, cout)
<< "No dependencies found for '" << corp2->get_path() << "':\n";
else
{
emit_prefix(prog_name, cout)
<< "dependencies of '" << corp2->get_path() << "':\n\t";
int n = 0;
for (const auto& dep : deps2)
{
if (n)
cout << ", ";
cout << dep;
++n;
}
cout << "\n";
}
}
int
main(int argc, char* argv[])
{
abigail::tools_utils::initialize();
options opts;
if (!parse_command_line(argc, argv, opts))
{
emit_prefix(argv[0], cerr)
<< "unrecognized option: "
<< opts.wrong_option << "\n"
<< "try the --help option for more information\n";
return (abigail::tools_utils::ABIDIFF_USAGE_ERROR
| abigail::tools_utils::ABIDIFF_ERROR);
}
if (opts.missing_operand)
{
emit_prefix(argv[0], cerr)
<< "missing operand to option: " << opts.wrong_option <<"\n"
<< "try the --help option for more information\n";
return (abigail::tools_utils::ABIDIFF_USAGE_ERROR
| abigail::tools_utils::ABIDIFF_ERROR);
}
if (opts.display_usage)
{
display_usage(argv[0], cout);
return (abigail::tools_utils::ABIDIFF_USAGE_ERROR
| abigail::tools_utils::ABIDIFF_ERROR);
}
if (opts.display_version)
{
emit_prefix(argv[0], cout)
<< abigail::tools_utils::get_library_version_string()
<< "\n";
return 0;
}
if (!maybe_check_suppression_files(opts))
return (abigail::tools_utils::ABIDIFF_USAGE_ERROR
| abigail::tools_utils::ABIDIFF_ERROR);
abidiff_status status = abigail::tools_utils::ABIDIFF_OK;
if (!opts.file1.empty() && !opts.file2.empty())
{
if (!check_file(opts.file1, cerr))
return abigail::tools_utils::ABIDIFF_ERROR;
if (!check_file(opts.file2, cerr))
return abigail::tools_utils::ABIDIFF_ERROR;
abigail::tools_utils::file_type t1_type, t2_type;
t1_type = guess_file_type(opts.file1);
t2_type = guess_file_type(opts.file2);
environment env;
if (opts.exported_interfaces_only.has_value())
env.analyze_exported_interfaces_only(*opts.exported_interfaces_only);
#ifdef WITH_DEBUG_SELF_COMPARISON
if (opts.do_debug_self_comparison)
env.self_comparison_debug_is_on(true);
#endif
#ifdef WITH_DEBUG_TYPE_CANONICALIZATION
if (opts.do_debug_type_canonicalization)
env.debug_type_canonicalization_is_on(true);
#endif
translation_unit_sptr t1, t2;
abigail::fe_iface::status c1_status =
abigail::fe_iface::STATUS_OK,
c2_status = abigail::fe_iface::STATUS_OK;
corpus_sptr c1, c2;
corpus_group_sptr g1, g2;
bool files_suppressed = false;
diff_context_sptr ctxt(new diff_context);
set_diff_context_from_opts(ctxt, opts);
suppressions_type& supprs = ctxt->suppressions();
files_suppressed = (file_is_suppressed(opts.file1, supprs)
|| file_is_suppressed(opts.file2, supprs));
if (files_suppressed)
// We don't have to compare anything because a user
// suppression specification file instructs us to avoid
// loading either one of the input files.
return abigail::tools_utils::ABIDIFF_OK;
switch (t1_type)
{
case abigail::tools_utils::FILE_TYPE_UNKNOWN:
emit_prefix(argv[0], cerr)
<< "Unknown content type for file " << opts.file1 << "\n";
return abigail::tools_utils::ABIDIFF_ERROR;
break;
case abigail::tools_utils::FILE_TYPE_NATIVE_BI:
t1 = abixml::read_translation_unit_from_file(opts.file1,
env);
break;
case abigail::tools_utils::FILE_TYPE_ELF: // fall through
case abigail::tools_utils::FILE_TYPE_AR:
{
corpus::origin requested_fe_kind = corpus::DWARF_ORIGIN;
#ifdef WITH_CTF
if (opts.use_ctf)
requested_fe_kind = corpus::CTF_ORIGIN;
#endif
#ifdef WITH_BTF
if (opts.use_btf)
requested_fe_kind = corpus::BTF_ORIGIN;
#endif
abigail::elf_based_reader_sptr rdr =
create_best_elf_based_reader(opts.file1,
opts.di_root_paths1,
env, requested_fe_kind,
opts.show_all_types,
opts.linux_kernel_mode);
ABG_ASSERT(rdr);
set_generic_options(*rdr, opts);
set_suppressions(*rdr, opts);
c1 = rdr->read_corpus(c1_status);
if (!c1
|| (opts.fail_no_debug_info
&& (c1_status & abigail::fe_iface::STATUS_ALT_DEBUG_INFO_NOT_FOUND)
&& (c1_status & abigail::fe_iface::STATUS_DEBUG_INFO_NOT_FOUND)))
return handle_error(c1_status, rdr.get(),
argv[0], opts);
if (!opts.added_bins1.empty())
g1 = stick_corpus_and_binaries_into_corpus_group(rdr, c1,
opts.added_bins1,
opts.added_bins_dirs1);
if (opts.follow_dependencies)
{
if (g1)
add_dependencies_into_corpus_group(rdr, *c1,
opts.added_bins_dirs1,
*g1);
else
g1 = stick_corpus_and_dependencies_into_corpus_group(rdr, c1,
opts.added_bins_dirs1);
}
}
break;
case abigail::tools_utils::FILE_TYPE_XML_CORPUS:
{
abigail::fe_iface_sptr rdr =
abixml::create_reader(opts.file1, env);
assert(rdr);
set_suppressions(*rdr, opts);
set_native_xml_reader_options(*rdr, opts);
c1 = rdr->read_corpus(c1_status);
if (!c1)
return handle_error(c1_status, /*ctxt=*/0, argv[0], opts);
}
break;
case abigail::tools_utils::FILE_TYPE_XML_CORPUS_GROUP:
{
abigail::fe_iface_sptr rdr =
abixml::create_reader(opts.file1, env);
assert(rdr);
set_suppressions(*rdr, opts);
set_native_xml_reader_options(*rdr, opts);
g1 = abixml::read_corpus_group_from_input(*rdr);
if (!g1)
return handle_error(c1_status, /*ctxt=*/0,
argv[0], opts);
}
break;
case abigail::tools_utils::FILE_TYPE_RPM:
case abigail::tools_utils::FILE_TYPE_SRPM:
case abigail::tools_utils::FILE_TYPE_DEB:
case abigail::tools_utils::FILE_TYPE_DIR:
case abigail::tools_utils::FILE_TYPE_TAR:
case abigail::tools_utils::FILE_TYPE_XZ:
break;
}
switch (t2_type)
{
case abigail::tools_utils::FILE_TYPE_UNKNOWN:
emit_prefix(argv[0], cerr)
<< "Unknown content type for file " << opts.file2 << "\n";
return abigail::tools_utils::ABIDIFF_ERROR;
break;
case abigail::tools_utils::FILE_TYPE_NATIVE_BI:
t2 = abixml::read_translation_unit_from_file(opts.file2,
env);
break;
case abigail::tools_utils::FILE_TYPE_ELF: // Fall through
case abigail::tools_utils::FILE_TYPE_AR:
{
corpus::origin requested_fe_kind = corpus::DWARF_ORIGIN;
#ifdef WITH_CTF
if (opts.use_ctf)
requested_fe_kind = corpus::CTF_ORIGIN;
#endif
#ifdef WITH_BTF
if (opts.use_btf)
requested_fe_kind = corpus::BTF_ORIGIN;
#endif
abigail::elf_based_reader_sptr rdr =
create_best_elf_based_reader(opts.file2,
opts.di_root_paths2,
env, requested_fe_kind,
opts.show_all_types,
opts.linux_kernel_mode);
ABG_ASSERT(rdr);
set_generic_options(*rdr, opts);
set_suppressions(*rdr, opts);
c2 = rdr->read_corpus(c2_status);
if (!c2
|| (opts.fail_no_debug_info
&& (c2_status & abigail::fe_iface::STATUS_ALT_DEBUG_INFO_NOT_FOUND)
&& (c2_status & abigail::fe_iface::STATUS_DEBUG_INFO_NOT_FOUND)))
return handle_error(c2_status, rdr.get(), argv[0], opts);
if (!opts.added_bins2.empty())
g2 = stick_corpus_and_binaries_into_corpus_group(rdr, c2,
opts.added_bins2,
opts.added_bins_dirs2);
if (opts.follow_dependencies)
{
if (g2)
add_dependencies_into_corpus_group(rdr, *c2,
opts.added_bins_dirs2,
*g2);
else
g2 = stick_corpus_and_dependencies_into_corpus_group(rdr, c2,
opts.added_bins_dirs2);
}
}
break;
case abigail::tools_utils::FILE_TYPE_XML_CORPUS:
{
abigail::fe_iface_sptr rdr = abixml::create_reader(opts.file2, env);
assert(rdr);
set_suppressions(*rdr, opts);
set_native_xml_reader_options(*rdr, opts);
c2 = rdr->read_corpus(c2_status);
if (!c2)
return handle_error(c2_status, /*ctxt=*/0, argv[0], opts);
}
break;
case abigail::tools_utils::FILE_TYPE_XML_CORPUS_GROUP:
{
abigail::fe_iface_sptr rdr = abixml::create_reader(opts.file2, env);
assert(rdr);
set_suppressions(*rdr, opts);
set_native_xml_reader_options(*rdr, opts);
g2 = abixml::read_corpus_group_from_input(*rdr);
if (!g2)
return handle_error(c2_status, /*ctxt=*/0, argv[0], opts);
}
break;
case abigail::tools_utils::FILE_TYPE_RPM:
case abigail::tools_utils::FILE_TYPE_SRPM:
case abigail::tools_utils::FILE_TYPE_DEB:
case abigail::tools_utils::FILE_TYPE_DIR:
case abigail::tools_utils::FILE_TYPE_TAR:
case abigail::tools_utils::FILE_TYPE_XZ:
break;
}
if (!opts.added_bins1.empty()
|| !opts.added_bins2.empty())
{
// We were requested to compare a set of binaries against
// another set of binaries. Let's make sure we construct
// two ABI construct groups in all cases.
if (!g1 && c1)
{
// We don't have a corpus group for the first argument.
// Let's build one and stick the ABI corpus at hand in
// it.
g1.reset(new corpus_group(c1->get_environment(),
c1->get_path()));
g1->add_corpus(c1);
}
if (!g2 && c2)
{
// We don't have a corpus group for the second argument.
// Let's build one and stick the ABI corpus at hand in
// it.
g2.reset(new corpus_group(c2->get_environment(),
c2->get_path()));
g2->add_corpus(c1);
}
}
if (!!c1 != !!c2
|| !!t1 != !!t2
|| !!g1 != !!g2)
{
emit_prefix(argv[0], cerr)
<< "the two input should be of the same kind\n";
return abigail::tools_utils::ABIDIFF_ERROR;
}
if (opts.no_arch)
{
if (c1)
c1->set_architecture_name("");
if (c2)
c2->set_architecture_name("");
}
if (opts.no_corpus)
{
if (c1)
c1->set_path("");
if (c2)
c2->set_path("");
}
if (t1)
{
tools_utils::timer t;
if (opts.do_log)
{
t.start();
std::cerr << "Compute diff ...\n";
}
translation_unit_diff_sptr diff = compute_diff(t1, t2, ctxt);
if (opts.do_log)
{
t.stop();
std::cerr << "diff computed!:" << t << "\n";
}
if (diff->has_changes())
{
tools_utils::timer t;
if (opts.do_log)
{
t.start();
std::cerr << "Computing the report ...\n";
}
diff->report(cout);
if (opts.do_log)
{
t.stop();
std::cerr << "Report computed!:" << t << "\n";
}
}
}
else if (g1)
{
if (opts.show_symtabs)
{
display_symtabs(c1, c2, cout);
return abigail::tools_utils::ABIDIFF_OK;
}
const auto g1_version = g1->get_format_major_version_number();
const auto g2_version = g2->get_format_major_version_number();
if (g1_version != g2_version)
{
emit_incompatible_format_version_error_message(opts.file1,
g1_version,
opts.file2,
g2_version,
argv[0]);
return abigail::tools_utils::ABIDIFF_ERROR;
}
adjust_diff_context_for_kmidiff(*ctxt);
tools_utils::timer t;
if (opts.do_log)
{
t.start();
std::cerr << "Compute diff ...\n";
}
corpus_diff_sptr diff = compute_diff(g1, g2, ctxt);
if (opts.do_log)
{
t.stop();
diff->do_log(true);
std::cerr << "diff computed!:" << t << "\n";
}
if (opts.do_log)
{
std::cerr << "Computing net changes ...\n";
t.start();
}
if (diff->has_net_changes())
status = abigail::tools_utils::ABIDIFF_ABI_CHANGE;
if (opts.do_log)
{
t.stop();
std::cerr << "net changes computed!: "<< t << "\n";
}
if (opts.do_log)
{
t.start();
std::cerr << "Computing incompatible changes ...\n";
}
if (diff->has_incompatible_changes())
status |= abigail::tools_utils::ABIDIFF_ABI_INCOMPATIBLE_CHANGE;
if (opts.do_log)
{
t.stop();
std::cerr << "incompatible changes computed!: "<< t << "\n";
}
if (opts.do_log)
{
t.start();
std::cerr << "Computing changes ...\n";
}
if (diff->has_changes())
{
if (opts.do_log)
{
t.stop();
std::cerr << "changes computed!: "<< t << "\n";
}
if (opts.do_log)
{
t.start();
std::cerr << "Computing report ...\n";
}
diff->report(cout);
if (opts.do_log)
{
t.stop();
std::cerr << "Report computed!:" << t << "\n";
}
}
else
{
if (opts.do_log)
{
t.stop();
std::cerr << "changes computed!: "<< t << "\n";
}
}
if (opts.list_dependencies)
{
set<string> deps1, deps2;
get_dependencies(*c1, opts.added_bins_dirs1, deps1);
get_dependencies(*c2, opts.added_bins_dirs2, deps2);
display_dependencies(argv[0], c1, c2, deps1, deps2);
}
}
else if (c1)
{
if (opts.show_symtabs)
{
display_symtabs(c1, c2, cout);
return abigail::tools_utils::ABIDIFF_OK;
}
if (opts.list_dependencies)
{
set<string> deps1, deps2;
get_dependencies(*c1, opts.added_bins_dirs1, deps1);
get_dependencies(*c2, opts.added_bins_dirs2, deps2);
display_dependencies(argv[0], c1, c2, deps1, deps2);
return abigail::tools_utils::ABIDIFF_OK;
}
const auto c1_version = c1->get_format_major_version_number();
const auto c2_version = c2->get_format_major_version_number();
if (c1_version != c2_version)
{
emit_incompatible_format_version_error_message(opts.file1,
c1_version,
opts.file2,
c2_version,
argv[0]);
return abigail::tools_utils::ABIDIFF_ERROR;
}
set_corpus_keep_drop_regex_patterns(opts, c1);
set_corpus_keep_drop_regex_patterns(opts, c2);
tools_utils::timer t;
if (opts.do_log)
{
t.start();
std::cerr << "Compute diff ...\n";
}
corpus_diff_sptr diff = compute_diff(c1, c2, ctxt);
if (opts.do_log)
{
t.stop();
std::cerr << "diff computed!:" << t << "\n";
}
if (opts.do_log)
{
t.start();
std::cerr << "Computing net changes ...\n";
}
if (diff->has_net_changes())
{
if (opts.do_log)
{
t.stop();
std::cerr << "net changes computed!: "<< t << "\n";
}
status = abigail::tools_utils::ABIDIFF_ABI_CHANGE;
}
if (opts.do_log)
{
t.start();
std::cerr << "Computing incompatible changes ...\n";
}
if (diff->has_incompatible_changes())
{
if (opts.do_log)
{
t.stop();
std::cerr << "incompatible changes computed!: "<< t << "\n";
}
status |= abigail::tools_utils::ABIDIFF_ABI_INCOMPATIBLE_CHANGE;
}
if (opts.do_log)
{
t.start();
std::cerr << "Computing changes ...\n";
}
if (diff->has_changes())
{
if (opts.do_log)
{
t.stop();
std::cerr << "changes computed!: "<< t << "\n";
}
if (opts.do_log)
{
t.start();
std::cerr << "Computing report ...\n";
}
diff->report(cout);
if (opts.do_log)
{
t.stop();
std::cerr << "Report computed!:" << t << "\n";
}
}
}
else
status = abigail::tools_utils::ABIDIFF_ERROR;
}
return status;
}
#ifdef __ABIGAIL_IN_THE_DEBUGGER__
/// Emit a textual representation of a given @ref corpus_diff tree to
/// stdout.
///
/// This is useful when debugging this program.
///
/// @param diff_tree the diff tree to emit a textual representation
/// for.
void
print_diff_tree(abigail::comparison::corpus_diff* diff_tree)
{
print_diff_tree(diff_tree, std::cout);
}
/// Emit a textual representation of a given @ref corpus_diff tree to
/// stdout.
///
/// This is useful when debugging this program.
///
/// @param diff_tree the diff tree to emit a textual representation
/// for.
void
print_diff_tree(abigail::comparison::corpus_diff_sptr diff_tree)
{
print_diff_tree(diff_tree, std::cout);
}
/// Emit a textual representation of a given @ref corpus_diff tree to
/// stdout.
///
/// This is useful when debugging this program.
///
/// @param diff_tree the diff tree to emit a textual representation
/// for.
void
print_diff_tree(abigail::comparison::diff_sptr diff_tree)
{
print_diff_tree(diff_tree.get(), std::cout);
}
/// Emit a textual representation of a given @ref diff tree to
/// stdout.
///
/// This is useful when debugging this program.
///
/// @param diff_tree the diff tree to emit a textual representation
/// for.
void
print_diff_tree(abigail::comparison::diff* diff_tree)
{
print_diff_tree(diff_tree, std::cout);
}
#endif // __ABIGAIL_IN_THE_DEBUGGER__
|