elf_writer.cc revision 3470ab4011b5e18d590d5375e2f13a1e3bd69222
1700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom/*
2700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom * Copyright (C) 2012 The Android Open Source Project
3700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom *
4700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom * Licensed under the Apache License, Version 2.0 (the "License");
5700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom * you may not use this file except in compliance with the License.
6700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom * You may obtain a copy of the License at
7700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom *
8700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom *      http://www.apache.org/licenses/LICENSE-2.0
9700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom *
10700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom * Unless required by applicable law or agreed to in writing, software
11700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom * distributed under the License is distributed on an "AS IS" BASIS,
12700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom * See the License for the specific language governing permissions and
14700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom * limitations under the License.
15700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom */
16700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom
17700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom#include "elf_writer.h"
18700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom
19265091e581c9f643b37e7966890911f09e223269Brian Carlstrom#include "base/unix_file/fd_file.h"
20265091e581c9f643b37e7966890911f09e223269Brian Carlstrom#include "class_linker.h"
21225ade2eef559a8609879f142789a4f59aec5704Ian Rogers#include "dex_file-inl.h"
22265091e581c9f643b37e7966890911f09e223269Brian Carlstrom#include "dex_method_iterator.h"
237940e44f4517de5e2634a7e07d58d0fb26160513Brian Carlstrom#include "driver/compiler_driver.h"
24265091e581c9f643b37e7966890911f09e223269Brian Carlstrom#include "elf_file.h"
25265091e581c9f643b37e7966890911f09e223269Brian Carlstrom#include "invoke_type.h"
26ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom#include "mirror/art_method-inl.h"
27225ade2eef559a8609879f142789a4f59aec5704Ian Rogers#include "mirror/object-inl.h"
28265091e581c9f643b37e7966890911f09e223269Brian Carlstrom#include "oat.h"
29265091e581c9f643b37e7966890911f09e223269Brian Carlstrom#include "scoped_thread_state_change.h"
30265091e581c9f643b37e7966890911f09e223269Brian Carlstrom
31700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstromnamespace art {
32700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom
333d504075f7c1204d581923460754bf6d3714b13fIan Rogersuint32_t ElfWriter::GetOatDataAddress(ElfFile* elf_file) {
3450cfe74daaece80853cb3b45d4338329b7d0345bNicolas Geoffray  Elf32_Addr oatdata_address = elf_file->FindSymbolAddress(SHT_DYNSYM,
3550cfe74daaece80853cb3b45d4338329b7d0345bNicolas Geoffray                                                           "oatdata",
3650cfe74daaece80853cb3b45d4338329b7d0345bNicolas Geoffray                                                           false);
37265091e581c9f643b37e7966890911f09e223269Brian Carlstrom  CHECK_NE(0U, oatdata_address);
38265091e581c9f643b37e7966890911f09e223269Brian Carlstrom  return oatdata_address;
39265091e581c9f643b37e7966890911f09e223269Brian Carlstrom}
40265091e581c9f643b37e7966890911f09e223269Brian Carlstrom
41700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstromvoid ElfWriter::GetOatElfInformation(File* file,
42700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom                                     size_t& oat_loaded_size,
43700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom                                     size_t& oat_data_offset) {
448d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  std::string error_msg;
45700a402244a1a423da4f3ba8032459f4b65fa18fIan Rogers  std::unique_ptr<ElfFile> elf_file(ElfFile::Open(file, false, false, &error_msg));
463470ab4011b5e18d590d5375e2f13a1e3bd69222Alex Light  CHECK(elf_file.get() != nullptr) << error_msg;
47700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom
48700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom  oat_loaded_size = elf_file->GetLoadedSize();
49700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom  CHECK_NE(0U, oat_loaded_size);
50265091e581c9f643b37e7966890911f09e223269Brian Carlstrom  oat_data_offset = GetOatDataAddress(elf_file.get());
51700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom  CHECK_NE(0U, oat_data_offset);
52700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom}
53700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom
54700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom}  // namespace art
55