• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
26 #include "llvm/utils_llvm.h"
27 #include "mirror/art_method-inl.h"
28 #include "mirror/object-inl.h"
29 #include "oat.h"
30 #include "scoped_thread_state_change.h"
31 
32 namespace art {
33 
ElfWriter(const CompilerDriver & driver,File * elf_file)34 ElfWriter::ElfWriter(const CompilerDriver& driver, File* elf_file)
35   : compiler_driver_(&driver), elf_file_(elf_file) {}
36 
~ElfWriter()37 ElfWriter::~ElfWriter() {}
38 
GetOatDataAddress(ElfFile * elf_file)39 llvm::ELF::Elf32_Addr ElfWriter::GetOatDataAddress(ElfFile* elf_file) {
40   llvm::ELF::Elf32_Addr oatdata_address = elf_file->FindSymbolAddress(llvm::ELF::SHT_DYNSYM,
41                                                                       "oatdata",
42                                                                       false);
43   CHECK_NE(0U, oatdata_address);
44   return oatdata_address;
45 }
46 
GetOatElfInformation(File * file,size_t & oat_loaded_size,size_t & oat_data_offset)47 void ElfWriter::GetOatElfInformation(File* file,
48                                      size_t& oat_loaded_size,
49                                      size_t& oat_data_offset) {
50   UniquePtr<ElfFile> elf_file(ElfFile::Open(file, false, false));
51   CHECK(elf_file.get() != NULL);
52 
53   oat_loaded_size = elf_file->GetLoadedSize();
54   CHECK_NE(0U, oat_loaded_size);
55   oat_data_offset = GetOatDataAddress(elf_file.get());
56   CHECK_NE(0U, oat_data_offset);
57 }
58 
59 }  // namespace art
60