|
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 ElfLocalRelocation for the elf2e32 tool |
|
15 // @internalComponent |
|
16 // @released |
|
17 // |
|
18 // |
|
19 |
|
20 #include "pl_elflocalrelocation.h" |
|
21 #include "pl_elfexecutable.h" |
|
22 #include "e32imagedefs.h" |
|
23 |
|
24 /** |
|
25 Constructor for class ElfLocalRelocation |
|
26 @param aElfExec - Instance of class ElfExecutable |
|
27 @param aAddr - location where the relocation refers to. |
|
28 @param aAddend - addend for the relocation entry |
|
29 @param aIndex - symbol index |
|
30 @param aRelType - Relocation type |
|
31 @param aRel - Elf relocation entry |
|
32 @internalComponent |
|
33 @released |
|
34 */ |
|
35 ElfLocalRelocation::ElfLocalRelocation(ElfExecutable *aElfExec, PLMemAddr32 aAddr, \ |
|
36 PLUINT32 aAddend, PLUINT32 aIndex, PLUCHAR aRelType, \ |
|
37 Elf32_Rel* aRel, bool aVeneerSymbol): \ |
|
38 ElfRelocation(aElfExec, aAddr, aAddend, aIndex, aRelType, aRel) |
|
39 { |
|
40 iSegment = aElfExec->Segment( iAddr ); |
|
41 iSegmentType = aElfExec->SegmentType( iAddr ); |
|
42 iSymbol = &(aElfExec->iElfDynSym[iSymNdx]); |
|
43 iDelSym = false; |
|
44 iVeneerSymbol = aVeneerSymbol; |
|
45 } |
|
46 |
|
47 /** |
|
48 Constructor for class ElfLocalRelocation |
|
49 @param aElfExec - Instance of class ElfExecutable |
|
50 @param aAddr - location where the relocation refers to. |
|
51 @param aAddend - addend for the relocation entry |
|
52 @param aIndex |
|
53 @param aRelType - Relocation type |
|
54 @param aRel - Elf relocation entry |
|
55 @param aSegmentType - Segment type |
|
56 @param aSym - Elf symbol |
|
57 @param aDelSym - indicate if the symbol is to be deleted by this relocation. |
|
58 @internalComponent |
|
59 @released |
|
60 */ |
|
61 ElfLocalRelocation::ElfLocalRelocation(ElfExecutable *aElfExec, PLMemAddr32 aAddr, \ |
|
62 PLUINT32 aAddend, PLUINT32 aIndex, PLUCHAR aRelType, \ |
|
63 Elf32_Rel* aRel, ESegmentType aSegmentType, Elf32_Sym* aSym,bool aDelSym, bool aVeneerSymbol): \ |
|
64 ElfRelocation(aElfExec, aAddr, aAddend, aIndex, aRelType, aRel) |
|
65 { |
|
66 iSegmentType = aSegmentType; |
|
67 iSegment = aElfExec->Segment(aSegmentType); |
|
68 //iSymbol = &(aElfExec->iElfDynSym[iSymNdx]); |
|
69 iSymbol = aSym; |
|
70 iDelSym = aDelSym; |
|
71 iVeneerSymbol = aVeneerSymbol; |
|
72 } |
|
73 |
|
74 |
|
75 /** |
|
76 Destructor for class ElfLocalRelocation |
|
77 @internalComponent |
|
78 @released |
|
79 */ |
|
80 ElfLocalRelocation::~ElfLocalRelocation() |
|
81 { |
|
82 if(iDelSym) |
|
83 { |
|
84 DELETE_PTR(iSymbol); |
|
85 } |
|
86 |
|
87 } |
|
88 |
|
89 |
|
90 /** |
|
91 This function overrides the virtual function to indicate that this |
|
92 relocation is not an import relocation. |
|
93 @return false |
|
94 @internalComponent |
|
95 @released |
|
96 */ |
|
97 bool ElfLocalRelocation::IsImportRelocation(){ |
|
98 return false; |
|
99 } |
|
100 |
|
101 /** |
|
102 Function to add local relocations |
|
103 @internalComponent |
|
104 @released |
|
105 */ |
|
106 void ElfLocalRelocation::Add() { |
|
107 iElfExec->AddToLocalRelocations(this); |
|
108 } |
|
109 |
|
110 /** |
|
111 This function adjusts the fixup for the relocation entry. |
|
112 @return - Relocation type |
|
113 @internalComponent |
|
114 @released |
|
115 */ |
|
116 PLUINT16 ElfLocalRelocation::Fixup() |
|
117 { |
|
118 if(!ExportTableReloc() && !iVeneerSymbol) |
|
119 { |
|
120 Elf32_Word * aLoc = iElfExec->GetFixupLocation(this, iAddr); |
|
121 Elf32_Word aLocVal = * aLoc; |
|
122 |
|
123 if (iRelType == R_ARM_ABS32 || iRelType == R_ARM_GLOB_DAT ) |
|
124 { |
|
125 |
|
126 Elf32_Word aFixedVal = aLocVal + iSymbol->st_value; |
|
127 *aLoc = aFixedVal; |
|
128 } |
|
129 } |
|
130 |
|
131 ESegmentType aType; |
|
132 if( iSymbol ) |
|
133 aType = iElfExec->Segment(iSymbol); |
|
134 else |
|
135 aType = iSegmentType; |
|
136 |
|
137 if (aType == ESegmentRO) |
|
138 return KTextRelocType; |
|
139 else if (aType == ESegmentRW) |
|
140 return KDataRelocType; |
|
141 |
|
142 // maybe this should be an error |
|
143 return KInferredRelocType; |
|
144 } |
|
145 |
|
146 /** |
|
147 Function for export table relocation |
|
148 @return - True |
|
149 @internalComponent |
|
150 @released |
|
151 */ |
|
152 bool ElfLocalRelocation::ExportTableReloc() |
|
153 { |
|
154 return iRel == 0; |
|
155 } |
|
156 |
|
157 |
|
158 |