blob: c9ea0083d52439532d805f9ddbc7dd1f10e5eace [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
David Srbeckyc5bfa972016-02-05 15:49:10 +000035namespace debug {
Vladimir Marko10c13562015-11-25 14:33:36 +000036struct MethodDebugInfo;
David Srbeckyc5bfa972016-02-05 15:49:10 +000037} // namespace debug
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;
Vladimir Marko944da602016-02-19 12:27:55 +000055 virtual void SetLoadedSectionSizes(size_t rodata_size, size_t text_size, size_t bss_size) = 0;
56 virtual void PrepareDebugInfo(const ArrayRef<const debug::MethodDebugInfo>& method_infos) = 0;
Vladimir Marko10c13562015-11-25 14:33:36 +000057 virtual OutputStream* StartRoData() = 0;
58 virtual void EndRoData(OutputStream* rodata) = 0;
59 virtual OutputStream* StartText() = 0;
60 virtual void EndText(OutputStream* text) = 0;
Vladimir Marko10c13562015-11-25 14:33:36 +000061 virtual void WriteDynamicSection() = 0;
David Srbeckyc5bfa972016-02-05 15:49:10 +000062 virtual void WriteDebugInfo(const ArrayRef<const debug::MethodDebugInfo>& method_infos) = 0;
Vladimir Marko10c13562015-11-25 14:33:36 +000063 virtual void WritePatchLocations(const ArrayRef<const uintptr_t>& patch_locations) = 0;
64 virtual bool End() = 0;
Brian Carlstrom265091e2013-01-30 14:08:26 -080065
Vladimir Marko131980f2015-12-03 18:29:23 +000066 // Get the ELF writer's stream. This stream can be used for writing data directly
67 // to a section after the section has been finished. When that's done, the user
68 // should Seek() back to the position where the stream was before this operation.
69 virtual OutputStream* GetStream() = 0;
70
Vladimir Marko944da602016-02-19 12:27:55 +000071 // Get the size that the loaded ELF file will occupy in memory.
72 virtual size_t GetLoadedSize() = 0;
73
Vladimir Marko10c13562015-11-25 14:33:36 +000074 protected:
75 ElfWriter() = default;
Brian Carlstrom700c8d32012-11-05 10:42:02 -080076};
77
78} // namespace art
79
Brian Carlstromfc0e3212013-07-17 14:40:12 -070080#endif // ART_COMPILER_ELF_WRITER_H_