OSDN Git Service

2019/02/17(Sun) 20:31
authorKoine Yuusuke(koinec) <koinec@users.osdn.me>
Sun, 17 Feb 2019 11:31:01 +0000 (20:31 +0900)
committerKoine Yuusuke(koinec) <koinec@users.osdn.me>
Sun, 17 Feb 2019 11:31:01 +0000 (20:31 +0900)
 (LibGoblin)
  * WorkBackup

libgoblin/drd64_libgoblin_binaryfile.c
libgoblin/drd64_libgoblin_debug_objinfo.c
libgoblin/drd64_libgoblin_elf.c
libgoblin/drd64_libgoblin_elf_section.c
libgoblin/drd64_libgoblin_elf_symtab.c
libgoblin/drd64_libgoblin_type.h

index 3828559..c73d8a2 100644 (file)
@@ -61,12 +61,17 @@ void
        BinaryFile_ClearBinaryFile(
                        LibGoblin_BinaryFile    *p_binfile )
 {
+       int             i_cnt;
+
        assert( NULL != p_binfile );
 
        memset( p_binfile, 0x00, sizeof( LibGoblin_BinaryFile ) );
 
        p_binfile->i_id = -0x01;
 
+       for( i_cnt = 0; i_cnt < LIBGOBLIN_SECTION_ID_MAX; i_cnt++ )
+               { p_binfile->i_secindex[i_cnt]  = -0x01; }
+
        return;
 }
 
index a004a3f..41d601e 100644 (file)
@@ -37,15 +37,15 @@ Comment:
 #define        DRD64_SRC_LIBGOBLIN_DEBUG_OBJINFO
 #include"drd64_libgoblin.h"
 
-static char    gstr_type[256][8]       = {
+static char    gstr_type[256][9]       = {
        "NULL",
        "MASTER",
        "PROGHDR",
        "SECTION",
-       "",
-       "",
-       "",
-       "",
+       "FUNCTION",
+       "OBJECT",
+       "COMMON",
+       "TLS",
        "", "", "", "", "", "", "", "",
        "", "", "", "", "", "", "", "",
        "", "", "", "", "", "", "", "",
@@ -202,8 +202,6 @@ void
                                pstr_space, p_obj->info.section.qw_entsize,
                                p_obj->info.section.dw_link, p_obj->info.section.dw_info );
 
-       printf(" %s\n", pstr_space );
-
        return;
 }
 
@@ -263,7 +261,6 @@ void
 
        printf(" %s\t\t[PROGHDR] Flag[%5s] Type: %s, align= %ld\n",
                                pstr_space, str_flag, str_type, p_obj->info.proghdr.qw_align );
-       printf(" %s\n", pstr_space );
 
        return;
 }
@@ -318,6 +315,7 @@ void
                default:
                        break;
        }
+       printf(" %s\n", pstr_space );
 
        *(pstr_space + i_len)   = '\0';
 
index 2e9fe77..b33cc15 100644 (file)
@@ -164,9 +164,13 @@ int
                return i_result;
        }
 
-       Debug_ObjectInfo_Print_AllGroupLink( p_pginfo, 0xff );
-
        /* Read SymbolTable to ObjectInfo ---------------------*/
