e32tools/elf2e32/source/pl_elfrelocations.cpp
changeset 0 044383f39525
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     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 ElfRelocations for the elf2e32 tool
       
    15 // @internalComponent
       
    16 // @released
       
    17 // 
       
    18 //
       
    19 
       
    20 #include "pl_elfrelocations.h"
       
    21 #include "pl_elflocalrelocation.h"
       
    22 
       
    23 /**
       
    24 Constructor for class ElfRelocations
       
    25 @internalComponent
       
    26 @released
       
    27 */
       
    28 ElfRelocations::ElfRelocations() : \
       
    29 	iCodeSortedP(false), iDataSortedP(false)
       
    30 {
       
    31 }
       
    32 
       
    33 /**
       
    34 Destructor for class ElfRelocations to release allocated memory
       
    35 @internalComponent
       
    36 @released
       
    37 */
       
    38 ElfRelocations::~ElfRelocations()
       
    39 {
       
    40 	if(iCodeRelocations.size())
       
    41 	{
       
    42 		RelocationList::iterator aItr = iCodeRelocations.begin();
       
    43 		RelocationList::iterator last = iCodeRelocations.end();
       
    44 		ElfLocalRelocation *temp;
       
    45 
       
    46 		while( aItr != last)
       
    47 		{
       
    48 			temp = *aItr;
       
    49 			aItr++;
       
    50 			delete temp;
       
    51 		}
       
    52 		iCodeRelocations.clear();
       
    53 	}
       
    54 	if(iDataRelocations.size())
       
    55 	{
       
    56 		RelocationList::iterator aItr = iDataRelocations.begin();
       
    57 		RelocationList::iterator last = iDataRelocations.end();
       
    58 		ElfLocalRelocation *temp;
       
    59 
       
    60 		while( aItr != last)
       
    61 		{
       
    62 			temp = *aItr;
       
    63 			aItr++;
       
    64 			delete temp;
       
    65 		}
       
    66 		iDataRelocations.clear();
       
    67 	}
       
    68 }
       
    69 
       
    70 
       
    71 /**
       
    72 Function for adding Elf local Relocations.
       
    73 @internalComponent
       
    74 @released
       
    75 @return 0 if therelocation is valid.
       
    76 */
       
    77 PLUINT32 ElfRelocations::Add(ElfLocalRelocation* aReloc){
       
    78 	if(!aReloc) return 1;
       
    79 	
       
    80 	switch (aReloc->iSegmentType)
       
    81 	{
       
    82 	case ESegmentRO:
       
    83 		iCodeSortedP = false;
       
    84 		iCodeRelocations.push_back(aReloc);
       
    85 		break;
       
    86 	case ESegmentRW:
       
    87 		iDataSortedP = false;
       
    88 		iDataRelocations.push_back(aReloc);
       
    89 		break;
       
    90 	default:
       
    91 		;
       
    92 	}
       
    93 
       
    94 	return 0;
       
    95 }
       
    96 
       
    97 /**
       
    98 Function for getting code relocations. The reloc entries are
       
    99 sorted on the address they refer to.
       
   100 @internalComponent
       
   101 @released
       
   102 @return list of code relocation
       
   103 */
       
   104 ElfRelocations::RelocationList & ElfRelocations::GetCodeRelocations()
       
   105 {
       
   106 	if (!iCodeSortedP) 
       
   107 	{
       
   108 		iCodeRelocations.sort(Cmp());
       
   109 		iCodeSortedP = true;
       
   110 	}
       
   111   return iCodeRelocations;
       
   112 }
       
   113 
       
   114 /**
       
   115 Function for getting data relocations. The reloc entries are
       
   116 sorted on the address they refer to.
       
   117 @internalComponent
       
   118 @released
       
   119 @return list of code relocation
       
   120 */
       
   121 ElfRelocations::RelocationList & ElfRelocations::GetDataRelocations()
       
   122 {
       
   123 	if (!iDataSortedP) 
       
   124 	{
       
   125 		iDataRelocations.sort(Cmp());
       
   126 		iDataSortedP = true;
       
   127 	}
       
   128   return iDataRelocations;
       
   129 }
       
   130 
       
   131 /**
       
   132 Overloaded operator for comparing location the relocations refer to.
       
   133 @internalComponent
       
   134 @released
       
   135 @return comparison of both relocation
       
   136 */
       
   137 bool ElfRelocations::Cmp::operator()(ElfRelocation * x, ElfRelocation * y)
       
   138 {
       
   139 	return x->iAddr < y->iAddr;
       
   140 }
       
   141 
       
   142