Find the answer to your Linux question:
Results 1 to 4 of 4
Hi , I am ok in c programming but poor in internals of C. the things like internals of the compiler ( lexical analyzer , hashtables, parsers , symbol tables ...
  1. #1
    Just Joined! linuxlittle's Avatar
    Join Date
    Nov 2009
    Location
    Usa
    Posts
    6

    Symbol Table understanding and reading

    Hi ,

    I am ok in c programming but poor in internals of C.

    the things like

    internals of the compiler ( lexical analyzer , hashtables, parsers , symbol tables etc..)

    please if any one has some idea or any links please share me .


    especially i need the information of symbol table and contents of the symbol table how to view the symbol table for a function or a program .

    i am working on linux so i am posting the query here .

    i am very thank full to you .

    Thanks,
    Little

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    The nm program shows the symbols of a given object/executable file.
    Debian GNU/Linux -- You know you want it.

  3. #3
    Just Joined! linuxlittle's Avatar
    Join Date
    Nov 2009
    Location
    Usa
    Posts
    6
    i just tried to check the symbol table by using foll files .


    I am using the following files

    Head_Symb.h

    Code:
    #define LV 20
    extern int Glb_Var;
    extern int fun( char *p , char a[]);
    Lib_Symb.c

    Code:
    #include "Head_Symb.h"
    int fun( char *p , char a[])
    {
            static int Stc_Var  ;
            int Lcl_Var2;
    
            printf("Ptr: = %s\n", p);
            printf("Arr: = %s\n", a);
            printf(" Glb_Var = %d \n", Glb_Var);
            return 0;
    
    }
    Main_Symb.c

    Code:
    #include "Head_Symb.h"
    #include<stdio.h>
    int Glb_Var = 10;
    int main( void )
    {
            int Local_Var = LV;
            char *Ptr = "pointer";
            char Arr[]= "array";
            fun ( Ptr , Arr);
    return 0;
    }
    i am using following commands

    gcc -c *.c
    Lib_Symb.o and Main_Symb.o are generated

    when i use the command
    nm Lib_Symb.o
    the following are listed :

    Code:
    00000000 T fun
                     U Glb_Var
                     U printf
    00000000 b Stc_Var.0
    and

    when i use the command

    nm Main_Symb.o

    Code:
                     U fun
    00000000 D Glb_Var
    00000000 T main
    gcc *c

    and when i use the command
    nm
    or
    nm a.out

    i got following list

    Code:
    08049628 A __bss_start
    080482e4 t call_gmon_start
    08049628 b completed.1
    08049528 d __CTOR_END__
    08049524 d __CTOR_LIST__
    08049618 D __data_start
    08049618 W data_start
    080484a4 t __do_global_ctors_aux
    08048308 t __do_global_dtors_aux
    0804961c D __dso_handle
    08049530 d __DTOR_END__
    0804952c d __DTOR_LIST__
    08049538 D _DYNAMIC
    08049628 A _edata
    08049630 A _end
    080484c8 T _fini
    08049524 A __fini_array_end
    08049524 A __fini_array_start
    080484e4 R _fp_hw
    0804833c t frame_dummy
    08048520 r __FRAME_END__
    08048368 T fun
    08049624 D Glb_Var
    08049604 D _GLOBAL_OFFSET_TABLE_
             w __gmon_start__
    08048278 T _init
    08049524 A __init_array_end
    08049524 A __init_array_start
    080484e8 R _IO_stdin_used
    08049534 d __JCR_END__
    08049534 d __JCR_LIST__
             w _Jv_RegisterClasses
    08048460 T __libc_csu_fini
    0804840c T __libc_csu_init
             U __libc_start_main@@GLIBC_2.0
    080483b4 T main
    08049620 d p.0
    08049524 A __preinit_array_end
    08049524 A __preinit_array_start
             U printf@@GLIBC_2.0
    080482c0 T _start
    0804962c b Stc_Var.0
    the things i dont understand here is :

    1) why the command nm Lib_Symb.o and Main_Symb.o are not having any address refereence, all address are zero there.

    2) many new symbols __init_array_end , __init_array_start __preinit_array_end
    __preinit_array_start

    3) Does this have any relation with the assembly file

    4) is there any relation between addresses
    in the command nm a.out
    because
    there are different things that are specifeid at some address
    ex : at
    08049628 A __bss_start
    08049628 b completed.1
    08049628 A _edata

    what all these specifies .
    i understood little bit from the command nm.


    but overall i dint understand completely what actually a symbol table of .0 files (Lib_Symb.o and Main_Symb.o ) consists of and .a.out consists of .

    please just give a breif discussion or links

    Thanks
    Little

  4. #4
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    I am no expert either, so be skeptical in anything I say.

    Quote Originally Posted by linuxlittle View Post
    1) why the command nm Lib_Symb.o and Main_Symb.o are not having any address refereence, all address are zero there.
    They do have. Pay attention to the characters. As the manual says, they refer to different sections. A section is kind of a reference frame. The address 0 is to be understood relative to that section. 0 just means "at the start". Introduce a second static variable in Lib_Symb.c and see what happens.

    Quote Originally Posted by linuxlittle View Post
    2) many new symbols __init_array_end , __init_array_start __preinit_array_end
    __preinit_array_start
    These are "operating system stuff". Your program isn't runnable on its own. It needs some init & cleanup work. For example, the command line parameters have to be put in the array argv so that your main function can read them. More details are to be found in the manual for the linker LD (from GNU binutils) and the C runtime library (the GNU libc).

    Quote Originally Posted by linuxlittle View Post
    3) Does this have any relation with the assembly file
    Yes. Compile with the -S option to obtain the assembler code. You will find the different sections annotated there already.

    Quote Originally Posted by linuxlittle View Post
    4) is there any relation between addresses
    in the command nm a.out
    because
    there are different things that are specifeid at some address
    ex : at
    08049628 A __bss_start
    08049628 b completed.1
    08049628 A _edata

    what all these specifies .
    It might mean that the bss section is of lenght 0. So _edata gets the same starting point.

    Quote Originally Posted by linuxlittle View Post
    but overall i dint understand completely what actually a symbol table of .0 files (Lib_Symb.o and Main_Symb.o ) consists of and .a.out consists of .
    Prosaic, the object files annotate what they will need in order to work and how the variables should be named. The linker later does the job to provide them with these variables and tells where to find them in the final executable.
    Debian GNU/Linux -- You know you want it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...