|
1 /* |
|
2 * Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #if !defined(__ELFDLL_H__) |
|
20 #define __ELFDLL_H__ |
|
21 //#include <e32rom.h> |
|
22 #include "e32ldfmt.h" |
|
23 #include <elfdefs.h> |
|
24 #include "elffile.h" |
|
25 |
|
26 #define DLLSYMPREFIX "#<DLL>" |
|
27 #define DLLSYMPREFIX0 "#" |
|
28 #define DLLSYMSUFFIX "#<\\DLL>" |
|
29 #define ORDBASE 16 |
|
30 #define EXPORTTABLENAME "DLL##ExportTable" |
|
31 #define EXPORTTABLESIZENAME "DLL##ExportTableSize" |
|
32 |
|
33 class NamedExportSymbol; |
|
34 class OrdZeroRecord; |
|
35 struct NeededDLLsList; |
|
36 |
|
37 const TUint KNameLookupOffsetFlag32 = 0x0001; |
|
38 |
|
39 class ELFFile::ELFDllData |
|
40 { |
|
41 public: |
|
42 ELFFile * iElfFile; |
|
43 |
|
44 char * iDynStrTab; |
|
45 // bytesize of the dynamic string table |
|
46 TInt iDynStrTabSize; |
|
47 Elf32_Sym * iDynSymTab; |
|
48 // size of an entry in the dynamic symbol table |
|
49 TInt iSymSize; |
|
50 // the rela relocation table |
|
51 Elf32_Rela * iRela; |
|
52 // size of rela relocation table in bytes |
|
53 TInt iRelaSz; |
|
54 // size of a rela entry in bytes |
|
55 TInt iRelaEnt; |
|
56 // the rel relocation table |
|
57 Elf32_Rel * iRel; |
|
58 // size of rel relocation table in bytes |
|
59 TInt iRelSz; |
|
60 // size of a rel entry in bytes |
|
61 TInt iRelEnt; |
|
62 |
|
63 Elf32_HashTable * iHashTable; |
|
64 |
|
65 // Exported symbols required for lookup via names. |
|
66 NamedExportSymbol *iNamedExportSymbolHead; |
|
67 // Number of exported symbols - this doesn't nclude the absent symbols. |
|
68 TInt iNamedExportCount; |
|
69 // header of the export symbol info table |
|
70 E32EpocExpSymInfoHdr iSymInfoHdr; |
|
71 // String table size for the symbol names. |
|
72 TUint iSymStringTableSize; |
|
73 TUint iStringNameOffset; |
|
74 |
|
75 // Dependency list |
|
76 // Static Dependencies - An 'import relocation' entry is required to be created |
|
77 // for each such record. |
|
78 OrdZeroRecord *iDepRecords; |
|
79 OrdZeroRecord *iDepRecordsTail; |
|
80 |
|
81 // List of names obtained from DT_NEEDED entries in ELF. |
|
82 // The order in which they appear is the order in which symbol |
|
83 // lookup shall be followed. |
|
84 NeededDLLsList *iNeededDllNames; |
|
85 NeededDLLsList *iNeededDllNamesTail; |
|
86 // Ordinal 0 of this binary. - A local relocation needs to be created for this |
|
87 // record. |
|
88 |
|
89 OrdZeroRecord *iOrdZeroRec; |
|
90 TInt iNamedLookupEnabled; |
|
91 |
|
92 ELFDllData(ELFFile * f); |
|
93 ~ELFDllData(); |
|
94 TBool Init(); |
|
95 |
|
96 TBool ParseDllSymbol(Elf32_Sym * s, char*& dll, TUint& len, TInt& ord); |
|
97 class DllSymbol |
|
98 { |
|
99 public: |
|
100 char * iDll; |
|
101 TUint iLen; |
|
102 TInt iOrd; |
|
103 Elf32_Phdr * iSegment; |
|
104 Elf32_Rel * iRel; |
|
105 DllSymbol * iNext; |
|
106 |
|
107 DllSymbol(char * n, TUint l, TInt o) |
|
108 : iDll(n), iLen(l), iOrd(o), iSegment(0),iRel(0),iNext(0) |
|
109 {} |
|
110 ~DllSymbol() |
|
111 { |
|
112 delete iNext; |
|
113 } |
|
114 }; |
|
115 DllSymbol * DllSymbolP(Elf32_Sym * s); |
|
116 TBool AddSymbol(DllSymbol * s); |
|
117 |
|
118 class DllRec |
|
119 { |
|
120 public: |
|
121 char * iName; |
|
122 TUint iLen; |
|
123 TInt nImports; |
|
124 DllSymbol * iHead; |
|
125 DllSymbol * iTail; |
|
126 DllRec * iNext; |
|
127 |
|
128 DllRec(char * n, TInt l, DllSymbol * s) : |
|
129 iName(n), iLen(l), nImports(1), iHead(s), iTail(s), iNext(0) |
|
130 {} |
|
131 ~DllRec() |
|
132 { |
|
133 delete iHead; |
|
134 delete iNext; |
|
135 } |
|
136 void AddSymbol(DllSymbol * s); |
|
137 }; |
|
138 |
|
139 DllRec * iDllHead; |
|
140 DllRec * iDllTail; |
|
141 |
|
142 Elf32_Word iExportTableSymIdx; |
|
143 Elf32_Word iExportTableSizeSymIdx; |
|
144 |
|
145 TBool InitExportInfo(); |
|
146 TBool iImageIsDll; |
|
147 TBool ImageIsDll() { return iImageIsDll; } |
|
148 |
|
149 Elf32_Word FindSymbolIndex(TText * s); |
|
150 |
|
151 TInt iNumberOfImports; |
|
152 TInt iNumberOfExports; |
|
153 TInt iNumberOfImportDlls; |
|
154 |
|
155 TInt iStringTableSize; |
|
156 |
|
157 TInt iNumberOfRelocs; |
|
158 TInt iNumberOfCodeRelocs; |
|
159 TInt iNumberOfDataRelocs; |
|
160 |
|
161 TInt NumberOfImports(void); |
|
162 TInt NumberOfExports(void); |
|
163 TInt NumberOfImportDlls(void); |
|
164 |
|
165 TInt NumberOfRelocs(void); |
|
166 |
|
167 TInt NumberOfCodeRelocs() { return iNumberOfCodeRelocs; } |
|
168 TInt NumberOfDataRelocs() { return iNumberOfDataRelocs; } |
|
169 |
|
170 TBool GetRelocs(Elf32_Rel **aCodeRelocs, Elf32_Rel **aDataRelocs); |
|
171 |
|
172 TUint GetExportTableOffset(void); |
|
173 char * CreateImportSection(TInt &aSize); |
|
174 TBool CreateSymLookupTable(); |
|
175 TBool SetupSymbolValues(); |
|
176 TBool SetupSymbolNames(); |
|
177 void Sort(NamedExportSymbol** aDstList, NamedExportSymbol* aSrcList); |
|
178 void MergeSort(NamedExportSymbol** aDstList, NamedExportSymbol** aSrcList); |
|
179 void MergeSort(NamedExportSymbol** aDstList, NamedExportSymbol** aSrcList, \ |
|
180 TUint aLeft, TUint aRight); |
|
181 TBool AddToDependency(TUint aOff); |
|
182 TBool CreateDependency(); |
|
183 OrdZeroRecord* FindDependency(char* aName, TUint aLen); |
|
184 DllRec * SearchImports(char *aName); |
|
185 TInt GetLookupTblSize(){ return iSymInfoHdr.iSize;} |
|
186 void SetLookupTblBase(TInt); |
|
187 void GetExportSymInfoHeader(E32EpocExpSymInfoHdr& aSymInfoHdr); |
|
188 void SetExportSymInfo(); |
|
189 TUint GetSymLookupSection(char* aBuff); |
|
190 }; |
|
191 |
|
192 // This class is used to create symbols to support named lookups. |
|
193 // |
|
194 class NamedExportSymbol |
|
195 { |
|
196 public: |
|
197 NamedExportSymbol(char* aName, Elf32_Addr aValue); |
|
198 ~NamedExportSymbol() |
|
199 { |
|
200 delete iNext; |
|
201 } |
|
202 |
|
203 char* Name() { return iSymbolName;} |
|
204 void Name(char* aName) {iSymbolName = aName;} |
|
205 |
|
206 TUint NameOffset() {return iSymbolNameOffset;} |
|
207 void NameOffset(TUint aOffset) {iSymbolNameOffset = aOffset;} |
|
208 |
|
209 Elf32_Addr Value() { return iValue;} |
|
210 void Value(Elf32_Addr aValue) { iValue = aValue;} |
|
211 |
|
212 NamedExportSymbol* Next() { return iNext;} |
|
213 void Next(NamedExportSymbol* aNext) { iNext = aNext;} |
|
214 |
|
215 Elf32_Rel iReloc; // relocation entry for the symbol address |
|
216 TUint iSymRelocType; // Whether it is a code or data relocation for this symbol |
|
217 private: |
|
218 char* iSymbolName; // Symbol name |
|
219 TInt iSymIdx; |
|
220 TUint iSymbolNameOffset;// offset of name in string table. |
|
221 Elf32_Addr iValue; // symbol value - this is the address of the symbol |
|
222 NamedExportSymbol *iNext; // next symbol |
|
223 }; |
|
224 |
|
225 // This class is used to support symbol lookup of the static dependencies by linking in their |
|
226 // 0th ordinal. |
|
227 class OrdZeroRecord |
|
228 { |
|
229 public: |
|
230 OrdZeroRecord(char* aName): |
|
231 iName(aName), iNext(0){} |
|
232 ~OrdZeroRecord() |
|
233 { |
|
234 delete iNext; |
|
235 } |
|
236 char *iName; // (linkas) name of the dependency |
|
237 Elf32_Rel iReloc; // a relocation entry for the 0th ordinal of each dependency |
|
238 OrdZeroRecord *iNext; // next dependency |
|
239 TUint iOffset; |
|
240 }; |
|
241 struct NeededDLLsList |
|
242 { |
|
243 NeededDLLsList(TUint aOff) : iOffset(aOff), iNext(0) |
|
244 {} |
|
245 ~NeededDLLsList() |
|
246 { |
|
247 delete iNext; |
|
248 } |
|
249 TUint iOffset; |
|
250 NeededDLLsList *iNext; |
|
251 }; |
|
252 |
|
253 #endif |
|
254 |