ROSE 0.11.145.192
BinaryLoaderElf.h
1#ifndef ROSE_BinaryAnalysis_BinaryLoaderElf_H
2#define ROSE_BinaryAnalysis_BinaryLoaderElf_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5#include <Rose/BinaryAnalysis/BinaryLoader.h>
6
7namespace Rose {
8namespace BinaryAnalysis {
9
12public:
15
16public:
17 /* FIXME: These should probably be in SgAsmElfSymver* classes instead. [RPM 2010-09-14] */
19 enum {
20 VER_FLG_BASE=0x1,
21 VER_FLG_WEAK=0x2,
22 VERSYM_HIDDEN=0x8000
23 };
24
33 private:
34 SgAsmElfSymbol* symbol_;
35 SgAsmElfSymverEntry* versionEntry_;
36 SgAsmElfSymverDefinedEntry* versionDef_;
37 SgAsmElfSymverNeededAux* versionNeed_;
38 public:
40 : symbol_(symbol), versionEntry_(NULL), versionDef_(NULL), versionNeed_(NULL)
41 {}
42
44 bool isLocal() const;
45
47 bool isHidden() const;
48
50 bool isReference() const;
51
54 bool isBaseDefinition() const;
55
59 void symbol(SgAsmElfSymbol *symbol) { symbol_ = symbol; }
60 SgAsmElfSymbol* symbol() const { return symbol_; }
65
67 std::string getVersion() const;
68
70 std::string getName() const;
71
73 std::string getVersionedName() const;
74
77
97 void print(std::ostream&) const;
98
100 void dump(FILE*, const char *prefix, ssize_t idx) const;
101 };
102
106 private:
107 /* Base version will be at the front if we have one; other entries are unsorted. */
108 std::vector<VersionedSymbol> versions_;
109 public:
112
115
120
123
126 void addVersion(const VersionedSymbol &vsymbol);
127
129 void merge(const SymbolMapEntry&);
130
132 void dump(FILE*, const char *prefix) const ;
133
134 private:
135 const VersionedSymbol& getBaseVersion() const;
136 };
137
139 class SymbolMap: public std::map<std::string/*symbol name*/, SymbolMapEntry> {
140 public:
142 const SymbolMapEntry *lookup(std::string name) const;
143
147 const SymbolMapEntry *lookup(std::string name, std::string version) const;
148
150 void dump(FILE*, const char *prefix) const;
151 };
152
154 public:
155 typedef std::map<SgAsmElfSymbol*, VersionedSymbol*> VersionedSymbolMap;
156 typedef std::map<uint16_t, SgAsmElfSymverDefinedEntry*> SymbolVersionDefinitionMap;
157 typedef std::map<uint16_t, SgAsmElfSymverNeededAux*> SymbolVersionNeededMap;
158
159 private:
160 // Map from each ELF Symbol Version Definition Table entry's get_index() to the entry itself.
161 SymbolVersionDefinitionMap symbolVersionDefMap_;
162
163 // Map from each auxiliary's get_other() to the auxiliary itself. The auxiliaries come from the GNU Symbol Version
164 // Requirements Table, each entry of which points to a list of auxiliaries. The parent of each auxiliary is the table
165 // entry that contained the auxiliary, thus this mapping also maps get_other() to GNU Symbol Version Requirements Table
166 // entries.
167 SymbolVersionNeededMap symbolVersionNeedMap_;
168
169 // Map from an SgAsmElfSymbol to a VersionedSymbol.
170 VersionedSymbolMap versionedSymbolMap_;
171 public:
173 ctor(header);
174 }
175
179
181 void dump(FILE*, const char *prefix, ssize_t idx) const;
182
183 private:
185 void ctor(SgAsmGenericHeader*);
186
189 void makeSymbolVersionDefMap(SgAsmElfSymverDefinedSection*);
190
194 void makeSymbolVersionNeedMap(SgAsmElfSymverNeededSection*);
195
199 void makeVersionedSymbolMap(SgAsmElfSymbolSection*, SgAsmElfSymverSection*);
200 };
201
202protected:
208
209protected:
210 BinaryLoaderElf() {}
211
212 BinaryLoaderElf(const BinaryLoaderElf &other)
213 : BinaryLoader(other)
214 {}
215
216public:
218 static Ptr instance() {
219 return Ptr(new BinaryLoaderElf);
220 }
221
222 virtual ~BinaryLoaderElf() {}
223
225 virtual BinaryLoaderPtr clone() const override {
226 return BinaryLoaderPtr(new BinaryLoaderElf(*this));
227 }
228
230 virtual bool canLoad(SgAsmGenericHeader*) const override;
231
248
250 static void getDynamicVars(SgAsmGenericHeader*, std::string &rpath/*out*/, std::string &runpath/*out*/);
251
252 // documented in superclass
253 virtual void fixup(SgAsmInterpretation *interp, FixupErrors *errors=NULL) override;
254
259
260protected:
264 virtual SgAsmGenericSectionPtrList getRemapSections(SgAsmGenericHeader*) override;
265
266public:
268 virtual rose_addr_t rebase(const MemoryMap::Ptr&, SgAsmGenericHeader*, const SgAsmGenericSectionPtrList&) override;
269
270protected:
273 rose_addr_t *malign_lo, rose_addr_t *malign_hi,
274 rose_addr_t *va, rose_addr_t *mem_size,
275 rose_addr_t *offset, rose_addr_t *file_size, bool *map_private,
276 rose_addr_t *va_offset, bool *anon_lo, bool *anon_hi,
277 ConflictResolution *resolve) override;
278
283
284 /*========================================================================================================================
285 * Methods returning prerequisite information for fixups. These names all begin with "fixup_info_".
286 *======================================================================================================================== */
287protected:
288
298
308 rose_addr_t fixupInfoTargetVa(SgAsmElfRelocEntry*, SgAsmGenericSection **section_p=NULL, rose_addr_t *adj_p=NULL);
309
319 rose_addr_t fixupInfoSymbolVa(SgAsmElfSymbol*, SgAsmGenericSection **section_p=NULL, rose_addr_t *adj_p=NULL);
320
330 rose_addr_t fixupInfoAddend(SgAsmElfRelocEntry*, rose_addr_t target_va, const MemoryMap::Ptr&, size_t nbytes=0);
331
364 rose_addr_t fixupInfoExpr(const std::string &expression, SgAsmElfRelocEntry *reloc, const SymverResolver &resolver,
365 const MemoryMap::Ptr &memmap, rose_addr_t *target_va_p=NULL);
366
367
368
369 /*========================================================================================================================
370 * Methods that apply a relocation fixup. These names all begin with "fixup_apply_".
371 *======================================================================================================================== */
372protected:
383 void fixupApply(rose_addr_t value, SgAsmElfRelocEntry*, const MemoryMap::Ptr&, rose_addr_t target_va=0, size_t nbytes=0);
384
388
389 /*========================================================================================================================
390 * Functions moved here from the BinaryLoader_ElfSupport name space.
391 *======================================================================================================================== */
392protected:
393 void performRelocation(SgAsmElfRelocEntry*, const SymverResolver&, const MemoryMap::Ptr&);
394 void performRelocations(SgAsmElfFileHeader*, const MemoryMap::Ptr&);
395};
396
397std::ostream& operator<<(std::ostream&, const BinaryLoaderElf::VersionedSymbol&);
398
399} // namespace
400} // namespace
401
402#endif
403#endif
A mapping from symbol name (with optional version in parentheses) to SymbolMapEntry.
const SymbolMapEntry * lookup(std::string name, std::string version) const
Finds and returns the entry having the specified name and version.
void dump(FILE *, const char *prefix) const
Print debugging information about this SymbolMap.
const SymbolMapEntry * lookup(std::string name) const
Finds and returns the entry having the specified name.
void dump(FILE *, const char *prefix, ssize_t idx) const
Print some info about the resolver.
VersionedSymbol getVersionedSymbol(SgAsmElfSymbol *symbol) const
Returns the VersionedSymbol corresponding to the specified symbol.
Symbol from .dynsym combined with additional information.
SgAsmElfSymverNeededAux * versionNeed() const
Property: The version requirement of this symbol.
void print(std::ostream &) const
Print used by operator<<.
void dump(FILE *, const char *prefix, ssize_t idx) const
Dump info like for SgAsm* objects.
SgAsmElfSymbolSection * getSection() const
Returns the symbol section (.dynsym) where this symbol was defined.
bool isBaseDefinition() const
Returns tru if this symbol is a base definition.
void versionEntry(SgAsmElfSymverEntry *)
Property: Version pointer for this symbol.
bool isLocal() const
Returns true if this symbol is visible only locally.
std::string getVersion() const
Returns the version string of this symbol.
std::string getVersionedName() const
Returns the full, versionioned name of this symbol.
bool isHidden() const
Returns true if this symbol is hidden.
void symbol(SgAsmElfSymbol *symbol)
Property: The symbol.
std::string getName() const
Returns the name of this symbol.
SgAsmElfSymbol * symbol() const
Property: The symbol.
bool isReference() const
Returns true if this symbol is a reference to an object rather than the definition of the object.
void versionNeed(SgAsmElfSymverNeededAux *)
Property: The version requirement of this symbol.
SgAsmElfSymverDefinedEntry * versionDef() const
Property: Version definition of this symbol.
void versionDef(SgAsmElfSymverDefinedEntry *)
Property: Version definition of this symbol.
virtual BinaryLoaderPtr clone() const override
Copy constructor.
rose_addr_t fixupInfoSymbolVa(SgAsmElfSymbol *, SgAsmGenericSection **section_p=NULL, rose_addr_t *adj_p=NULL)
Returns the virtual address of a symbol adjusted for remapping.
virtual SgAsmGenericSection * findSectionByPreferredVa(SgAsmGenericHeader *, rose_addr_t va)
Find the section containing the specified virtual address.
SymbolMap symbols_
Symbol table for an entire interpretation.
rose_addr_t fixupInfoExpr(const std::string &expression, SgAsmElfRelocEntry *reloc, const SymverResolver &resolver, const MemoryMap::Ptr &memmap, rose_addr_t *target_va_p=NULL)
Evaluates a simple postfix expression and returns the result.
void fixupApplySymbolCopy(SgAsmElfRelocEntry *, const SymverResolver &, const MemoryMap::Ptr &)
Copies symbol memory to the relocation target.
void buildMasterSymbolTable(SgAsmInterpretation *)
Builds the master symbol table.
static void getDynamicVars(SgAsmGenericHeader *, std::string &rpath, std::string &runpath)
Returns the strings associated with certain variables in the ".dynamic" section.
virtual bool canLoad(SgAsmGenericHeader *) const override
Capability query.
virtual rose_addr_t rebase(const MemoryMap::Ptr &, SgAsmGenericHeader *, const SgAsmGenericSectionPtrList &) override
Returns a new, temporary base address which is greater than everything that's been mapped already.
virtual MappingContribution alignValues(SgAsmGenericSection *, const MemoryMap::Ptr &, rose_addr_t *malign_lo, rose_addr_t *malign_hi, rose_addr_t *va, rose_addr_t *mem_size, rose_addr_t *offset, rose_addr_t *file_size, bool *map_private, rose_addr_t *va_offset, bool *anon_lo, bool *anon_hi, ConflictResolution *resolve) override
Linux-specific ELF Segment and Section alignment.
virtual SgAsmGenericSectionPtrList getRemapSections(SgAsmGenericHeader *) override
Returns mappable sections in a particular order.
BinaryLoaderElfPtr Ptr
Reference counting pointer to BinaryLoaderElf.
void addLibDefaults(SgAsmGenericHeader *header=NULL)
Sets up library search paths and preloads from the environment.
rose_addr_t fixupInfoAddend(SgAsmElfRelocEntry *, rose_addr_t target_va, const MemoryMap::Ptr &, size_t nbytes=0)
Returns the addend associated with a relocation.
static Ptr instance()
Allocating constructor.
rose_addr_t fixupInfoTargetVa(SgAsmElfRelocEntry *, SgAsmGenericSection **section_p=NULL, rose_addr_t *adj_p=NULL)
Returns the virtual address where a relocation should be supplied.
SgAsmElfSymbol * fixupInfoRelocSymbol(SgAsmElfRelocEntry *, const SymverResolver &)
Returns the defining symbol for a relocation, if any.
void fixupApply(rose_addr_t value, SgAsmElfRelocEntry *, const MemoryMap::Ptr &, rose_addr_t target_va=0, size_t nbytes=0)
Writes a value into memory at the relocation target.
virtual void fixup(SgAsmInterpretation *interp, FixupErrors *errors=NULL) override
Performs relocation fixups on the specified interpretation.
Base class for loading a static or dynamic object.
MappingContribution
Describes how a section contributes to the overall memory map.
ConflictResolution
Describes how conflicts are resolved when mapping a section.
Reference-counting intrusive smart pointer.
Represents the file header of an ELF binary container.
One entry of an ELF relocation table.
ELF file section containing symbols.
Represents a single ELF symbol.
One entry from an ELF symbol version definition table.
The GNU symbol version definitions.
Entry in an ELF symbol version table.
Auxiliary info for needed symbol version.
GNU symbol version requirements table.
The ELF symbol version table.
Base class for container file headers.
Contiguous region of a file.
Represents an interpretation of a binary container.
Sawyer::SharedPointer< BinaryLoaderElf > BinaryLoaderElfPtr
Reference counting pointer.
Sawyer::SharedPointer< BinaryLoader > BinaryLoaderPtr
Reference counting pointer.
The ROSE library.
void merge(const SymbolMapEntry &)
Merge the versions from the specified entry into this entry.
void dump(FILE *, const char *prefix) const
Print info about this symbol map entry.
VersionedSymbol getVSymbol(const VersionedSymbol &version) const
Find definition of symbol.
SgAsmElfSymbol * getSymbol() const
Returns the ELF symbol from the base version.
void addVersion(const VersionedSymbol &vsymbol)
Add an additional versioned symbol to this entry.
SgAsmElfSymbolSection * getSection() const
Returns the section where the base version symbol was defined.
const VersionedSymbol & getVSymbol() const
Returns the base version.