e32tools/elf2e32/source/pl_elfrelocation.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 ElfRelocation for the elf2e32 tool
       
    15 // @internalComponent
       
    16 // @released
       
    17 // 
       
    18 //
       
    19 
       
    20 #include "pl_elfrelocation.h"
       
    21 #include "pl_elfimportrelocation.h"
       
    22 #include "pl_elflocalrelocation.h"
       
    23 #include "pl_dllsymbol.h"
       
    24 
       
    25 /**
       
    26 Constructor for class ElfRelocation
       
    27 @param aElfExec - Instance of class ELfExecutable
       
    28 @param aAddr
       
    29 @param aAddend
       
    30 @param aIndex
       
    31 @param aRelType - Relocation type
       
    32 @param aRel
       
    33 @internalComponent
       
    34 @released
       
    35 */
       
    36 ElfRelocation::ElfRelocation(ElfExecutable *aElfExec, PLMemAddr32 aAddr, \
       
    37 			PLUINT32 aAddend, PLUINT32 aIndex, PLUCHAR aRelType, \
       
    38 			Elf32_Rel* aRel) : iAddr(aAddr), iAddend(aAddend), \
       
    39 			iSymNdx(aIndex), iRelType(aRelType), iRel(aRel),  iElfExec(aElfExec)
       
    40 {
       
    41 }
       
    42 
       
    43 
       
    44 
       
    45 /**
       
    46 Destructor for class ElfRelocation
       
    47 @internalComponent
       
    48 @released
       
    49 */
       
    50 ElfRelocation::~ElfRelocation(){
       
    51 
       
    52 }
       
    53 
       
    54 
       
    55 /**
       
    56 Function to create new relocation entry
       
    57 @param aElfExec - Instance of class ElfExecutable
       
    58 @param aAddr    - location where the relocation refers to.
       
    59 @param aAddend  - addend for the relocation entry
       
    60 @param aIndex   - symbol index
       
    61 @param aRelType - Relocation type
       
    62 @param aRel     - Elf relocation entry
       
    63 @param aImportRel - Import relocation
       
    64 @internalComponent
       
    65 @released
       
    66 */
       
    67 ElfRelocation* ElfRelocation::NewRelocEntry(ElfExecutable *aElfExec, PLMemAddr32 aAddr, \
       
    68 				PLUINT32 aAddend, PLUINT32 aIndex, PLUCHAR aRelType, \
       
    69 				void* aRel, bool aImportRel)
       
    70 {
       
    71 	ElfRelocation	*aReloc = NULL;
       
    72 	if(aImportRel)
       
    73 		aReloc = new ElfImportRelocation(aElfExec, aAddr, aAddend, aIndex, aRelType, (Elf32_Rel*)aRel);
       
    74 	else
       
    75 		aReloc = new ElfLocalRelocation(aElfExec, aAddr, aAddend, aIndex, aRelType, (Elf32_Rel*)aRel);
       
    76 
       
    77 	return aReloc;
       
    78 }
       
    79 
       
    80 
       
    81 /**
       
    82 This function verifies if the relocation entry is required to be
       
    83 handled by the postlinker.
       
    84 @param aType - type of relocation
       
    85 @return - True if valid relocation type, otherwise false
       
    86 @internalComponent
       
    87 @released
       
    88 */
       
    89 bool ElfRelocation::ValidRelocEntry(PLUCHAR aType) {
       
    90 	
       
    91 	switch(aType)
       
    92 	{
       
    93 	case R_ARM_ABS32:
       
    94 	case R_ARM_GLOB_DAT:
       
    95 	case R_ARM_JUMP_SLOT:
       
    96 	case R_ARM_RELATIVE:
       
    97 	case R_ARM_GOT_BREL:
       
    98 		return true;
       
    99 	case R_ARM_NONE:
       
   100 		return false;
       
   101 	default:
       
   102 		return false;
       
   103 	}
       
   104 }
       
   105 
       
   106