• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 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_ELF_WRITER_H_
18 #define ART_DEX2OAT_LINKER_ELF_WRITER_H_
19 
20 #include <stdint.h>
21 
22 #include <cstddef>
23 #include <string>
24 #include <vector>
25 
26 #include "base/array_ref.h"
27 #include "base/macros.h"
28 #include "base/mutex.h"
29 #include "base/os.h"
30 #include "debug/debug_info.h"
31 #include "thread_pool.h"
32 
33 namespace art {
34 
35 class ElfFile;
36 class OutputStream;
37 
38 namespace debug {
39 struct MethodDebugInfo;
40 }  // namespace debug
41 
42 namespace linker {
43 
44 class ElfWriter {
45  public:
~ElfWriter()46   virtual ~ElfWriter() {}
47 
48   virtual void Start() = 0;
49   // Prepares memory layout of the whole ELF file, and creates dynamic symbols
50   // which point to specific areas of interest (usually section begin and end).
51   // This is needed as multi-image needs to know the memory layout of all ELF
52   // files, before starting to write them.
53   // This method must be called before calling GetLoadedSize().
54   virtual void PrepareDynamicSection(size_t rodata_size,
55                                      size_t text_size,
56                                      size_t data_img_rel_ro_size,
57                                      size_t data_img_rel_ro_app_image_offset,
58                                      size_t bss_size,
59                                      size_t bss_methods_offset,
60                                      size_t bss_roots_offset,
61                                      size_t dex_section_size) = 0;
62   virtual std::unique_ptr<ThreadPool> PrepareDebugInfo(const debug::DebugInfo& debug_info) = 0;
63   virtual OutputStream* StartRoData() = 0;
64   virtual void EndRoData(OutputStream* rodata) = 0;
65   virtual OutputStream* StartText() = 0;
66   virtual void EndText(OutputStream* text) = 0;
67   virtual OutputStream* StartDataImgRelRo() = 0;
68   virtual void EndDataImgRelRo(OutputStream* data_img_rel_ro) = 0;
69   virtual void WriteDynamicSection() = 0;
70   virtual void WriteDebugInfo(const debug::DebugInfo& debug_info) = 0;
71   virtual bool StripDebugInfo() = 0;
72   virtual bool End() = 0;
73 
74   // Get the ELF writer's stream. This stream can be used for writing data directly
75   // to a section after the section has been finished. When that's done, the user
76   // should Seek() back to the position where the stream was before this operation.
77   virtual OutputStream* GetStream() = 0;
78 
79   // Get the size that the loaded ELF file will occupy in memory.
80   virtual size_t GetLoadedSize() = 0;
81 
82  protected:
83   ElfWriter() = default;
84 };
85 
86 }  // namespace linker
87 }  // namespace art
88 
89 #endif  // ART_DEX2OAT_LINKER_ELF_WRITER_H_
90