EmbLogic's Blog

calloc

int *data;
data=calloc(3,sizeof(int));
int i=0;
for(i=0;i<3;i++)
scanf("%d",&data[i]);
for(i=0;i<3;i++)
printf("%d",data[i]);
free(data)

//i get segmentataion fault….

Posted in Uncategorized | 1 Comment

detailed info about elf format…

Starting

The question is simple: how does linux execute my main()?
Through this document, I’ll use the following simple C program to illustrate how it works. It’s called “simple.c”

main()
{
   return(0);
}

Build

 

gcc -o simple simple.c

What’s in the executable?

To see what’s in the executable, let’s use a tool “objdump”

objdump -f simple

simple:     file format elf32-i386
architecture: i386, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x080482d0

The output gives us some critical information about the executable.
First of all, the file is “ELF32″ format. Second of all, the start address is “0x080482d0″

What’s ELF?

ELF is acronym for Executable and Linking Format. It’s one of several object and executable file formats used on Unix systems. For our discussion, the interesting thing about ELF is its header format. Every ELF executable has ELF header, which is the following.

typedef struct
{
	unsigned char	e_ident[EI_NIDENT];	/* Magic number and other info */
	Elf32_Half	e_type;			/* Object file type */
	Elf32_Half	e_machine;		/* Architecture */
	Elf32_Word	e_version;		/* Object file version */
	Elf32_Addr	e_entry;		/* Entry point virtual address */
	Elf32_Off	e_phoff;		/* Program header table file offset */
	Elf32_Off	e_shoff;		/* Section header table file offset */
	Elf32_Word	e_flags;		/* Processor-specific flags */
	Elf32_Half	e_ehsize;		/* ELF header size in bytes */
	Elf32_Half	e_phentsize;		/* Program header table entry size */
	Elf32_Half	e_phnum;		/* Program header table entry count */
	Elf32_Half	e_shentsize;		/* Section header table entry size */
	Elf32_Half	e_shnum;		/* Section header table entry count */
	Elf32_Half	e_shstrndx;		/* Section header string table index */
} Elf32_Ehdr;

In the above structure, there is “e_entry” field, which is starting address of an executable.

What’s at address “0x080482d0″, that is, starting address?

For this question, let’s disassemble “simple”. There are several tools to disassemble an executable. I’ll use objdump for this purpose.

objdump --disassemble simple

The output is a little bit long so I’ll not paste all the output from objdump. Our intention is see what’s at address 0x080482d0. Here is the output.

080482d0 <_start>:
 80482d0:       31 ed                   xor    %ebp,%ebp
 80482d2:       5e                      pop    %esi
 80482d3:       89 e1                   mov    %esp,%ecx
 80482d5:       83 e4 f0                and    $0xfffffff0,%esp
 80482d8:       50                      push   %eax
 80482d9:       54                      push   %esp
 80482da:       52                      push   %edx
 80482db:       68 20 84 04 08          push   $0x8048420
 80482e0:       68 74 82 04 08          push   $0x8048274
 80482e5:       51                      push   %ecx
 80482e6:       56                      push   %esi
 80482e7:       68 d0 83 04 08          push   $0x80483d0
 80482ec:       e8 cb ff ff ff          call   80482bc <_init+0x48>
 80482f1:       f4                      hlt    
 80482f2:       89 f6                   mov    %esi,%esi

Looks like some kind of starting routine called “_start” is at the starting address. What it does is clear a register, push some values into stack and call a function. According to this instruction, the stack frame should look like this.

Stack Top	-------------------
		0x80483d
		-------------------
		esi
		-------------------
		ecx
		-------------------
		0x8048274
		-------------------
		0x8048420
		-------------------
		edx
		-------------------
		esp
		-------------------
		eax
		-------------------

hope u find it useful...thanx
Posted in Uncategorized | 3 Comments

What are PIEs…?

Scrt1.o
  Used in place of crt1.o when generating PIEs.
.
.
what are PIEs...?.
.
.
I already know about crt1.o but didn't get PIEs..
Posted in ARM Embedded Processors, Data Structures with C, Embedded Controllers, Embedded Linux | Leave a comment

Ram alwys ur’s

Respected sir and yes

hello friends,,,,,,Today i m writing my first blog;,,,,,,,,,,,,i m writing this blog only bcz,,,,,,,,  i don’t know why ….. but yes i can say ……………..emblogic  is really awsome……………..specially::::—

