source: soft/giet_vm/mover/include/libelfpp/elfpp/elfpp_section.hh @ 160

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

giet-vm new version

File size: 4.9 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_SECTION_HH_
22#define ELFPP_SECTION_HH_
23
24#include <string>
25#include <map>
26#include <stdint.h>
27
28#include "elfpp.hh"
29#include "elfpp_bits.hh"
30
31namespace elfpp
32{
33
34  class object;
35  class section;
36  class symbol;
37  class reloc;
38
39  std::ostream & operator<<(std::ostream &o, const section &v);
40
41  /**
42      @short ELF section class
43      @header elfpp/section
44   */
45  class section : public section_table_t::item_type
46  {
47    template <typename, int> friend class elfn_access;
48    friend std::ostream & operator<<(std::ostream &o, const section &v);
49    friend class symbol;
50    friend class object;
51
52  public:
53    /** @this creates a new section associated with given object */
54    section(object &obj, sh_type_e type);
55
56    ~section();
57
58    /** @this sets section name */
59    inline void set_name(const std::string &name);
60    /** @this gets section name */
61    inline const std::string & get_name() const;
62
63    /** @this gets section type */
64    inline sh_type_e get_type() const;
65
66    /** @this sets section flags */
67    inline void set_flags(sh_flags_e flags);
68    /** @this gets section flags */
69    inline sh_flags_e get_flags() const;
70
71    /** @this sets section address */
72    inline void set_vaddr(uint64_t vaddr);
73    /** @this gets section address */
74    inline uint64_t get_vaddr() const;
75
76    /** @this sets section size, reallocate section content buffer */
77    void set_size(size_t size);
78    /** @this gets section size */
79    inline size_t get_size() const;
80
81    /** @this sets section link to an other section */
82    inline void set_link(section *s);
83    /** @this gets section link */
84    inline section * get_link() const;
85    /** @this gets section with a link to this section, may be unreliable if
86        multiple links exits */
87    inline section * get_back_link() const;
88
89    /** @this sets section info as link to section */
90    inline void set_info(section *s);
91    /** @this gets section info as link to section */
92    inline section * get_info() const;
93    /** @this gets section info as back link to section */
94    inline section * get_back_info() const;
95
96    /** @this sets section info as last local symbol index */
97    inline void set_info_last(unsigned int last);
98    /** @this gets section info as last local symbol index */
99    inline unsigned int get_info_last();
100
101    /** @this sets section alignement */
102    inline void set_align(uint32_t align);
103    /** @this gets section alignement */
104    inline uint32_t get_align() const;
105
106    /** @this sets section entry size */
107    inline void set_entsize(uint32_t entsize);
108    /** @this sets section entry size */
109    inline uint32_t get_entsize() const;
110
111    /** @this sets pointer to section content buffer */
112    inline void set_content(void* a);
113    /** @this gets pointer to section content buffer */
114    inline uint8_t *get_content() const;
115
116    /** @this gets pointer to container segment if any */
117    segment *get_segment() const;
118
119    /** @this gets associated object */
120    inline object * get_object() const;
121
122    /** @this gets load address from segment info  */
123    uint64_t get_load_address() const;
124
125    inline off_t get_file_offset() const;
126
127    /** @this adds symbol to section */
128    void add_symbol(symbol &sym);
129    /** @this removes symbol from section */
130    void remove_symbol(symbol &sym);
131    /** @this gets symbol by name */
132    inline symbol & get_symbol(const std::string &name);
133    /** @this gets symbol containing given offset */
134    symbol & get_symbol(uint64_t offset);
135    /** @this gets symbol table */
136    inline const sym_tab_map_t & get_symbol_table() const;
137
138   private:
139    inline void set_file_offset(off_t a);
140
141    /** start of flags present in elf section entry */
142    std::string name_;
143    sh_type_e type_;
144    sh_flags_e flags_;
145    uint64_t vaddr_;
146    off_t offset_;
147    size_t size_;
148    section *link_;
149    union {
150      section *info_;
151      unsigned int info_last_;
152    };
153    uint32_t align_;
154    uint32_t entsize_;
155    /** end of flags present in elf section entry */
156
157    // index of section
158    unsigned int index_;
159
160    section *back_info_;        // link to associated relocation table
161    section *back_link_;        // link to associated relocation table
162    object *object_;
163    uint8_t *content_;
164    sym_tab_map_t sym_tab_;
165  };
166
167}
168
169#endif
170
Note: See TracBrowser for help on using the repository browser.