Home | History | Annotate | Download | only in courgette
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef COURGETTE_DISASSEMBLER_ELF_32_X86_H_
      6 #define COURGETTE_DISASSEMBLER_ELF_32_X86_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "courgette/disassembler_elf_32.h"
     10 #include "courgette/memory_allocator.h"
     11 #include "courgette/types_elf.h"
     12 
     13 namespace courgette {
     14 
     15 class AssemblyProgram;
     16 
     17 class DisassemblerElf32X86 : public DisassemblerElf32 {
     18  public:
     19   class TypedRVAX86 : public TypedRVA {
     20    public:
     21     explicit TypedRVAX86(RVA rva) : TypedRVA(rva) {
     22     }
     23 
     24     virtual CheckBool ComputeRelativeTarget(const uint8* op_pointer) OVERRIDE {
     25       set_relative_target(Read32LittleEndian(op_pointer) + 4);
     26       return true;
     27     }
     28 
     29     virtual CheckBool EmitInstruction(AssemblyProgram* program,
     30                                        RVA target_rva) OVERRIDE {
     31       return program->EmitRel32(program->FindOrMakeRel32Label(target_rva));
     32     }
     33 
     34     virtual uint16 op_size() const OVERRIDE { return 4; }
     35   };
     36 
     37   explicit DisassemblerElf32X86(const void* start, size_t length);
     38 
     39   virtual ExecutableType kind() { return EXE_ELF_32_X86; }
     40 
     41   virtual e_machine_values ElfEM() { return EM_386; }
     42 
     43  protected:
     44   virtual CheckBool RelToRVA(Elf32_Rel rel, RVA* result)
     45       const WARN_UNUSED_RESULT;
     46 
     47   virtual CheckBool ParseRelocationSection(
     48       const Elf32_Shdr *section_header,
     49       AssemblyProgram* program) WARN_UNUSED_RESULT;
     50 
     51   virtual CheckBool ParseRel32RelocsFromSection(
     52       const Elf32_Shdr* section) WARN_UNUSED_RESULT;
     53 
     54 #if COURGETTE_HISTOGRAM_TARGETS
     55   std::map<RVA, int> rel32_target_rvas_;
     56 #endif
     57 
     58   DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32X86);
     59 };
     60 
     61 }  // namespace courgette
     62 
     63 #endif  // COURGETTE_DISASSEMBLER_ELF_32_X86_H_
     64