blob: 8e13b51bbe1b35901fa31d9cd3bb7ff307d0a188 [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"
28
Brian Carlstrom700c8d32012-11-05 10:42:02 -080029namespace art {
Brian Carlstrom265091e2013-01-30 14:08:26 -080030
Ian Rogers1212a022013-03-04 10:48:41 -080031class CompilerDriver;
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070032class DexFile;
Brian Carlstrom265091e2013-01-30 14:08:26 -080033class ElfFile;
Brian Carlstromc50d8e12013-07-23 22:35:16 -070034class OatWriter;
Brian Carlstrom700c8d32012-11-05 10:42:02 -080035
36class ElfWriter {
37 public:
Brian Carlstrom700c8d32012-11-05 10:42:02 -080038 // Looks up information about location of oat file in elf file container.
39 // Used for ImageWriter to perform memory layout.
40 static void GetOatElfInformation(File* file,
Vladimir Marko3fc99032015-05-13 19:06:30 +010041 size_t* oat_loaded_size,
42 size_t* oat_data_offset);
Brian Carlstrom700c8d32012-11-05 10:42:02 -080043
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070044 // Returns runtime oat_data runtime address for an opened ElfFile.
Tong Shen62d1ca32014-09-03 17:24:56 -070045 static uintptr_t GetOatDataAddress(ElfFile* elf_file);
46
47 static bool Fixup(File* file, uintptr_t oat_data_begin);
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070048
49 protected:
Ian Rogers3d504072014-03-01 09:16:49 -080050 ElfWriter(const CompilerDriver& driver, File* elf_file)
51 : compiler_driver_(&driver), elf_file_(elf_file) {
52 }
Brian Carlstrom700c8d32012-11-05 10:42:02 -080053
Ian Rogers3d504072014-03-01 09:16:49 -080054 virtual ~ElfWriter() {}
55
56 virtual bool Write(OatWriter* oat_writer,
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070057 const std::vector<const DexFile*>& dex_files,
58 const std::string& android_root,
59 bool is_host)
60 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0;
Brian Carlstrom265091e2013-01-30 14:08:26 -080061
Ian Rogers3d504072014-03-01 09:16:49 -080062 const CompilerDriver* const compiler_driver_;
63 File* const elf_file_;
Brian Carlstrom700c8d32012-11-05 10:42:02 -080064};
65
66} // namespace art
67
Brian Carlstromfc0e3212013-07-17 14:40:12 -070068#endif // ART_COMPILER_ELF_WRITER_H_