Understanding Very Minimal C Program and its execution in Ubuntu Linux – Part 1

Following is the very minimum syntax required for the “C” program, we can call it as the first C program which we can write.

 vim minimum-c-program.c 
main() {
}

That is, the most minimum syntax required for a simple C program should contain 3 important things as,
1. main function which is the entry point of the C program
2. open & close bracket () after main
3. open & close curly brace {}

Now, Lets try to compile this program as,

 $ gcc -o minimum-c-program_exe minimum-c-program.c 

Execute the binary executable created using above command as,

 ./minimum-c-program_exe 

Now, we can check code & data size of this program as,

 $ size minimum-c-program_exe
   text	   data	    bss	    dec	    hex	filename
   1017	    272	      4	   1293	    50d	minimum-c-program
$ nm -S minimum-c-program
0804a018 B __bss_start
0804a018 00000001 b completed.7200
0804a010 D __data_start
0804a010 W data_start
08048320 t deregister_tm_clones
08048390 t __do_global_dtors_aux
08049f0c t __do_global_dtors_aux_fini_array_entry
0804a014 D __dso_handle
08049f14 d _DYNAMIC
0804a018 D _edata
0804a01c B _end
08048454 T _fini
08048468 00000004 R _fp_hw
080483b0 t frame_dummy
08049f08 t __frame_dummy_init_array_entry
08048558 r __FRAME_END__
0804a000 d _GLOBAL_OFFSET_TABLE_
         w __gmon_start__
08048470 r __GNU_EH_FRAME_HDR
0804828c T _init
08049f0c t __init_array_end
08049f08 t __init_array_start
0804846c 00000004 R _IO_stdin_used
         w _ITM_deregisterTMCloneTable
         w _ITM_registerTMCloneTable
08049f10 d __JCR_END__
08049f10 d __JCR_LIST__
         w _Jv_RegisterClasses
08048450 00000002 T __libc_csu_fini
080483f0 0000005d T __libc_csu_init
         U __libc_start_main@@GLIBC_2.0
080483db 0000000a T main
08048350 t register_tm_clones
080482e0 T _start
0804a018 D __TMC_END__
08048310 00000004 T __x86.get_pc_thunk.bx

You can check which libraries this program uses using following command,

$ ldd minimum-c-program_exe
	linux-gate.so.1 =>  (0xb7722000)
	libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb753d000)
	/lib/ld-linux.so.2 (0x80038000)

The other important commands you can try to udnerstand are as bellow,

 $ objdump -Dxls minimum-c-program_exe 
 $ readelf -a minimum-c-program_exe 

In the next post, we will try to understand how this program executes in run time as “Understanding execution of very minimal C program in Linux / Ubuntu

Android Android Commands Android Java Applications Application Libraries Bash / Shell Scripts Bluetooth driver Build Frameworks Commands and Packages Core Kernel C Programs Development Environment Setup Documents / Books Errors & Failures File Systems Framebuffer / Display Driver git Go Language Programs Hardware Platforms Home Kernel & Device Drivers Kernel Booting and Porting Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL NDK / Middleware / HAL Network Driver OS Concepts PHP Procfs Filesystem Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Userspace Utilities Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply