• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2016 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef ABI_DIFF_H_
16 #define ABI_DIFF_H_
17 
18 #include "diff/abi_diff_wrappers.h"
19 #include "repr/ir_representation.h"
20 
21 #include <string>
22 #include <vector>
23 
24 
25 namespace header_checker {
26 namespace diff {
27 
28 
29 using repr::AbiElementMap;
30 using repr::DiffPolicyOptions;
31 
32 
33 class HeaderAbiDiff {
34  public:
HeaderAbiDiff(const std::string & lib_name,const std::string & arch,const std::string & old_dump,const std::string & new_dump,const std::string & compatibility_report,const std::set<std::string> & ignored_symbols,bool allow_adding_removing_weak_symbols,const DiffPolicyOptions & diff_policy_options,bool check_all_apis,repr::TextFormatIR text_format_old,repr::TextFormatIR text_format_new,repr::TextFormatIR text_format_diff)35   HeaderAbiDiff(const std::string &lib_name, const std::string &arch,
36                 const std::string &old_dump, const std::string &new_dump,
37                 const std::string &compatibility_report,
38                 const std::set<std::string> &ignored_symbols,
39                 bool allow_adding_removing_weak_symbols,
40                 const DiffPolicyOptions &diff_policy_options,
41                 bool check_all_apis, repr::TextFormatIR text_format_old,
42                 repr::TextFormatIR text_format_new,
43                 repr::TextFormatIR text_format_diff)
44       : lib_name_(lib_name), arch_(arch), old_dump_(old_dump),
45         new_dump_(new_dump), cr_(compatibility_report),
46         ignored_symbols_(ignored_symbols),
47         diff_policy_options_(diff_policy_options),
48         allow_adding_removing_weak_symbols_(allow_adding_removing_weak_symbols),
49         check_all_apis_(check_all_apis),
50         text_format_old_(text_format_old), text_format_new_(text_format_new),
51         text_format_diff_(text_format_diff) {}
52 
53   repr::CompatibilityStatusIR GenerateCompatibilityReport();
54 
55  private:
56   repr::CompatibilityStatusIR CompareTUs(
57       const repr::ModuleIR &old_tu,
58       const repr::ModuleIR &new_tu,
59       repr::IRDiffDumper *ir_diff_dumper);
60 
61   template <typename T, typename ElfSymbolType>
62   bool CollectDynsymExportables(
63       const AbiElementMap<T> &old_exportables,
64       const AbiElementMap<T> &new_exportables,
65       const AbiElementMap<ElfSymbolType> &old_elf_symbols,
66       const AbiElementMap<ElfSymbolType> &new_elf_symbols,
67       const AbiElementMap<const repr::TypeIR *> &old_types_map,
68       const AbiElementMap<const repr::TypeIR *> &new_types_map,
69       repr::IRDiffDumper *ir_diff_dumper);
70 
71   template <typename T>
72   bool Collect(
73       const AbiElementMap<const T *> &old_elements_map,
74       const AbiElementMap<const T *> &new_elements_map,
75       const AbiElementMap<const repr::ElfSymbolIR *> *old_elf_map,
76       const AbiElementMap<const repr::ElfSymbolIR *> *new_elf_map,
77       repr::IRDiffDumper *ir_diff_dumper,
78       const AbiElementMap<const repr::TypeIR *> &old_types_map,
79       const AbiElementMap<const repr::TypeIR *> &new_types_map);
80 
81   bool CollectElfSymbols(
82       const AbiElementMap<const repr::ElfSymbolIR *> &old_symbols,
83       const AbiElementMap<const repr::ElfSymbolIR *> &new_symbols,
84       repr::IRDiffDumper *ir_diff_dumper);
85 
86   bool PopulateElfElements(
87       std::vector<const repr::ElfSymbolIR *> &elf_elements,
88       repr::IRDiffDumper *ir_diff_dumper,
89       repr::IRDiffDumper::DiffKind diff_kind);
90 
91   template <typename T>
92   bool PopulateRemovedElements(
93       const AbiElementMap<const T *> &old_elements_map,
94       const AbiElementMap<const T *> &new_elements_map,
95       const AbiElementMap<const repr::ElfSymbolIR *> *old_elf_map,
96       const AbiElementMap<const repr::ElfSymbolIR *> *new_elf_map,
97       repr::IRDiffDumper *ir_diff_dumper,
98       repr::IRDiffDumper::DiffKind diff_kind,
99       const AbiElementMap<const repr::TypeIR *> &types_map);
100 
101   template <typename T>
102   bool PopulateCommonElements(
103       const AbiElementMap<const T *> &old_elements_map,
104       const AbiElementMap<const T *> &new_elements_map,
105       const AbiElementMap<const repr::TypeIR *> &old_types,
106       const AbiElementMap<const repr::TypeIR *> &new_types,
107       repr::IRDiffDumper *ir_diff_dumper,
108       repr::IRDiffDumper::DiffKind diff_kind);
109 
110   template <typename T>
111   bool DumpDiffElements(
112       std::vector<std::pair<const T *, const T *>> &pairs,
113       const AbiElementMap<const repr::TypeIR *> &old_types,
114       const AbiElementMap<const repr::TypeIR *> &new_types,
115       repr::IRDiffDumper *ir_diff_dumper,
116       repr::IRDiffDumper::DiffKind diff_kind);
117 
118   template <typename T>
119   bool DumpLoneElements(
120       std::vector<const T *> &elements,
121       const AbiElementMap<const repr::ElfSymbolIR *> *old_elf_map,
122       const AbiElementMap<const repr::ElfSymbolIR *> *new_elf_map,
123       repr::IRDiffDumper *ir_diff_dumper,
124       repr::IRDiffDumper::DiffKind diff_kind,
125       const AbiElementMap<const repr::TypeIR *> &old_types_map);
126 
127   std::pair<AbiElementMap<const repr::EnumTypeIR *>,
128             AbiElementMap<const repr::RecordTypeIR *>>
129   ExtractUserDefinedTypes(const repr::ModuleIR &tu);
130 
131   bool CollectUserDefinedTypes(
132       const repr::ModuleIR &old_tu,
133       const repr::ModuleIR &new_tu,
134       const AbiElementMap<const repr::TypeIR *> &old_types_map,
135       const AbiElementMap<const repr::TypeIR *> &new_types_map,
136       repr::IRDiffDumper *ir_diff_dumper);
137 
138   template <typename T>
139   bool CollectUserDefinedTypesInternal(
140       const AbiElementMap<const T*> &old_ud_types_map,
141       const AbiElementMap<const T*> &new_ud_types_map,
142       const AbiElementMap<const repr::TypeIR *> &old_types_map,
143       const AbiElementMap<const repr::TypeIR *> &new_types_map,
144       repr::IRDiffDumper *ir_diff_dumper);
145 
146  private:
147   const std::string &lib_name_;
148   const std::string &arch_;
149   const std::string &old_dump_;
150   const std::string &new_dump_;
151   const std::string &cr_;
152   const std::set<std::string> &ignored_symbols_;
153   const DiffPolicyOptions &diff_policy_options_;
154   bool allow_adding_removing_weak_symbols_;
155   bool check_all_apis_;
156   std::set<std::string> type_cache_;
157   repr::TextFormatIR text_format_old_;
158   repr::TextFormatIR text_format_new_;
159   repr::TextFormatIR text_format_diff_;
160 };
161 
162 
163 }  // namespace diff
164 }  // namespace header_checker
165 
166 
167 #endif  // ABI_DIFF_H_
168