blob: 5dbf7360f85b28840acc2bcbee854cae5d3b4ad8 [file] [log] [blame]
Brian Carlstrom700c8d32012-11-05 10:42:02 -08001/*
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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_COMPILER_ELF_WRITER_H_
18#define ART_COMPILER_ELF_WRITER_H_
Brian Carlstrom700c8d32012-11-05 10:42:02 -080019
Brian Carlstrom265091e2013-01-30 14:08:26 -080020#include <stdint.h>
Brian Carlstrom265091e2013-01-30 14:08:26 -080021#include <cstddef>
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070022#include <string>
Ian Rogers1212a022013-03-04 10:48:41 -080023#include <vector>
24
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070025#include "base/macros.h"
Ian Rogers719d1a32014-03-06 12:13:39 -080026#include "base/mutex.h"
Brian Carlstrom265091e2013-01-30 14:08:26 -080027#include "os.h"
Vladimir Marko10c13562015-11-25 14:33:36 +000028#include "utils/array_ref.h"
Brian Carlstrom265091e2013-01-30 14:08:26 -080029
Brian Carlstrom700c8d32012-11-05 10:42:02 -080030namespace art {
Brian Carlstrom265091e2013-01-30 14:08:26 -080031
Brian Carlstrom265091e2013-01-30 14:08:26 -080032class ElfFile;
Vladimir Marko10c13562015-11-25 14:33:36 +000033class OutputStream;
34
35namespace dwarf {
36struct MethodDebugInfo;
37} // namespace dwarf
Brian Carlstrom700c8d32012-11-05 10:42:02 -080038
39class ElfWriter {
40 public:
Brian Carlstrom700c8d32012-11-05 10:42:02 -080041 // 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,
Vladimir Marko3fc99032015-05-13 19:06:30 +010044 size_t* oat_loaded_size,
45 size_t* oat_data_offset);
Brian Carlstrom700c8d32012-11-05 10:42:02 -080046
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070047 // Returns runtime oat_data runtime address for an opened ElfFile.
Tong Shen62d1ca32014-09-03 17:24:56 -070048 static uintptr_t GetOatDataAddress(ElfFile* elf_file);
49
50 static bool Fixup(File* file, uintptr_t oat_data_begin);
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070051
Ian Rogers3d504072014-03-01 09:16:49 -080052 virtual ~ElfWriter() {}
53
Vladimir Marko10c13562015-11-25 14:33:36 +000054 virtual void Start() = 0;
David Srbecky0c4572e2016-01-22 19:19:25 +000055 virtual void PrepareDebugInfo(size_t rodata_section_size,
56 size_t text_section_size,
57 const ArrayRef<const dwarf::MethodDebugInfo>& method_infos) = 0;
Vladimir Marko10c13562015-11-25 14:33:36 +000058 virtual OutputStream* StartRoData() = 0;
59 virtual void EndRoData(OutputStream* rodata) = 0;
60 virtual OutputStream* StartText() = 0;
61 virtual void EndText(OutputStream* text) = 0;
62 virtual void SetBssSize(size_t bss_size) = 0;
63 virtual void WriteDynamicSection() = 0;
64 virtual void WriteDebugInfo(const ArrayRef<const dwarf::MethodDebugInfo>& method_infos) = 0;
65 virtual void WritePatchLocations(const ArrayRef<const uintptr_t>& patch_locations) = 0;
66 virtual bool End() = 0;
Brian Carlstrom265091e2013-01-30 14:08:26 -080067
Vladimir Marko131980f2015-12-03 18:29:23 +000068 // 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
Vladimir Marko10c13562015-11-25 14:33:36 +000073 protected:
74 ElfWriter() = default;
Brian Carlstrom700c8d32012-11-05 10:42:02 -080075};
76
77} // namespace art
78
Brian Carlstromfc0e3212013-07-17 14:40:12 -070079#endif // ART_COMPILER_ELF_WRITER_H_