More dynamic object support, initial scripting support.
[platform/upstream/binutils.git] / gold / dynobj.h
1 // dynobj.h -- dynamic object support for gold   -*- C++ -*-
2
3 #ifndef GOLD_DYNOBJ_H
4 #define GOLD_DYNOBJ_H
5
6 #include <vector>
7
8 #include "object.h"
9
10 namespace gold
11 {
12
13 // A dynamic object (ET_DYN).  This is an abstract base class itself.
14 // The implementations is the template class Sized_dynobj.
15
16 class Dynobj : public Object
17 {
18  public:
19   Dynobj(const std::string& name, Input_file* input_file, off_t offset = 0)
20     : Object(name, input_file, true, offset)
21   { }
22 };
23
24 // A dynamic object, size and endian specific version.
25
26 template<int size, bool big_endian>
27 class Sized_dynobj : public Dynobj
28 {
29  public:
30   Sized_dynobj(const std::string& name, Input_file* input_file, off_t offset,
31                const typename elfcpp::Ehdr<size, big_endian>&);
32
33   // Set up the object file based on the ELF header.
34   void
35   setup(const typename elfcpp::Ehdr<size, big_endian>&);
36
37   // Read the symbols.
38   void
39   do_read_symbols(Read_symbols_data*);
40
41   // Lay out the input sections.
42   void
43   do_layout(const General_options&, Symbol_table*, Layout*,
44             Read_symbols_data*);
45
46   // Add the symbols to the symbol table.
47   void
48   do_add_symbols(Symbol_table*, Read_symbols_data*);
49
50   // Get the name of a section.
51   std::string
52   do_section_name(unsigned int shndx)
53   { return this->elf_file_.section_name(shndx); }
54
55   // Return a view of the contents of a section.  Set *PLEN to the
56   // size.
57   Object::Location
58   do_section_contents(unsigned int shndx)
59   { return this->elf_file_.section_contents(shndx); }
60
61  private:
62   // For convenience.
63   typedef Sized_dynobj<size, big_endian> This;
64   static const int shdr_size = elfcpp::Elf_sizes<size>::shdr_size;
65   static const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
66   static const int dyn_size = elfcpp::Elf_sizes<size>::dyn_size;
67   typedef elfcpp::Shdr<size, big_endian> Shdr;
68   typedef elfcpp::Dyn<size, big_endian> Dyn;
69
70   // Find the dynamic symbol table and the version sections, given the
71   // section headers.
72   void
73   find_dynsym_sections(const unsigned char* pshdrs,
74                        unsigned int* pdynshm_shndx,
75                        unsigned int* pversym_shndx,
76                        unsigned int* pverdef_shndx,
77                        unsigned int* pverneed_shndx,
78                        unsigned int* pdynamic_shndx);
79
80   // Read the dynamic symbol section SHNDX.
81   void
82   read_dynsym_section(const unsigned char* pshdrs, unsigned int shndx,
83                       elfcpp::SHT type, unsigned int link,
84                       File_view** view, off_t* view_size,
85                       unsigned int* view_info);
86
87   // Set the SONAME from the SHT_DYNAMIC section at DYNAMIC_SHNDX.
88   // The STRTAB parameters may have the relevant string table.
89   void
90   set_soname(const unsigned char* pshdrs, unsigned int dynamic_shndx,
91              unsigned int strtab_shndx, const unsigned char* strtabu,
92              off_t strtab_size);
93
94   // Mapping from version number to version name.
95   typedef std::vector<const char*> Version_map;
96
97   // Create the version map.
98   void
99   make_version_map(Read_symbols_data* sd, Version_map*) const;
100
101   // Add an entry to the version map.
102   void
103   set_version_map(Version_map*, unsigned int ndx, const char* name) const;
104
105   // General access to the ELF file.
106   elfcpp::Elf_file<size, big_endian, Object> elf_file_;
107   // The DT_SONAME name, if any.
108   std::string soname_;
109 };
110
111 } // End namespace gold.
112
113 #endif // !defined(GOLD_DYNOBJ_H)