blob: f55003f36ed98b4f3c7deda759400522a7443dfd [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
17#ifndef ART_SRC_ELF_WRITER_H_
18#define ART_SRC_ELF_WRITER_H_
19
Ian Rogers1212a022013-03-04 10:48:41 -080020#include "elf_file.h"
Brian Carlstrom700c8d32012-11-05 10:42:02 -080021#include "os.h"
22
Ian Rogers1212a022013-03-04 10:48:41 -080023#include <vector>
24
Brian Carlstrom700c8d32012-11-05 10:42:02 -080025namespace art {
Ian Rogers1212a022013-03-04 10:48:41 -080026class CompilerDriver;
Brian Carlstrom700c8d32012-11-05 10:42:02 -080027
28class ElfWriter {
29 public:
30 // Write an ELF file. Returns true on success, false on failure.
Ian Rogers1212a022013-03-04 10:48:41 -080031 static bool Create(File* file, std::vector<uint8_t>& oat_contents, const CompilerDriver& compiler);
Brian Carlstrom700c8d32012-11-05 10:42:02 -080032
33 // Fixup an ELF file so that that oat header will be loaded at oat_begin.
34 // Returns true on success, false on failure.
35 static bool Fixup(File* file, uintptr_t oat_data_begin);
36
37 // Looks up information about location of oat file in elf file container.
38 // Used for ImageWriter to perform memory layout.
39 static void GetOatElfInformation(File* file,
40 size_t& oat_loaded_size,
41 size_t& oat_data_offset);
42
43 private:
Ian Rogers1212a022013-03-04 10:48:41 -080044 ElfWriter(const CompilerDriver* driver);
Brian Carlstrom700c8d32012-11-05 10:42:02 -080045 ~ElfWriter();
46
47 bool Write(std::vector<uint8_t>& oat_contents, File* elf_file);
48
49 // Fixup .dynamic d_ptr values for the expected base_address.
50 static bool FixupDynamic(ElfFile& elf_file, uintptr_t base_address);
51
52 // Fixup Elf32_Shdr p_vaddr to load at the desired address.
53 static bool FixupSectionHeaders(ElfFile& elf_file,uintptr_t base_address);
54
55 // Fixup Elf32_Phdr p_vaddr to load at the desired address.
56 static bool FixupProgramHeaders(ElfFile& elf_file,uintptr_t base_address);
57
58 // Fixup symbol table
59 static bool FixupSymbols(ElfFile& elf_file, uintptr_t base_address, bool dynamic);
60
Ian Rogers1212a022013-03-04 10:48:41 -080061 const CompilerDriver* const compiler_driver_;
Brian Carlstrom700c8d32012-11-05 10:42:02 -080062};
63
64} // namespace art
65
66#endif // ART_SRC_ELF_WRITER_H_