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

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

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

Dave Brolley-2
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  <[hidden email]>

        * 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,