Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [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 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_ELF_WRITER_MCLINKER_H_ |
| 18 | #define ART_COMPILER_ELF_WRITER_MCLINKER_H_ |
Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 19 | |
| 20 | #include "elf_writer.h" |
| 21 | |
| 22 | #include "UniquePtr.h" |
| 23 | #include "safe_map.h" |
| 24 | |
| 25 | namespace mcld { |
| 26 | class IRBuilder; |
| 27 | class Input; |
| 28 | class LDSection; |
| 29 | class LDSymbol; |
| 30 | class Linker; |
| 31 | class LinkerConfig; |
Brian Carlstrom | 4e3b284 | 2014-01-18 11:26:51 -0800 | [diff] [blame] | 32 | class LinkerScript; |
Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 33 | class Module; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 34 | } // namespace mcld |
Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 35 | |
| 36 | namespace art { |
| 37 | |
| 38 | class CompiledCode; |
| 39 | |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 40 | class ElfWriterMclinker FINAL : public ElfWriter { |
Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 41 | public: |
Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 42 | // Write an ELF file. Returns true on success, false on failure. |
| 43 | static bool Create(File* file, |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 44 | OatWriter* oat_writer, |
Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 45 | const std::vector<const DexFile*>& dex_files, |
| 46 | const std::string& android_root, |
| 47 | bool is_host, |
| 48 | const CompilerDriver& driver) |
| 49 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 50 | |
| 51 | protected: |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 52 | bool Write(OatWriter* oat_writer, |
| 53 | const std::vector<const DexFile*>& dex_files, |
| 54 | const std::string& android_root, |
| 55 | bool is_host) |
| 56 | OVERRIDE |
Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 57 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 58 | |
| 59 | private: |
| 60 | ElfWriterMclinker(const CompilerDriver& driver, File* elf_file); |
| 61 | ~ElfWriterMclinker(); |
| 62 | |
| 63 | void Init(); |
| 64 | void AddOatInput(std::vector<uint8_t>& oat_contents); |
| 65 | void AddMethodInputs(const std::vector<const DexFile*>& dex_files); |
| 66 | void AddCompiledCodeInput(const CompiledCode& compiled_code); |
| 67 | void AddRuntimeInputs(const std::string& android_root, bool is_host); |
| 68 | bool Link(); |
Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 69 | void FixupOatMethodOffsets(const std::vector<const DexFile*>& dex_files) |
| 70 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 71 | uint32_t FixupCompiledCodeOffset(ElfFile& elf_file, |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 72 | uint32_t oatdata_address, |
Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 73 | const CompiledCode& compiled_code); |
Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 74 | |
| 75 | // Setup by Init() |
| 76 | UniquePtr<mcld::LinkerConfig> linker_config_; |
Brian Carlstrom | 4e3b284 | 2014-01-18 11:26:51 -0800 | [diff] [blame] | 77 | UniquePtr<mcld::LinkerScript> linker_script_; |
Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 78 | UniquePtr<mcld::Module> module_; |
| 79 | UniquePtr<mcld::IRBuilder> ir_builder_; |
| 80 | UniquePtr<mcld::Linker> linker_; |
| 81 | |
| 82 | // Setup by AddOatInput() |
| 83 | // TODO: ownership of oat_input_? |
| 84 | mcld::Input* oat_input_; |
| 85 | |
| 86 | // Setup by AddCompiledCodeInput |
| 87 | // set of symbols for already added mcld::Inputs |
| 88 | SafeMap<const std::string*, const std::string*> added_symbols_; |
| 89 | |
| 90 | // Setup by FixupCompiledCodeOffset |
| 91 | // map of symbol names to oatdata offset |
| 92 | SafeMap<const std::string*, uint32_t> symbol_to_compiled_code_offset_; |
| 93 | |
| 94 | DISALLOW_IMPLICIT_CONSTRUCTORS(ElfWriterMclinker); |
| 95 | }; |
| 96 | |
| 97 | } // namespace art |
| 98 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 99 | #endif // ART_COMPILER_ELF_WRITER_MCLINKER_H_ |