ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BinaryLoaderElf.h
Go to the documentation of this file.
1 #ifndef ROSE_BINARYLOADERELF_H
2 #define ROSE_BINARYLOADERELF_H
3 
4 #include "BinaryLoader.h"
5 
7 public:
9 
11  : BinaryLoader(other)
12  {}
13 
14  virtual ~BinaryLoaderElf() {}
15 
17  virtual BinaryLoaderElf *clone() const {
18  return new BinaryLoaderElf(*this);
19  }
20 
22  virtual bool can_load(SgAsmGenericHeader*) const;
23 
39  void add_lib_defaults(SgAsmGenericHeader *header=NULL);
40 
42  static void get_dynamic_vars(SgAsmGenericHeader*, std::string &rpath/*out*/, std::string &runpath/*out*/);
43 
44  // documented in superclass
45  virtual void fixup(SgAsmInterpretation *interp, FixupErrors *errors=NULL) /*override*/;
46 
47  /* FIXME: These should probably be in SgAsmElfSymver* classes instead. [RPM 2010-09-14] */
49  enum {
53  };
54 
63  private:
68  public:
69  explicit VersionedSymbol(SgAsmElfSymbol* symbol)
70  : p_symbol(symbol), p_version_entry(NULL), p_version_def(NULL), p_version_need(NULL)
71  {}
72 
74  bool is_local() const;
75 
77  bool is_hidden() const;
78 
80  bool is_reference() const;
81 
84  bool is_base_definition() const;
85 
87  void set_symbol(SgAsmElfSymbol *symbol) {
88  p_symbol = symbol;
89  }
90 
93  return p_symbol;
94  }
95 
98  SgAsmElfSymbolSection *retval = SageInterface::getEnclosingNode<SgAsmElfSymbolSection>(p_symbol);
99  ROSE_ASSERT(retval!=NULL);
100  return retval;
101  }
102 
104  std::string get_version() const;
105 
107  std::string get_name() const {
108  return p_symbol->get_name()->get_string();
109  }
110 
112  std::string get_versioned_name() const;
113 
116  p_version_entry = entry;
117  }
118 
121  ROSE_ASSERT(def->get_flags() == 0 || def->get_flags() == VER_FLG_BASE);
122  p_version_def = def;
123  }
124 
127  ROSE_ASSERT(need->get_flags() == 0 || need->get_flags() == VER_FLG_WEAK);
128  p_version_need = need;
129  }
130 
133  return p_version_need;
134  }
135 
138  return p_version_def;
139  }
140 
142  void print(std::ostream&) const;
143 
145  void dump(FILE*, const char *prefix, ssize_t idx) const;
146  };
147 
150  struct SymbolMapEntry {
151  private:
152  /* Base version will be at the front if we have one; other entries are unsorted. */
153  std::vector<VersionedSymbol> p_versions;
154  public:
156  const VersionedSymbol &get_vsymbol() const {
157  return get_base_version();
158  }
159 
162  return get_vsymbol().get_symbol();
163  }
164 
168  VersionedSymbol get_vsymbol(const VersionedSymbol &version) const;
169 
172  return get_vsymbol().get_section();
173  }
174 
177  void addVersion(const VersionedSymbol &vsymbol);
178 
180  void merge(const SymbolMapEntry&);
181 
183  void dump(FILE*, const char *prefix) const ;
184 
185  private:
187  ROSE_ASSERT(!p_versions.empty());
188  return p_versions.front();
189  }
190  };
191 
193  class SymbolMap: public std::map<std::string/*symbol name*/, SymbolMapEntry> {
194  public:
196  const SymbolMapEntry *lookup(std::string name) const;
197 
201  const SymbolMapEntry *lookup(std::string name, std::string version) const;
202 
204  void dump(FILE*, const char *prefix) const;
205  };
206 
208  public:
210  ctor(header);
211  }
212 
216 
218  void dump(FILE*, const char *prefix, ssize_t idx) const;
219 
220  private:
222  void ctor(SgAsmGenericHeader*);
223 
227 
232 
237 
238  typedef std::map<SgAsmElfSymbol*, VersionedSymbol*> VersionedSymbolMap;
239  typedef std::map<uint16_t, SgAsmElfSymverDefinedEntry*> SymbolVersionDefinitionMap;
240  typedef std::map<uint16_t, SgAsmElfSymverNeededAux*> SymbolVersionNeededMap;
241 
244 
250 
253  };
254 
259 
260 protected:
265 
268 
271  rose_addr_t *malign_lo, rose_addr_t *malign_hi,
272  rose_addr_t *va, rose_addr_t *mem_size,
273  rose_addr_t *offset, rose_addr_t *file_size, bool *map_private,
274  rose_addr_t *va_offset, bool *anon_lo, bool *anon_hi,
275  ConflictResolution *resolve);
276 
281 
282  /*========================================================================================================================
283  * Methods returning prerequisite information for fixups. These names all begin with "fixup_info_".
284  *======================================================================================================================== */
285 protected:
286 
296 
307 
318 
328  rose_addr_t fixup_info_addend(SgAsmElfRelocEntry*, rose_addr_t target_va, MemoryMap*, size_t nbytes=0);
329 
362  rose_addr_t fixup_info_expr(const std::string &expression, SgAsmElfRelocEntry *reloc, const SymverResolver &resolver,
363  MemoryMap *memmap, rose_addr_t *target_va_p=NULL);
364 
365 
366 
367  /*========================================================================================================================
368  * Methods that apply a relocation fixup. These names all begin with "fixup_apply_".
369  *======================================================================================================================== */
370 protected:
381  void fixup_apply(rose_addr_t value, SgAsmElfRelocEntry*, MemoryMap*, rose_addr_t target_va=0, size_t nbytes=0);
382 
386 
387  /*========================================================================================================================
388  * Functions moved here from the BinaryLoader_ElfSupport name space.
389  *======================================================================================================================== */
390 protected:
393 
394  /*========================================================================================================================
395  * Data members
396  *======================================================================================================================== */
397 protected:
398 
402 };
403 
404 std::ostream& operator<<(std::ostream&, const BinaryLoaderElf::VersionedSymbol&);
405 
406 #endif /*ROSE_BINARYLOADERELF_H*/