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.h" |
| 18 | |
| 19 | #include "base/unix_file/fd_file.h" |
| 20 | #include "class_linker.h" |
| 21 | #include "dex_file-inl.h" |
| 22 | #include "dex_method_iterator.h" |
| 23 | #include "driver/compiler_driver.h" |
| 24 | #include "elf_file.h" |
| 25 | #include "invoke_type.h" |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 26 | #include "mirror/art_method-inl.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 27 | #include "mirror/object-inl.h" |
| 28 | #include "oat.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 29 | #include "scoped_thread_state_change.h" |
| 30 | |
| 31 | namespace art { |
| 32 | |
Tong Shen | 62d1ca3 | 2014-09-03 17:24:56 -0700 | [diff] [blame] | 33 | uintptr_t ElfWriter::GetOatDataAddress(ElfFile* elf_file) { |
| 34 | uintptr_t oatdata_address = elf_file->FindSymbolAddress(SHT_DYNSYM, |
Nicolas Geoffray | 50cfe74 | 2014-02-19 13:27:42 +0000 | [diff] [blame] | 35 | "oatdata", |
| 36 | false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 37 | CHECK_NE(0U, oatdata_address); |
| 38 | return oatdata_address; |
| 39 | } |
| 40 | |
| 41 | void ElfWriter::GetOatElfInformation(File* file, |
| 42 | size_t& oat_loaded_size, |
| 43 | size_t& oat_data_offset) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 44 | std::string error_msg; |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 45 | std::unique_ptr<ElfFile> elf_file(ElfFile::Open(file, false, false, &error_msg)); |
Alex Light | 3470ab4 | 2014-06-18 10:35:45 -0700 | [diff] [blame] | 46 | CHECK(elf_file.get() != nullptr) << error_msg; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 47 | |
| 48 | oat_loaded_size = elf_file->GetLoadedSize(); |
| 49 | CHECK_NE(0U, oat_loaded_size); |
| 50 | oat_data_offset = GetOatDataAddress(elf_file.get()); |
| 51 | CHECK_NE(0U, oat_data_offset); |
| 52 | } |
| 53 | |
Tong Shen | 62d1ca3 | 2014-09-03 17:24:56 -0700 | [diff] [blame] | 54 | bool ElfWriter::Fixup(File* file, uintptr_t oat_data_begin) { |
| 55 | std::string error_msg; |
| 56 | std::unique_ptr<ElfFile> elf_file(ElfFile::Open(file, true, false, &error_msg)); |
| 57 | CHECK(elf_file.get() != nullptr) << error_msg; |
| 58 | |
| 59 | // Lookup "oatdata" symbol address. |
| 60 | uintptr_t oatdata_address = ElfWriter::GetOatDataAddress(elf_file.get()); |
| 61 | uintptr_t base_address = oat_data_begin - oatdata_address; |
| 62 | |
| 63 | return elf_file->Fixup(base_address); |
| 64 | } |
| 65 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 66 | } // namespace art |