| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CRAZY_LINKER_ELF_RELOCATIONS_H | 5 #ifndef CRAZY_LINKER_ELF_RELOCATIONS_H |
| 6 #define CRAZY_LINKER_ELF_RELOCATIONS_H | 6 #define CRAZY_LINKER_ELF_RELOCATIONS_H |
| 7 | 7 |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <unistd.h> |
| 9 | 10 |
| 10 #include "elf_traits.h" | 11 #include "elf_traits.h" |
| 11 | 12 |
| 12 namespace crazy { | 13 namespace crazy { |
| 13 | 14 |
| 14 class ElfSymbols; | 15 class ElfSymbols; |
| 15 class ElfView; | 16 class ElfView; |
| 16 class Error; | 17 class Error; |
| 17 | 18 |
| 18 // An ElfRelocations instance holds information about relocations in a mapped | 19 // An ElfRelocations instance holds information about relocations in a mapped |
| (...skipping 15 matching lines...) Expand all Loading... |
| 34 virtual void* Lookup(const char* symbol_name) = 0; | 35 virtual void* Lookup(const char* symbol_name) = 0; |
| 35 }; | 36 }; |
| 36 | 37 |
| 37 // Apply all relocations to the target mapped ELF binary. Must be called | 38 // Apply all relocations to the target mapped ELF binary. Must be called |
| 38 // after Init(). | 39 // after Init(). |
| 39 // |symbols| maps to the symbol entries for the target library only. | 40 // |symbols| maps to the symbol entries for the target library only. |
| 40 // |resolver| can resolve symbols out of the current library. | 41 // |resolver| can resolve symbols out of the current library. |
| 41 // On error, return false and set |error| message. | 42 // On error, return false and set |error| message. |
| 42 bool ApplyAll(const ElfSymbols* symbols, | 43 bool ApplyAll(const ElfSymbols* symbols, |
| 43 SymbolResolver* resolver, | 44 SymbolResolver* resolver, |
| 45 const char* full_path, |
| 44 Error* error); | 46 Error* error); |
| 45 | 47 |
| 46 // This function is used to adjust relocated addresses in a copy of an | 48 // This function is used to adjust relocated addresses in a copy of an |
| 47 // existing section of an ELF binary. I.e. |src_addr|...|src_addr + size| | 49 // existing section of an ELF binary. I.e. |src_addr|...|src_addr + size| |
| 48 // must be inside the mapped ELF binary, this function will first copy its | 50 // must be inside the mapped ELF binary, this function will first copy its |
| 49 // content into |dst_addr|...|dst_addr + size|, then adjust all relocated | 51 // content into |dst_addr|...|dst_addr + size|, then adjust all relocated |
| 50 // addresses inside the destination section as if it was loaded/mapped | 52 // addresses inside the destination section as if it was loaded/mapped |
| 51 // at |map_addr|...|map_addr + size|. Only relative relocations are processed, | 53 // at |map_addr|...|map_addr + size|. Only relative relocations are processed, |
| 52 // symbolic ones are ignored. | 54 // symbolic ones are ignored. |
| 53 void CopyAndRelocate(size_t src_addr, | 55 void CopyAndRelocate(size_t src_addr, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 size_t map_delta); | 89 size_t map_delta); |
| 88 void RelocateRela(size_t src_addr, | 90 void RelocateRela(size_t src_addr, |
| 89 size_t dst_addr, | 91 size_t dst_addr, |
| 90 size_t map_addr, | 92 size_t map_addr, |
| 91 size_t size); | 93 size_t size); |
| 92 void RelocateRel(size_t src_addr, | 94 void RelocateRel(size_t src_addr, |
| 93 size_t dst_addr, | 95 size_t dst_addr, |
| 94 size_t map_addr, | 96 size_t map_addr, |
| 95 size_t size); | 97 size_t size); |
| 96 | 98 |
| 99 #if defined(__arm__) |
| 100 bool ApplyArmPackedRelocs(const char* full_path, |
| 101 Error* error); |
| 102 #endif |
| 103 |
| 97 #if defined(__mips__) | 104 #if defined(__mips__) |
| 98 bool RelocateMipsGot(const ElfSymbols* symbols, | 105 bool RelocateMipsGot(const ElfSymbols* symbols, |
| 99 SymbolResolver* resolver, | 106 SymbolResolver* resolver, |
| 100 Error* error); | 107 Error* error); |
| 101 #endif | 108 #endif |
| 102 | 109 |
| 103 const ELF::Phdr* phdr_; | 110 const ELF::Phdr* phdr_; |
| 104 size_t phdr_count_; | 111 size_t phdr_count_; |
| 105 size_t load_bias_; | 112 size_t load_bias_; |
| 106 | 113 |
| 107 ELF::Addr relocations_type_; | 114 ELF::Addr relocations_type_; |
| 108 ELF::Addr plt_relocations_; | 115 ELF::Addr plt_relocations_; |
| 109 size_t plt_relocations_size_; | 116 size_t plt_relocations_size_; |
| 110 ELF::Addr* plt_got_; | 117 ELF::Addr* plt_got_; |
| 111 | 118 |
| 112 ELF::Addr relocations_; | 119 ELF::Addr relocations_; |
| 113 size_t relocations_size_; | 120 size_t relocations_size_; |
| 114 | 121 |
| 122 #if defined(__arm__) |
| 123 // ARM-specific data, supports decoding packed relocations. |
| 124 off_t arm_packed_relocations_; |
| 125 size_t arm_packed_relocations_size_; |
| 126 #endif |
| 127 |
| 115 #if defined(__mips__) | 128 #if defined(__mips__) |
| 116 // MIPS-specific relocation fields. | 129 // MIPS-specific relocation fields. |
| 117 ELF::Word mips_symtab_count_; | 130 ELF::Word mips_symtab_count_; |
| 118 ELF::Word mips_local_got_count_; | 131 ELF::Word mips_local_got_count_; |
| 119 ELF::Word mips_gotsym_; | 132 ELF::Word mips_gotsym_; |
| 120 #endif | 133 #endif |
| 121 | 134 |
| 122 bool has_text_relocations_; | 135 bool has_text_relocations_; |
| 123 bool has_symbolic_; | 136 bool has_symbolic_; |
| 124 }; | 137 }; |
| 125 | 138 |
| 126 } // namespace crazy | 139 } // namespace crazy |
| 127 | 140 |
| 128 #endif // CRAZY_LINKER_ELF_RELOCATIONS_H | 141 #endif // CRAZY_LINKER_ELF_RELOCATIONS_H |
| OLD | NEW |