blob: 0402c400a86f964bc804fd489439f9faf0a1ef89 [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
20#include "compiler.h"
21#include "os.h"
22
23namespace art {
24
25class ElfWriter {
26 public:
27 // Write an ELF file. Returns true on success, false on failure.
28 static bool Create(File* file, std::vector<uint8_t>& oat_contents, const Compiler& compiler);
29
30 // Fixup an ELF file so that that oat header will be loaded at oat_begin.
31 // Returns true on success, false on failure.
32 static bool Fixup(File* file, uintptr_t oat_data_begin);
33
34 // Looks up information about location of oat file in elf file container.
35 // Used for ImageWriter to perform memory layout.
36 static void GetOatElfInformation(File* file,
37 size_t& oat_loaded_size,
38 size_t& oat_data_offset);
39
40 private:
41 ElfWriter(const Compiler& compiler);
42 ~ElfWriter();
43
44 bool Write(std::vector<uint8_t>& oat_contents, File* elf_file);
45
46 // Fixup .dynamic d_ptr values for the expected base_address.
47 static bool FixupDynamic(ElfFile& elf_file, uintptr_t base_address);
48
49 // Fixup Elf32_Shdr p_vaddr to load at the desired address.
50 static bool FixupSectionHeaders(ElfFile& elf_file,uintptr_t base_address);
51
52 // Fixup Elf32_Phdr p_vaddr to load at the desired address.
53 static bool FixupProgramHeaders(ElfFile& elf_file,uintptr_t base_address);
54
55 // Fixup symbol table
56 static bool FixupSymbols(ElfFile& elf_file, uintptr_t base_address, bool dynamic);
57
58 const Compiler* compiler_;
59};
60
61} // namespace art
62
63#endif // ART_SRC_ELF_WRITER_H_