diff --git a/vndk/tools/header-checker/src/diff/abi_diff.cpp b/vndk/tools/header-checker/src/diff/abi_diff.cpp index 0dd4439c8..b8f82f9ce 100644 --- a/vndk/tools/header-checker/src/diff/abi_diff.cpp +++ b/vndk/tools/header-checker/src/diff/abi_diff.cpp @@ -387,7 +387,7 @@ bool HeaderAbiDiff::DumpDiffElements( DiffWrapper diff_wrapper( old_element, new_element, ir_diff_dumper, old_types, new_types, - diff_policy_options_, &type_cache_); + diff_policy_options_, &type_cache_, ignored_linker_set_keys_); if (!diff_wrapper.DumpDiff(diff_kind)) { llvm::errs() << "Failed to diff elements\n"; return false; diff --git a/vndk/tools/header-checker/src/diff/abi_diff.h b/vndk/tools/header-checker/src/diff/abi_diff.h index ca64716a5..dbe387d53 100644 --- a/vndk/tools/header-checker/src/diff/abi_diff.h +++ b/vndk/tools/header-checker/src/diff/abi_diff.h @@ -36,6 +36,7 @@ class HeaderAbiDiff { const std::string &old_dump, const std::string &new_dump, const std::string &compatibility_report, const std::set &ignored_symbols, + const std::set &ignored_linker_set_keys, bool allow_adding_removing_weak_symbols, const DiffPolicyOptions &diff_policy_options, bool check_all_apis, repr::TextFormatIR text_format_old, @@ -44,6 +45,7 @@ class HeaderAbiDiff { : lib_name_(lib_name), arch_(arch), old_dump_(old_dump), new_dump_(new_dump), cr_(compatibility_report), ignored_symbols_(ignored_symbols), + ignored_linker_set_keys_(ignored_linker_set_keys), diff_policy_options_(diff_policy_options), allow_adding_removing_weak_symbols_(allow_adding_removing_weak_symbols), check_all_apis_(check_all_apis), @@ -150,6 +152,7 @@ class HeaderAbiDiff { const std::string &new_dump_; const std::string &cr_; const std::set &ignored_symbols_; + const std::set &ignored_linker_set_keys_; const DiffPolicyOptions &diff_policy_options_; bool allow_adding_removing_weak_symbols_; bool check_all_apis_; diff --git a/vndk/tools/header-checker/src/diff/abi_diff_wrappers.h b/vndk/tools/header-checker/src/diff/abi_diff_wrappers.h index baa4a5f19..6d1a04c75 100644 --- a/vndk/tools/header-checker/src/diff/abi_diff_wrappers.h +++ b/vndk/tools/header-checker/src/diff/abi_diff_wrappers.h @@ -43,9 +43,10 @@ class DiffWrapper : public AbiDiffHelper { const AbiElementMap &old_types, const AbiElementMap &new_types, const repr::DiffPolicyOptions &diff_policy_options, - std::set *type_cache) + std::set *type_cache, + const std::set &ignored_linker_set_keys) : AbiDiffHelper(old_types, new_types, diff_policy_options, type_cache, - ir_diff_dumper), + ignored_linker_set_keys, ir_diff_dumper), oldp_(oldp), newp_(newp) {} bool DumpDiff(repr::IRDiffDumper::DiffKind diff_kind); diff --git a/vndk/tools/header-checker/src/diff/header_abi_diff.cpp b/vndk/tools/header-checker/src/diff/header_abi_diff.cpp index 224f522c9..a4a37048f 100644 --- a/vndk/tools/header-checker/src/diff/header_abi_diff.cpp +++ b/vndk/tools/header-checker/src/diff/header_abi_diff.cpp @@ -139,6 +139,11 @@ static llvm::cl::opt target_version( llvm::cl::init("current"), llvm::cl::Optional, llvm::cl::cat(header_checker_category)); +static llvm::cl::list ignore_linker_set_keys( + "ignore-linker-set-key", + llvm::cl::desc("Ignore a specific type or function in the comparison."), + llvm::cl::ZeroOrMore, llvm::cl::cat(header_checker_category)); + static std::set LoadIgnoredSymbols(std::string &symbol_list_path) { std::ifstream symbol_ifstream(symbol_list_path); std::set ignored_symbols; @@ -161,6 +166,9 @@ static std::string GetConfigFilePath(const std::string &dump_file_path) { } static void UpdateFlags(const ConfigSection §ion) { + for (auto &&i : section.GetIgnoredLinkerSetKeys()) { + ignore_linker_set_keys.push_back(i); + } for (auto &&p : section) { auto &&key = p.first; bool value_bool = p.second; @@ -223,12 +231,16 @@ int main(int argc, const char **argv) { ignored_symbols = LoadIgnoredSymbols(ignore_symbol_list); } + std::set ignored_linker_set_keys_set( + ignore_linker_set_keys.begin(), ignore_linker_set_keys.end()); + DiffPolicyOptions diff_policy_options(consider_opaque_types_different); HeaderAbiDiff judge(lib_name, arch, old_dump, new_dump, compatibility_report, - ignored_symbols, allow_adding_removing_weak_symbols, - diff_policy_options, check_all_apis, text_format_old, - text_format_new, text_format_diff); + ignored_symbols, ignored_linker_set_keys_set, + allow_adding_removing_weak_symbols, diff_policy_options, + check_all_apis, text_format_old, text_format_new, + text_format_diff); CompatibilityStatusIR status = judge.GenerateCompatibilityReport(); diff --git a/vndk/tools/header-checker/src/linker/module_merger.cpp b/vndk/tools/header-checker/src/linker/module_merger.cpp index af175ed2e..2ec368bc9 100644 --- a/vndk/tools/header-checker/src/linker/module_merger.cpp +++ b/vndk/tools/header-checker/src/linker/module_merger.cpp @@ -63,7 +63,7 @@ MergeStatus ModuleMerger::LookupUserDefinedType( std::set type_cache; repr::DiffPolicyOptions diff_policy_options(false); repr::AbiDiffHelper diff_helper(module_->type_graph_, addend.type_graph_, - diff_policy_options, &type_cache, nullptr); + diff_policy_options, &type_cache, {}, nullptr); // Compare each user-defined type with the latest input user-defined type. // If there is a match, re-use the existing user-defined type. diff --git a/vndk/tools/header-checker/src/repr/abi_diff_helpers.cpp b/vndk/tools/header-checker/src/repr/abi_diff_helpers.cpp index f2db7b4b7..f50d5d559 100644 --- a/vndk/tools/header-checker/src/repr/abi_diff_helpers.cpp +++ b/vndk/tools/header-checker/src/repr/abi_diff_helpers.cpp @@ -732,6 +732,11 @@ DiffStatus AbiDiffHelper::CompareAndDumpTypeDiff( const TypeIR *old_type, const TypeIR *new_type, LinkableMessageKind kind, std::deque *type_queue, DiffMessageIR::DiffKind diff_kind) { + if (ignored_linker_set_keys_.find(new_type->GetLinkerSetKey()) != + ignored_linker_set_keys_.end()) { + return DiffStatus::no_diff; + } + if (kind == LinkableMessageKind::BuiltinTypeKind) { return CompareBuiltinTypes( static_cast(old_type), diff --git a/vndk/tools/header-checker/src/repr/abi_diff_helpers.h b/vndk/tools/header-checker/src/repr/abi_diff_helpers.h index 7b67d2be3..2d0774b28 100644 --- a/vndk/tools/header-checker/src/repr/abi_diff_helpers.h +++ b/vndk/tools/header-checker/src/repr/abi_diff_helpers.h @@ -20,6 +20,7 @@ #include "repr/ir_representation.h" #include +#include namespace header_checker { @@ -80,9 +81,11 @@ class AbiDiffHelper { const AbiElementMap &new_types, const DiffPolicyOptions &diff_policy_options, std::set *type_cache, + const std::set &ignored_linker_set_keys, IRDiffDumper *ir_diff_dumper = nullptr) : old_types_(old_types), new_types_(new_types), diff_policy_options_(diff_policy_options), type_cache_(type_cache), + ignored_linker_set_keys_(ignored_linker_set_keys), ir_diff_dumper_(ir_diff_dumper) {} DiffStatus CompareAndDumpTypeDiff( @@ -208,6 +211,7 @@ class AbiDiffHelper { const AbiElementMap &new_types_; const DiffPolicyOptions &diff_policy_options_; std::set *type_cache_; + const std::set &ignored_linker_set_keys_; IRDiffDumper *ir_diff_dumper_; }; diff --git a/vndk/tools/header-checker/src/utils/config_file.cpp b/vndk/tools/header-checker/src/utils/config_file.cpp index e3efb6555..7f76d12df 100644 --- a/vndk/tools/header-checker/src/utils/config_file.cpp +++ b/vndk/tools/header-checker/src/utils/config_file.cpp @@ -39,6 +39,15 @@ static std::map LoadFlags(const Json::Value §ion) { return map; } +static std::vector +LoadIgnoreLinkerSetKeys(const Json::Value §ion) { + std::vector vec; + for (auto &key : section.get("ignore_linker_set_keys", {})) { + vec.emplace_back(key.asString()); + } + return vec; +} + bool ConfigFile::HasGlobalSection() { return HasSection(GLOBAL_SECTION_NAME, ""); } @@ -59,12 +68,15 @@ bool ConfigFile::Load(std::istream &istream) { if (key == GLOBAL_SECTION_NAME) { ConfigSection &config_section = map_[{GLOBAL_SECTION_NAME, ""}]; config_section.map_ = LoadFlags(root[GLOBAL_SECTION_NAME]); + config_section.ignored_linker_set_keys_ = + LoadIgnoreLinkerSetKeys(root[GLOBAL_SECTION_NAME]); continue; } for (auto §ion : root[key]) { ConfigSection &config_section = map_[{key, section["target_version"].asString()}]; config_section.map_ = LoadFlags(section); + config_section.ignored_linker_set_keys_ = LoadIgnoreLinkerSetKeys(section); } } return true; diff --git a/vndk/tools/header-checker/src/utils/config_file.h b/vndk/tools/header-checker/src/utils/config_file.h index 215215dfe..8048b1814 100644 --- a/vndk/tools/header-checker/src/utils/config_file.h +++ b/vndk/tools/header-checker/src/utils/config_file.h @@ -19,6 +19,7 @@ #include #include #include +#include namespace header_checker { @@ -48,6 +49,10 @@ class ConfigSection { return it->second; } + const std::vector &GetIgnoredLinkerSetKeys() const { + return ignored_linker_set_keys_; + } + bool operator[](const std::string &name) const { return GetProperty(name); } const_iterator begin() const { return map_.begin(); } @@ -61,6 +66,7 @@ class ConfigSection { private: MapType map_; + std::vector ignored_linker_set_keys_; friend class ConfigFile; }; diff --git a/vndk/tools/header-checker/src/utils/config_file_test.cpp b/vndk/tools/header-checker/src/utils/config_file_test.cpp index 806d15353..628d3c711 100644 --- a/vndk/tools/header-checker/src/utils/config_file_test.cpp +++ b/vndk/tools/header-checker/src/utils/config_file_test.cpp @@ -15,6 +15,8 @@ #include "utils/config_file.h" #include +#include +#include #include @@ -29,6 +31,10 @@ TEST(ConfigFileTest, Parse) { /* embedded comment */ { "global": { + "ignore_linker_set_keys": [ + "set_key1", + "set_key3", + ], "flags": { "key1": true, "key2": false, @@ -37,6 +43,10 @@ TEST(ConfigFileTest, Parse) { "library1": [ { "target_version": "current", + "ignore_linker_set_keys": [ + "set_key1", + "set_key2", + ], "flags": { "key1": true, "key2": false, @@ -68,12 +78,14 @@ TEST(ConfigFileTest, Parse) { EXPECT_FALSE(section1.HasProperty("key3")); EXPECT_FALSE(section1.GetProperty("key3")); + EXPECT_EQ(std::vector({"set_key1", "set_key3"}), section1.GetIgnoredLinkerSetKeys()); auto &§ion2 = cfg.GetSection("library1", "current"); EXPECT_TRUE(section2.HasProperty("key1")); EXPECT_TRUE(section2.GetProperty("key1")); EXPECT_TRUE(section2.HasProperty("key2")); EXPECT_FALSE(section2.GetProperty("key2")); + EXPECT_EQ(std::vector({"set_key1", "set_key2"}), section2.GetIgnoredLinkerSetKeys()); EXPECT_TRUE(cfg.GetProperty("global", "", "key1")); EXPECT_TRUE(cfg.GetProperty("library1", "34", "key2"));