• 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,const std::set<std::string> & ignored_linker_set_keys,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                 const std::set<std::string> &ignored_linker_set_keys,
40                 bool allow_adding_removing_weak_symbols,
41                 const DiffPolicyOptions &diff_policy_options,
42                 bool check_all_apis, repr::TextFormatIR text_format_old,
43                 repr::TextFormatIR text_format_new,
44                 repr::TextFormatIR text_format_diff)
45       : lib_name_(lib_name), arch_(arch), old_dump_(old_dump),
46         new_dump_(new_dump), cr_(compatibility_report),
47         ignored_symbols_(ignored_symbols),
48         ignored_linker_set_keys_(ignored_linker_set_keys),
49         diff_policy_options_(diff_policy_options),
50         allow_adding_removing_weak_symbols_(allow_adding_removing_weak_symbols),
51         check_all_apis_(check_all_apis),
52         text_format_old_(text_format_old), text_format_new_(text_format_new),
53         text_format_diff_(text_format_diff) {}
54 
55   repr::CompatibilityStatusIR GenerateCompatibilityReport();
56 
57  private:
58   repr::CompatibilityStatusIR CompareTUs(
59       const repr::ModuleIR &old_tu,
60       const repr::ModuleIR &new_tu,
61       repr::IRDiffDumper *ir_diff_dumper);
62 
63   template <typename T, typename ElfSymbolType>
64   bool CollectDynsymExportables(
65       const AbiElementMap<T> &old_exportables,
66       const AbiElementMap<T> &new_exportables,
67       const AbiElementMap<ElfSymbolType> &old_elf_symbols,
68       const AbiElementMap<ElfSymbolType> &new_elf_symbols,
69       const AbiElementMap<const repr::TypeIR *> &old_types_map,
70       const AbiElementMap<const repr::TypeIR *> &new_types_map,
71       repr::IRDiffDumper *ir_diff_dumper);
72 
73   template <typename T>
74   bool Collect(
75       const AbiElementMap<const T *> &old_elements_map,
76       const AbiElementMap<const T *> &new_elements_map,
77       const AbiElementMap<const repr::ElfSymbolIR *> *old_elf_map,
78       const AbiElementMap<const repr::ElfSymbolIR *> *new_elf_map,
79       repr::IRDiffDumper *ir_diff_dumper,
80       const AbiElementMap<const repr::TypeIR *> &old_types_map,
81       const AbiElementMap<const repr::TypeIR *> &new_types_map);
82 
83   bool CollectElfSymbols(
84       const AbiElementMap<const repr::ElfSymbolIR *> &old_symbols,
85       const AbiElementMap<const repr::ElfSymbolIR *> &new_symbols,
86       repr::IRDiffDumper *ir_diff_dumper);
87 
88   bool PopulateElfElements(
89       std::vector<const repr::ElfSymbolIR *> &elf_elements,
90       repr::IRDiffDumper *ir_diff_dumper,
91       repr::IRDiffDumper::DiffKind diff_kind);
92 
93   template <typename T>
94   bool PopulateRemovedElements(
95       const AbiElementMap<const T *> &old_elements_map,
96       const AbiElementMap<const T *> &new_elements_map,
97       const AbiElementMap<const repr::ElfSymbolIR *> *old_elf_map,
98       const AbiElementMap<const repr::ElfSymbolIR *> *new_elf_map,
99       repr::IRDiffDumper *ir_diff_dumper,
100       repr::IRDiffDumper::DiffKind diff_kind,
101       const AbiElementMap<const repr::TypeIR *> &types_map);
102 
103   template <typename T>
104   bool PopulateCommonElements(
105       const AbiElementMap<const T *> &old_elements_map,
106       const AbiElementMap<const T *> &new_elements_map,
107       const AbiElementMap<const repr::TypeIR *> &old_types,
108       const AbiElementMap<const repr::TypeIR *> &new_types,
109       repr::IRDiffDumper *ir_diff_dumper,
110       repr::IRDiffDumper::DiffKind diff_kind);
111 
112   template <typename T>
113   bool DumpDiffElements(
114       std::vector<std::pair<const T *, const T *>> &pairs,
115       const AbiElementMap<const repr::TypeIR *> &old_types,
116       const AbiElementMap<const repr::TypeIR *> &new_types,
117       repr::IRDiffDumper *ir_diff_dumper,
118       repr::IRDiffDumper::DiffKind diff_kind);
119 
120   template <typename T>
121   bool DumpLoneElements(
122       std::vector<const T *> &elements,
123       const AbiElementMap<const repr::ElfSymbolIR *> *old_elf_map,
124       const AbiElementMap<const repr::ElfSymbolIR *> *new_elf_map,
125       repr::IRDiffDumper *ir_diff_dumper,
126       repr::IRDiffDumper::DiffKind diff_kind,
127       const AbiElementMap<const repr::TypeIR *> &old_types_map);
128 
129   std::pair<AbiElementMap<const repr::EnumTypeIR *>,
130             AbiElementMap<const repr::RecordTypeIR *>>
131   ExtractUserDefinedTypes(const repr::ModuleIR &tu);
132 
133   bool CollectUserDefinedTypes(
134       const repr::ModuleIR &old_tu,
135       const repr::ModuleIR &new_tu,
136       const AbiElementMap<const repr::TypeIR *> &old_types_map,
137       const AbiElementMap<const repr::TypeIR *> &new_types_map,
138       repr::IRDiffDumper *ir_diff_dumper);
139 
140   template <typename T>
141   bool CollectUserDefinedTypesInternal(
142       const AbiElementMap<const T*> &old_ud_types_map,
143       const AbiElementMap<const T*> &new_ud_types_map,
144       const AbiElementMap<const repr::TypeIR *> &old_types_map,
145       const AbiElementMap<const repr::TypeIR *> &new_types_map,
146       repr::IRDiffDumper *ir_diff_dumper);
147 
148  private:
149   const std::string &lib_name_;
150   const std::string &arch_;
151   const std::string &old_dump_;
152   const std::string &new_dump_;
153   const std::string &cr_;
154   const std::set<std::string> &ignored_symbols_;
155   const std::set<std::string> &ignored_linker_set_keys_;
156   const DiffPolicyOptions &diff_policy_options_;
157   bool allow_adding_removing_weak_symbols_;
158   bool check_all_apis_;
159   std::set<std::string> type_cache_;
160   repr::TextFormatIR text_format_old_;
161   repr::TextFormatIR text_format_new_;
162   repr::TextFormatIR text_format_diff_;
163 };
164 
165 
166 }  // namespace diff
167 }  // namespace header_checker
168 
169 
170 #endif  // ABI_DIFF_H_
171