Home | History | Annotate | Download | only in compiler
      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_COMPILER_ELF_WRITER_H_
     18 #define ART_COMPILER_ELF_WRITER_H_
     19 
     20 #include <stdint.h>
     21 #include <cstddef>
     22 #include <string>
     23 #include <vector>
     24 
     25 #include "base/array_ref.h"
     26 #include "base/macros.h"
     27 #include "base/mutex.h"
     28 #include "os.h"
     29 
     30 namespace art {
     31 
     32 class ElfFile;
     33 class OutputStream;
     34 
     35 namespace debug {
     36 struct MethodDebugInfo;
     37 }  // namespace debug
     38 
     39 class ElfWriter {
     40  public:
     41   // Looks up information about location of oat file in elf file container.
     42   // Used for ImageWriter to perform memory layout.
     43   static void GetOatElfInformation(File* file,
     44                                    size_t* oat_loaded_size,
     45                                    size_t* oat_data_offset);
     46 
     47   // Returns runtime oat_data runtime address for an opened ElfFile.
     48   static uintptr_t GetOatDataAddress(ElfFile* elf_file);
     49 
     50   static bool Fixup(File* file, uintptr_t oat_data_begin);
     51 
     52   virtual ~ElfWriter() {}
     53 
     54   virtual void Start() = 0;
     55   virtual void PrepareDynamicSection(size_t rodata_size,
     56                                      size_t text_size,
     57                                      size_t bss_size,
     58                                      size_t bss_roots_offset) = 0;
     59   virtual void PrepareDebugInfo(const ArrayRef<const debug::MethodDebugInfo>& method_infos) = 0;
     60   virtual OutputStream* StartRoData() = 0;
     61   virtual void EndRoData(OutputStream* rodata) = 0;
     62   virtual OutputStream* StartText() = 0;
     63   virtual void EndText(OutputStream* text) = 0;
     64   virtual void WriteDynamicSection() = 0;
     65   virtual void WriteDebugInfo(const ArrayRef<const debug::MethodDebugInfo>& method_infos) = 0;
     66   virtual bool End() = 0;
     67 
     68   // Get the ELF writer's stream. This stream can be used for writing data directly
     69   // to a section after the section has been finished. When that's done, the user
     70   // should Seek() back to the position where the stream was before this operation.
     71   virtual OutputStream* GetStream() = 0;
     72 
     73   // Get the size that the loaded ELF file will occupy in memory.
     74   virtual size_t GetLoadedSize() = 0;
     75 
     76  protected:
     77   ElfWriter() = default;
     78 };
     79 
     80 }  // namespace art
     81 
     82 #endif  // ART_COMPILER_ELF_WRITER_H_
     83