Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: courgette/disassembler_elf_32.cc

Issue 2583373002: [Courgette] Simple AssemblyProgram and Disassembler cleanups. (Closed)
Patch Set: Sync. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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.h" 5 #include "courgette/disassembler_elf_32.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <utility> 9 #include <utility>
grt (UTC plus 2) 2017/01/12 11:56:41 unused?
huangs 2017/01/12 19:54:42 Done.
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "courgette/assembly_program.h" 13 #include "courgette/assembly_program.h"
14 #include "courgette/courgette.h" 14 #include "courgette/courgette.h"
15 15
16 namespace courgette { 16 namespace courgette {
17 17
18 namespace { 18 namespace {
19 19
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 if (default_string_section_[default_string_section_size_ - 1] != '\0') 157 if (default_string_section_[default_string_section_size_ - 1] != '\0')
158 return Bad("String section does not terminate"); 158 return Bad("String section does not terminate");
159 } 159 }
160 160
161 if (!UpdateLength()) 161 if (!UpdateLength())
162 return Bad("Out of bounds section or segment"); 162 return Bad("Out of bounds section or segment");
163 163
164 return Good(); 164 return Good();
165 } 165 }
166 166
167 bool DisassemblerElf32::Disassemble(AssemblyProgram* target) { 167 bool DisassemblerElf32::Disassemble(AssemblyProgram* program) {
168 if (!ok()) 168 if (!ok())
169 return false; 169 return false;
170 170
171 // The Image Base is always 0 for ELF Executables
172 target->set_image_base(0);
173
174 if (!ParseAbs32Relocs()) 171 if (!ParseAbs32Relocs())
175 return false; 172 return false;
176 173
177 if (!ParseRel32RelocsFromSections()) // Does not sort rel32 locations. 174 if (!ParseRel32RelocsFromSections()) // Does not sort rel32 locations.
178 return false; 175 return false;
179 176
180 PrecomputeLabels(target); 177 PrecomputeLabels(program);
181 RemoveUnusedRel32Locations(target); 178 RemoveUnusedRel32Locations(program);
182 179
183 if (!target->GenerateInstructions( 180 if (!program->GenerateInstructions(
184 base::Bind(&DisassemblerElf32::ParseFile, base::Unretained(this)))) { 181 base::Bind(&DisassemblerElf32::ParseFile, base::Unretained(this)))) {
185 return false; 182 return false;
186 } 183 }
187 184
188 // Finally sort rel32 locations. 185 // Finally sort rel32 locations.
189 std::sort(rel32_locations_.begin(), 186 std::sort(rel32_locations_.begin(),
190 rel32_locations_.end(), 187 rel32_locations_.end(),
191 TypedRVA::IsLessThanByRVA); 188 TypedRVA::IsLessThanByRVA);
192 DCHECK(rel32_locations_.empty() || 189 DCHECK(rel32_locations_.empty() ||
193 rel32_locations_.back()->rva() != kUnassignedRVA); 190 rel32_locations_.back()->rva() != kUnassignedRVA);
194 191
195 target->DefaultAssignIndexes(); 192 program->DefaultAssignIndexes();
196 return true; 193 return true;
197 } 194 }
198 195
199 CheckBool DisassemblerElf32::IsValidTargetRVA(RVA rva) const { 196 CheckBool DisassemblerElf32::IsValidTargetRVA(RVA rva) const {
200 if (rva == kUnassignedRVA) 197 if (rva == kUnassignedRVA)
201 return false; 198 return false;
202 199
203 // |rva| is valid if it's contained in any program segment. 200 // |rva| is valid if it's contained in any program segment.
204 for (Elf32_Half segment_id = 0; segment_id < ProgramSegmentHeaderCount(); 201 for (Elf32_Half segment_id = 0; segment_id < ProgramSegmentHeaderCount();
205 ++segment_id) { 202 ++segment_id) {
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 if (!ParseRel32RelocsFromSection(section_header)) 624 if (!ParseRel32RelocsFromSection(section_header))
628 return false; 625 return false;
629 } 626 }
630 if (!found_rel32) 627 if (!found_rel32)
631 VLOG(1) << "Warning: Found no rel32 addresses. Missing .text section?"; 628 VLOG(1) << "Warning: Found no rel32 addresses. Missing .text section?";
632 629
633 return true; 630 return true;
634 } 631 }
635 632
636 } // namespace courgette 633 } // namespace courgette
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698