+       i_result        = ELF64_Symtab_ReadSection( p_binfo );
+       if( 0x00 != i_result )  {
+               return i_result;
+       }
+
+       Debug_ObjectInfo_Print_AllGroupLink( p_pginfo, 0xff );
 
        /* Create Symbol-Table ------------------*/
 /*
index 5539605..f8c21c8 100644 (file)
@@ -100,6 +100,9 @@ int
                                // sh_addr - Address in memory image.
                                p_sectbl->ptr_addr.value        = p_sechdr->sh_addr;
                                p_sectbl->i_fid                         = p_binfo->i_filetype;
+                               p_sectbl->w_index                       = (Word)i_cnt;
+
+                               p_bfile->i_secindex[ i_cnt ]    = i_index;
                                break;
                        }
                }
@@ -117,7 +120,10 @@ int
                        // sh_addr - Address in memory image.
                        p_sectbl->ptr_addr.value        = p_sechdr->sh_addr;
                        p_sectbl->i_fid                         = p_binfo->i_filetype;
+                       p_sectbl->w_index                       = (Word)i_cnt;
                                
+                       p_bfile->i_secindex[ i_cnt ]    = i_user_section;
+
                        i_user_section++;
                }
 
index 37a3311..251f39e 100644 (file)
@@ -47,35 +47,101 @@ int
 {
 
        Byte            *pb_symtab;
+       Byte            *pb_strtab;
        int                     i_result        = 0x00;
        DWord           dw_symbols;
        DWord           dw_cnt;
        Elf64_Shdr      *p_shdr;
        Elf64_Sym       *p_sym  = NULL;
        LibGoblin_SectionInfo   *p_secinfo;
+       LibGoblin_SectionInfo   *p_secstr;
+       LibGoblin_SrcFile               *p_srcfile;
+       LibGoblin_ObjectInfo    *p_obj;
+       LibGoblin_ProgramInfo   *p_pginfo;
        
        assert( NULL != p_binfo );
 
        // Check BinaryInfo & Get SymbolEntires
        p_secinfo       = LibGoblin_Section_GetSectionInfo_fid(
-                                               p_binfo, LIBGOBLIN_SECTION_ID_SYMTAB );
+                                                       p_binfo, LIBGOBLIN_SECTION_ID_SYMTAB );
        if( NULL == p_secinfo ) {
                return 0x00;
        }
+       pb_symtab       = p_secinfo->pb_data;
+
+       p_secstr        = LibGoblin_Section_GetSectionInfo_fid(
+                                                       p_binfo, LIBGOBLIN_SECTION_ID_STRTAB );
+       if( NULL == p_secstr )  {
+               return 0x00;
+       }
+       pb_strtab       = p_secstr->pb_data;
 
        p_shdr  = (Elf64_Shdr *)(p_secinfo->pb_sechdr);
        if( 0 == p_shdr->sh_entsize )   {
                return -0x02;
        }
        dw_symbols      = (DWord)p_shdr->sh_size / (DWord)p_shdr->sh_entsize;
-       pb_symtab       = p_secinfo->pb_data;
+
+       p_pginfo        = ProgInfo_GetProgInfo( p_binfo->i_pginfo );
+       assert( NULL != p_pginfo );
 
        p_sym   = (Elf64_Sym *)pb_symtab;
        for( dw_cnt = 0; ((dw_cnt < dw_symbols) && (0x00 == i_result)); dw_cnt++, p_sym++ )     {
 
-
-
+               // Source file.
+               if( STT_FILE == ELF64_ST_TYPE( p_sym->st_info ) )       {
+                       p_srcfile       = SrcFile_DispenseSrcFile( (char *)pb_strtab + p_sym->st_name );
+                       assert( NULL != p_srcfile );
+                       continue;
+               }
+
+               if(( 0x00000000 == p_sym->st_value )
+                               && ( STT_NOTYPE == ELF64_ST_TYPE( p_sym->st_info ) ))
+                       { continue; }
+
+       // st_value - Symbol value.
+       // st_size - Size of associated object.
+               p_obj   = ObjectInfo_InsetObject( p_pginfo,
+                                                       (PtrValue)p_sym->st_value, (QWord)p_sym->st_size, NULL, 0x01 );
+
+       // st_name - String table index of name.
+               p_obj->pstr_name        = (char *)(pb_strtab + p_sym->st_name);
+
+       // st_info - Type and binding information.
+               p_obj->info.symbol.b_type       = ELF64_ST_TYPE( p_sym->st_info );
+               switch( ELF64_ST_TYPE( p_sym->st_info ) )       {
+                       // Unspecified type.
+                       case STT_NOTYPE:
+                               p_obj->b_type   = OBJINFO_TYPE_NULL;            break;
+                       // Data object.
+                       case STT_OBJECT:
+                               p_obj->b_type   = OBJINFO_TYPE_OBJECT;          break;
+                       // Function.
+                       case STT_FUNC:
+                               p_obj->b_type   = OBJINFO_TYPE_FUNCTION;        break;
+                       // Section.
+                       case STT_SECTION:
+                               p_obj->b_type   = OBJINFO_TYPE_SECTION;         break;
+                       // Uninitialized common block.
+                       case STT_COMMON:
+                               p_obj->b_type   = OBJINFO_TYPE_COMMON;          break;
+                       // TLS object.
+                       case STT_TLS:
+                               p_obj->b_type   = OBJINFO_TYPE_TLS;             break;
+                       default:
+                               p_obj->b_type   = OBJINFO_TYPE_NULL;            break;
+               }
+
+       // st_info - Type and binding information.
+               p_obj->info.symbol.b_binding    = ELF64_ST_BIND( p_sym->st_info );
+
+               // st_other - Reserved (not used).
+               p_obj->info.symbol.b_visibility = p_sym->st_other;
+
+               // st_shndx - Section index of symbol.
+               p_obj->info.symbol.w_secindex   = p_sym->st_shndx;
        }
+
        if( 0x00 != i_result )  {
                return -0x04;
        }
index 9dfd63d..6d16c16 100644 (file)
@@ -42,6 +42,7 @@ Comment:
 typedef struct {
        Byte    *pb_sechdr;
        Byte    *pb_data;               // FileLocation (Offset)
+       Word    w_index;
        Ptr             ptr_addr;
        QWord   qw_size;
        char    *pstr_secname;
@@ -69,6 +70,10 @@ typedef struct       {
 #define        OBJINFO_TYPE_MASTER             0x01
 #define        OBJINFO_TYPE_PROGHDR    0x02
 #define        OBJINFO_TYPE_SECTION    0x03
+#define        OBJINFO_TYPE_FUNCTION   0x04
+#define        OBJINFO_TYPE_OBJECT             0x05
+#define        OBJINFO_TYPE_COMMON             0x06
+#define        OBJINFO_TYPE_TLS                0x07
 
 typedef        struct  {
        int             i_id;
@@ -79,7 +84,9 @@ typedef       struct  {
        struct  {
                Ptr             ptr_addr;               // Object Address
                //   [Section] sh_addr - Address in memory image.
+               //   [Symbol ] st_value - Symbol value.
                QWord   qw_size;                // Object Size (Address Range)
+               //   [Symbol ] st_size - Size of associated object.
        } addr;
 
        // Group(Parent-Child) Order Link ---
@@ -107,6 +114,7 @@ typedef     struct  {
        // ObjectInfo (DATA) ---
        char    *pstr_name;             // Object Name (Param./Func./etc...)
        //   [Section] = sh_name - Section name (index into the section header string table).
+       //   [Symbol ] = st_name - String table index of name.
        DWord   dw_hash;
 
        union   {
@@ -129,12 +137,21 @@ typedef   struct  {
                        void    *pv_sechdr;
                } section;
 
+               struct  {
+                       Byte    b_type;                 // st_info - Type and binding information.
+                       Byte    b_binding;              // st_info - Type and binding information.
+                       Byte    b_visibility;   // st_other - Reserved (not used).
+                       Word    w_secindex;             // st_shndx - Section index of symbol.
+               } symbol;
+
        } info;
+
+       int             i_secid;
        
        int             i_srcid;                // SourceInfo struct ID
 
        Byte    b_elf_flags;
-       Word    w_secid;                // SectionInfo ItemIndex belong with this object.
+       Word    w_secid;                // ==OLD== SectionInfo ItemIndex belong with this object.
 
 } LibGoblin_ObjectInfo;
 
@@ -193,6 +210,7 @@ typedef struct      {
        void            *p_elf;
 
        LibGoblin_SectionInfo   t_section[LIBGOBLIN_SECTION_ID_MAX];
+       int                                             i_secindex[LIBGOBLIN_SECTION_ID_MAX];
 } LibGoblin_BinaryFile;