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 | |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 20 | #include <memory> |
Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 21 | |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 22 | #include "elf_writer.h" |
Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 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(); |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 64 | mcld::LDSection* AddOatInput(OatWriter* oat_writer, std::vector<uint8_t>* oat_contents); |
Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 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); |
Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 68 | void FixupOatMethodOffsets(const std::vector<const DexFile*>& dex_files) |
| 69 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 70 | uint32_t FixupCompiledCodeOffset(ElfFile& elf_file, |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 71 | uint32_t oatdata_address, |
Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 72 | const CompiledCode& compiled_code); |
Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 73 | |
| 74 | // Setup by Init() |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 75 | std::unique_ptr<mcld::LinkerConfig> linker_config_; |
| 76 | std::unique_ptr<mcld::LinkerScript> linker_script_; |
| 77 | std::unique_ptr<mcld::Module> module_; |
| 78 | std::unique_ptr<mcld::IRBuilder> ir_builder_; |
| 79 | std::unique_ptr<mcld::Linker> linker_; |
Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 80 | |
| 81 | // Setup by AddOatInput() |
| 82 | // TODO: ownership of oat_input_? |
| 83 | mcld::Input* oat_input_; |
| 84 | |
| 85 | // Setup by AddCompiledCodeInput |
| 86 | // set of symbols for already added mcld::Inputs |
| 87 | SafeMap<const std::string*, const std::string*> added_symbols_; |
| 88 | |
| 89 | // Setup by FixupCompiledCodeOffset |
| 90 | // map of symbol names to oatdata offset |
| 91 | SafeMap<const std::string*, uint32_t> symbol_to_compiled_code_offset_; |
| 92 | |
| 93 | DISALLOW_IMPLICIT_CONSTRUCTORS(ElfWriterMclinker); |
| 94 | }; |
| 95 | |
| 96 | } // namespace art |
| 97 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 98 | #endif // ART_COMPILER_ELF_WRITER_MCLINKER_H_ |