OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "courgette/disassembler_elf_32_x86.h" | 5 #include "courgette/disassembler_elf_32_x86.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "courgette/assembly_program.h" | 12 #include "courgette/assembly_program.h" |
13 #include "courgette/courgette.h" | 13 #include "courgette/courgette.h" |
14 | 14 |
15 namespace courgette { | 15 namespace courgette { |
16 | 16 |
17 CheckBool DisassemblerElf32X86::TypedRVAX86::ComputeRelativeTarget( | 17 CheckBool DisassemblerElf32X86::TypedRVAX86::ComputeRelativeTarget( |
18 const uint8_t* op_pointer) { | 18 const uint8_t* op_pointer) { |
19 set_relative_target(Read32LittleEndian(op_pointer) + 4); | 19 set_relative_target(Read32LittleEndian(op_pointer) + 4); |
20 return true; | 20 return true; |
21 } | 21 } |
22 | 22 |
23 CheckBool DisassemblerElf32X86::TypedRVAX86::EmitInstruction( | 23 CheckBool DisassemblerElf32X86::TypedRVAX86::EmitInstruction( |
24 AssemblyProgram* program, | 24 Label* label, |
25 Label* label) { | 25 InstructionReceptor* receptor) { |
26 return program->EmitRel32(label); | 26 return receptor->EmitRel32(label); |
27 } | 27 } |
28 | 28 |
29 uint16_t DisassemblerElf32X86::TypedRVAX86::op_size() const { | 29 uint16_t DisassemblerElf32X86::TypedRVAX86::op_size() const { |
30 return 4; | 30 return 4; |
31 } | 31 } |
32 | 32 |
33 DisassemblerElf32X86::DisassemblerElf32X86(const uint8_t* start, size_t length) | 33 DisassemblerElf32X86::DisassemblerElf32X86(const uint8_t* start, size_t length) |
34 : DisassemblerElf32(start, length) {} | 34 : DisassemblerElf32(start, length) {} |
35 | 35 |
36 // Convert an ELF relocation struction into an RVA. | 36 // Convert an ELF relocation struction into an RVA. |
(...skipping 28 matching lines...) Expand all Loading... |
65 case R_386_GOTPC: | 65 case R_386_GOTPC: |
66 case R_386_TLS_TPOFF: | 66 case R_386_TLS_TPOFF: |
67 return false; | 67 return false; |
68 } | 68 } |
69 | 69 |
70 return false; | 70 return false; |
71 } | 71 } |
72 | 72 |
73 CheckBool DisassemblerElf32X86::ParseRelocationSection( | 73 CheckBool DisassemblerElf32X86::ParseRelocationSection( |
74 const Elf32_Shdr* section_header, | 74 const Elf32_Shdr* section_header, |
75 AssemblyProgram* program) { | 75 InstructionReceptor* receptor) const { |
76 // We can reproduce the R_386_RELATIVE entries in one of the relocation table | 76 // We can reproduce the R_386_RELATIVE entries in one of the relocation table |
77 // based on other information in the patch, given these conditions: | 77 // based on other information in the patch, given these conditions: |
78 // | 78 // |
79 // All R_386_RELATIVE entries are: | 79 // All R_386_RELATIVE entries are: |
80 // 1) In the same relocation table | 80 // 1) In the same relocation table |
81 // 2) Are consecutive | 81 // 2) Are consecutive |
82 // 3) Are sorted in memory address order | 82 // 3) Are sorted in memory address order |
83 // | 83 // |
84 // Happily, this is normally the case, but it's not required by spec, so we | 84 // Happily, this is normally the case, but it's not required by spec, so we |
85 // check, and just don't do it if we don't match up. | 85 // check, and just don't do it if we don't match up. |
(...skipping 26 matching lines...) Expand all Loading... |
112 if (section_relocs_iter->r_info != R_386_RELATIVE || | 112 if (section_relocs_iter->r_info != R_386_RELATIVE || |
113 section_relocs_iter->r_offset != *reloc_iter) { | 113 section_relocs_iter->r_offset != *reloc_iter) { |
114 match = false; | 114 match = false; |
115 } | 115 } |
116 ++section_relocs_iter; | 116 ++section_relocs_iter; |
117 ++reloc_iter; | 117 ++reloc_iter; |
118 } | 118 } |
119 | 119 |
120 if (match) { | 120 if (match) { |
121 // Skip over relocation tables. | 121 // Skip over relocation tables. |
122 if (!program->EmitElfRelocationInstruction()) | 122 if (!receptor->EmitElfRelocation()) |
123 return false; | 123 return false; |
124 file_offset += sizeof(Elf32_Rel) * abs32_locations_.size(); | 124 file_offset += sizeof(Elf32_Rel) * abs32_locations_.size(); |
125 } | 125 } |
126 | 126 |
127 return ParseSimpleRegion(file_offset, section_end, program); | 127 return ParseSimpleRegion(file_offset, section_end, receptor); |
128 } | 128 } |
129 | 129 |
130 CheckBool DisassemblerElf32X86::ParseRel32RelocsFromSection( | 130 CheckBool DisassemblerElf32X86::ParseRel32RelocsFromSection( |
131 const Elf32_Shdr* section_header) { | 131 const Elf32_Shdr* section_header) { |
132 FileOffset start_file_offset = section_header->sh_offset; | 132 FileOffset start_file_offset = section_header->sh_offset; |
133 FileOffset end_file_offset = start_file_offset + section_header->sh_size; | 133 FileOffset end_file_offset = start_file_offset + section_header->sh_size; |
134 | 134 |
135 const uint8_t* start_pointer = FileOffsetToPointer(start_file_offset); | 135 const uint8_t* start_pointer = FileOffsetToPointer(start_file_offset); |
136 const uint8_t* end_pointer = FileOffsetToPointer(end_file_offset); | 136 const uint8_t* end_pointer = FileOffsetToPointer(end_file_offset); |
137 | 137 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 continue; | 193 continue; |
194 } | 194 } |
195 } | 195 } |
196 p += 1; | 196 p += 1; |
197 } | 197 } |
198 | 198 |
199 return true; | 199 return true; |
200 } | 200 } |
201 | 201 |
202 } // namespace courgette | 202 } // namespace courgette |
OLD | NEW |