• 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 #include "abi_diff_wrappers.h"
16 
17 #include <ir_representation.h>
18 
19 #include <string>
20 #include <vector>
21 
22 using abi_util::AbiElementMap;
23 
24 class HeaderAbiDiff {
25  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 check_all_apis,abi_util::TextFormatIR text_format_old,abi_util::TextFormatIR text_format_new,abi_util::TextFormatIR text_format_diff)26   HeaderAbiDiff(const std::string &lib_name, const std::string &arch,
27                 const std::string &old_dump, const std::string &new_dump,
28                 const std::string &compatibility_report,
29                 const std::set<std::string> &ignored_symbols,
30                 bool check_all_apis, abi_util::TextFormatIR text_format_old,
31                 abi_util::TextFormatIR text_format_new,
32                 abi_util::TextFormatIR text_format_diff)
33       : lib_name_(lib_name), arch_(arch), old_dump_(old_dump),
34         new_dump_(new_dump), cr_(compatibility_report),
35         ignored_symbols_(ignored_symbols), check_all_apis_(check_all_apis),
36         text_format_old_(text_format_old), text_format_new_(text_format_new),
37         text_format_diff_(text_format_diff) { }
38 
39   abi_util::CompatibilityStatusIR GenerateCompatibilityReport();
40 
41  private:
42   abi_util::CompatibilityStatusIR CompareTUs(
43       const abi_util::TextFormatToIRReader *old_tu,
44       const abi_util::TextFormatToIRReader *new_tu,
45       abi_util::IRDiffDumper *ir_diff_dumper);
46 
47   template <typename T, typename ElfSymbolType>
48   bool CollectDynsymExportables(
49     const AbiElementMap<T> &old_exportables,
50     const AbiElementMap<T> &new_exportables,
51     const AbiElementMap<ElfSymbolType> &old_elf_symbols,
52     const AbiElementMap<ElfSymbolType> &new_elf_symbols,
53     const AbiElementMap<const abi_util::TypeIR *> &old_types_map,
54     const AbiElementMap<const abi_util::TypeIR *> &new_types_map,
55     abi_util::IRDiffDumper *ir_diff_dumper);
56 
57   template <typename T>
58   bool Collect(
59       const AbiElementMap<const T *> &old_elements_map,
60       const AbiElementMap<const T *> &new_elements_map,
61       const AbiElementMap<const abi_util::ElfSymbolIR *> *old_elf_map,
62       const AbiElementMap<const abi_util::ElfSymbolIR *> *new_elf_map,
63       abi_util::IRDiffDumper *ir_diff_dumper,
64       const AbiElementMap<const abi_util::TypeIR *> &old_types_map,
65       const AbiElementMap<const abi_util::TypeIR *> &new_types_map);
66 
67   bool CollectElfSymbols(
68       const AbiElementMap<const abi_util::ElfSymbolIR *> &old_symbols,
69       const AbiElementMap<const abi_util::ElfSymbolIR *> &new_symbols,
70       abi_util::IRDiffDumper *ir_diff_dumper);
71 
72   bool PopulateElfElements(
73       std::vector<const abi_util::ElfSymbolIR *> &elf_elements,
74       abi_util::IRDiffDumper *ir_diff_dumper,
75       abi_util::IRDiffDumper::DiffKind diff_kind);
76 
77   template <typename T>
78   bool PopulateRemovedElements(
79       const AbiElementMap<const T *> &old_elements_map,
80       const AbiElementMap<const T *> &new_elements_map,
81       const AbiElementMap<const abi_util::ElfSymbolIR *> *elf_map,
82       abi_util::IRDiffDumper *ir_diff_dumper,
83       abi_util::IRDiffDumper::DiffKind diff_kind,
84       const AbiElementMap<const abi_util::TypeIR *> &types_map);
85 
86   template <typename T>
87   bool PopulateCommonElements(
88       const AbiElementMap<const T *> &old_elements_map,
89       const AbiElementMap<const T *> &new_elements_map,
90       const AbiElementMap<const abi_util::TypeIR *> &old_types,
91       const AbiElementMap<const abi_util::TypeIR *> &new_types,
92       abi_util::IRDiffDumper *ir_diff_dumper,
93       abi_util::IRDiffDumper::DiffKind diff_kind);
94 
95   template <typename T>
96   bool DumpDiffElements(
97       std::vector<std::pair<const T *, const T *>> &pairs,
98       const AbiElementMap<const abi_util::TypeIR *> &old_types,
99       const AbiElementMap<const abi_util::TypeIR *> &new_types,
100       abi_util::IRDiffDumper *ir_diff_dumper,
101       abi_util::IRDiffDumper::DiffKind diff_kind);
102 
103   template <typename T>
104   bool DumpLoneElements(
105       std::vector<const T *> &elements,
106       const AbiElementMap<const abi_util::ElfSymbolIR *> *elf_map,
107       abi_util::IRDiffDumper *ir_diff_dumper,
108       abi_util::IRDiffDumper::DiffKind diff_kind,
109       const AbiElementMap<const abi_util::TypeIR *> &old_types_map);
110 
111   std::pair<AbiElementMap<const abi_util::EnumTypeIR *>,
112             AbiElementMap<const abi_util::RecordTypeIR *>>
113   ExtractUserDefinedTypes(const abi_util::TextFormatToIRReader *tu);
114 
115   bool CollectUserDefinedTypes(
116       const abi_util::TextFormatToIRReader *old_tu,
117       const abi_util::TextFormatToIRReader *new_tu,
118       const AbiElementMap<const abi_util::TypeIR *> &old_types_map,
119       const AbiElementMap<const abi_util::TypeIR *> &new_types_map,
120       abi_util::IRDiffDumper *ir_diff_dumper);
121 
122   template <typename T>
123   bool CollectUserDefinedTypesInternal(
124       const AbiElementMap<const T*> &old_ud_types_map,
125       const AbiElementMap<const T*> &new_ud_types_map,
126       const AbiElementMap<const abi_util::TypeIR *> &old_types_map,
127       const AbiElementMap<const abi_util::TypeIR *> &new_types_map,
128       abi_util::IRDiffDumper *ir_diff_dumper);
129 
130  private:
131   const std::string &lib_name_;
132   const std::string &arch_;
133   const std::string &old_dump_;
134   const std::string &new_dump_;
135   const std::string &cr_;
136   const std::set<std::string> &ignored_symbols_;
137   bool check_all_apis_;
138   std::set<std::string> type_cache_;
139   abi_util::TextFormatIR text_format_old_;
140   abi_util::TextFormatIR text_format_new_;
141   abi_util::TextFormatIR text_format_diff_;
142 };
143