This is the mail archive of the sid@sourceware.org mailing list for the SID project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch][commit] 64 Bit Support for elf Symbol Table and String Table


Hi,

I've committed the attached patch which adds 64 bit support for the symbol table and string table in the elf loader. Tested on an internal port which required the support.

Dave

2006-05-11  Dave Brolley  <brolley@redhat.com>

	* elfload.c (readElfFile): symTabEntry is now 24 bytes in length.
	Add 64 bit support for SHT_STRTAB and SHT_SYMTAB. Add 64 bit support
	for reading the symbol table.

Index: sid/component/loader/elfload.c
===================================================================
RCS file: /cvs/src/src/sid/component/loader/elfload.c,v
retrieving revision 1.12
diff -c -p -r1.12 elfload.c
*** sid/component/loader/elfload.c	19 Aug 2005 19:45:22 -0000	1.12
--- sid/component/loader/elfload.c	11 May 2006 15:03:36 -0000
***************
*** 1,6 ****
  /* Simple ELF loader
   *
!  * Copyright (c) 1998, 2002, 2004, 2005 Red Hat
   *
   * The authors hereby grant permission to use, copy, modify, distribute,
   * and license this software and its documentation for any purpose, provided
--- 1,6 ----
  /* Simple ELF loader
   *
!  * Copyright (c) 1998, 2002, 2004, 2005, 2006 Red Hat
   *
   * The authors hereby grant permission to use, copy, modify, distribute,
   * and license this software and its documentation for any purpose, provided
*************** readElfFile (PFLOAD func, unsigned* entr
*** 119,125 ****
    unsigned char fileHeader [64];
    unsigned char psymHdr [56];
    unsigned char secHdr [64];
!   unsigned char symTabEntry [16];
    unsigned long long psymOffset;
    int psymSize;
    int psymNum;
--- 119,125 ----
    unsigned char fileHeader [64];
    unsigned char psymHdr [56];
    unsigned char secHdr [64];
!   unsigned char symTabEntry [24];
    unsigned long long psymOffset;
    int psymSize;
    int psymNum;
*************** readElfFile (PFLOAD func, unsigned* entr
*** 284,289 ****
--- 284,307 ----
  	      textSectionCount++;
  	      newTextSection (textSectionCount);
  	    }
+ 	  else if (fetchWord(secHdr+4, littleEndian) == SHT_STRTAB)
+ 	    {
+ 	      unsigned offset = fetchQuad(secHdr+24, littleEndian);
+ 	      unsigned size = fetchQuad(secHdr+32, littleEndian);
+ 	      char *strings = xmalloc (size);
+ 	      newStringTable (stringTableCount);
+ 	      stringTables[stringTableCount].ix = x;
+ 	      stringTables[stringTableCount].strings = strings;
+ 	      if (func (0, strings, offset, size, 0) != size)
+ 		return 0;
+ 	      ++stringTableCount;
+ 	    }
+ 	  else if (fetchWord(secHdr+4, littleEndian) == SHT_SYMTAB)
+ 	    {
+ 	      symbolTableOffset = fetchQuad(secHdr+24, littleEndian);
+ 	      symbolTableSize = fetchQuad(secHdr+32, littleEndian);
+ 	      symbolTableStringTableIx = fetchWord(secHdr+40, littleEndian);
+ 	    }
          }
        else
          {
*************** readElfFile (PFLOAD func, unsigned* entr
*** 341,355 ****
    newSymbol (symbolCount);
    if (strings)
      {
!       for (x = 0; x < symbolTableSize; x += sizeof (symTabEntry))
  	{
! 	  if (func (0, symTabEntry, symbolTableOffset + x, sizeof (symTabEntry), 0) != sizeof (symTabEntry))
  	    return 0;
  	  // TODO: Save only symbols representing functions
  	  // PROBLEM: Some don't have the STT_FUNC flag set
! 	  symbolTable[symbolCount].name = strings + fetchWord(symTabEntry+0, littleEndian);
! 	  symbolTable[symbolCount].addr = fetchWord(symTabEntry+4, littleEndian);
! 	  symbolTable[symbolCount].size = fetchWord(symTabEntry+8, littleEndian);
  #if 0
  	  printf ("found symbol %s at 0x%Lx for 0x%Lx\n",
  		  symbolTable[symbolCount].name,
--- 359,383 ----
    newSymbol (symbolCount);
    if (strings)
      {
!       const unsigned symTabEntrySize = sixtyfourbit ? 24 : 16;
!       for (x = 0; x < symbolTableSize; x += symTabEntrySize)
  	{
! 	  if (func (0, symTabEntry, symbolTableOffset + x, symTabEntrySize, 0) != symTabEntrySize)
  	    return 0;
  	  // TODO: Save only symbols representing functions
  	  // PROBLEM: Some don't have the STT_FUNC flag set
! 	  if (sixtyfourbit)
! 	    {
! 	      symbolTable[symbolCount].name = strings + fetchWord(symTabEntry+0, littleEndian);
! 	      symbolTable[symbolCount].addr = fetchQuad(symTabEntry+8, littleEndian);
! 	      symbolTable[symbolCount].size = fetchQuad(symTabEntry+16, littleEndian);
! 	    }
! 	  else
! 	    {
! 	      symbolTable[symbolCount].name = strings + fetchWord(symTabEntry+0, littleEndian);
! 	      symbolTable[symbolCount].addr = fetchWord(symTabEntry+4, littleEndian);
! 	      symbolTable[symbolCount].size = fetchWord(symTabEntry+8, littleEndian);
! 	    }
  #if 0
  	  printf ("found symbol %s at 0x%Lx for 0x%Lx\n",
  		  symbolTable[symbolCount].name,

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]