source: soft/giet_vm/memo/include/libelfpp/elfpp/elfpp_access.hh @ 763

Last change on this file since 763 was 163, checked in by karaoui, 12 years ago

changing mover to memo
changing soft.bin to soft.elf
...

File size: 3.1 KB
Line 
1/*
2    This file is part of Libelfpp.
3
4    Libelfpp is free software: you can redistribute it and/or modify
5    it under the terms of the GNU Lesser General Public License as
6    published by the Free Software Foundation, either version 3 of the
7    License, or (at your option) any later version.
8
9    Libelfpp is distributed in the hope that it will be useful, but
10    WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    General Public License for more details.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with Libelfpp.  If not, see
16    <http://www.gnu.org/licenses/>.
17
18   Copyright (c) Alexandre Becoulet <alexandre.becoulet@free.fr>
19*/
20
21#ifndef ELFPP_ACCESS_HH_
22#define ELFPP_ACCESS_HH_
23
24#include <stdio.h>
25#include "elfpp_bits.hh"
26
27namespace elfpp
28{
29
30  class object;
31  class section;
32  class reloc;
33
34  /** @internal */
35  class elf_access
36  {
37  public:
38    virtual ~elf_access() {}
39    virtual void read(object &obj, FILE *file) = 0;
40    virtual void write(object &obj, FILE *file) = 0;
41    virtual void load_symtab(object &obj) = 0;
42    virtual void load_reltab(object &obj) = 0;
43    virtual void save_symtab(object &obj) = 0;
44  };
45
46  /** @internal */
47  template <class bits_t, int width>
48  class elfn_access : public elf_access
49  {
50    typedef typename bits_t::elf_hdr_t elf_hdr_t;
51    typedef typename bits_t::elf_shdr_t elf_shdr_t;
52    typedef typename bits_t::elf_phdr_t elf_phdr_t;
53    typedef typename bits_t::elf_sym_t elf_sym_t;
54    typedef typename bits_t::elf_rel_t elf_rel_t;
55    typedef typename bits_t::elf_rela_t elf_rela_t;
56
57    void load_symtab(object &obj);
58    void load_reltab(object &obj);
59    void save_symtab(object &obj);
60    void create_segments(object &obj);
61
62    void read(object &obj, FILE *file);
63    void write(object &obj, FILE *file);
64
65    inline uint16_t swap(uint16_t x);
66    inline uint32_t swap(uint32_t x);
67    inline uint64_t swap(uint64_t x);
68
69    inline int16_t swap(int16_t x);
70    inline int32_t swap(int32_t x);
71    inline int64_t swap(int64_t x);
72
73    inline unsigned int rel_sym(uint64_t info);
74    inline enum reloc_e rel_type(uint64_t info);
75    inline uint64_t rel_info(unsigned int sym, enum reloc_e type);
76
77    void load_addend(const object &obj, reloc &r, const elf_rel_t *reltab, size_t count, int index, uint8_t *data);
78    void rel_write(const object &obj, enum reloc_e type, void *data, int64_t value);
79
80    template <typename X, typename Y>
81    inline void swap(X *a, Y x);
82
83    ei_data_e byteorder_;
84  };
85
86  struct elf32_bits_s
87  {
88    typedef Elf32_Ehdr elf_hdr_t;
89    typedef Elf32_Shdr elf_shdr_t;
90    typedef Elf32_Phdr elf_phdr_t;
91    typedef Elf32_Sym elf_sym_t;
92    typedef Elf32_Rel elf_rel_t;
93    typedef Elf32_Rela elf_rela_t;
94  };
95
96  struct elf64_bits_s
97  {
98    typedef Elf64_Ehdr elf_hdr_t;
99    typedef Elf64_Shdr elf_shdr_t;
100    typedef Elf64_Phdr elf_phdr_t;
101    typedef Elf64_Sym elf_sym_t;
102    typedef Elf64_Rel elf_rel_t;
103    typedef Elf64_Rela elf_rela_t;
104  };
105
106  typedef elfn_access<elf32_bits_s, 32> elf32_access;
107  typedef elfn_access<elf64_bits_s, 64> elf64_access;
108
109}
110
111#endif
112
Note: See TracBrowser for help on using the repository browser.