Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make objdump show assembly of sections only appeared in source code?

Tags:

c

gcc

objdump

I would like to produce assemblies like the one in the answer of this question Using GCC to produce readable assembly?

for simple test code: test.c

void main(){
   int i;
   for(i=0;i<10;i++){
   printf("%d\n",i);
   }
} 

gcc command : gcc -g test.c -o test.o

objdump command: objdump -d -M intel -S test.o

But what i got is assemblies starts with .init section 080482bc<_init>: and end with .fini section 080484cc<_fini>

which i do not want them to be shown.

why is this happening ? and how can i avoid showing sections that are not in the source file?

like image 492
JerseyGood Avatar asked Feb 15 '23 22:02

JerseyGood


2 Answers

Right now you're creating an executable file and not an object file. The executable file of course contains lot of extra sections.

If you want to create an object file, use the -c flag to GCC.

like image 119
Some programmer dude Avatar answered Feb 17 '23 11:02

Some programmer dude


You can specify sections using -j option.

So objdump -d executable -j .text -j .plt will only show disassembly from .text and .plt sections.

like image 21
Zifre Avatar answered Feb 17 '23 11:02

Zifre