Пример #1
0
/**
This function initializes the Elf members
@internalComponent
@released
*/
void ElfProducer::InitElfContents() {

	iElfHeader		= new Elf32_Ehdr;
	iSections		= new Elf32_Shdr[MAX_SECTIONS+1];

	iElfDynSym		= new Elf32_Sym[iNSymbols];
	iVersionTbl		= new Elf32_Half[iNSymbols];
	iVersionDef		= new Elf32_Verdef[2];
	iDSODaux		= new Elf32_Verdaux[2];

	iProgHeader		 = new Elf32_Phdr[2];
	iCodeSectionData = new PLUINT32[iNSymbols];	

	iHashTbl = new Elf32_HashTable;
	
	//premeditated
	iHashTbl->nBuckets = (iNSymbols /3) + (iNSymbols % 0x3);
	
	iHashTbl->nChains = iNSymbols;

	iDSOBuckets = new Elf32_Sword[iHashTbl->nBuckets];
	iDSOChains = new Elf32_Sword[iHashTbl->nChains];

	Elf32_Sword	aNullPtr = 0;

	memset(iDSOBuckets, aNullPtr, sizeof(Elf32_Sword)*iHashTbl->nBuckets);
	memset(iDSOChains,  aNullPtr, sizeof(Elf32_Sword)*iHashTbl->nChains);
	memset(iCodeSectionData,  0, sizeof(PLUINT32)*iNSymbols);

	CreateElfHeader();

	SymbolList::iterator aItr = iSymbolsList->begin();
	SymbolList::iterator aEnd = iSymbolsList->end();
	Symbol		*aSym;
	PLUINT32	aIdx = 1;

	memset( &iElfDynSym[0], 0, sizeof(Elf32_Sym));
	iDSOSymNameStrTbl.insert(iDSOSymNameStrTbl.end(), 0);

	while(aItr != aEnd) {
		String		aSymName("");
		aSym = *aItr;
		aSymName = aSym->SymbolName();
		//set symbol info..
		iElfDynSym[aIdx].st_name = iDSOSymNameStrTbl.size();

		iDSOSymNameStrTbl.insert(iDSOSymNameStrTbl.end(), aSymName.begin(), aSymName.end() );
		iDSOSymNameStrTbl.insert(iDSOSymNameStrTbl.end(), 0);

		SetSymolFields( aSym, &iElfDynSym[aIdx], aIdx);

		//set version table info...
		iVersionTbl[aIdx] = DEFAULT_VERSION;
		AddToHashTable(aSym->SymbolName(), aIdx);
		aItr++;aIdx++;
	}

	CreateVersionTable();
	
	//Fill section headers...
	CreateSections();

	//Copy dyn entries..
	CreateDynamicEntries();

	//create code section data - this has the ordinal numbers...
	CreateProgHeader();
}
Пример #2
0
/**
Function to generate ASM File.
@param afileName - ASM File name
@return 0 on success, otherwise throw error
@internalComponent
@released
*/
int FileDump::GenerateAsmFile(const char* afileName)//DumpAsm
{
    DefFile *iDefFile = new DefFile();
    SymbolList *aSymList;
    aSymList = iDefFile->ReadDefFile(iParameterListInterface->DefInput());

    FILE *fptr;

    if((fptr=fopen(afileName,"w"))==NULL)
    {
        throw FileError(FILEOPENERROR,(char*)afileName);
    }
    else
    {
        SymbolList::iterator aItr = aSymList->begin();
        SymbolList::iterator last = aSymList->end();
        Symbol *aSym;

        while( aItr != last)
        {
            aSym = *aItr;

            if(aSym->Absent())
            {
                aItr++;
                continue;
            }

            fputs("\tIMPORT ",fptr);
            fputs(aSym->SymbolName(),fptr);
            //Set the visibility of the symbols as default."DYNAMIC" option is
            //added to remove STV_HIDDEN visibility warnings generated by every
            //export during kernel build
            fputs(" [DYNAMIC]", fptr);
            fputs("\n",fptr);
            aItr++;
        }

        // Create a directive section that instructs the linker to make all listed
        // symbols visible.

        fputs("\n AREA |.directive|, READONLY, NOALLOC\n\n",fptr);

        fputs("\tDCB \"#<SYMEDIT>#\\n\"\n", fptr);

        aItr = aSymList->begin();
        while (aItr != last)
        {
            aSym = *aItr;

            if ( aSym->Absent() )
            {
                aItr++;
                continue;
            }

            // Example:
            //  DCB "EXPORT __ARM_ll_mlass\n"
            fputs("\tDCB \"EXPORT ",fptr);
            fputs(aSym->SymbolName(),fptr);
            fputs("\\n\"\n", fptr);

            aItr++;
        }

        fputs("\n END\n",fptr);
        fclose(fptr);
    }
    return 0;
}