toolsandutils/e32tools/elf2e32/source/e32exporttable.cpp
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     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 //
       
    15 
       
    16 #include "e32exporttable.h"
       
    17 #include "pl_elfexecutable.h"
       
    18 #include "pl_elfexports.h"
       
    19 #include "pl_dllsymbol.h"
       
    20 #include "pl_elflocalrelocation.h"
       
    21 
       
    22 /**
       
    23 Destructor for E32ExportTable class.
       
    24 @internalComponent
       
    25 @released
       
    26 */
       
    27 E32ExportTable::~E32ExportTable()
       
    28 {
       
    29 	delete [] iTable;
       
    30 }
       
    31 
       
    32 /**
       
    33 This function updates the e32 export table.
       
    34 @param aElfExecutable - Elf executable
       
    35 @param aExportList - export symbol list
       
    36 @internalComponent
       
    37 @released
       
    38 */
       
    39 void E32ExportTable::CreateExportTable(ElfExecutable * aElfExecutable, ElfExports::ExportList & aExportList)
       
    40 {
       
    41 	iElfExecutable = aElfExecutable;
       
    42 	// ELFExports::ExportList aExportList = aElfExecutable->GetExportsInOrdinalOrder();
       
    43 	// The export table has a header containing the number of entries
       
    44 	// before the entries themselves. So add 1 to number of exports
       
    45 	iNumExports = aExportList.size();
       
    46 	size_t aSize = iNumExports + 1;
       
    47 	iSize = aSize * sizeof(MemAddr);
       
    48 	iTable = new unsigned int[aSize];
       
    49 	// Set up header
       
    50 	iTable[0] = aExportList.size();
       
    51 	Elf32_Phdr * aROHdr = aElfExecutable->iCodeSegmentHdr;
       
    52 	// The export table starts after the header. NB this is a virtual address in the RO
       
    53 	// segment of the E32Image. It is outside the ELF RO segment.
       
    54 	Elf32_Addr * aPlace =  ELF_ENTRY_PTR(Elf32_Addr, aROHdr->p_vaddr, aROHdr->p_filesz) + 1;
       
    55 	iExportTableAddress = (Elf32_Addr)aPlace;
       
    56 	// Tell the E32Image constructor that it must allocate the export table
       
    57 	// i.e. copy it from iTable.
       
    58 	iAllocateP = true;
       
    59 	bool aDelSym;
       
    60 	ElfExports::ExportList::iterator first = aExportList.begin();
       
    61 	for (PLUINT32 i = 1; i < aSize; i++, first++) 
       
    62 	{
       
    63 		Elf32_Sym * sym;
       
    64 
       
    65 		unsigned int ptr;
       
    66 		if ((*first)->Absent())
       
    67 		{
       
    68 			ptr = aElfExecutable->iEntryPoint;
       
    69 			sym = new Elf32_Sym;
       
    70 			memset(sym, 0, sizeof(Elf32_Sym));
       
    71 			sym->st_value = ptr;
       
    72 			aDelSym = true;
       
    73 		}
       
    74 		else
       
    75 		{
       
    76 			ptr = (*first)->iElfSym->st_value;
       
    77 			sym = (*first)->iElfSym;
       
    78 			aDelSym = false;
       
    79 		}
       
    80 		// set up the pointer
       
    81 		iTable[i] = ptr;
       
    82 		ElfLocalRelocation * aRel = new ElfLocalRelocation(iElfExecutable, (Elf32_Addr)aPlace++, 0, i, R_ARM_ABS32, NULL, ESegmentRO, sym, aDelSym);														   
       
    83 		aRel->Add();
       
    84 
       
    85 	}
       
    86 }
       
    87 
       
    88 /**
       
    89 This function returns the number of exports.
       
    90 @internalComponent
       
    91 @released
       
    92 */
       
    93 size_t E32ExportTable::GetNumExports()
       
    94 {
       
    95 	return iNumExports;
       
    96 }
       
    97 
       
    98 /**
       
    99 This function tells the e32 image allocator if space is required to 
       
   100 be allocated for export table.
       
   101 @internalComponent
       
   102 @released
       
   103 */
       
   104 bool E32ExportTable::AllocateP(){ 
       
   105 	return iAllocateP;
       
   106 }
       
   107 
       
   108 /**
       
   109 This function returns the e32 export table size.
       
   110 @internalComponent
       
   111 @released
       
   112 */
       
   113 size_t E32ExportTable::GetExportTableSize(){ 
       
   114 	return iSize;
       
   115 }
       
   116 
       
   117 /**
       
   118 This function returns e32 export table.
       
   119 @internalComponent
       
   120 @released
       
   121 */
       
   122 unsigned int * E32ExportTable::GetExportTable() {
       
   123 	 return iTable; 
       
   124 }
       
   125