C:/

@include<emblogic>

emblogic main()

{

name siddarth sir,pravjot sir;

if (session taken by==siddarth sir)

printf(“%emblogic”,The best teacher i ever met );

elseif (session taken by ==pravjot sir)

printf(“%emblogic”,best  teacher as will as CEO i ever met);

return Emblogic;

}

Posted in Data Structures with C, Shell Scripts | Leave a comment

Daily Report to Pravjot sir

Sir,
Today I devote my entire day to tool chain. I start entire process from beginning .I am handling crt0,crt1,crtbegin crtend error .
regards and thanks
Dharmendra Nath Shandilya

Posted in Uncategorized | Leave a comment

Re: View Documents

Sir/Madam,
I am not able to browse Documents of session 10 & 11.

Posted in Uncategorized | 1 Comment

Daily Report to Pravjot sir

Sir,
Today I devote my entire day to tool chain. I start entire process from beginning to manage one more time .
I have attended session of Project Manger regarding Project.
regards and thanks
Dharmendra Nath Shandilya

Posted in Uncategorized | Leave a comment

RE: Makefile Install

what is the meaning of og-w in this line:-
chmod og-w $(INSTDIR)/myapp

Posted in Uncategorized | 1 Comment

It may help somewhere in Toolchain..

crt0.o
  Older style of the initial runtime code ?  Usually not generated anymore
  with Linux toolchains, but often found in bare metal toolchains.  Serves
  same purpose as crt1.o (see below).
crt1.o
  Newer style of the initial runtime code.  Contains the _start symbol which
  sets up the env with argc/argv/libc _init/libc _fini before jumping to the
  libc main.  glibc calls this file 'start.S'.
crti.o
  Defines the function prolog; _init in the .init section and _fini in the
  .fini section.  glibc calls this 'initfini.c'.
crtn.o
  Defines the function epilog.  glibc calls this 'initfini.c'.
Scrt1.o
  Used in place of crt1.o when generating PIEs.
gcrt1.o
  Used in place of crt1.o when generating code with profiling information.
  Compile with -pg.  Produces output suitable for the gprof util.
Mcrt1.o
  Like gcrt1.o, but is used with the prof utility.  glibc installs this as
  a dummy file as it's useless on linux systems.

crtbegin.o
  GCC uses this to find the start of the constructors.
crtbeginS.o
  Used in place of crtbegin.o when generating shared objects/PIEs.
crtbeginT.o
  Used in place of crtbegin.o when generating static executables.
crtend.o
  GCC uses this to find the start of the destructors.
crtendS.o
  Used in place of crtend.o when generating shared objects/PIEs.

.
.
.
.
.
if there is any other information.. please let me & others know.
Posted in ARM Embedded Processors, Embedded Linux | 1 Comment

today’s work

class assignment is done

Posted in Uncategorized | Leave a comment

Solve the Mystery of pre and post increment operators

Assume any value of k eg 1

Q1 d=k++/++k……..print d and k, k=3;

why is the reult 1 for d???

Q2 d=printf(“%d%d%d”,++k,k,k++);

 

printf(“%d%d%d”,k++,k,k++);

Why the result vary in both the printf statements.???

Q3 printf(“%d%d%d”,k,k++,++k);

what will be the output and WHY???

Q4 printf(“%d%d%d”,++k,k++,k);

output and WHY??

Q5 printf(“%d%d%d”,k++,++k,k);

output and WHY??

Posted in Data Structures with C | 5 Comments

I need to know this…

Sir,

Is there any way available to convert an .obj (object file) file to a .c file…?

Posted in ARM Embedded Processors, Data Structures with C, Embedded Linux | 1 Comment

int i=1;
printf(“%d”,–i + ++i + ++i);

why the result is coming 4.

Posted in Uncategorized | Leave a comment

Daily Report to Pravjot sir

Sir,
Today I devote my entire day to tool chain , There is error come always at last step Link test are not allowed after GCC_NO_EXECUTABLES, I tried to solve it by –without-gmp-zlib but many times but i didn’t got success. I start entire process from beginning to manage one more time .

regards and thanks
Dharmendra Nath Shandilya

Posted in Uncategorized | Leave a comment

work update on 9/06/2012

tasks performed today:

1. linux installation

2. completed assignment number 1 with some problems.

Posted in Data Structures with C | 1 Comment