Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 1 | /* |
| 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 Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 20 | #include "elf_file.h" |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 21 | #include "os.h" |
| 22 | |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 23 | #include <vector> |
| 24 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 25 | namespace art { |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 26 | class CompilerDriver; |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 27 | |
| 28 | class ElfWriter { |
| 29 | public: |
| 30 | // Write an ELF file. Returns true on success, false on failure. |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 31 | static bool Create(File* file, std::vector<uint8_t>& oat_contents, const CompilerDriver& compiler); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 32 | |
| 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 Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 44 | ElfWriter(const CompilerDriver* driver); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 45 | ~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 Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 61 | const CompilerDriver* const compiler_driver_; |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | } // namespace art |
| 65 | |
| 66 | #endif // ART_SRC_ELF_WRITER_H_ |