1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ART_DEX2OAT_LINKER_OAT_WRITER_H_
18 #define ART_DEX2OAT_LINKER_OAT_WRITER_H_
19 
20 #include <stdint.h>
21 #include <cstddef>
22 #include <list>
23 #include <memory>
24 #include <vector>
25 
26 #include "base/array_ref.h"
27 #include "base/dchecked_vector.h"
28 #include "base/os.h"
29 #include "base/mem_map.h"
30 #include "base/safe_map.h"
31 #include "debug/debug_info.h"
32 #include "dex/method_reference.h"
33 #include "dex/string_reference.h"
34 #include "dex/proto_reference.h"
35 #include "dex/type_reference.h"
36 #include "linker/relative_patcher.h"  // For RelativePatcherTargetProvider.
37 #include "mirror/class.h"
38 
39 namespace art {
40 
41 class BitVector;
42 class CompiledMethod;
43 class CompilerDriver;
44 class CompilerOptions;
45 class OatHeader;
46 class OutputStream;
47 class ProfileCompilationInfo;
48 class TimingLogger;
49 class TypeLookupTable;
50 class VdexFile;
51 class VerificationResults;
52 class ZipEntry;
53 
54 namespace debug {
55 struct MethodDebugInfo;
56 }  // namespace debug
57 
58 namespace verifier {
59 class VerifierDeps;
60 }  // namespace verifier
61 
62 namespace linker {
63 
64 class ImageWriter;
65 class MultiOatRelativePatcher;
66 
67 enum class CopyOption {
68   kNever,
69   kAlways,
70   kOnlyIfCompressed
71 };
72 
73 // OatHeader         variable length with count of D OatDexFiles
74 //
75 // TypeLookupTable[0] one descriptor to class def index hash table for each OatDexFile.
76 // TypeLookupTable[1]
77 // ...
78 // TypeLookupTable[D]
79 //
80 // ClassOffsets[0]   one table of OatClass offsets for each class def for each OatDexFile.
81 // ClassOffsets[1]
82 // ...
83 // ClassOffsets[D]
84 //
85 // OatClass[0]       one variable sized OatClass for each of C DexFile::ClassDefs
86 // OatClass[1]       contains OatClass entries with class status, offsets to code, etc.
87 // ...
88 // OatClass[C]
89 //
90 // MethodBssMapping  one variable sized MethodBssMapping for each dex file, optional.
91 // MethodBssMapping
92 // ...
93 // MethodBssMapping
94 //
95 // VmapTable         one variable sized VmapTable blob (CodeInfo).
96 // VmapTable         VmapTables are deduplicated.
97 // ...
98 // VmapTable
99 //
100 // OatDexFile[0]     one variable sized OatDexFile with offsets to Dex and OatClasses
101 // OatDexFile[1]
102 // ...
103 // OatDexFile[D]
104 //
105 // padding           if necessary so that the following code will be page aligned
106 //
107 // OatMethodHeader   fixed size header for a CompiledMethod including the size of the MethodCode.
108 // MethodCode        one variable sized blob with the code of a CompiledMethod.
109 // OatMethodHeader   (OatMethodHeader, MethodCode) pairs are deduplicated.
110 // MethodCode
111 // ...
112 // OatMethodHeader
113 // MethodCode
114 //
115 class OatWriter {
116  public:
117   OatWriter(const CompilerOptions& compiler_options,
118             const VerificationResults* verification_results,
119             TimingLogger* timings,
120             ProfileCompilationInfo* info);
121 
122   // To produce a valid oat file, the user must first add sources with any combination of
123   //   - AddDexFileSource(),
124   //   - AddRawDexFileSource(),
125   //   - AddVdexDexFilesSource().
126   // Then the user must call in order
127   //   - WriteAndOpenDexFiles()
128   //   - StartRoData()
129   //   - FinishVdexFile()
130   //   - PrepareLayout(),
131   //   - WriteRodata(),
132   //   - WriteCode(),
133   //   - WriteDataImgRelRo() iff GetDataImgRelRoSize() != 0,
134   //   - WriteHeader().
135 
136   // Add dex file source(s) from a file, either a plain dex file or
137   // a zip file with one or more dex files.
138   bool AddDexFileSource(
139       const char* filename,
140       const char* location);
141   // Add dex file source(s) from a file specified by a file handle.
142   // Note: The `dex_file_fd` specifies a plain dex file or a zip file.
143   bool AddDexFileSource(
144       File&& dex_file_fd,
145       const char* location);
146   // Add dex file source from raw memory.
147   bool AddRawDexFileSource(const std::shared_ptr<DexFileContainer>& container,
148                            const uint8_t* dex_file_begin,
149                            const char* location,
150                            uint32_t location_checksum);
151   // Add dex file source(s) from a vdex file.
152   bool AddVdexDexFilesSource(
153       const VdexFile& vdex_file,
154       const char* location);
155   dchecked_vector<std::string> GetSourceLocations() const;
156 
157   // Write raw dex files to the vdex file, mmap the file and open the dex files from it.
158   // The `verify` setting dictates whether the dex file verifier should check the dex files.
159   // This is generally the case, and should only be false for tests.
160   // If `use_existing_vdex` is true, then this method won't actually write the dex files,
161   // and the compiler will just re-use the existing vdex file.
162   bool WriteAndOpenDexFiles(File* vdex_file,
163                             bool verify,
164                             bool use_existing_vdex,
165                             CopyOption copy_dex_files,
166                             /*out*/ std::vector<MemMap>* opened_dex_files_map,
167                             /*out*/ std::vector<std::unique_ptr<const DexFile>>* opened_dex_files);
168   // Start writing .rodata, including supporting data structures for dex files.
169   bool StartRoData(const std::vector<const DexFile*>& dex_files,
170                    OutputStream* oat_rodata,
171                    SafeMap<std::string, std::string>* key_value_store);
172   // Initialize the writer with the given parameters.
173   void Initialize(const CompilerDriver* compiler_driver,
174                   ImageWriter* image_writer,
175                   const std::vector<const DexFile*>& dex_files);
176   bool FinishVdexFile(File* vdex_file, verifier::VerifierDeps* verifier_deps);
177 
178   // Prepare layout of remaining data.
179   void PrepareLayout(MultiOatRelativePatcher* relative_patcher);
180   // Write the rest of .rodata section (ClassOffsets[], OatClass[], maps).
181   bool WriteRodata(OutputStream* out);
182   // Write the code to the .text section.
183   bool WriteCode(OutputStream* out);
184   // Write the image relocation data to the .data.img.rel.ro section.
185   bool WriteDataImgRelRo(OutputStream* out);
186   // Check the size of the written oat file.
187   bool CheckOatSize(OutputStream* out, size_t file_offset, size_t relative_offset);
188   // Write the oat header. This finalizes the oat file.
189   bool WriteHeader(OutputStream* out);
190 
191   // Returns whether the oat file has an associated image.
HasImage()192   bool HasImage() const {
193     // Since the image is being created at the same time as the oat file,
194     // check if there's an image writer.
195     return image_writer_ != nullptr;
196   }
197 
GetOatHeader()198   const OatHeader& GetOatHeader() const {
199     return *oat_header_;
200   }
201 
GetCodeSize()202   size_t GetCodeSize() const {
203     return code_size_;
204   }
205 
GetOatSize()206   size_t GetOatSize() const {
207     return oat_size_;
208   }
209 
GetDataImgRelRoSize()210   size_t GetDataImgRelRoSize() const {
211     return data_img_rel_ro_size_;
212   }
213 
GetDataImgRelRoAppImageOffset()214   size_t GetDataImgRelRoAppImageOffset() const {
215     return data_img_rel_ro_app_image_offset_;
216   }
217 
GetBssSize()218   size_t GetBssSize() const {
219     return bss_size_;
220   }
221 
GetBssMethodsOffset()222   size_t GetBssMethodsOffset() const {
223     return bss_methods_offset_;
224   }
225 
GetBssRootsOffset()226   size_t GetBssRootsOffset() const {
227     return bss_roots_offset_;
228   }
229 
GetVdexSize()230   size_t GetVdexSize() const {
231     return vdex_size_;
232   }
233 
GetOatDataOffset()234   size_t GetOatDataOffset() const {
235     return oat_data_offset_;
236   }
237 
238   ~OatWriter();
239 
240   debug::DebugInfo GetDebugInfo() const;
241 
GetCompilerDriver()242   const CompilerDriver* GetCompilerDriver() const {
243     return compiler_driver_;
244   }
245 
GetCompilerOptions()246   const CompilerOptions& GetCompilerOptions() const {
247     return compiler_options_;
248   }
249 
250  private:
251   struct BssMappingInfo;
252   class ChecksumUpdatingOutputStream;
253   class OatClassHeader;
254   class OatClass;
255   class OatDexFile;
256 
257   // The function VisitDexMethods() below iterates through all the methods in all
258   // the compiled dex files in order of their definitions. The method visitor
259   // classes provide individual bits of processing for each of the passes we need to
260   // first collect the data we want to write to the oat file and then, in later passes,
261   // to actually write it.
262   class DexMethodVisitor;
263   class OatDexMethodVisitor;
264   class InitBssLayoutMethodVisitor;
265   class InitOatClassesMethodVisitor;
266   class LayoutCodeMethodVisitor;
267   class LayoutReserveOffsetCodeMethodVisitor;
268   struct OrderedMethodData;
269   class OrderedMethodVisitor;
270   class InitCodeMethodVisitor;
271   template <bool kDeduplicate> class InitMapMethodVisitor;
272   class InitImageMethodVisitor;
273   class WriteCodeMethodVisitor;
274   class WriteMapMethodVisitor;
275 
276   // Visit all the methods in all the compiled dex files in their definition order
277   // with a given DexMethodVisitor.
278   bool VisitDexMethods(DexMethodVisitor* visitor);
279 
280   // If `update_input_vdex` is true, then this method won't actually write the dex files,
281   // and the compiler will just re-use the existing vdex file.
282   bool WriteDexFiles(File* file,
283                      bool verify,
284                      bool use_existing_vdex,
285                      CopyOption copy_dex_files,
286                      /*out*/ std::vector<MemMap>* opened_dex_files_map);
287   bool LayoutDexFile(OatDexFile* oat_dex_file);
288   bool OpenDexFiles(File* file,
289                     /*inout*/ std::vector<MemMap>* opened_dex_files_map,
290                     /*out*/ std::vector<std::unique_ptr<const DexFile>>* opened_dex_files);
291   void WriteTypeLookupTables(/*out*/std::vector<uint8_t>* buffer);
292   void WriteVerifierDeps(verifier::VerifierDeps* verifier_deps,
293                          /*out*/std::vector<uint8_t>* buffer);
294 
295   size_t InitOatHeader(uint32_t num_dex_files, SafeMap<std::string, std::string>* key_value_store);
296   size_t InitClassOffsets(size_t offset);
297   size_t InitOatClasses(size_t offset);
298   size_t InitOatMaps(size_t offset);
299   size_t InitIndexBssMappings(size_t offset);
300   size_t InitOatDexFiles(size_t offset);
301   size_t InitBcpBssInfo(size_t offset);
302   size_t InitOatCode(size_t offset);
303   size_t InitOatCodeDexFiles(size_t offset);
304   size_t InitDataImgRelRoLayout(size_t offset);
305   void InitBssLayout(InstructionSet instruction_set);
306 
307   size_t WriteClassOffsets(OutputStream* out, size_t file_offset, size_t relative_offset);
308   size_t WriteClasses(OutputStream* out, size_t file_offset, size_t relative_offset);
309   size_t WriteMaps(OutputStream* out, size_t file_offset, size_t relative_offset);
310   size_t WriteIndexBssMappings(OutputStream* out, size_t file_offset, size_t relative_offset);
311   size_t WriteOatDexFiles(OutputStream* out, size_t file_offset, size_t relative_offset);
312   size_t WriteBcpBssInfo(OutputStream* out, size_t file_offset, size_t relative_offset);
313   size_t WriteCode(OutputStream* out, size_t file_offset, size_t relative_offset);
314   size_t WriteCodeDexFiles(OutputStream* out, size_t file_offset, size_t relative_offset);
315   size_t WriteDataImgRelRo(OutputStream* out, size_t file_offset, size_t relative_offset);
316   // These helpers extract common code from BCP and non-BCP DexFiles from its corresponding methods.
317   size_t WriteIndexBssMappingsHelper(OutputStream* out,
318                                      size_t file_offset,
319                                      size_t relative_offset,
320                                      const DexFile* dex_file,
321                                      uint32_t method_bss_mapping_offset,
322                                      uint32_t type_bss_mapping_offset,
323                                      uint32_t public_type_bss_mapping_offset,
324                                      uint32_t package_type_bss_mapping_offset,
325                                      uint32_t string_bss_mapping_offset,
326                                      uint32_t method_type_bss_mapping_offset);
327   size_t InitIndexBssMappingsHelper(size_t offset,
328                                     const DexFile* dex_file,
329                                     /*inout*/ size_t& number_of_method_dex_files,
330                                     /*inout*/ size_t& number_of_type_dex_files,
331                                     /*inout*/ size_t& number_of_public_type_dex_files,
332                                     /*inout*/ size_t& number_of_package_type_dex_files,
333                                     /*inout*/ size_t& number_of_string_dex_files,
334                                     /*inout*/ size_t& number_of_method_type_dex_files,
335                                     /*inout*/ uint32_t& method_bss_mapping_offset,
336                                     /*inout*/ uint32_t& type_bss_mapping_offset,
337                                     /*inout*/ uint32_t& public_type_bss_mapping_offset,
338                                     /*inout*/ uint32_t& package_type_bss_mapping_offset,
339                                     /*inout*/ uint32_t& string_bss_mapping_offset,
340                                     /*inout*/ uint32_t& method_type_bss_mapping_offset);
341 
342   bool RecordOatDataOffset(OutputStream* out);
343   void InitializeTypeLookupTables(
344       const std::vector<std::unique_ptr<const DexFile>>& opened_dex_files);
345   bool WriteDexLayoutSections(OutputStream* oat_rodata,
346                               const std::vector<const DexFile*>& opened_dex_files);
347   bool WriteCodeAlignment(OutputStream* out, uint32_t aligned_code_delta);
348   bool WriteUpTo16BytesAlignment(OutputStream* out, uint32_t size, uint32_t* stat);
349   void SetMultiOatRelativePatcherAdjustment();
350   void CloseSources();
351 
352   bool MayHaveCompiledMethods() const;
353 
VdexWillContainDexFiles()354   bool VdexWillContainDexFiles() const {
355     return dex_files_ != nullptr && extract_dex_files_into_vdex_;
356   }
357 
358   enum class WriteState {
359     kAddingDexFileSources,
360     kStartRoData,
361     kInitialize,
362     kPrepareLayout,
363     kWriteRoData,
364     kWriteText,
365     kWriteDataImgRelRo,
366     kWriteHeader,
367     kDone
368   };
369 
370   WriteState write_state_;
371   TimingLogger* timings_;
372 
373   dchecked_vector<debug::MethodDebugInfo> method_info_;
374 
375   std::vector<uint8_t> code_info_data_;
376 
377   const CompilerDriver* compiler_driver_;
378   const CompilerOptions& compiler_options_;
379   const VerificationResults* const verification_results_;
380   ImageWriter* image_writer_;
381   // Whether the dex files being compiled are going to be extracted to the vdex.
382   bool extract_dex_files_into_vdex_;
383   // The start of the vdex file section mmapped for writing dex files.
384   uint8_t* vdex_begin_;
385 
386   // note OatFile does not take ownership of the DexFiles
387   const std::vector<const DexFile*>* dex_files_;
388 
389   // Whether this is the primary oat file.
390   bool primary_oat_file_;
391 
392   // Size required for Vdex data structures.
393   size_t vdex_size_;
394 
395   // Offset of section holding Dex files inside Vdex.
396   size_t vdex_dex_files_offset_;
397 
398   // Offset of section holding shared dex data section in the Vdex.
399   size_t vdex_dex_shared_data_offset_;
400 
401   // Offset of section holding VerifierDeps inside Vdex.
402   size_t vdex_verifier_deps_offset_;
403 
404   // Offset of type lookup tables inside Vdex.
405   size_t vdex_lookup_tables_offset_;
406 
407   // OAT checksum.
408   uint32_t oat_checksum_;
409 
410   // Size of the .text segment.
411   size_t code_size_;
412 
413   // Size required for Oat data structures.
414   size_t oat_size_;
415 
416   // The start of the optional .data.img.rel.ro section.
417   size_t data_img_rel_ro_start_;
418 
419   // The size of the optional .data.img.rel.ro section holding the image relocations.
420   size_t data_img_rel_ro_size_;
421 
422   // The start of app image relocations in the .data.img.rel.ro section.
423   size_t data_img_rel_ro_app_image_offset_;
424 
425   // The start of the optional .bss section.
426   size_t bss_start_;
427 
428   // The size of the optional .bss section holding the DexCache data and GC roots.
429   size_t bss_size_;
430 
431   // The offset of the methods in .bss section.
432   size_t bss_methods_offset_;
433 
434   // The offset of the GC roots in .bss section.
435   size_t bss_roots_offset_;
436 
437   // OatFile's information regarding the bss metadata for BCP DexFiles. Empty for boot image
438   // compiles.
439   std::vector<BssMappingInfo> bcp_bss_info_;
440 
441   // Map for allocating boot image .data.img.rel.ro entries. Indexed by the boot image offset
442   // of the relocation. The value is the assigned offset within the .data.img.rel.ro section.
443   SafeMap<uint32_t, size_t> boot_image_rel_ro_entries_;
444 
445   // Map for recording references to ArtMethod entries in .bss.
446   SafeMap<const DexFile*, BitVector> bss_method_entry_references_;
447 
448   // Map for recording references to GcRoot<mirror::Class> entries in .bss.
449   SafeMap<const DexFile*, BitVector> bss_type_entry_references_;
450 
451   // Map for recording references to public GcRoot<mirror::Class> entries in .bss.
452   SafeMap<const DexFile*, BitVector> bss_public_type_entry_references_;
453 
454   // Map for recording references to package GcRoot<mirror::Class> entries in .bss.
455   SafeMap<const DexFile*, BitVector> bss_package_type_entry_references_;
456 
457   // Map for recording references to GcRoot<mirror::String> entries in .bss.
458   SafeMap<const DexFile*, BitVector> bss_string_entry_references_;
459 
460   // Map for recording references to GcRoot<mirror::MethodType> entries in .bss.
461   SafeMap<const DexFile*, BitVector> bss_method_type_entry_references_;
462 
463   // Map for allocating ArtMethod entries in .bss. Indexed by MethodReference for the target
464   // method in the dex file with the "method reference value comparator" for deduplication.
465   // The value is the target offset for patching, starting at `bss_start_ + bss_methods_offset_`.
466   SafeMap<MethodReference, size_t, MethodReferenceValueComparator> bss_method_entries_;
467 
468   // Map for allocating app image Class entries in .data.img.rel.ro. Indexed by TypeReference for
469   // the source type in the dex file with the "type value comparator" for deduplication. The value
470   // is the target offset for patching, starting at `data_img_rel_ro_start_`.
471   SafeMap<TypeReference, size_t, TypeReferenceValueComparator> app_image_rel_ro_type_entries_;
472 
473   // Map for allocating Class entries in .bss. Indexed by TypeReference for the source
474   // type in the dex file with the "type value comparator" for deduplication. The value
475   // is the target offset for patching, starting at `bss_start_ + bss_roots_offset_`.
476   SafeMap<TypeReference, size_t, TypeReferenceValueComparator> bss_type_entries_;
477 
478   // Map for allocating public Class entries in .bss. Indexed by TypeReference for the source
479   // type in the dex file with the "type value comparator" for deduplication. The value
480   // is the target offset for patching, starting at `bss_start_ + bss_roots_offset_`.
481   SafeMap<TypeReference, size_t, TypeReferenceValueComparator> bss_public_type_entries_;
482 
483   // Map for allocating package Class entries in .bss. Indexed by TypeReference for the source
484   // type in the dex file with the "type value comparator" for deduplication. The value
485   // is the target offset for patching, starting at `bss_start_ + bss_roots_offset_`.
486   SafeMap<TypeReference, size_t, TypeReferenceValueComparator> bss_package_type_entries_;
487 
488   // Map for allocating String entries in .bss. Indexed by StringReference for the source
489   // string in the dex file with the "string value comparator" for deduplication. The value
490   // is the target offset for patching, starting at `bss_start_ + bss_roots_offset_`.
491   SafeMap<StringReference, size_t, StringReferenceValueComparator> bss_string_entries_;
492 
493   // Map for allocating MethodType entries in .bss. Indexed by ProtoReference for the source
494   // proto in the dex file with the "proto value comparator" for deduplication. The value
495   // is the target offset for patching, starting at `bss_start_ + bss_roots_offset_`.
496   SafeMap<ProtoReference, size_t, ProtoReferenceValueComparator> bss_method_type_entries_;
497 
498   // Offset of the oat data from the start of the mmapped region of the elf file.
499   size_t oat_data_offset_;
500 
501   // Fake OatDexFiles to hold type lookup tables for the compiler.
502   std::vector<std::unique_ptr<art::OatDexFile>> type_lookup_table_oat_dex_files_;
503 
504   // data to write
505   std::unique_ptr<OatHeader> oat_header_;
506   dchecked_vector<OatDexFile> oat_dex_files_;
507   dchecked_vector<OatClassHeader> oat_class_headers_;
508   dchecked_vector<OatClass> oat_classes_;
509   std::unique_ptr<const std::vector<uint8_t>> jni_dlsym_lookup_trampoline_;
510   std::unique_ptr<const std::vector<uint8_t>> jni_dlsym_lookup_critical_trampoline_;
511   std::unique_ptr<const std::vector<uint8_t>> quick_generic_jni_trampoline_;
512   std::unique_ptr<const std::vector<uint8_t>> quick_imt_conflict_trampoline_;
513   std::unique_ptr<const std::vector<uint8_t>> quick_resolution_trampoline_;
514   std::unique_ptr<const std::vector<uint8_t>> quick_to_interpreter_bridge_;
515   std::unique_ptr<const std::vector<uint8_t>> nterp_trampoline_;
516 
517   // output stats
518   uint32_t size_vdex_header_ = 0;
519   uint32_t size_vdex_checksums_ = 0;
520   uint32_t size_dex_file_alignment_ = 0;
521   uint32_t size_executable_offset_alignment_ = 0;
522   uint32_t size_oat_header_ = 0;
523   uint32_t size_oat_header_key_value_store_ = 0;
524   uint32_t size_dex_file_ = 0;
525   uint32_t size_verifier_deps_ = 0;
526   uint32_t size_verifier_deps_alignment_ = 0;
527   uint32_t size_vdex_lookup_table_alignment_ = 0;
528   uint32_t size_vdex_lookup_table_ = 0;
529   uint32_t size_interpreter_to_interpreter_bridge_ = 0;
530   uint32_t size_interpreter_to_compiled_code_bridge_ = 0;
531   uint32_t size_jni_dlsym_lookup_trampoline_ = 0;
532   uint32_t size_jni_dlsym_lookup_critical_trampoline_ = 0;
533   uint32_t size_quick_generic_jni_trampoline_ = 0;
534   uint32_t size_quick_imt_conflict_trampoline_ = 0;
535   uint32_t size_quick_resolution_trampoline_ = 0;
536   uint32_t size_quick_to_interpreter_bridge_ = 0;
537   uint32_t size_nterp_trampoline_ = 0;
538   uint32_t size_trampoline_alignment_ = 0;
539   uint32_t size_method_header_ = 0;
540   uint32_t size_code_ = 0;
541   uint32_t size_code_alignment_ = 0;
542   uint32_t size_data_img_rel_ro_ = 0;
543   uint32_t size_data_img_rel_ro_alignment_ = 0;
544   uint32_t size_relative_call_thunks_ = 0;
545   uint32_t size_misc_thunks_ = 0;
546   uint32_t size_vmap_table_ = 0;
547   uint32_t size_method_info_ = 0;
548   uint32_t size_oat_dex_file_location_size_ = 0;
549   uint32_t size_oat_dex_file_location_data_ = 0;
550   uint32_t size_oat_dex_file_magic_ = 0;
551   uint32_t size_oat_dex_file_location_checksum_ = 0;
552   uint32_t size_oat_dex_file_sha1_ = 0;
553   uint32_t size_oat_dex_file_offset_ = 0;
554   uint32_t size_oat_dex_file_class_offsets_offset_ = 0;
555   uint32_t size_oat_dex_file_lookup_table_offset_ = 0;
556   uint32_t size_oat_dex_file_dex_layout_sections_offset_ = 0;
557   uint32_t size_oat_dex_file_dex_layout_sections_ = 0;
558   uint32_t size_oat_dex_file_dex_layout_sections_alignment_ = 0;
559   uint32_t size_oat_dex_file_method_bss_mapping_offset_ = 0;
560   uint32_t size_oat_dex_file_type_bss_mapping_offset_ = 0;
561   uint32_t size_oat_dex_file_public_type_bss_mapping_offset_ = 0;
562   uint32_t size_oat_dex_file_package_type_bss_mapping_offset_ = 0;
563   uint32_t size_oat_dex_file_string_bss_mapping_offset_ = 0;
564   uint32_t size_oat_dex_file_method_type_bss_mapping_offset_ = 0;
565   uint32_t size_bcp_bss_info_size_ = 0;
566   uint32_t size_bcp_bss_info_method_bss_mapping_offset_ = 0;
567   uint32_t size_bcp_bss_info_type_bss_mapping_offset_ = 0;
568   uint32_t size_bcp_bss_info_public_type_bss_mapping_offset_ = 0;
569   uint32_t size_bcp_bss_info_package_type_bss_mapping_offset_ = 0;
570   uint32_t size_bcp_bss_info_string_bss_mapping_offset_ = 0;
571   uint32_t size_bcp_bss_info_method_type_bss_mapping_offset_ = 0;
572   uint32_t size_oat_class_offsets_alignment_ = 0;
573   uint32_t size_oat_class_offsets_ = 0;
574   uint32_t size_oat_class_type_ = 0;
575   uint32_t size_oat_class_status_ = 0;
576   uint32_t size_oat_class_num_methods_ = 0;
577   uint32_t size_oat_class_method_bitmaps_ = 0;
578   uint32_t size_oat_class_method_offsets_ = 0;
579   uint32_t size_method_bss_mappings_ = 0;
580   uint32_t size_type_bss_mappings_ = 0;
581   uint32_t size_public_type_bss_mappings_ = 0;
582   uint32_t size_package_type_bss_mappings_ = 0;
583   uint32_t size_string_bss_mappings_ = 0;
584   uint32_t size_method_type_bss_mappings_ = 0;
585 
586   // The helper for processing relative patches is external so that we can patch across oat files.
587   MultiOatRelativePatcher* relative_patcher_;
588 
589   // Profile info used to generate new layout of files.
590   ProfileCompilationInfo* profile_compilation_info_;
591 
592   using OrderedMethodList = std::vector<OrderedMethodData>;
593 
594   // List of compiled methods, sorted by the order defined in OrderedMethodData.
595   // Methods can be inserted more than once in case of duplicated methods.
596   // This pointer is only non-null after InitOatCodeDexFiles succeeds.
597   std::unique_ptr<OrderedMethodList> ordered_methods_;
598 
599   DISALLOW_COPY_AND_ASSIGN(OatWriter);
600 };
601 
602 }  // namespace linker
603 }  // namespace art
604 
605 #endif  // ART_DEX2OAT_LINKER_OAT_WRITER_H_
606