Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | */ |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 16 | |
| 17 | #include "oat_file.h" |
| 18 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 19 | #include <dlfcn.h> |
Calin Juravle | 4e1d579 | 2014-07-15 23:56:47 +0100 | [diff] [blame] | 20 | #include <string.h> |
Andreas Gampe | daab38c | 2014-09-12 18:38:24 -0700 | [diff] [blame] | 21 | #include <unistd.h> |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 22 | |
Andreas Gampe | 7848da4 | 2015-04-09 11:15:04 -0700 | [diff] [blame] | 23 | #include <cstdlib> |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 24 | #include <sstream> |
| 25 | |
Andreas Gampe | fa8429b | 2015-04-07 18:34:42 -0700 | [diff] [blame] | 26 | // dlopen_ext support from bionic. |
| 27 | #ifdef HAVE_ANDROID_OS |
| 28 | #include "android/dlext.h" |
| 29 | #endif |
| 30 | |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 31 | #include "base/bit_vector.h" |
Elliott Hughes | 1aa246d | 2012-12-13 09:29:36 -0800 | [diff] [blame] | 32 | #include "base/stl_util.h" |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 33 | #include "base/unix_file/fd_file.h" |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 34 | #include "elf_file.h" |
Alex Light | 84d7605 | 2014-08-22 17:49:35 -0700 | [diff] [blame] | 35 | #include "elf_utils.h" |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 36 | #include "oat.h" |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 37 | #include "mirror/art_method.h" |
| 38 | #include "mirror/art_method-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 39 | #include "mirror/class.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 40 | #include "mirror/object-inl.h" |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 41 | #include "os.h" |
Andreas Gampe | 22f8e5c | 2014-07-09 11:38:21 -0700 | [diff] [blame] | 42 | #include "runtime.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 43 | #include "utils.h" |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 44 | #include "vmap_table.h" |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 45 | |
| 46 | namespace art { |
| 47 | |
Andreas Gampe | fa8429b | 2015-04-07 18:34:42 -0700 | [diff] [blame] | 48 | // Whether OatFile::Open will try DlOpen() first. Fallback is our own ELF loader. |
| 49 | static constexpr bool kUseDlopen = false; |
| 50 | |
| 51 | // Whether OatFile::Open will try DlOpen() on the host. On the host we're not linking against |
| 52 | // bionic, so cannot take advantage of the support for changed semantics (loading the same soname |
| 53 | // multiple times). However, if/when we switch the above, we likely want to switch this, too, |
| 54 | // to get test coverage of the code paths. |
| 55 | static constexpr bool kUseDlopenOnHost = false; |
| 56 | |
| 57 | // For debugging, Open will print DlOpen error message if set to true. |
| 58 | static constexpr bool kPrintDlOpenErrorMessage = false; |
| 59 | |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 60 | std::string OatFile::ResolveRelativeEncodedDexLocation( |
| 61 | const char* abs_dex_location, const std::string& rel_dex_location) { |
| 62 | if (abs_dex_location != nullptr && rel_dex_location[0] != '/') { |
| 63 | // Strip :classes<N>.dex used for secondary multidex files. |
| 64 | std::string base = DexFile::GetBaseLocation(rel_dex_location); |
| 65 | std::string multidex_suffix = DexFile::GetMultiDexSuffix(rel_dex_location); |
| 66 | |
| 67 | // Check if the base is a suffix of the provided abs_dex_location. |
| 68 | std::string target_suffix = "/" + base; |
| 69 | std::string abs_location(abs_dex_location); |
| 70 | if (abs_location.size() > target_suffix.size()) { |
| 71 | size_t pos = abs_location.size() - target_suffix.size(); |
| 72 | if (abs_location.compare(pos, std::string::npos, target_suffix) == 0) { |
| 73 | return abs_location + multidex_suffix; |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | return rel_dex_location; |
| 78 | } |
| 79 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 80 | void OatFile::CheckLocation(const std::string& location) { |
Brian Carlstrom | 7a967b3 | 2012-03-28 15:23:10 -0700 | [diff] [blame] | 81 | CHECK(!location.empty()); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 82 | } |
| 83 | |
Alex Light | 84d7605 | 2014-08-22 17:49:35 -0700 | [diff] [blame] | 84 | OatFile* OatFile::OpenWithElfFile(ElfFile* elf_file, |
| 85 | const std::string& location, |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 86 | const char* abs_dex_location, |
Alex Light | 84d7605 | 2014-08-22 17:49:35 -0700 | [diff] [blame] | 87 | std::string* error_msg) { |
| 88 | std::unique_ptr<OatFile> oat_file(new OatFile(location, false)); |
| 89 | oat_file->elf_file_.reset(elf_file); |
Tong Shen | 62d1ca3 | 2014-09-03 17:24:56 -0700 | [diff] [blame] | 90 | uint64_t offset, size; |
| 91 | bool has_section = elf_file->GetSectionOffsetAndSize(".rodata", &offset, &size); |
| 92 | CHECK(has_section); |
| 93 | oat_file->begin_ = elf_file->Begin() + offset; |
| 94 | oat_file->end_ = elf_file->Begin() + size + offset; |
Vladimir Marko | 5c42c29 | 2015-02-25 12:02:49 +0000 | [diff] [blame] | 95 | // Ignore the optional .bss section when opening non-executable. |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 96 | return oat_file->Setup(abs_dex_location, error_msg) ? oat_file.release() : nullptr; |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | OatFile* OatFile::Open(const std::string& filename, |
| 100 | const std::string& location, |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 101 | uint8_t* requested_base, |
Igor Murashkin | 4677476 | 2014-10-22 11:37:02 -0700 | [diff] [blame] | 102 | uint8_t* oat_file_begin, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 103 | bool executable, |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 104 | const char* abs_dex_location, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 105 | std::string* error_msg) { |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 106 | CHECK(!filename.empty()) << location; |
Andreas Gampe | 7ba6496 | 2014-10-23 11:37:40 -0700 | [diff] [blame] | 107 | CheckLocation(location); |
Andreas Gampe | 22f8e5c | 2014-07-09 11:38:21 -0700 | [diff] [blame] | 108 | std::unique_ptr<OatFile> ret; |
Andreas Gampe | fa8429b | 2015-04-07 18:34:42 -0700 | [diff] [blame] | 109 | |
| 110 | // Use dlopen only when flagged to do so, and when it's OK to load things executable. |
| 111 | // TODO: Also try when not executable? The issue here could be re-mapping as writable (as |
| 112 | // !executable is a sign that we may want to patch), which may not be allowed for |
| 113 | // various reasons. |
| 114 | if (kUseDlopen && (kIsTargetBuild || kUseDlopenOnHost) && executable) { |
| 115 | // Try to use dlopen. This may fail for various reasons, outlined below. We try dlopen, as |
| 116 | // this will register the oat file with the linker and allows libunwind to find our info. |
| 117 | ret.reset(OpenDlopen(filename, location, requested_base, abs_dex_location, error_msg)); |
| 118 | if (ret.get() != nullptr) { |
| 119 | return ret.release(); |
| 120 | } |
| 121 | if (kPrintDlOpenErrorMessage) { |
| 122 | LOG(ERROR) << "Failed to dlopen: " << *error_msg; |
| 123 | } |
| 124 | } |
| 125 | |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 126 | // If we aren't trying to execute, we just use our own ElfFile loader for a couple reasons: |
| 127 | // |
| 128 | // On target, dlopen may fail when compiling due to selinux restrictions on installd. |
| 129 | // |
| 130 | // We use our own ELF loader for Quick to deal with legacy apps that |
| 131 | // open a generated dex file by name, remove the file, then open |
| 132 | // another generated dex file with the same name. http://b/10614658 |
| 133 | // |
| 134 | // On host, dlopen is expected to fail when cross compiling, so fall back to OpenElfFile. |
Andreas Gampe | fa8429b | 2015-04-07 18:34:42 -0700 | [diff] [blame] | 135 | // |
| 136 | // |
| 137 | // Another independent reason is the absolute placement of boot.oat. dlopen on the host usually |
| 138 | // does honor the virtual address encoded in the ELF file only for ET_EXEC files, not ET_DYN. |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 139 | std::unique_ptr<File> file(OS::OpenFileForReading(filename.c_str())); |
Andreas Gampe | fa8429b | 2015-04-07 18:34:42 -0700 | [diff] [blame] | 140 | if (file == nullptr) { |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 141 | *error_msg = StringPrintf("Failed to open oat filename for reading: %s", strerror(errno)); |
| 142 | return nullptr; |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 143 | } |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 144 | ret.reset(OpenElfFile(file.get(), location, requested_base, oat_file_begin, false, executable, |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 145 | abs_dex_location, error_msg)); |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 146 | |
| 147 | // It would be nice to unlink here. But we might have opened the file created by the |
| 148 | // ScopedLock, which we better not delete to avoid races. TODO: Investigate how to fix the API |
| 149 | // to allow removal when we know the ELF must be borked. |
Dave Allison | 69dfe51 | 2014-07-11 17:11:58 +0000 | [diff] [blame] | 150 | return ret.release(); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 151 | } |
| 152 | |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 153 | OatFile* OatFile::OpenWritable(File* file, const std::string& location, |
| 154 | const char* abs_dex_location, |
| 155 | std::string* error_msg) { |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 156 | CheckLocation(location); |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 157 | return OpenElfFile(file, location, nullptr, nullptr, true, false, abs_dex_location, error_msg); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 158 | } |
| 159 | |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 160 | OatFile* OatFile::OpenReadable(File* file, const std::string& location, |
| 161 | const char* abs_dex_location, |
| 162 | std::string* error_msg) { |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 163 | CheckLocation(location); |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 164 | return OpenElfFile(file, location, nullptr, nullptr, false, false, abs_dex_location, error_msg); |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Andreas Gampe | fa8429b | 2015-04-07 18:34:42 -0700 | [diff] [blame] | 167 | OatFile* OatFile::OpenDlopen(const std::string& elf_filename, |
| 168 | const std::string& location, |
| 169 | uint8_t* requested_base, |
| 170 | const char* abs_dex_location, |
| 171 | std::string* error_msg) { |
| 172 | std::unique_ptr<OatFile> oat_file(new OatFile(location, true)); |
| 173 | bool success = oat_file->Dlopen(elf_filename, requested_base, abs_dex_location, error_msg); |
| 174 | if (!success) { |
| 175 | return nullptr; |
| 176 | } |
| 177 | return oat_file.release(); |
| 178 | } |
| 179 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 180 | OatFile* OatFile::OpenElfFile(File* file, |
| 181 | const std::string& location, |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 182 | uint8_t* requested_base, |
Igor Murashkin | 4677476 | 2014-10-22 11:37:02 -0700 | [diff] [blame] | 183 | uint8_t* oat_file_begin, |
Brian Carlstrom | f1d3455 | 2013-07-12 20:22:23 -0700 | [diff] [blame] | 184 | bool writable, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 185 | bool executable, |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 186 | const char* abs_dex_location, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 187 | std::string* error_msg) { |
Alex Light | 9dcc457 | 2014-08-14 14:16:26 -0700 | [diff] [blame] | 188 | std::unique_ptr<OatFile> oat_file(new OatFile(location, executable)); |
Igor Murashkin | 4677476 | 2014-10-22 11:37:02 -0700 | [diff] [blame] | 189 | bool success = oat_file->ElfFileOpen(file, requested_base, oat_file_begin, writable, executable, |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 190 | abs_dex_location, error_msg); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 191 | if (!success) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 192 | CHECK(!error_msg->empty()); |
| 193 | return nullptr; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 194 | } |
| 195 | return oat_file.release(); |
| 196 | } |
| 197 | |
Alex Light | 9dcc457 | 2014-08-14 14:16:26 -0700 | [diff] [blame] | 198 | OatFile::OatFile(const std::string& location, bool is_executable) |
Andreas Gampe | fa8429b | 2015-04-07 18:34:42 -0700 | [diff] [blame] | 199 | : location_(location), begin_(nullptr), end_(nullptr), bss_begin_(nullptr), bss_end_(nullptr), |
| 200 | is_executable_(is_executable), dlopen_handle_(nullptr), |
Vladimir Marko | 3f5838d | 2014-08-07 18:07:18 +0100 | [diff] [blame] | 201 | secondary_lookup_lock_("OatFile secondary lookup lock", kOatFileSecondaryLookupLock) { |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 202 | CHECK(!location_.empty()); |
| 203 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 204 | |
| 205 | OatFile::~OatFile() { |
Vladimir Marko | aa4497d | 2014-09-05 14:01:17 +0100 | [diff] [blame] | 206 | STLDeleteElements(&oat_dex_files_storage_); |
Andreas Gampe | fa8429b | 2015-04-07 18:34:42 -0700 | [diff] [blame] | 207 | if (dlopen_handle_ != nullptr) { |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 208 | dlclose(dlopen_handle_); |
| 209 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Andreas Gampe | fa8429b | 2015-04-07 18:34:42 -0700 | [diff] [blame] | 212 | bool OatFile::Dlopen(const std::string& elf_filename, uint8_t* requested_base, |
| 213 | const char* abs_dex_location, std::string* error_msg) { |
| 214 | std::unique_ptr<char> absolute_path(realpath(elf_filename.c_str(), nullptr)); |
| 215 | if (absolute_path == nullptr) { |
| 216 | *error_msg = StringPrintf("Failed to find absolute path for '%s'", elf_filename.c_str()); |
| 217 | return false; |
| 218 | } |
| 219 | #ifdef HAVE_ANDROID_OS |
| 220 | android_dlextinfo extinfo; |
| 221 | extinfo.flags = ANDROID_DLEXT_FORCE_LOAD; |
| 222 | dlopen_handle_ = android_dlopen_ext(absolute_path.get(), RTLD_NOW, &extinfo); |
| 223 | #else |
| 224 | dlopen_handle_ = dlopen(absolute_path.get(), RTLD_NOW); |
| 225 | #endif |
| 226 | if (dlopen_handle_ == nullptr) { |
| 227 | *error_msg = StringPrintf("Failed to dlopen '%s': %s", elf_filename.c_str(), dlerror()); |
| 228 | return false; |
| 229 | } |
| 230 | begin_ = reinterpret_cast<uint8_t*>(dlsym(dlopen_handle_, "oatdata")); |
| 231 | if (begin_ == nullptr) { |
| 232 | *error_msg = StringPrintf("Failed to find oatdata symbol in '%s': %s", elf_filename.c_str(), |
| 233 | dlerror()); |
| 234 | return false; |
| 235 | } |
| 236 | if (requested_base != nullptr && begin_ != requested_base) { |
| 237 | PrintFileToLog("/proc/self/maps", LogSeverity::WARNING); |
| 238 | *error_msg = StringPrintf("Failed to find oatdata symbol at expected address: " |
| 239 | "oatdata=%p != expected=%p, %s. See process maps in the log.", |
| 240 | begin_, requested_base, elf_filename.c_str()); |
| 241 | return false; |
| 242 | } |
| 243 | end_ = reinterpret_cast<uint8_t*>(dlsym(dlopen_handle_, "oatlastword")); |
| 244 | if (end_ == nullptr) { |
| 245 | *error_msg = StringPrintf("Failed to find oatlastword symbol in '%s': %s", elf_filename.c_str(), |
| 246 | dlerror()); |
| 247 | return false; |
| 248 | } |
| 249 | // Readjust to be non-inclusive upper bound. |
| 250 | end_ += sizeof(uint32_t); |
| 251 | |
| 252 | bss_begin_ = reinterpret_cast<uint8_t*>(dlsym(dlopen_handle_, "oatbss")); |
| 253 | if (bss_begin_ == nullptr) { |
| 254 | // No .bss section. Clear dlerror(). |
| 255 | bss_end_ = nullptr; |
| 256 | dlerror(); |
| 257 | } else { |
| 258 | bss_end_ = reinterpret_cast<uint8_t*>(dlsym(dlopen_handle_, "oatbsslastword")); |
| 259 | if (bss_end_ == nullptr) { |
| 260 | *error_msg = StringPrintf("Failed to find oatbasslastword symbol in '%s'", |
| 261 | elf_filename.c_str()); |
| 262 | return false; |
| 263 | } |
| 264 | // Readjust to be non-inclusive upper bound. |
| 265 | bss_end_ += sizeof(uint32_t); |
| 266 | } |
| 267 | |
| 268 | return Setup(abs_dex_location, error_msg); |
| 269 | } |
| 270 | |
Igor Murashkin | 4677476 | 2014-10-22 11:37:02 -0700 | [diff] [blame] | 271 | bool OatFile::ElfFileOpen(File* file, uint8_t* requested_base, uint8_t* oat_file_begin, |
| 272 | bool writable, bool executable, |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 273 | const char* abs_dex_location, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 274 | std::string* error_msg) { |
Igor Murashkin | 4677476 | 2014-10-22 11:37:02 -0700 | [diff] [blame] | 275 | // TODO: rename requested_base to oat_data_begin |
| 276 | elf_file_.reset(ElfFile::Open(file, writable, /*program_header_only*/true, error_msg, |
| 277 | oat_file_begin)); |
Andreas Gampe | fa8429b | 2015-04-07 18:34:42 -0700 | [diff] [blame] | 278 | if (elf_file_ == nullptr) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 279 | DCHECK(!error_msg->empty()); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 280 | return false; |
| 281 | } |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 282 | bool loaded = elf_file_->Load(executable, error_msg); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 283 | if (!loaded) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 284 | DCHECK(!error_msg->empty()); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 285 | return false; |
| 286 | } |
| 287 | begin_ = elf_file_->FindDynamicSymbolAddress("oatdata"); |
Andreas Gampe | fa8429b | 2015-04-07 18:34:42 -0700 | [diff] [blame] | 288 | if (begin_ == nullptr) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 289 | *error_msg = StringPrintf("Failed to find oatdata symbol in '%s'", file->GetPath().c_str()); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 290 | return false; |
| 291 | } |
Andreas Gampe | fa8429b | 2015-04-07 18:34:42 -0700 | [diff] [blame] | 292 | if (requested_base != nullptr && begin_ != requested_base) { |
Andreas Gampe | a6dfdae | 2015-02-24 15:50:19 -0800 | [diff] [blame] | 293 | PrintFileToLog("/proc/self/maps", LogSeverity::WARNING); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 294 | *error_msg = StringPrintf("Failed to find oatdata symbol at expected address: " |
Andreas Gampe | a6dfdae | 2015-02-24 15:50:19 -0800 | [diff] [blame] | 295 | "oatdata=%p != expected=%p. See process maps in the log.", |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 296 | begin_, requested_base); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 297 | return false; |
| 298 | } |
| 299 | end_ = elf_file_->FindDynamicSymbolAddress("oatlastword"); |
Andreas Gampe | fa8429b | 2015-04-07 18:34:42 -0700 | [diff] [blame] | 300 | if (end_ == nullptr) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 301 | *error_msg = StringPrintf("Failed to find oatlastword symbol in '%s'", file->GetPath().c_str()); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 302 | return false; |
| 303 | } |
| 304 | // Readjust to be non-inclusive upper bound. |
| 305 | end_ += sizeof(uint32_t); |
Vladimir Marko | 5c42c29 | 2015-02-25 12:02:49 +0000 | [diff] [blame] | 306 | |
| 307 | bss_begin_ = elf_file_->FindDynamicSymbolAddress("oatbss"); |
| 308 | if (bss_begin_ == nullptr) { |
| 309 | // No .bss section. Clear dlerror(). |
| 310 | bss_end_ = nullptr; |
| 311 | dlerror(); |
| 312 | } else { |
| 313 | bss_end_ = elf_file_->FindDynamicSymbolAddress("oatbsslastword"); |
| 314 | if (bss_end_ == nullptr) { |
| 315 | *error_msg = StringPrintf("Failed to find oatbasslastword symbol in '%s'", |
| 316 | file->GetPath().c_str()); |
| 317 | return false; |
| 318 | } |
| 319 | // Readjust to be non-inclusive upper bound. |
| 320 | bss_end_ += sizeof(uint32_t); |
| 321 | } |
| 322 | |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 323 | return Setup(abs_dex_location, error_msg); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 324 | } |
Brian Carlstrom | 6e3b1d9 | 2012-01-11 01:36:32 -0800 | [diff] [blame] | 325 | |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 326 | bool OatFile::Setup(const char* abs_dex_location, std::string* error_msg) { |
Brian Carlstrom | f1b3030 | 2013-03-28 10:35:32 -0700 | [diff] [blame] | 327 | if (!GetOatHeader().IsValid()) { |
Andreas Gampe | 2bcb3b2 | 2014-12-12 15:25:14 -0800 | [diff] [blame] | 328 | std::string cause = GetOatHeader().GetValidationErrorMessage(); |
| 329 | *error_msg = StringPrintf("Invalid oat header for '%s': %s", GetLocation().c_str(), |
| 330 | cause.c_str()); |
Brian Carlstrom | f1b3030 | 2013-03-28 10:35:32 -0700 | [diff] [blame] | 331 | return false; |
| 332 | } |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 333 | const uint8_t* oat = Begin(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 334 | oat += sizeof(OatHeader); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 335 | if (oat > End()) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 336 | *error_msg = StringPrintf("In oat file '%s' found truncated OatHeader", GetLocation().c_str()); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 337 | return false; |
| 338 | } |
Brian Carlstrom | 81f3ca1 | 2012-03-17 00:27:35 -0700 | [diff] [blame] | 339 | |
Andreas Gampe | 22f8e5c | 2014-07-09 11:38:21 -0700 | [diff] [blame] | 340 | oat += GetOatHeader().GetKeyValueStoreSize(); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 341 | if (oat > End()) { |
Andreas Gampe | 22f8e5c | 2014-07-09 11:38:21 -0700 | [diff] [blame] | 342 | *error_msg = StringPrintf("In oat file '%s' found truncated variable-size data: " |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 343 | "%p + %zd + %ud <= %p", GetLocation().c_str(), |
Andreas Gampe | 22f8e5c | 2014-07-09 11:38:21 -0700 | [diff] [blame] | 344 | Begin(), sizeof(OatHeader), GetOatHeader().GetKeyValueStoreSize(), |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 345 | End()); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 346 | return false; |
| 347 | } |
| 348 | |
Vladimir Marko | aa4497d | 2014-09-05 14:01:17 +0100 | [diff] [blame] | 349 | uint32_t dex_file_count = GetOatHeader().GetDexFileCount(); |
| 350 | oat_dex_files_storage_.reserve(dex_file_count); |
| 351 | for (size_t i = 0; i < dex_file_count; i++) { |
Dmitry Petrochenko | 83bef92 | 2014-02-03 12:34:59 +0700 | [diff] [blame] | 352 | uint32_t dex_file_location_size = *reinterpret_cast<const uint32_t*>(oat); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 353 | if (UNLIKELY(dex_file_location_size == 0U)) { |
| 354 | *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zd with empty location name", |
| 355 | GetLocation().c_str(), i); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 356 | return false; |
| 357 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 358 | oat += sizeof(dex_file_location_size); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 359 | if (UNLIKELY(oat > End())) { |
| 360 | *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zd truncated after dex file " |
| 361 | "location size", GetLocation().c_str(), i); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 362 | return false; |
| 363 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 364 | |
| 365 | const char* dex_file_location_data = reinterpret_cast<const char*>(oat); |
| 366 | oat += dex_file_location_size; |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 367 | if (UNLIKELY(oat > End())) { |
| 368 | *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zd with truncated dex file " |
| 369 | "location", GetLocation().c_str(), i); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 370 | return false; |
| 371 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 372 | |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 373 | std::string dex_file_location = ResolveRelativeEncodedDexLocation( |
| 374 | abs_dex_location, |
| 375 | std::string(dex_file_location_data, dex_file_location_size)); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 376 | |
| 377 | uint32_t dex_file_checksum = *reinterpret_cast<const uint32_t*>(oat); |
| 378 | oat += sizeof(dex_file_checksum); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 379 | if (UNLIKELY(oat > End())) { |
| 380 | *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zd for '%s' truncated after " |
| 381 | "dex file checksum", GetLocation().c_str(), i, |
| 382 | dex_file_location.c_str()); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 383 | return false; |
| 384 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 385 | |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 386 | uint32_t dex_file_offset = *reinterpret_cast<const uint32_t*>(oat); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 387 | if (UNLIKELY(dex_file_offset == 0U)) { |
| 388 | *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zd for '%s' with zero dex " |
| 389 | "file offset", GetLocation().c_str(), i, dex_file_location.c_str()); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 390 | return false; |
| 391 | } |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 392 | if (UNLIKELY(dex_file_offset > Size())) { |
| 393 | *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zd for '%s' with dex file " |
| 394 | "offset %ud > %zd", GetLocation().c_str(), i, |
| 395 | dex_file_location.c_str(), dex_file_offset, Size()); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 396 | return false; |
| 397 | } |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 398 | oat += sizeof(dex_file_offset); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 399 | if (UNLIKELY(oat > End())) { |
| 400 | *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zd for '%s' truncated " |
Brian Carlstrom | 37628b7 | 2014-10-28 13:54:26 -0700 | [diff] [blame] | 401 | "after dex file offsets", GetLocation().c_str(), i, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 402 | dex_file_location.c_str()); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 403 | return false; |
| 404 | } |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 405 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 406 | const uint8_t* dex_file_pointer = Begin() + dex_file_offset; |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 407 | if (UNLIKELY(!DexFile::IsMagicValid(dex_file_pointer))) { |
| 408 | *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zd for '%s' with invalid " |
Brian Carlstrom | 37628b7 | 2014-10-28 13:54:26 -0700 | [diff] [blame] | 409 | "dex file magic '%s'", GetLocation().c_str(), i, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 410 | dex_file_location.c_str(), dex_file_pointer); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 411 | return false; |
| 412 | } |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 413 | if (UNLIKELY(!DexFile::IsVersionValid(dex_file_pointer))) { |
| 414 | *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zd for '%s' with invalid " |
Brian Carlstrom | 37628b7 | 2014-10-28 13:54:26 -0700 | [diff] [blame] | 415 | "dex file version '%s'", GetLocation().c_str(), i, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 416 | dex_file_location.c_str(), dex_file_pointer); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 417 | return false; |
| 418 | } |
Brian Carlstrom | 6e3b1d9 | 2012-01-11 01:36:32 -0800 | [diff] [blame] | 419 | const DexFile::Header* header = reinterpret_cast<const DexFile::Header*>(dex_file_pointer); |
| 420 | const uint32_t* methods_offsets_pointer = reinterpret_cast<const uint32_t*>(oat); |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 421 | |
Brian Carlstrom | 6e3b1d9 | 2012-01-11 01:36:32 -0800 | [diff] [blame] | 422 | oat += (sizeof(*methods_offsets_pointer) * header->class_defs_size_); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 423 | if (UNLIKELY(oat > End())) { |
| 424 | *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zd for '%s' with truncated " |
Brian Carlstrom | 37628b7 | 2014-10-28 13:54:26 -0700 | [diff] [blame] | 425 | "method offsets", GetLocation().c_str(), i, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 426 | dex_file_location.c_str()); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 427 | return false; |
| 428 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 429 | |
Vladimir Marko | aa4497d | 2014-09-05 14:01:17 +0100 | [diff] [blame] | 430 | std::string canonical_location = DexFile::GetDexCanonicalLocation(dex_file_location.c_str()); |
| 431 | |
| 432 | // Create the OatDexFile and add it to the owning container. |
Vladimir Marko | 539690a | 2014-06-05 18:36:42 +0100 | [diff] [blame] | 433 | OatDexFile* oat_dex_file = new OatDexFile(this, |
| 434 | dex_file_location, |
Vladimir Marko | aa4497d | 2014-09-05 14:01:17 +0100 | [diff] [blame] | 435 | canonical_location, |
Vladimir Marko | 539690a | 2014-06-05 18:36:42 +0100 | [diff] [blame] | 436 | dex_file_checksum, |
| 437 | dex_file_pointer, |
| 438 | methods_offsets_pointer); |
Vladimir Marko | aa4497d | 2014-09-05 14:01:17 +0100 | [diff] [blame] | 439 | oat_dex_files_storage_.push_back(oat_dex_file); |
| 440 | |
| 441 | // Add the location and canonical location (if different) to the oat_dex_files_ table. |
Vladimir Marko | 3f5838d | 2014-08-07 18:07:18 +0100 | [diff] [blame] | 442 | StringPiece key(oat_dex_file->GetDexFileLocation()); |
Vladimir Marko | 539690a | 2014-06-05 18:36:42 +0100 | [diff] [blame] | 443 | oat_dex_files_.Put(key, oat_dex_file); |
Vladimir Marko | aa4497d | 2014-09-05 14:01:17 +0100 | [diff] [blame] | 444 | if (canonical_location != dex_file_location) { |
| 445 | StringPiece canonical_key(oat_dex_file->GetCanonicalDexFileLocation()); |
| 446 | oat_dex_files_.Put(canonical_key, oat_dex_file); |
| 447 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 448 | } |
Brian Carlstrom | f1b3030 | 2013-03-28 10:35:32 -0700 | [diff] [blame] | 449 | return true; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | const OatHeader& OatFile::GetOatHeader() const { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 453 | return *reinterpret_cast<const OatHeader*>(Begin()); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 456 | const uint8_t* OatFile::Begin() const { |
Andreas Gampe | fa8429b | 2015-04-07 18:34:42 -0700 | [diff] [blame] | 457 | CHECK(begin_ != nullptr); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 458 | return begin_; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 461 | const uint8_t* OatFile::End() const { |
Andreas Gampe | fa8429b | 2015-04-07 18:34:42 -0700 | [diff] [blame] | 462 | CHECK(end_ != nullptr); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 463 | return end_; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Vladimir Marko | 5c42c29 | 2015-02-25 12:02:49 +0000 | [diff] [blame] | 466 | const uint8_t* OatFile::BssBegin() const { |
| 467 | return bss_begin_; |
| 468 | } |
| 469 | |
| 470 | const uint8_t* OatFile::BssEnd() const { |
| 471 | return bss_end_; |
| 472 | } |
| 473 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 474 | const OatFile::OatDexFile* OatFile::GetOatDexFile(const char* dex_location, |
| 475 | const uint32_t* dex_location_checksum, |
Ian Rogers | 7fe2c69 | 2011-12-06 16:35:59 -0800 | [diff] [blame] | 476 | bool warn_if_not_found) const { |
Vladimir Marko | 3f5838d | 2014-08-07 18:07:18 +0100 | [diff] [blame] | 477 | // NOTE: We assume here that the canonical location for a given dex_location never |
| 478 | // changes. If it does (i.e. some symlink used by the filename changes) we may return |
| 479 | // an incorrect OatDexFile. As long as we have a checksum to check, we shall return |
| 480 | // an identical file or fail; otherwise we may see some unpredictable failures. |
Calin Juravle | 4e1d579 | 2014-07-15 23:56:47 +0100 | [diff] [blame] | 481 | |
Vladimir Marko | 3f5838d | 2014-08-07 18:07:18 +0100 | [diff] [blame] | 482 | // TODO: Additional analysis of usage patterns to see if this can be simplified |
| 483 | // without any performance loss, for example by not doing the first lock-free lookup. |
| 484 | |
| 485 | const OatFile::OatDexFile* oat_dex_file = nullptr; |
| 486 | StringPiece key(dex_location); |
| 487 | // Try to find the key cheaply in the oat_dex_files_ map which holds dex locations |
| 488 | // directly mentioned in the oat file and doesn't require locking. |
| 489 | auto primary_it = oat_dex_files_.find(key); |
| 490 | if (primary_it != oat_dex_files_.end()) { |
| 491 | oat_dex_file = primary_it->second; |
| 492 | DCHECK(oat_dex_file != nullptr); |
| 493 | } else { |
| 494 | // This dex_location is not one of the dex locations directly mentioned in the |
| 495 | // oat file. The correct lookup is via the canonical location but first see in |
| 496 | // the secondary_oat_dex_files_ whether we've looked up this location before. |
| 497 | MutexLock mu(Thread::Current(), secondary_lookup_lock_); |
| 498 | auto secondary_lb = secondary_oat_dex_files_.lower_bound(key); |
| 499 | if (secondary_lb != secondary_oat_dex_files_.end() && key == secondary_lb->first) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 500 | oat_dex_file = secondary_lb->second; // May be null. |
Vladimir Marko | 3f5838d | 2014-08-07 18:07:18 +0100 | [diff] [blame] | 501 | } else { |
| 502 | // We haven't seen this dex_location before, we must check the canonical location. |
Vladimir Marko | 3f5838d | 2014-08-07 18:07:18 +0100 | [diff] [blame] | 503 | std::string dex_canonical_location = DexFile::GetDexCanonicalLocation(dex_location); |
Vladimir Marko | aa4497d | 2014-09-05 14:01:17 +0100 | [diff] [blame] | 504 | if (dex_canonical_location != dex_location) { |
| 505 | StringPiece canonical_key(dex_canonical_location); |
| 506 | auto canonical_it = oat_dex_files_.find(canonical_key); |
| 507 | if (canonical_it != oat_dex_files_.end()) { |
| 508 | oat_dex_file = canonical_it->second; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 509 | } // else keep null. |
| 510 | } // else keep null. |
Vladimir Marko | 3f5838d | 2014-08-07 18:07:18 +0100 | [diff] [blame] | 511 | |
| 512 | // Copy the key to the string_cache_ and store the result in secondary map. |
| 513 | string_cache_.emplace_back(key.data(), key.length()); |
| 514 | StringPiece key_copy(string_cache_.back()); |
| 515 | secondary_oat_dex_files_.PutBefore(secondary_lb, key_copy, oat_dex_file); |
Brian Carlstrom | 756ee4e | 2013-10-03 15:46:12 -0700 | [diff] [blame] | 516 | } |
| 517 | } |
Vladimir Marko | 3f5838d | 2014-08-07 18:07:18 +0100 | [diff] [blame] | 518 | if (oat_dex_file != nullptr && |
| 519 | (dex_location_checksum == nullptr || |
| 520 | oat_dex_file->GetDexFileLocationChecksum() == *dex_location_checksum)) { |
| 521 | return oat_dex_file; |
| 522 | } |
Brian Carlstrom | 756ee4e | 2013-10-03 15:46:12 -0700 | [diff] [blame] | 523 | |
| 524 | if (warn_if_not_found) { |
Vladimir Marko | 3f5838d | 2014-08-07 18:07:18 +0100 | [diff] [blame] | 525 | std::string dex_canonical_location = DexFile::GetDexCanonicalLocation(dex_location); |
Brian Carlstrom | 0d6adac | 2014-02-05 17:39:16 -0800 | [diff] [blame] | 526 | std::string checksum("<unspecified>"); |
Andreas Gampe | fa8429b | 2015-04-07 18:34:42 -0700 | [diff] [blame] | 527 | if (dex_location_checksum != nullptr) { |
Brian Carlstrom | 0d6adac | 2014-02-05 17:39:16 -0800 | [diff] [blame] | 528 | checksum = StringPrintf("0x%08x", *dex_location_checksum); |
| 529 | } |
Brian Carlstrom | 756ee4e | 2013-10-03 15:46:12 -0700 | [diff] [blame] | 530 | LOG(WARNING) << "Failed to find OatDexFile for DexFile " << dex_location |
Calin Juravle | 4e1d579 | 2014-07-15 23:56:47 +0100 | [diff] [blame] | 531 | << " ( canonical path " << dex_canonical_location << ")" |
Brian Carlstrom | 0d6adac | 2014-02-05 17:39:16 -0800 | [diff] [blame] | 532 | << " with checksum " << checksum << " in OatFile " << GetLocation(); |
Brian Carlstrom | 756ee4e | 2013-10-03 15:46:12 -0700 | [diff] [blame] | 533 | if (kIsDebugBuild) { |
Vladimir Marko | aa4497d | 2014-09-05 14:01:17 +0100 | [diff] [blame] | 534 | for (const OatDexFile* odf : oat_dex_files_storage_) { |
Brian Carlstrom | 756ee4e | 2013-10-03 15:46:12 -0700 | [diff] [blame] | 535 | LOG(WARNING) << "OatFile " << GetLocation() |
Vladimir Marko | aa4497d | 2014-09-05 14:01:17 +0100 | [diff] [blame] | 536 | << " contains OatDexFile " << odf->GetDexFileLocation() |
| 537 | << " (canonical path " << odf->GetCanonicalDexFileLocation() << ")" |
| 538 | << " with checksum 0x" << std::hex << odf->GetDexFileLocationChecksum(); |
Brian Carlstrom | 7571e8b | 2013-08-12 17:04:14 -0700 | [diff] [blame] | 539 | } |
Ian Rogers | 7fe2c69 | 2011-12-06 16:35:59 -0800 | [diff] [blame] | 540 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 541 | } |
Calin Juravle | 4e1d579 | 2014-07-15 23:56:47 +0100 | [diff] [blame] | 542 | |
Andreas Gampe | fa8429b | 2015-04-07 18:34:42 -0700 | [diff] [blame] | 543 | return nullptr; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 546 | OatFile::OatDexFile::OatDexFile(const OatFile* oat_file, |
Elliott Hughes | aa6a588 | 2012-01-13 19:39:16 -0800 | [diff] [blame] | 547 | const std::string& dex_file_location, |
Vladimir Marko | aa4497d | 2014-09-05 14:01:17 +0100 | [diff] [blame] | 548 | const std::string& canonical_dex_file_location, |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 549 | uint32_t dex_file_location_checksum, |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 550 | const uint8_t* dex_file_pointer, |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 551 | const uint32_t* oat_class_offsets_pointer) |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 552 | : oat_file_(oat_file), |
| 553 | dex_file_location_(dex_file_location), |
Vladimir Marko | aa4497d | 2014-09-05 14:01:17 +0100 | [diff] [blame] | 554 | canonical_dex_file_location_(canonical_dex_file_location), |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 555 | dex_file_location_checksum_(dex_file_location_checksum), |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 556 | dex_file_pointer_(dex_file_pointer), |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 557 | oat_class_offsets_pointer_(oat_class_offsets_pointer) {} |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 558 | |
| 559 | OatFile::OatDexFile::~OatDexFile() {} |
| 560 | |
Ian Rogers | 05f28c6 | 2012-10-23 18:12:13 -0700 | [diff] [blame] | 561 | size_t OatFile::OatDexFile::FileSize() const { |
| 562 | return reinterpret_cast<const DexFile::Header*>(dex_file_pointer_)->file_size_; |
| 563 | } |
| 564 | |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 565 | std::unique_ptr<const DexFile> OatFile::OatDexFile::OpenDexFile(std::string* error_msg) const { |
Ian Rogers | 05f28c6 | 2012-10-23 18:12:13 -0700 | [diff] [blame] | 566 | return DexFile::Open(dex_file_pointer_, FileSize(), dex_file_location_, |
Richard Uhler | 07b3c23 | 2015-03-31 15:57:54 -0700 | [diff] [blame] | 567 | dex_file_location_checksum_, this, error_msg); |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 568 | } |
| 569 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 570 | uint32_t OatFile::OatDexFile::GetOatClassOffset(uint16_t class_def_index) const { |
| 571 | return oat_class_offsets_pointer_[class_def_index]; |
| 572 | } |
| 573 | |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 574 | OatFile::OatClass OatFile::OatDexFile::GetOatClass(uint16_t class_def_index) const { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 575 | uint32_t oat_class_offset = GetOatClassOffset(class_def_index); |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 576 | |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 577 | const uint8_t* oat_class_pointer = oat_file_->Begin() + oat_class_offset; |
Brian Carlstrom | 7571e8b | 2013-08-12 17:04:14 -0700 | [diff] [blame] | 578 | CHECK_LT(oat_class_pointer, oat_file_->End()) << oat_file_->GetLocation(); |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 579 | |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 580 | const uint8_t* status_pointer = oat_class_pointer; |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 581 | CHECK_LT(status_pointer, oat_file_->End()) << oat_file_->GetLocation(); |
| 582 | mirror::Class::Status status = |
| 583 | static_cast<mirror::Class::Status>(*reinterpret_cast<const int16_t*>(status_pointer)); |
| 584 | CHECK_LT(status, mirror::Class::kStatusMax); |
| 585 | |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 586 | const uint8_t* type_pointer = status_pointer + sizeof(uint16_t); |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 587 | CHECK_LT(type_pointer, oat_file_->End()) << oat_file_->GetLocation(); |
| 588 | OatClassType type = static_cast<OatClassType>(*reinterpret_cast<const uint16_t*>(type_pointer)); |
| 589 | CHECK_LT(type, kOatClassMax); |
| 590 | |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 591 | const uint8_t* after_type_pointer = type_pointer + sizeof(int16_t); |
Brian Carlstrom | cd937a9 | 2014-03-04 22:53:23 -0800 | [diff] [blame] | 592 | CHECK_LE(after_type_pointer, oat_file_->End()) << oat_file_->GetLocation(); |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 593 | |
Brian Carlstrom | cd937a9 | 2014-03-04 22:53:23 -0800 | [diff] [blame] | 594 | uint32_t bitmap_size = 0; |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 595 | const uint8_t* bitmap_pointer = nullptr; |
| 596 | const uint8_t* methods_pointer = nullptr; |
Ian Rogers | 97b52f8 | 2014-08-14 11:34:07 -0700 | [diff] [blame] | 597 | if (type != kOatClassNoneCompiled) { |
| 598 | if (type == kOatClassSomeCompiled) { |
| 599 | bitmap_size = static_cast<uint32_t>(*reinterpret_cast<const uint32_t*>(after_type_pointer)); |
| 600 | bitmap_pointer = after_type_pointer + sizeof(bitmap_size); |
| 601 | CHECK_LE(bitmap_pointer, oat_file_->End()) << oat_file_->GetLocation(); |
| 602 | methods_pointer = bitmap_pointer + bitmap_size; |
| 603 | } else { |
| 604 | methods_pointer = after_type_pointer; |
| 605 | } |
| 606 | CHECK_LE(methods_pointer, oat_file_->End()) << oat_file_->GetLocation(); |
Brian Carlstrom | cd937a9 | 2014-03-04 22:53:23 -0800 | [diff] [blame] | 607 | } |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 608 | |
Richard Uhler | 07b3c23 | 2015-03-31 15:57:54 -0700 | [diff] [blame] | 609 | return OatFile::OatClass(oat_file_, |
| 610 | status, |
| 611 | type, |
| 612 | bitmap_size, |
| 613 | reinterpret_cast<const uint32_t*>(bitmap_pointer), |
| 614 | reinterpret_cast<const OatMethodOffsets*>(methods_pointer)); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 615 | } |
| 616 | |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 617 | OatFile::OatClass::OatClass(const OatFile* oat_file, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 618 | mirror::Class::Status status, |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 619 | OatClassType type, |
| 620 | uint32_t bitmap_size, |
| 621 | const uint32_t* bitmap_pointer, |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 622 | const OatMethodOffsets* methods_pointer) |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 623 | : oat_file_(oat_file), status_(status), type_(type), |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 624 | bitmap_(bitmap_pointer), methods_pointer_(methods_pointer) { |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 625 | switch (type_) { |
| 626 | case kOatClassAllCompiled: { |
| 627 | CHECK_EQ(0U, bitmap_size); |
Brian Carlstrom | cd937a9 | 2014-03-04 22:53:23 -0800 | [diff] [blame] | 628 | CHECK(bitmap_pointer == nullptr); |
Ian Rogers | 97b52f8 | 2014-08-14 11:34:07 -0700 | [diff] [blame] | 629 | CHECK(methods_pointer != nullptr); |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 630 | break; |
| 631 | } |
| 632 | case kOatClassSomeCompiled: { |
| 633 | CHECK_NE(0U, bitmap_size); |
Brian Carlstrom | cd937a9 | 2014-03-04 22:53:23 -0800 | [diff] [blame] | 634 | CHECK(bitmap_pointer != nullptr); |
Ian Rogers | 97b52f8 | 2014-08-14 11:34:07 -0700 | [diff] [blame] | 635 | CHECK(methods_pointer != nullptr); |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 636 | break; |
| 637 | } |
| 638 | case kOatClassNoneCompiled: { |
| 639 | CHECK_EQ(0U, bitmap_size); |
Brian Carlstrom | cd937a9 | 2014-03-04 22:53:23 -0800 | [diff] [blame] | 640 | CHECK(bitmap_pointer == nullptr); |
Ian Rogers | 97b52f8 | 2014-08-14 11:34:07 -0700 | [diff] [blame] | 641 | CHECK(methods_pointer_ == nullptr); |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 642 | break; |
| 643 | } |
| 644 | case kOatClassMax: { |
| 645 | LOG(FATAL) << "Invalid OatClassType " << type_; |
| 646 | break; |
| 647 | } |
| 648 | } |
| 649 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 650 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 651 | uint32_t OatFile::OatClass::GetOatMethodOffsetsOffset(uint32_t method_index) const { |
| 652 | const OatMethodOffsets* oat_method_offsets = GetOatMethodOffsets(method_index); |
| 653 | if (oat_method_offsets == nullptr) { |
| 654 | return 0u; |
| 655 | } |
| 656 | return reinterpret_cast<const uint8_t*>(oat_method_offsets) - oat_file_->Begin(); |
| 657 | } |
| 658 | |
| 659 | const OatMethodOffsets* OatFile::OatClass::GetOatMethodOffsets(uint32_t method_index) const { |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 660 | // NOTE: We don't keep the number of methods and cannot do a bounds check for method_index. |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 661 | if (methods_pointer_ == nullptr) { |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 662 | CHECK_EQ(kOatClassNoneCompiled, type_); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 663 | return nullptr; |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 664 | } |
| 665 | size_t methods_pointer_index; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 666 | if (bitmap_ == nullptr) { |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 667 | CHECK_EQ(kOatClassAllCompiled, type_); |
| 668 | methods_pointer_index = method_index; |
| 669 | } else { |
| 670 | CHECK_EQ(kOatClassSomeCompiled, type_); |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 671 | if (!BitVector::IsBitSet(bitmap_, method_index)) { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 672 | return nullptr; |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 673 | } |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 674 | size_t num_set_bits = BitVector::NumSetBits(bitmap_, method_index); |
| 675 | methods_pointer_index = num_set_bits; |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 676 | } |
| 677 | const OatMethodOffsets& oat_method_offsets = methods_pointer_[methods_pointer_index]; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 678 | return &oat_method_offsets; |
| 679 | } |
| 680 | |
| 681 | const OatFile::OatMethod OatFile::OatClass::GetOatMethod(uint32_t method_index) const { |
| 682 | const OatMethodOffsets* oat_method_offsets = GetOatMethodOffsets(method_index); |
| 683 | if (oat_method_offsets == nullptr) { |
Mathieu Chartier | 957ca1c | 2014-11-21 16:51:29 -0800 | [diff] [blame] | 684 | return OatMethod(nullptr, 0); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 685 | } |
| 686 | if (oat_file_->IsExecutable() || |
| 687 | Runtime::Current() == nullptr || // This case applies for oatdump. |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 688 | Runtime::Current()->IsAotCompiler()) { |
Mathieu Chartier | 957ca1c | 2014-11-21 16:51:29 -0800 | [diff] [blame] | 689 | return OatMethod(oat_file_->Begin(), oat_method_offsets->code_offset_); |
Alex Light | 9dcc457 | 2014-08-14 14:16:26 -0700 | [diff] [blame] | 690 | } |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 691 | // We aren't allowed to use the compiled code. We just force it down the interpreted / jit |
| 692 | // version. |
| 693 | return OatMethod(oat_file_->Begin(), 0); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 694 | } |
| 695 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 696 | void OatFile::OatMethod::LinkMethod(mirror::ArtMethod* method) const { |
Andreas Gampe | fa8429b | 2015-04-07 18:34:42 -0700 | [diff] [blame] | 697 | CHECK(method != nullptr); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 698 | method->SetEntryPointFromQuickCompiledCode(GetQuickCode()); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 699 | } |
| 700 | |
Andreas Gampe | 7ba6496 | 2014-10-23 11:37:40 -0700 | [diff] [blame] | 701 | bool OatFile::IsPic() const { |
Igor Murashkin | 4677476 | 2014-10-22 11:37:02 -0700 | [diff] [blame] | 702 | return GetOatHeader().IsPic(); |
Andreas Gampe | 7ba6496 | 2014-10-23 11:37:40 -0700 | [diff] [blame] | 703 | // TODO: Check against oat_patches. b/18144996 |
| 704 | } |
| 705 | |
Sebastien Hertz | 0de1133 | 2015-05-13 12:14:05 +0200 | [diff] [blame] | 706 | bool OatFile::IsDebuggable() const { |
| 707 | return GetOatHeader().IsDebuggable(); |
| 708 | } |
| 709 | |
Andreas Gampe | 7848da4 | 2015-04-09 11:15:04 -0700 | [diff] [blame] | 710 | static constexpr char kDexClassPathEncodingSeparator = '*'; |
| 711 | |
| 712 | std::string OatFile::EncodeDexFileDependencies(const std::vector<const DexFile*>& dex_files) { |
| 713 | std::ostringstream out; |
| 714 | |
| 715 | for (const DexFile* dex_file : dex_files) { |
| 716 | out << dex_file->GetLocation().c_str(); |
| 717 | out << kDexClassPathEncodingSeparator; |
| 718 | out << dex_file->GetLocationChecksum(); |
| 719 | out << kDexClassPathEncodingSeparator; |
| 720 | } |
| 721 | |
| 722 | return out.str(); |
| 723 | } |
| 724 | |
| 725 | bool OatFile::CheckStaticDexFileDependencies(const char* dex_dependencies, std::string* msg) { |
| 726 | if (dex_dependencies == nullptr || dex_dependencies[0] == 0) { |
| 727 | // No dependencies. |
| 728 | return true; |
| 729 | } |
| 730 | |
| 731 | // Assumption: this is not performance-critical. So it's OK to do this with a std::string and |
| 732 | // Split() instead of manual parsing of the combined char*. |
| 733 | std::vector<std::string> split; |
| 734 | Split(dex_dependencies, kDexClassPathEncodingSeparator, &split); |
| 735 | if (split.size() % 2 != 0) { |
| 736 | // Expected pairs of location and checksum. |
| 737 | *msg = StringPrintf("Odd number of elements in dependency list %s", dex_dependencies); |
| 738 | return false; |
| 739 | } |
| 740 | |
| 741 | for (auto it = split.begin(), end = split.end(); it != end; it += 2) { |
| 742 | std::string& location = *it; |
| 743 | std::string& checksum = *(it + 1); |
| 744 | int64_t converted = strtoll(checksum.c_str(), nullptr, 10); |
| 745 | if (converted == 0) { |
| 746 | // Conversion error. |
| 747 | *msg = StringPrintf("Conversion error for %s", checksum.c_str()); |
| 748 | return false; |
| 749 | } |
| 750 | |
| 751 | uint32_t dex_checksum; |
| 752 | std::string error_msg; |
| 753 | if (DexFile::GetChecksum(DexFile::GetDexCanonicalLocation(location.c_str()).c_str(), |
| 754 | &dex_checksum, |
| 755 | &error_msg)) { |
| 756 | if (converted != dex_checksum) { |
| 757 | *msg = StringPrintf("Checksums don't match for %s: %" PRId64 " vs %u", |
| 758 | location.c_str(), converted, dex_checksum); |
| 759 | return false; |
| 760 | } |
| 761 | } else { |
| 762 | // Problem retrieving checksum. |
| 763 | // TODO: odex files? |
| 764 | *msg = StringPrintf("Could not retrieve checksum for %s: %s", location.c_str(), |
| 765 | error_msg.c_str()); |
| 766 | return false; |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | return true; |
| 771 | } |
| 772 | |
| 773 | bool OatFile::GetDexLocationsFromDependencies(const char* dex_dependencies, |
| 774 | std::vector<std::string>* locations) { |
| 775 | DCHECK(locations != nullptr); |
| 776 | if (dex_dependencies == nullptr || dex_dependencies[0] == 0) { |
| 777 | return true; |
| 778 | } |
| 779 | |
| 780 | // Assumption: this is not performance-critical. So it's OK to do this with a std::string and |
| 781 | // Split() instead of manual parsing of the combined char*. |
| 782 | std::vector<std::string> split; |
| 783 | Split(dex_dependencies, kDexClassPathEncodingSeparator, &split); |
| 784 | if (split.size() % 2 != 0) { |
| 785 | // Expected pairs of location and checksum. |
| 786 | return false; |
| 787 | } |
| 788 | |
| 789 | for (auto it = split.begin(), end = split.end(); it != end; it += 2) { |
| 790 | locations->push_back(*it); |
| 791 | } |
| 792 | |
| 793 | return true; |
| 794 | } |
| 795 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 796 | } // namespace art |