aboutsummaryrefslogtreecommitdiff
path: root/src/clients/reconcilio/littlelf/elf_relocation_section.hh
blob: 7b63997f9bcd5b3718238f3b6e59483f9664c2d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2007 Tiziano Müller
 * Copyright (c) 2007 David Leverton
 *
 * This file is part of the Paludis package manager. Paludis is free software;
 * you can redistribute it and/or modify it under the terms of the GNU General
 * Public License version 2, as published by the Free Software Foundation.
 *
 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef ELFRELOCATIONSECTION_HH_
#define ELFRELOCATIONSECTION_HH_

#include "elf_sections.hh"

#include <paludis/util/private_implementation_pattern.hh>
#include <paludis/util/wrapped_forward_iterator-fwd.hh>

#include <iosfwd>

template <typename ElfType_>
class RelocationEntry
{
    private:
        typename ElfType_::Relocation _my_relocation;

    public:
        RelocationEntry(const typename ElfType_::Relocation &);
        ~RelocationEntry();

        typename ElfType_::RelocationOffset get_offset() const
        {
            return _my_relocation.r_offset;
        }

        typename ElfType_::RelocationInfo get_info() const
        {
            return _my_relocation.r_info;
        }
};

template <typename ElfType_>
class RelocationAEntry
{
    private:
        typename ElfType_::RelocationA _my_relocation;

    public:
        RelocationAEntry(const typename ElfType_::RelocationA &);
        ~RelocationAEntry();

        typename ElfType_::RelocationOffset get_offset() const
        {
            return _my_relocation.r_offset;
        }

        typename ElfType_::RelocationInfo get_info() const
        {
            return _my_relocation.r_info;
        }

        typename ElfType_::RelocationAddend get_addend() const
        {
            return _my_relocation.r_addend;
        }
};

template <typename ElfType_>
struct Relocation
{
    typedef typename ElfType_::Relocation Type;
    typedef RelocationEntry<ElfType_> Entry;
    const static std::string type_name;
};

template <typename ElfType_>
struct RelocationA
{
    typedef typename ElfType_::RelocationA Type;
    typedef RelocationAEntry<ElfType_> Entry;
    const static std::string type_name;
};

template <typename ElfType_, typename Relocation_>
class RelocationSection :
    public Section<ElfType_>,
    public paludis::AcceptInterfaceVisitsThis<SectionVisitorTypes<ElfType_> , RelocationSection<ElfType_, Relocation_> >,
    private paludis::PrivateImplementationPattern<RelocationSection<ElfType_, Relocation_> >
{
    using paludis::PrivateImplementationPattern<RelocationSection>::_imp;

    public:
        RelocationSection(const typename ElfType_::SectionHeader &, std::istream &, bool);
        virtual ~RelocationSection();

        virtual std::string get_type() const
        {
            return Relocation_::type_name;
        }

        struct RelocationIteratorTag;
        typedef paludis::WrappedForwardIterator<RelocationIteratorTag, const typename Relocation_::Entry> RelocationIterator;
        RelocationIterator relocation_begin() const;
        RelocationIterator relocation_end() const;
};

#endif /*ELFRELOCATIONSECTION_HH_*/