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_RELOC_HH_ |
---|
22 | #define ELFPP_RELOC_HH_ |
---|
23 | |
---|
24 | #include <iostream> |
---|
25 | |
---|
26 | #include <dpp/linked_list> |
---|
27 | |
---|
28 | #include "elfpp.hh" |
---|
29 | #include "elfpp_bits.hh" |
---|
30 | |
---|
31 | namespace elfpp |
---|
32 | { |
---|
33 | |
---|
34 | class reloc; |
---|
35 | class symbol; |
---|
36 | class section; |
---|
37 | template <typename bits_t, int width> class elfn_access; |
---|
38 | |
---|
39 | std::ostream & operator<<(std::ostream &o, const reloc &v); |
---|
40 | |
---|
41 | /** |
---|
42 | @short ELF relocation class |
---|
43 | @header elfpp/reloc |
---|
44 | */ |
---|
45 | class reloc : public reloc_table_t::item_type, |
---|
46 | public reloc_modlist_t::item_type |
---|
47 | { |
---|
48 | friend class section; |
---|
49 | friend class symbol; |
---|
50 | template <typename, int> friend class elfn_access; |
---|
51 | friend std::ostream & operator<<(std::ostream &o, const reloc &v); |
---|
52 | |
---|
53 | public: |
---|
54 | reloc(); |
---|
55 | ~reloc(); |
---|
56 | |
---|
57 | /** Set pointer to mangled symbol. Relocation offset become |
---|
58 | relative to mangled symbol value when set. */ |
---|
59 | void set_mangled_symbol(symbol *s); |
---|
60 | /** Get pointer to mangled symbol. */ |
---|
61 | inline symbol * get_mangled_symbol() const; |
---|
62 | |
---|
63 | /** Set relocation symbol */ |
---|
64 | void set_symbol(symbol *s); |
---|
65 | /** Get relocation symbol */ |
---|
66 | inline symbol * get_symbol() const; |
---|
67 | |
---|
68 | /** Set relocation section */ |
---|
69 | inline void set_section(section *s); |
---|
70 | /** Get relocation section */ |
---|
71 | inline section * get_section() const; |
---|
72 | |
---|
73 | /** Set relocation type */ |
---|
74 | inline void set_type(enum reloc_e type); |
---|
75 | /** Get relocation type */ |
---|
76 | inline enum reloc_e get_type() const; |
---|
77 | |
---|
78 | /** Set relocation addend */ |
---|
79 | inline void set_addend(int64_t addend); |
---|
80 | /** Get relocation addend */ |
---|
81 | inline int64_t get_addend() const; |
---|
82 | |
---|
83 | /** Set relocation offset. Relocation offset is relative to |
---|
84 | mangled symbol value if available. It is relative to section |
---|
85 | if no mangled symbol is defined. */ |
---|
86 | inline void set_offset(uint64_t offset); |
---|
87 | /** Get relocation offset */ |
---|
88 | inline uint64_t get_offset() const; |
---|
89 | |
---|
90 | private: |
---|
91 | symbol *sym_mod_; |
---|
92 | symbol *sym_; |
---|
93 | section *sec_; |
---|
94 | enum reloc_e type_; |
---|
95 | int64_t addend_; |
---|
96 | uint64_t offset_; |
---|
97 | }; |
---|
98 | |
---|
99 | } |
---|
100 | |
---|
101 | #endif |
---|
102 | |
---|