18 |
18 |
19 |
19 |
20 #include <e32def.h> |
20 #include <e32def.h> |
21 #include <e32std.h> |
21 #include <e32std.h> |
22 #include "elftran.h" |
22 #include "elftran.h" |
23 #include <elfdefs.h> |
23 #include "elfdefs.h" |
24 #include "elffile.h" |
24 #include "elffile.h" |
25 #include "elfdll.h" |
25 #include "elfdll.h" |
26 #include <h_utl.h> |
26 #include "h_utl.h" |
27 #include <string.h> |
27 #include <string.h> |
28 #include <stdlib.h> |
28 #include <stdlib.h> |
29 |
29 |
30 TBool hadText, hadReloc = EFalse; |
30 TBool hadText, hadReloc = EFalse; |
31 |
31 |
32 ELFFile::ELFFile() |
32 ELFFile::ELFFile() |
33 : |
33 : iHeapCommittedSize(0x1000), iHeapReservedSize(0x100000), iStackCommittedSize(0), |
34 iHeapCommittedSize(0x1000), |
34 iFileName(0), iFileHandle(-1) , iElfFile(0), |
35 iHeapReservedSize(0x100000), |
35 iDynamicSegmentHdr(0), iDynamicSegmentIdx(0), |
36 iStackCommittedSize(0), |
36 iCodeSegmentHdr(0), iCodeSegmentIdx(0), |
37 |
37 iDataSegmentHdr(0), iDataSegmentIdx(0), |
38 iFileName(0), |
38 iDllData(0), iCpu(ECpuUnknown) |
39 iFileHandle(-1), |
39 {} |
40 iElfFile(0), |
|
41 |
|
42 iDynamicSegmentHdr(0), |
|
43 iDynamicSegmentIdx(0), |
|
44 |
|
45 iCodeSegmentHdr(0), |
|
46 iCodeSegmentIdx(0), |
|
47 |
|
48 iDataSegmentHdr(0), |
|
49 iDataSegmentIdx(0), |
|
50 |
|
51 iDllData(0), |
|
52 iCpu(ECpuUnknown) |
|
53 {} |
|
54 |
|
55 |
|
56 |
|
57 |
40 |
58 ELFFile::~ELFFile() |
41 ELFFile::~ELFFile() |
59 { |
42 // |
60 delete [] iFileName; |
43 // Destructor |
|
44 // |
|
45 { |
|
46 if(iFileName) |
|
47 delete [] iFileName; |
61 delete iElfFile; |
48 delete iElfFile; |
62 delete iDllData; |
49 delete iDllData; |
63 } |
50 } |
64 |
51 |
65 |
52 |
66 TBool ELFFile::Init(const TText * const aFileName) |
53 TBool ELFFile::Init(const char* aFileName) |
67 // |
54 // |
68 // Read the ELF file into memory |
55 // Read the ELF file into memory |
69 // |
56 // |
70 { |
57 { |
71 |
58 if(iFileName){ |
72 delete [] iFileName; |
59 delete [] iFileName; |
73 iFileName = new TText[strlen((const char *)aFileName)+1]; |
60 iFileName = 0; |
74 strcpy ((char *)iFileName, (const char *)aFileName); |
61 } |
|
62 size_t length = strlen(aFileName) + 1 ; |
|
63 iFileName = new char[length]; |
|
64 memcpy (iFileName, aFileName,length); |
75 |
65 |
76 TInt error = HFile::Open(iFileName, &iFileHandle); |
66 TInt error = HFile::Open(iFileName, &iFileHandle); |
77 if (error!=0) |
67 if (error!=0) |
78 return EFalse; |
68 return EFalse; |
79 |
69 |
455 #define ORDINAL_DONE 0x40000000 |
445 #define ORDINAL_DONE 0x40000000 |
456 |
446 |
457 |
447 |
458 // The following static functions are passed an array of PE files to operate on |
448 // The following static functions are passed an array of PE files to operate on |
459 |
449 |
460 Elf32_Sym * ELFFile::FindSymbol(const TText *aName) |
450 Elf32_Sym * ELFFile::FindSymbol(const char* aName) |
461 { |
451 { |
462 Elf32_Shdr * s = ELFADDR(Elf32_Shdr, iElfFile, iElfFile->e_shoff); |
452 Elf32_Shdr * s = ELFADDR(Elf32_Shdr, iElfFile, iElfFile->e_shoff); |
463 TInt symIdx = iSymIdx; |
453 TInt symIdx = iSymIdx; |
464 Elf32_Sym * sym = iSymTab; |
454 Elf32_Sym * sym = iSymTab; |
465 TInt nSyms = s[symIdx].sh_size / s[symIdx].sh_entsize; |
455 TInt nSyms = s[symIdx].sh_size / s[symIdx].sh_entsize; |
470 return &sym[jdx]; |
460 return &sym[jdx]; |
471 } |
461 } |
472 return (Elf32_Sym *)0; |
462 return (Elf32_Sym *)0; |
473 } |
463 } |
474 |
464 |
475 TBool ELFFile::SymbolPresent(TText *aName) |
465 TBool ELFFile::SymbolPresent(const char* aName) |
476 { |
466 { |
477 return (FindSymbol(aName) != 0); |
467 return (FindSymbol(aName) != 0); |
478 } |
468 } |
479 |
469 |
480 TBool ELFFile::GetExceptionIndexInfo(TUint32 &aOffset) |
470 TBool ELFFile::GetExceptionIndexInfo(TUint32 &aOffset) |
481 { |
471 { |
482 const TText * aBase = (TText *)".ARM.exidx$$Base"; |
472 Elf32_Sym * exidxBase = FindSymbol(".ARM.exidx$$Base"); |
483 const TText * aLimit = (TText *)".ARM.exidx$$Limit"; |
473 Elf32_Sym * exidxLimit = FindSymbol(".ARM.exidx$$Limit"); |
484 Elf32_Sym * exidxBase = FindSymbol(aBase); |
|
485 Elf32_Sym * exidxLimit = FindSymbol(aLimit); |
|
486 if (exidxBase && exidxLimit && (exidxLimit->st_value - exidxBase->st_value)) |
474 if (exidxBase && exidxLimit && (exidxLimit->st_value - exidxBase->st_value)) |
487 { |
475 { |
488 const TText * aExceptionDescriptor = (TText *)"Symbian$$CPP$$Exception$$Descriptor"; |
476 Elf32_Sym * aED = FindSymbol("Symbian$$CPP$$Exception$$Descriptor"); |
489 Elf32_Sym * aED = FindSymbol(aExceptionDescriptor); |
|
490 if (aED) |
477 if (aED) |
491 { |
478 { |
492 // Set bottom bit so 0 in header slot means an old binary. |
479 // Set bottom bit so 0 in header slot means an old binary. |
493 // The decriptor is always aligned on a 4 byte boundary. |
480 // The decriptor is always aligned on a 4 byte boundary. |
494 aOffset = (aED->st_value - iLinkedBase) | 0x00000001; |
481 aOffset = (aED->st_value - iLinkedBase) | 0x00000001; |