Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -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 | |
| 17 | #include "elf_writer_quick.h" |
| 18 | |
Yevgeny Rouban | e3ea838 | 2014-08-08 16:29:38 +0700 | [diff] [blame] | 19 | #include <unordered_map> |
David Srbecky | 626a166 | 2015-04-12 13:12:26 +0100 | [diff] [blame] | 20 | #include <unordered_set> |
Yevgeny Rouban | e3ea838 | 2014-08-08 16:29:38 +0700 | [diff] [blame] | 21 | |
David Srbecky | f898087 | 2015-05-22 17:04:47 +0100 | [diff] [blame] | 22 | #include "base/casts.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 23 | #include "base/logging.h" |
| 24 | #include "base/unix_file/fd_file.h" |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 25 | #include "compiled_method.h" |
David Srbecky | 0df9e1f | 2015-04-07 19:02:58 +0100 | [diff] [blame] | 26 | #include "dex_file-inl.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 27 | #include "driver/compiler_driver.h" |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 28 | #include "driver/compiler_options.h" |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 29 | #include "elf_builder.h" |
Yevgeny Rouban | e3ea838 | 2014-08-08 16:29:38 +0700 | [diff] [blame] | 30 | #include "elf_file.h" |
Nicolas Geoffray | 50cfe74 | 2014-02-19 13:27:42 +0000 | [diff] [blame] | 31 | #include "elf_utils.h" |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 32 | #include "elf_writer_debug.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 33 | #include "globals.h" |
Andreas Gampe | 7927380 | 2014-08-05 20:21:05 -0700 | [diff] [blame] | 34 | #include "leb128.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 35 | #include "oat.h" |
Brian Carlstrom | c50d8e1 | 2013-07-23 22:35:16 -0700 | [diff] [blame] | 36 | #include "oat_writer.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 37 | #include "utils.h" |
| 38 | |
| 39 | namespace art { |
| 40 | |
David Srbecky | ad5fa8c | 2015-05-06 18:27:35 +0100 | [diff] [blame] | 41 | // .eh_frame and .debug_frame are almost identical. |
| 42 | // Except for some minor formatting differences, the main difference |
| 43 | // is that .eh_frame is allocated within the running program because |
| 44 | // it is used by C++ exception handling (which we do not use so we |
| 45 | // can choose either). C++ compilers generally tend to use .eh_frame |
| 46 | // because if they need it sometimes, they might as well always use it. |
David Srbecky | aaf143d | 2015-05-21 14:03:48 +0100 | [diff] [blame] | 47 | // Let's use .debug_frame because it is easier to strip or compress. |
| 48 | constexpr dwarf::CFIFormat kCFIFormat = dwarf::DW_DEBUG_FRAME_FORMAT; |
David Srbecky | ad5fa8c | 2015-05-06 18:27:35 +0100 | [diff] [blame] | 49 | |
David Srbecky | 388d286 | 2015-05-21 19:11:18 +0100 | [diff] [blame] | 50 | // The ARM specification defines three special mapping symbols |
| 51 | // $a, $t and $d which mark ARM, Thumb and data ranges respectively. |
| 52 | // These symbols can be used by tools, for example, to pretty |
| 53 | // print instructions correctly. Objdump will use them if they |
| 54 | // exist, but it will still work well without them. |
| 55 | // However, these extra symbols take space, so let's just generate |
| 56 | // one symbol which marks the whole .text section as code. |
| 57 | constexpr bool kGenerateSingleArmMappingSymbol = true; |
| 58 | |
David Srbecky | 533c207 | 2015-04-22 12:20:22 +0100 | [diff] [blame] | 59 | template <typename ElfTypes> |
| 60 | bool ElfWriterQuick<ElfTypes>::Create(File* elf_file, |
| 61 | OatWriter* oat_writer, |
| 62 | const std::vector<const DexFile*>& dex_files, |
| 63 | const std::string& android_root, |
| 64 | bool is_host, |
| 65 | const CompilerDriver& driver) { |
Brian Carlstrom | b12f347 | 2014-06-11 14:54:46 -0700 | [diff] [blame] | 66 | ElfWriterQuick elf_writer(driver, elf_file); |
| 67 | return elf_writer.Write(oat_writer, dex_files, android_root, is_host); |
| 68 | } |
| 69 | |
David Srbecky | 533c207 | 2015-04-22 12:20:22 +0100 | [diff] [blame] | 70 | template <typename ElfTypes> |
| 71 | static void WriteDebugSymbols(ElfBuilder<ElfTypes>* builder, OatWriter* oat_writer); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 72 | |
David Srbecky | f898087 | 2015-05-22 17:04:47 +0100 | [diff] [blame] | 73 | // Encode patch locations as LEB128 list of deltas between consecutive addresses. |
David Srbecky | 533c207 | 2015-04-22 12:20:22 +0100 | [diff] [blame] | 74 | template <typename ElfTypes> |
David Srbecky | f898087 | 2015-05-22 17:04:47 +0100 | [diff] [blame] | 75 | void ElfWriterQuick<ElfTypes>::EncodeOatPatches(const std::vector<uintptr_t>& locations, |
| 76 | std::vector<uint8_t>* buffer) { |
| 77 | buffer->reserve(buffer->size() + locations.size() * 2); // guess 2 bytes per ULEB128. |
| 78 | uintptr_t address = 0; // relative to start of section. |
| 79 | for (uintptr_t location : locations) { |
| 80 | DCHECK_GE(location, address) << "Patch locations are not in sorted order"; |
| 81 | EncodeUnsignedLeb128(buffer, dchecked_integral_cast<uint32_t>(location - address)); |
| 82 | address = location; |
David Srbecky | 2f6cdb0 | 2015-04-11 00:17:53 +0100 | [diff] [blame] | 83 | } |
David Srbecky | 2f6cdb0 | 2015-04-11 00:17:53 +0100 | [diff] [blame] | 84 | } |
| 85 | |
David Srbecky | bc90fd0 | 2015-04-22 19:40:27 +0100 | [diff] [blame] | 86 | class RodataWriter FINAL : public CodeOutput { |
| 87 | public: |
| 88 | explicit RodataWriter(OatWriter* oat_writer) : oat_writer_(oat_writer) {} |
| 89 | |
| 90 | bool Write(OutputStream* out) OVERRIDE { |
| 91 | return oat_writer_->WriteRodata(out); |
David Srbecky | 527c9c7 | 2015-04-17 21:14:10 +0100 | [diff] [blame] | 92 | } |
David Srbecky | bc90fd0 | 2015-04-22 19:40:27 +0100 | [diff] [blame] | 93 | |
| 94 | private: |
| 95 | OatWriter* oat_writer_; |
| 96 | }; |
| 97 | |
| 98 | class TextWriter FINAL : public CodeOutput { |
| 99 | public: |
| 100 | explicit TextWriter(OatWriter* oat_writer) : oat_writer_(oat_writer) {} |
| 101 | |
| 102 | bool Write(OutputStream* out) OVERRIDE { |
| 103 | return oat_writer_->WriteCode(out); |
| 104 | } |
| 105 | |
| 106 | private: |
| 107 | OatWriter* oat_writer_; |
| 108 | }; |
David Srbecky | 527c9c7 | 2015-04-17 21:14:10 +0100 | [diff] [blame] | 109 | |
David Srbecky | 033d745 | 2015-04-30 19:57:35 +0100 | [diff] [blame] | 110 | enum PatchResult { |
| 111 | kAbsoluteAddress, // Absolute memory location. |
| 112 | kPointerRelativeAddress, // Offset relative to the location of the pointer. |
| 113 | kSectionRelativeAddress, // Offset relative to start of containing section. |
| 114 | }; |
| 115 | |
| 116 | // Patch memory addresses within a buffer. |
| 117 | // It assumes that the unpatched addresses are offsets relative to base_address. |
| 118 | // (which generally means method's low_pc relative to the start of .text) |
| 119 | template <typename Elf_Addr, typename Address, PatchResult kPatchResult> |
| 120 | static void Patch(const std::vector<uintptr_t>& patch_locations, |
| 121 | Elf_Addr buffer_address, Elf_Addr base_address, |
| 122 | std::vector<uint8_t>* buffer) { |
| 123 | for (uintptr_t location : patch_locations) { |
| 124 | typedef __attribute__((__aligned__(1))) Address UnalignedAddress; |
| 125 | auto* to_patch = reinterpret_cast<UnalignedAddress*>(buffer->data() + location); |
| 126 | switch (kPatchResult) { |
| 127 | case kAbsoluteAddress: |
| 128 | *to_patch = (base_address + *to_patch); |
| 129 | break; |
| 130 | case kPointerRelativeAddress: |
| 131 | *to_patch = (base_address + *to_patch) - (buffer_address + location); |
| 132 | break; |
| 133 | case kSectionRelativeAddress: |
| 134 | *to_patch = (base_address + *to_patch) - buffer_address; |
| 135 | break; |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | |
David Srbecky | 533c207 | 2015-04-22 12:20:22 +0100 | [diff] [blame] | 140 | template <typename ElfTypes> |
| 141 | bool ElfWriterQuick<ElfTypes>::Write( |
| 142 | OatWriter* oat_writer, |
| 143 | const std::vector<const DexFile*>& dex_files_unused ATTRIBUTE_UNUSED, |
| 144 | const std::string& android_root_unused ATTRIBUTE_UNUSED, |
| 145 | bool is_host_unused ATTRIBUTE_UNUSED) { |
David Srbecky | 033d745 | 2015-04-30 19:57:35 +0100 | [diff] [blame] | 146 | using Elf_Addr = typename ElfTypes::Addr; |
David Srbecky | bc90fd0 | 2015-04-22 19:40:27 +0100 | [diff] [blame] | 147 | const InstructionSet isa = compiler_driver_->GetInstructionSet(); |
Brian Carlstrom | b12f347 | 2014-06-11 14:54:46 -0700 | [diff] [blame] | 148 | |
David Srbecky | bc90fd0 | 2015-04-22 19:40:27 +0100 | [diff] [blame] | 149 | // Setup the builder with the main OAT sections (.rodata .text .bss). |
| 150 | const size_t rodata_size = oat_writer->GetOatHeader().GetExecutableOffset(); |
| 151 | const size_t text_size = oat_writer->GetSize() - rodata_size; |
| 152 | const size_t bss_size = oat_writer->GetBssSize(); |
| 153 | RodataWriter rodata_writer(oat_writer); |
| 154 | TextWriter text_writer(oat_writer); |
David Srbecky | 533c207 | 2015-04-22 12:20:22 +0100 | [diff] [blame] | 155 | std::unique_ptr<ElfBuilder<ElfTypes>> builder(new ElfBuilder<ElfTypes>( |
David Srbecky | bc90fd0 | 2015-04-22 19:40:27 +0100 | [diff] [blame] | 156 | isa, rodata_size, &rodata_writer, text_size, &text_writer, bss_size)); |
Alex Light | 78382fa | 2014-06-06 15:45:32 -0700 | [diff] [blame] | 157 | |
David Srbecky | bc90fd0 | 2015-04-22 19:40:27 +0100 | [diff] [blame] | 158 | // Add debug sections. |
David Srbecky | 491a7fe | 2015-05-28 00:59:08 +0100 | [diff] [blame] | 159 | // They are allocated here (in the same scope as the builder), |
David Srbecky | f898087 | 2015-05-22 17:04:47 +0100 | [diff] [blame] | 160 | // but they are registered with the builder only if they are used. |
David Srbecky | bc90fd0 | 2015-04-22 19:40:27 +0100 | [diff] [blame] | 161 | using RawSection = typename ElfBuilder<ElfTypes>::RawSection; |
David Srbecky | bc90fd0 | 2015-04-22 19:40:27 +0100 | [diff] [blame] | 162 | const auto* text = builder->GetText(); |
David Srbecky | bc90fd0 | 2015-04-22 19:40:27 +0100 | [diff] [blame] | 163 | const bool is64bit = Is64BitInstructionSet(isa); |
David Srbecky | ad5fa8c | 2015-05-06 18:27:35 +0100 | [diff] [blame] | 164 | const int pointer_size = GetInstructionSetPointerSize(isa); |
David Srbecky | 491a7fe | 2015-05-28 00:59:08 +0100 | [diff] [blame] | 165 | std::unique_ptr<RawSection> eh_frame(new RawSection( |
| 166 | ".eh_frame", SHT_PROGBITS, SHF_ALLOC, nullptr, 0, kPageSize, 0, |
| 167 | is64bit ? Patch<Elf_Addr, uint64_t, kPointerRelativeAddress> : |
| 168 | Patch<Elf_Addr, uint32_t, kPointerRelativeAddress>, |
| 169 | text)); |
| 170 | std::unique_ptr<RawSection> eh_frame_hdr(new RawSection( |
| 171 | ".eh_frame_hdr", SHT_PROGBITS, SHF_ALLOC, nullptr, 0, 4, 0, |
| 172 | Patch<Elf_Addr, uint32_t, kSectionRelativeAddress>, text)); |
| 173 | std::unique_ptr<RawSection> debug_frame(new RawSection( |
| 174 | ".debug_frame", SHT_PROGBITS, 0, nullptr, 0, pointer_size, 0, |
| 175 | is64bit ? Patch<Elf_Addr, uint64_t, kAbsoluteAddress> : |
| 176 | Patch<Elf_Addr, uint32_t, kAbsoluteAddress>, |
| 177 | text)); |
| 178 | std::unique_ptr<RawSection> debug_frame_oat_patches(new RawSection( |
| 179 | ".debug_frame.oat_patches", SHT_OAT_PATCH)); |
| 180 | std::unique_ptr<RawSection> debug_info(new RawSection( |
| 181 | ".debug_info", SHT_PROGBITS, 0, nullptr, 0, 1, 0, |
| 182 | Patch<Elf_Addr, uint32_t, kAbsoluteAddress>, text)); |
| 183 | std::unique_ptr<RawSection> debug_info_oat_patches(new RawSection( |
| 184 | ".debug_info.oat_patches", SHT_OAT_PATCH)); |
| 185 | std::unique_ptr<RawSection> debug_abbrev(new RawSection( |
| 186 | ".debug_abbrev", SHT_PROGBITS)); |
| 187 | std::unique_ptr<RawSection> debug_str(new RawSection( |
| 188 | ".debug_str", SHT_PROGBITS)); |
| 189 | std::unique_ptr<RawSection> debug_line(new RawSection( |
| 190 | ".debug_line", SHT_PROGBITS, 0, nullptr, 0, 1, 0, |
| 191 | Patch<Elf_Addr, uint32_t, kAbsoluteAddress>, text)); |
| 192 | std::unique_ptr<RawSection> debug_line_oat_patches(new RawSection( |
| 193 | ".debug_line.oat_patches", SHT_OAT_PATCH)); |
David Srbecky | bc90fd0 | 2015-04-22 19:40:27 +0100 | [diff] [blame] | 194 | if (!oat_writer->GetMethodDebugInfo().empty()) { |
David Srbecky | 8363c77 | 2015-05-28 16:12:43 +0100 | [diff] [blame] | 195 | if (compiler_driver_->GetCompilerOptions().GetGenerateDebugInfo()) { |
| 196 | // Generate CFI (stack unwinding information). |
David Srbecky | ad5fa8c | 2015-05-06 18:27:35 +0100 | [diff] [blame] | 197 | if (kCFIFormat == dwarf::DW_EH_FRAME_FORMAT) { |
| 198 | dwarf::WriteCFISection( |
| 199 | compiler_driver_, oat_writer, |
| 200 | dwarf::DW_EH_PE_pcrel, kCFIFormat, |
David Srbecky | 491a7fe | 2015-05-28 00:59:08 +0100 | [diff] [blame] | 201 | eh_frame->GetBuffer(), eh_frame->GetPatchLocations(), |
| 202 | eh_frame_hdr->GetBuffer(), eh_frame_hdr->GetPatchLocations()); |
| 203 | builder->RegisterSection(eh_frame.get()); |
| 204 | builder->RegisterSection(eh_frame_hdr.get()); |
David Srbecky | ad5fa8c | 2015-05-06 18:27:35 +0100 | [diff] [blame] | 205 | } else { |
| 206 | DCHECK(kCFIFormat == dwarf::DW_DEBUG_FRAME_FORMAT); |
| 207 | dwarf::WriteCFISection( |
| 208 | compiler_driver_, oat_writer, |
| 209 | dwarf::DW_EH_PE_absptr, kCFIFormat, |
David Srbecky | 491a7fe | 2015-05-28 00:59:08 +0100 | [diff] [blame] | 210 | debug_frame->GetBuffer(), debug_frame->GetPatchLocations(), |
David Srbecky | ad5fa8c | 2015-05-06 18:27:35 +0100 | [diff] [blame] | 211 | nullptr, nullptr); |
David Srbecky | 491a7fe | 2015-05-28 00:59:08 +0100 | [diff] [blame] | 212 | builder->RegisterSection(debug_frame.get()); |
| 213 | EncodeOatPatches(*debug_frame->GetPatchLocations(), |
| 214 | debug_frame_oat_patches->GetBuffer()); |
| 215 | builder->RegisterSection(debug_frame_oat_patches.get()); |
David Srbecky | ad5fa8c | 2015-05-06 18:27:35 +0100 | [diff] [blame] | 216 | } |
David Srbecky | bc90fd0 | 2015-04-22 19:40:27 +0100 | [diff] [blame] | 217 | // Add methods to .symtab. |
| 218 | WriteDebugSymbols(builder.get(), oat_writer); |
| 219 | // Generate DWARF .debug_* sections. |
| 220 | dwarf::WriteDebugSections( |
| 221 | compiler_driver_, oat_writer, |
David Srbecky | 491a7fe | 2015-05-28 00:59:08 +0100 | [diff] [blame] | 222 | debug_info->GetBuffer(), debug_info->GetPatchLocations(), |
| 223 | debug_abbrev->GetBuffer(), |
| 224 | debug_str->GetBuffer(), |
| 225 | debug_line->GetBuffer(), debug_line->GetPatchLocations()); |
| 226 | builder->RegisterSection(debug_info.get()); |
| 227 | EncodeOatPatches(*debug_info->GetPatchLocations(), |
| 228 | debug_info_oat_patches->GetBuffer()); |
| 229 | builder->RegisterSection(debug_info_oat_patches.get()); |
| 230 | builder->RegisterSection(debug_abbrev.get()); |
| 231 | builder->RegisterSection(debug_str.get()); |
| 232 | builder->RegisterSection(debug_line.get()); |
| 233 | EncodeOatPatches(*debug_line->GetPatchLocations(), |
| 234 | debug_line_oat_patches->GetBuffer()); |
| 235 | builder->RegisterSection(debug_line_oat_patches.get()); |
David Srbecky | bc90fd0 | 2015-04-22 19:40:27 +0100 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | |
David Srbecky | f898087 | 2015-05-22 17:04:47 +0100 | [diff] [blame] | 239 | // Add relocation section for .text. |
David Srbecky | 491a7fe | 2015-05-28 00:59:08 +0100 | [diff] [blame] | 240 | std::unique_ptr<RawSection> text_oat_patches(new RawSection( |
| 241 | ".text.oat_patches", SHT_OAT_PATCH)); |
David Srbecky | f898087 | 2015-05-22 17:04:47 +0100 | [diff] [blame] | 242 | if (compiler_driver_->GetCompilerOptions().GetIncludePatchInformation()) { |
| 243 | // Note that ElfWriter::Fixup will be called regardless and therefore |
| 244 | // we need to include oat_patches for debug sections unconditionally. |
| 245 | EncodeOatPatches(oat_writer->GetAbsolutePatchLocations(), |
David Srbecky | 491a7fe | 2015-05-28 00:59:08 +0100 | [diff] [blame] | 246 | text_oat_patches->GetBuffer()); |
| 247 | builder->RegisterSection(text_oat_patches.get()); |
David Srbecky | 527c9c7 | 2015-04-17 21:14:10 +0100 | [diff] [blame] | 248 | } |
| 249 | |
David Srbecky | bc90fd0 | 2015-04-22 19:40:27 +0100 | [diff] [blame] | 250 | return builder->Write(elf_file_); |
Brian Carlstrom | b12f347 | 2014-06-11 14:54:46 -0700 | [diff] [blame] | 251 | } |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 252 | |
David Srbecky | 533c207 | 2015-04-22 12:20:22 +0100 | [diff] [blame] | 253 | template <typename ElfTypes> |
David Srbecky | 533c207 | 2015-04-22 12:20:22 +0100 | [diff] [blame] | 254 | static void WriteDebugSymbols(ElfBuilder<ElfTypes>* builder, OatWriter* oat_writer) { |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 255 | const std::vector<OatWriter::DebugInfo>& method_info = oat_writer->GetMethodDebugInfo(); |
David Srbecky | 388d286 | 2015-05-21 19:11:18 +0100 | [diff] [blame] | 256 | bool generated_mapping_symbol = false; |
David Srbecky | 626a166 | 2015-04-12 13:12:26 +0100 | [diff] [blame] | 257 | |
| 258 | // Find all addresses (low_pc) which contain deduped methods. |
| 259 | // The first instance of method is not marked deduped_, but the rest is. |
| 260 | std::unordered_set<uint32_t> deduped_addresses; |
| 261 | for (auto it = method_info.begin(); it != method_info.end(); ++it) { |
| 262 | if (it->deduped_) { |
| 263 | deduped_addresses.insert(it->low_pc_); |
| 264 | } |
| 265 | } |
| 266 | |
David Srbecky | bc90fd0 | 2015-04-22 19:40:27 +0100 | [diff] [blame] | 267 | auto* symtab = builder->GetSymtab(); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 268 | for (auto it = method_info.begin(); it != method_info.end(); ++it) { |
David Srbecky | 6d73c9d | 2015-05-01 15:00:40 +0100 | [diff] [blame] | 269 | if (it->deduped_) { |
| 270 | continue; // Add symbol only for the first instance. |
| 271 | } |
David Srbecky | 0df9e1f | 2015-04-07 19:02:58 +0100 | [diff] [blame] | 272 | std::string name = PrettyMethod(it->dex_method_index_, *it->dex_file_, true); |
David Srbecky | 626a166 | 2015-04-12 13:12:26 +0100 | [diff] [blame] | 273 | if (deduped_addresses.find(it->low_pc_) != deduped_addresses.end()) { |
| 274 | name += " [DEDUPED]"; |
David Srbecky | 0df9e1f | 2015-04-07 19:02:58 +0100 | [diff] [blame] | 275 | } |
| 276 | |
David Srbecky | 6f71589 | 2015-03-30 14:21:42 +0100 | [diff] [blame] | 277 | uint32_t low_pc = it->low_pc_; |
| 278 | // Add in code delta, e.g., thumb bit 0 for Thumb2 code. |
| 279 | low_pc += it->compiled_method_->CodeDelta(); |
David Srbecky | bc90fd0 | 2015-04-22 19:40:27 +0100 | [diff] [blame] | 280 | symtab->AddSymbol(name, builder->GetText(), low_pc, |
David Srbecky | 6f71589 | 2015-03-30 14:21:42 +0100 | [diff] [blame] | 281 | true, it->high_pc_ - it->low_pc_, STB_GLOBAL, STT_FUNC); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 282 | |
Ningsheng Jian | f973455 | 2014-10-27 14:56:34 +0800 | [diff] [blame] | 283 | // Conforming to aaelf, add $t mapping symbol to indicate start of a sequence of thumb2 |
| 284 | // instructions, so that disassembler tools can correctly disassemble. |
David Srbecky | 388d286 | 2015-05-21 19:11:18 +0100 | [diff] [blame] | 285 | // Note that even if we generate just a single mapping symbol, ARM's Streamline |
| 286 | // requires it to match function symbol. Just address 0 does not work. |
Ningsheng Jian | f973455 | 2014-10-27 14:56:34 +0800 | [diff] [blame] | 287 | if (it->compiled_method_->GetInstructionSet() == kThumb2) { |
David Srbecky | 388d286 | 2015-05-21 19:11:18 +0100 | [diff] [blame] | 288 | if (!generated_mapping_symbol || !kGenerateSingleArmMappingSymbol) { |
| 289 | symtab->AddSymbol("$t", builder->GetText(), it->low_pc_ & ~1, true, |
| 290 | 0, STB_LOCAL, STT_NOTYPE); |
| 291 | generated_mapping_symbol = true; |
| 292 | } |
Ningsheng Jian | f973455 | 2014-10-27 14:56:34 +0800 | [diff] [blame] | 293 | } |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 294 | } |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Nicolas Geoffray | f9b87b1 | 2014-09-02 08:12:09 +0000 | [diff] [blame] | 297 | // Explicit instantiations |
David Srbecky | 533c207 | 2015-04-22 12:20:22 +0100 | [diff] [blame] | 298 | template class ElfWriterQuick<ElfTypes32>; |
| 299 | template class ElfWriterQuick<ElfTypes64>; |
Nicolas Geoffray | f9b87b1 | 2014-09-02 08:12:09 +0000 | [diff] [blame] | 300 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 301 | } // namespace art |