blob: 8ee7231f7917a0903b3e36db79f3d659dc374a4d [file] [log] [blame]
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -07001/*
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 Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_COMPILER_ELF_WRITER_MCLINKER_H_
18#define ART_COMPILER_ELF_WRITER_MCLINKER_H_
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070019
20#include "elf_writer.h"
21
22#include "UniquePtr.h"
23#include "safe_map.h"
24
25namespace mcld {
26class IRBuilder;
27class Input;
28class LDSection;
29class LDSymbol;
30class Linker;
31class LinkerConfig;
Brian Carlstrom4e3b2842014-01-18 11:26:51 -080032class LinkerScript;
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070033class Module;
Brian Carlstrom7934ac22013-07-26 10:54:15 -070034} // namespace mcld
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070035
36namespace art {
37
38class CompiledCode;
39
40class ElfWriterMclinker : public ElfWriter {
41 public:
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070042 // Write an ELF file. Returns true on success, false on failure.
43 static bool Create(File* file,
Brian Carlstromc50d8e12013-07-23 22:35:16 -070044 OatWriter& oat_writer,
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070045 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:
Brian Carlstromc50d8e12013-07-23 22:35:16 -070052 virtual bool Write(OatWriter& oat_writer,
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070053 const std::vector<const DexFile*>& dex_files,
54 const std::string& android_root,
55 bool is_host)
56 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
57
58 private:
59 ElfWriterMclinker(const CompilerDriver& driver, File* elf_file);
60 ~ElfWriterMclinker();
61
62 void Init();
63 void AddOatInput(std::vector<uint8_t>& oat_contents);
64 void AddMethodInputs(const std::vector<const DexFile*>& dex_files);
65 void AddCompiledCodeInput(const CompiledCode& compiled_code);
66 void AddRuntimeInputs(const std::string& android_root, bool is_host);
67 bool Link();
68#if defined(ART_USE_PORTABLE_COMPILER)
69 void FixupOatMethodOffsets(const std::vector<const DexFile*>& dex_files)
70 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
71 uint32_t FixupCompiledCodeOffset(ElfFile& elf_file,
Vladimir Markod9de8392014-01-23 12:45:05 +000072 ::llvm::ELF::Elf32_Addr oatdata_address,
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070073 const CompiledCode& compiled_code);
74#endif
75
76 // Setup by Init()
77 UniquePtr<mcld::LinkerConfig> linker_config_;
Brian Carlstrom4e3b2842014-01-18 11:26:51 -080078 UniquePtr<mcld::LinkerScript> linker_script_;
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070079 UniquePtr<mcld::Module> module_;
80 UniquePtr<mcld::IRBuilder> ir_builder_;
81 UniquePtr<mcld::Linker> linker_;
82
83 // Setup by AddOatInput()
84 // TODO: ownership of oat_input_?
85 mcld::Input* oat_input_;
86
87 // Setup by AddCompiledCodeInput
88 // set of symbols for already added mcld::Inputs
89 SafeMap<const std::string*, const std::string*> added_symbols_;
90
91 // Setup by FixupCompiledCodeOffset
92 // map of symbol names to oatdata offset
93 SafeMap<const std::string*, uint32_t> symbol_to_compiled_code_offset_;
94
95 DISALLOW_IMPLICIT_CONSTRUCTORS(ElfWriterMclinker);
96};
97
98} // namespace art
99
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700100#endif // ART_COMPILER_ELF_WRITER_MCLINKER_H_