|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Implementation of the Class ElfExecutable for the elf2e32 tool |
|
15 // @internalComponent |
|
16 // @released |
|
17 // |
|
18 // |
|
19 |
|
20 #if !defined(_PL_ELFEXECUTABLE_H_) |
|
21 #define _PL_ELFEXECUTABLE_H_ |
|
22 |
|
23 #include "pl_common.h" |
|
24 #include <list> |
|
25 #include <hash_map> |
|
26 #include "pl_elfimports.h" |
|
27 #include "pl_elfrelocations.h" |
|
28 #include "pl_elfexports.h" |
|
29 |
|
30 using std::list; |
|
31 using std::hash_map; |
|
32 |
|
33 class DllSymbol; |
|
34 class Symbol; |
|
35 class ElfRelocations; |
|
36 class ElfExports; |
|
37 class ParameterListInterface; |
|
38 class ElfLocalRelocation; |
|
39 /** |
|
40 This class is for ELF object carrying the elf header, sections, segments. |
|
41 @internalComponent |
|
42 @released |
|
43 */ |
|
44 class ElfExecutable |
|
45 { |
|
46 |
|
47 public: |
|
48 ElfExecutable(ParameterListInterface *aParameterListInterface); |
|
49 virtual ~ElfExecutable(); |
|
50 |
|
51 PLUINT32 ProcessElfFile(Elf32_Ehdr *aElfHdr); |
|
52 void DumpElfFile(char* aFile); |
|
53 |
|
54 PLUINT32 ProcessSymbols(); |
|
55 ElfImports::ImportMap GetImports(); |
|
56 ElfExports* GetExports(); |
|
57 DllSymbol* AddToExports(char* aDll, DllSymbol* aSymbol); |
|
58 void AddToImports(ElfImportRelocation* aReloc); |
|
59 PLUINT32 AddToRelocations(ElfRelocation* aReloc); |
|
60 void AddToLocalRelocations(ElfRelocation* aReloc); |
|
61 void ProcessVerInfo(); |
|
62 |
|
63 Elf32_Sym* FindSymbol(char* aSymName); |
|
64 |
|
65 PLUINT32 GetSymbolOrdinal( char* aSymName); |
|
66 PLUINT32 GetSymbolOrdinal( Elf32_Sym* ); |
|
67 char* GetSymbolName( PLUINT32 aSymIdx); |
|
68 Elf32_Word GetRelocationOffset(ElfRelocation * aReloc); |
|
69 Elf32_Word *GetRelocationPlace(ElfRelocation * aReloc); |
|
70 |
|
71 Elf32_Word GetROBase(); |
|
72 Elf32_Word GetRWBase(); |
|
73 size_t GetROSize(); |
|
74 size_t GetRWSize(); |
|
75 size_t GetBssSize(); |
|
76 MemAddr GetRawROSegment(); |
|
77 MemAddr GetRawRWSegment(); |
|
78 Elf32_Word EntryPointOffset(); |
|
79 ESegmentType SegmentType(Elf32_Addr aAddr); |
|
80 Elf32_Phdr* Segment(Elf32_Addr aAddr); |
|
81 ElfRelocations::RelocationList & GetCodeRelocations(); |
|
82 ElfRelocations::RelocationList & GetDataRelocations(); |
|
83 ElfRelocations& GetLocalRelocations(); |
|
84 bool ExeceptionsPresentP(); |
|
85 ElfExports::ExportList& GetExportsInOrdinalOrder(); |
|
86 Elf32_Sym* LookupStaticSymbol(char * aName); |
|
87 public: |
|
88 /** |
|
89 * The elf header pointer which points to the base of the file records |
|
90 */ |
|
91 Elf32_Ehdr *iElfHeader; |
|
92 Elf32_Addr iEntryPoint; |
|
93 /** |
|
94 * The dynamic program header of the elf file |
|
95 */ |
|
96 Elf32_Phdr *iProgHeader; |
|
97 |
|
98 PLUINT32 iSONameOffset; |
|
99 char *iSOName; |
|
100 /** |
|
101 * This member points to the base of the section header table. |
|
102 */ |
|
103 Elf32_Shdr *iSections; |
|
104 Elf32_Verdef *iVersionDef; |
|
105 PLUINT32 iVerDefCount; |
|
106 Elf32_Verneed *iVersionNeed; |
|
107 PLUINT32 iVerNeedCount; |
|
108 Elf32_Half *iVersionTbl; |
|
109 PLUINT32 iRelSize; |
|
110 PLUINT32 iRelEntSize; |
|
111 PLUINT32 iNRelocs; |
|
112 Elf32_Rel *iRel; |
|
113 PLUINT32 iRelaSize; |
|
114 PLUINT32 iRelaEntSize; |
|
115 Elf32_Rela *iRela; |
|
116 char *iStringTable; |
|
117 char *iSectionHdrStrTbl; |
|
118 |
|
119 list<char*> iNeeded; |
|
120 VersionInfo *iVerInfo; |
|
121 /** |
|
122 * The dynamic symbol array. |
|
123 */ |
|
124 Elf32_Sym *iElfDynSym;//The ELF symbol |
|
125 hash_map<PLUINT32, DllSymbol*> iSymbolTable; //The representation |
|
126 |
|
127 /** |
|
128 * The static symbol table. |
|
129 */ |
|
130 Elf32_Sym *iSymTab; |
|
131 char *iStrTab; |
|
132 Elf32_Sym *iLim; |
|
133 |
|
134 PLUINT32 iNSymbols; |
|
135 Elf32_HashTable *iHashTbl; |
|
136 Elf32_Phdr *iDynSegmentHdr; |
|
137 Elf32_Phdr *iDataSegmentHdr; |
|
138 MemAddr iDataSegment; |
|
139 size_t iDataSegmentSize; |
|
140 PLUINT32 iDataSegmentIdx; |
|
141 Elf32_Phdr *iCodeSegmentHdr; |
|
142 MemAddr iCodeSegment; |
|
143 size_t iCodeSegmentSize; |
|
144 PLUINT32 iCodeSegmentIdx; |
|
145 ElfImports iImports; |
|
146 ElfExports *iExports; |
|
147 ElfRelocations iLocalRelocations; |
|
148 ParameterListInterface *iParameterListInterface; |
|
149 PLUINT32 iPltGotBase; |
|
150 PLUINT32 iPltGotLimit; |
|
151 PLUINT32 iStrTabSz; |
|
152 PLUINT32 iSymEntSz; |
|
153 Elf32_Word *iPltGot; |
|
154 PLUINT32 iPltRelType; |
|
155 Elf32_Rel *iPltRel; |
|
156 PLUINT32 iPltRelaSz; |
|
157 Elf32_Rela *iPltRela; |
|
158 PLUINT32 iPltRelSz; |
|
159 PLUINT32 iJmpRelOffset; |
|
160 |
|
161 PLUINT32 ValidateElfFile(); |
|
162 PLUINT32 ProcessDynamicEntries(); |
|
163 void ProcessRelocations(); |
|
164 template <class T> void ProcessRelocations(T *aElfRel, size_t aSize); |
|
165 |
|
166 VersionInfo* GetVersionInfo(PLUINT32 aIndex); |
|
167 char* SymbolDefinedInDll(PLUINT32 aSymbolIndex); |
|
168 void SetVersionRecord( ElfRelocation* aReloc ); |
|
169 |
|
170 /** This function says if the Symbol is a global symbol |
|
171 @return It returns true if the Symbol is a global one. |
|
172 @param aSym The reference to the Symbol whose attribute is being checked |
|
173 */ |
|
174 bool GlobalSymbol(Elf32_Sym* aSym); |
|
175 |
|
176 /** This function says if the Symbol is Exported |
|
177 @return It returns true if the Symbol is an exported one. |
|
178 @param aSym The reference to the Symbol whose attribute is being checked |
|
179 */ |
|
180 bool ExportedSymbol(Elf32_Sym* aSym); |
|
181 |
|
182 /** This function says if the Symbol is Imported |
|
183 @return It returns true if the Symbol is an imported one. |
|
184 @param aSym The reference to the Symbol whose attribute is being checked |
|
185 */ |
|
186 bool ImportedSymbol(Elf32_Sym* aSym); |
|
187 |
|
188 /** This function says if the Symbol is a Code Symbol |
|
189 @return It returns true if the Symbol is of Code type. |
|
190 @param aSym The reference to the Symbol whose attribute is being checked |
|
191 */ |
|
192 bool FunctionSymbol(Elf32_Sym* aSym); |
|
193 |
|
194 /** This function says if the Symbol is a Data Symbol |
|
195 @return It returns true if the Symbol is of Data type. |
|
196 @param aSym The reference to the Symbol whose attribute is being checked |
|
197 */ |
|
198 bool DataSymbol(Elf32_Sym* aSym); |
|
199 |
|
200 /** This function says if the Symbol is Defined |
|
201 @return It returns true if the Symbol is defined. |
|
202 @param aSym The reference to the Symbol whose attribute is being checked |
|
203 */ |
|
204 bool DefinedSymbol(Elf32_Sym* aSym); |
|
205 |
|
206 /** This function says if the Symbol has a default Visibility |
|
207 @return It returns true if the Symbol has a default Visibility |
|
208 @param aSym The reference to the Symbol whose attribute is being checked |
|
209 */ |
|
210 bool VisibleSymbol(Elf32_Sym* aSym); |
|
211 |
|
212 /** This function finds the segment in which this address belongs |
|
213 @return the segment type |
|
214 @param aAddr The address within the executable |
|
215 */ |
|
216 |
|
217 Elf32_Word Addend(Elf32_Rel* aRel); |
|
218 Elf32_Word Addend(Elf32_Rela* aRel); |
|
219 |
|
220 char* SymbolFromDSO(PLUINT32 aSymbolIndex); |
|
221 Elf32_Word* GetFixupLocation(ElfLocalRelocation* aReloc, Elf32_Addr aPlace); |
|
222 ESegmentType Segment(Elf32_Sym *aSym); |
|
223 Elf32_Phdr* SegmentFromAbs(Elf32_Addr aAddr); |
|
224 Elf32_Phdr* Segment(ESegmentType aType); |
|
225 |
|
226 /** This function processes the linker generated Veneer symbols and |
|
227 * creates a relocation entry. |
|
228 */ |
|
229 void ProcessVeneers(); |
|
230 /** This function processes the ELF file to find the static symbol table. |
|
231 */ |
|
232 void FindStaticSymbolTable(); |
|
233 /** This function finds the .comment section |
|
234 @return the pointer to the comment section |
|
235 */ |
|
236 char* FindCommentSection(); |
|
237 /** This function finds the value at the address passed in |
|
238 @return the value at the address passed in |
|
239 @param aAddr The address within the executable |
|
240 */ |
|
241 Elf32_Word FindValueAtLoc(Elf32_Addr aOffset); |
|
242 }; |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 #endif // !defined(_PL_ELFEXECUTABLE_H_) |