blob: 0ef4185431d3d84759fab1a3d3171ec12db7d37b [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 Carlstrom700c8d32012-11-05 10:42:02 -080021
Brian Carlstrom265091e2013-01-30 14:08:26 -080022#include <cstddef>
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070023#include <string>
Ian Rogers1212a022013-03-04 10:48:41 -080024#include <vector>
25
Brian Carlstrom265091e2013-01-30 14:08:26 -080026#include <llvm/Support/ELF.h>
27
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070028#include "base/macros.h"
Brian Carlstrom265091e2013-01-30 14:08:26 -080029#include "os.h"
30
Brian Carlstrom700c8d32012-11-05 10:42:02 -080031namespace art {
Brian Carlstrom265091e2013-01-30 14:08:26 -080032
Ian Rogers1212a022013-03-04 10:48:41 -080033class CompilerDriver;
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070034class DexFile;
Brian Carlstrom265091e2013-01-30 14:08:26 -080035class ElfFile;
Brian Carlstromc50d8e12013-07-23 22:35:16 -070036class OatWriter;
Brian Carlstrom700c8d32012-11-05 10:42:02 -080037
38class ElfWriter {
39 public:
Brian Carlstrom700c8d32012-11-05 10:42:02 -080040 // Looks up information about location of oat file in elf file container.
41 // Used for ImageWriter to perform memory layout.
42 static void GetOatElfInformation(File* file,
43 size_t& oat_loaded_size,
44 size_t& oat_data_offset);
45
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070046 // Returns runtime oat_data runtime address for an opened ElfFile.
47 static llvm::ELF::Elf32_Addr GetOatDataAddress(ElfFile* elf_file);
48
49 protected:
Brian Carlstrom265091e2013-01-30 14:08:26 -080050 ElfWriter(const CompilerDriver& driver, File* elf_file);
Brian Carlstromfb6996f2013-07-18 18:21:14 -070051 virtual ~ElfWriter();
Brian Carlstrom700c8d32012-11-05 10:42:02 -080052
Brian Carlstromc50d8e12013-07-23 22:35:16 -070053 virtual bool Write(OatWriter& oat_writer,
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070054 const std::vector<const DexFile*>& dex_files,
55 const std::string& android_root,
56 bool is_host)
57 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0;
Brian Carlstrom265091e2013-01-30 14:08:26 -080058
59 // Setup by constructor
60 const CompilerDriver* compiler_driver_;
61 File* elf_file_;
Brian Carlstrom700c8d32012-11-05 10:42:02 -080062};
63
64} // namespace art
65
Brian Carlstromfc0e3212013-07-17 14:40:12 -070066#endif // ART_COMPILER_ELF_WRITER_H_