| 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 | #include <elfpp/reloc> |
|---|
| 22 | #include <elfpp/symbol> |
|---|
| 23 | #include <elfpp/section> |
|---|
| 24 | |
|---|
| 25 | namespace elfpp |
|---|
| 26 | { |
|---|
| 27 | |
|---|
| 28 | reloc::reloc() |
|---|
| 29 | : sym_mod_(0), |
|---|
| 30 | sym_(0), |
|---|
| 31 | type_(R_NONE), |
|---|
| 32 | addend_(0) |
|---|
| 33 | { |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | reloc::~reloc() |
|---|
| 37 | { |
|---|
| 38 | if (!reloc_table_t::item_type::orphan()) |
|---|
| 39 | reloc_table_t::item_type::remove(); |
|---|
| 40 | |
|---|
| 41 | if (!reloc_modlist_t::item_type::orphan()) |
|---|
| 42 | reloc_modlist_t::item_type::remove(); |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | void reloc::set_mangled_symbol(symbol *s) |
|---|
| 46 | { |
|---|
| 47 | if (sym_mod_) |
|---|
| 48 | reloc_modlist_t::item_type::remove(); |
|---|
| 49 | sym_mod_ = s; |
|---|
| 50 | if (sym_mod_) |
|---|
| 51 | sym_mod_->reloc_mod_.push_back(*this); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | void reloc::set_symbol(symbol *s) |
|---|
| 55 | { |
|---|
| 56 | if (sym_) |
|---|
| 57 | reloc_table_t::item_type::remove(); |
|---|
| 58 | sym_ = s; |
|---|
| 59 | if (sym_) |
|---|
| 60 | sym_->reloc_tab_.push_back(*this); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | std::ostream & operator<<(std::ostream &o, const reloc &r) |
|---|
| 64 | { |
|---|
| 65 | o << "[sym:" << *r.sym_ << " sec:" << *r.sec_ << " offset:" << r.offset_ << "]"; |
|---|
| 66 | return o; |
|---|
| 67 | }; |
|---|
| 68 | |
|---|
| 69 | } |
|---|
| 70 | |
|---|