blob: 5da178c0c4199c644963a24d4d6d8f9c2dd1e0c2 [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;
32class Module;
Brian Carlstrom7934ac22013-07-26 10:54:15 -070033} // namespace mcld
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070034
35namespace art {
36
37class CompiledCode;
38
39class ElfWriterMclinker : public ElfWriter {
40 public:
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070041 // Write an ELF file. Returns true on success, false on failure.
42 static bool Create(File* file,
Brian Carlstromc50d8e12013-07-23 22:35:16 -070043 OatWriter& oat_writer,
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070044 const std::vector<const DexFile*>& dex_files,
45 const std::string& android_root,
46 bool is_host,
47 const CompilerDriver& driver)
48 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
49
50 protected:
Brian Carlstromc50d8e12013-07-23 22:35:16 -070051 virtual bool Write(OatWriter& oat_writer,
Brian Carlstrom6a47b9d2013-05-17 10:58:25 -070052 const std::vector<const DexFile*>& dex_files,
53 const std::string& android_root,
54 bool is_host)
55 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
56
57 private:
58 ElfWriterMclinker(const CompilerDriver& driver, File* elf_file);
59 ~ElfWriterMclinker();
60
61 void Init();
62 void AddOatInput(std::vector<uint8_t>& oat_contents);
63 void AddMethodInputs(const std::vector<const DexFile*>& dex_files);
64 void AddCompiledCodeInput(const CompiledCode& compiled_code);
65 void AddRuntimeInputs(const std::string& android_root, bool is_host);
66 bool Link();
67#if defined(ART_USE_PORTABLE_COMPILER)
68 void FixupOatMethodOffsets(const std::vector<const DexFile*>& dex_files)
69 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
70 uint32_t FixupCompiledCodeOffset(ElfFile& elf_file,
71 llvm::ELF::Elf32_Addr oatdata_address,
72 const CompiledCode& compiled_code);
73#endif
74
75 // Setup by Init()
76 UniquePtr<mcld::LinkerConfig> linker_config_;
77 UniquePtr<mcld::Module> module_;
78 UniquePtr<mcld::IRBuilder> ir_builder_;
79 UniquePtr<mcld::Linker> linker_;
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 Carlstromfc0e3212013-07-17 14:40:12 -070098#endif // ART_COMPILER_ELF_WRITER_MCLINKER_H_