assembly - where is the C language global array located in its disassembly code -



assembly - where is the C language global array located in its disassembly code -

i wrote simple c code follow:

int data_items[] = {3,67,32,4,89,6,34,2,9,0}; int max(int* pt) { int val = *pt; while(*pt != 0) { if (*pt > val) { val = *pt; } ++pt; } homecoming val; } int main() { max(data_items); homecoming 0; }

then compiled gcc:

gcc main.c

and disassembled with:

objdump -d a.out

at lastly assemble code:

a.out: file format elf64-x86-64 disassembly of section .init: 00000000004003a8 <_init>: 4003a8: 48 83 ec 08 sub $0x8,%rsp 4003ac: 48 8b 05 45 0c 20 00 mov 0x200c45(%rip),%rax # 600ff8 <_dynamic+0x1d0> 4003b3: 48 85 c0 test %rax,%rax 4003b6: 74 05 je 4003bd <_init+0x15> 4003b8: e8 33 00 00 00 callq 4003f0 <__gmon_start__@plt> 4003bd: 48 83 c4 08 add together $0x8,%rsp 4003c1: c3 retq disassembly of section .plt: 00000000004003d0 <__libc_start_main@plt-0x10>: 4003d0: ff 35 32 0c 20 00 pushq 0x200c32(%rip) # 601008 <_global_offset_table_+0x8> 4003d6: ff 25 34 0c 20 00 jmpq *0x200c34(%rip) # 601010 <_global_offset_table_+0x10> 4003dc: 0f 1f 40 00 nopl 0x0(%rax) 00000000004003e0 <__libc_start_main@plt>: 4003e0: ff 25 32 0c 20 00 jmpq *0x200c32(%rip) # 601018 <_global_offset_table_+0x18> 4003e6: 68 00 00 00 00 pushq $0x0 4003eb: e9 e0 ff ff ff jmpq 4003d0 <_init+0x28> 00000000004003f0 <__gmon_start__@plt>: 4003f0: ff 25 2a 0c 20 00 jmpq *0x200c2a(%rip) # 601020 <_global_offset_table_+0x20> 4003f6: 68 01 00 00 00 pushq $0x1 4003fb: e9 d0 ff ff ff jmpq 4003d0 <_init+0x28> disassembly of section .text: 0000000000400400 <_start>: 400400: 31 ed xor %ebp,%ebp 400402: 49 89 d1 mov %rdx,%r9 400405: 5e pop %rsi 400406: 48 89 e2 mov %rsp,%rdx 400409: 48 83 e4 f0 , $0xfffffffffffffff0,%rsp 40040d: 50 force %rax 40040e: 54 force %rsp 40040f: 49 c7 c0 b0 05 40 00 mov $0x4005b0,%r8 400416: 48 c7 c1 40 05 40 00 mov $0x400540,%rcx 40041d: 48 c7 c7 28 05 40 00 mov $0x400528,%rdi 400424: e8 b7 ff ff ff callq 4003e0 <__libc_start_main@plt> 400429: f4 hlt 40042a: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1) 0000000000400430 <deregister_tm_clones>: 400430: b8 8f 10 60 00 mov $0x60108f,%eax 400435: 55 force %rbp 400436: 48 2d 88 10 60 00 sub $0x601088,%rax 40043c: 48 83 f8 0e cmp $0xe,%rax 400440: 48 89 e5 mov %rsp,%rbp 400443: 77 02 ja 400447 <deregister_tm_clones+0x17> 400445: 5d pop %rbp 400446: c3 retq 400447: b8 00 00 00 00 mov $0x0,%eax 40044c: 48 85 c0 test %rax,%rax 40044f: 74 f4 je 400445 <deregister_tm_clones+0x15> 400451: 5d pop %rbp 400452: bf 88 10 60 00 mov $0x601088,%edi 400457: ff e0 jmpq *%rax 400459: 0f 1f 80 00 00 00 00 nopl 0x0(%rax) 0000000000400460 <register_tm_clones>: 400460: b8 88 10 60 00 mov $0x601088,%eax 400465: 55 force %rbp 400466: 48 2d 88 10 60 00 sub $0x601088,%rax 40046c: 48 c1 f8 03 sar $0x3,%rax 400470: 48 89 e5 mov %rsp,%rbp 400473: 48 89 c2 mov %rax,%rdx 400476: 48 c1 ea 3f shr $0x3f,%rdx 40047a: 48 01 d0 add together %rdx,%rax 40047d: 48 d1 f8 sar %rax 400480: 75 02 jne 400484 <register_tm_clones+0x24> 400482: 5d pop %rbp 400483: c3 retq 400484: ba 00 00 00 00 mov $0x0,%edx 400489: 48 85 d2 test %rdx,%rdx 40048c: 74 f4 je 400482 <register_tm_clones+0x22> 40048e: 5d pop %rbp 40048f: 48 89 c6 mov %rax,%rsi 400492: bf 88 10 60 00 mov $0x601088,%edi 400497: ff e2 jmpq *%rdx 400499: 0f 1f 80 00 00 00 00 nopl 0x0(%rax) 00000000004004a0 <__do_global_dtors_aux>: 4004a0: 80 3d e1 0b 20 00 00 cmpb $0x0,0x200be1(%rip) # 601088 <__tmc_end__> 4004a7: 75 11 jne 4004ba <__do_global_dtors_aux+0x1a> 4004a9: 55 force %rbp 4004aa: 48 89 e5 mov %rsp,%rbp 4004ad: e8 7e ff ff ff callq 400430 <deregister_tm_clones> 4004b2: 5d pop %rbp 4004b3: c6 05 ce 0b 20 00 01 movb $0x1,0x200bce(%rip) # 601088 <__tmc_end__> 4004ba: f3 c3 repz retq 4004bc: 0f 1f 40 00 nopl 0x0(%rax) 00000000004004c0 <frame_dummy>: 4004c0: 48 83 3d 58 09 20 00 cmpq $0x0,0x200958(%rip) # 600e20 <__jcr_end__> 4004c7: 00 4004c8: 74 1e je 4004e8 <frame_dummy+0x28> 4004ca: b8 00 00 00 00 mov $0x0,%eax 4004cf: 48 85 c0 test %rax,%rax 4004d2: 74 14 je 4004e8 <frame_dummy+0x28> 4004d4: 55 force %rbp 4004d5: bf 20 0e 60 00 mov $0x600e20,%edi 4004da: 48 89 e5 mov %rsp,%rbp 4004dd: ff d0 callq *%rax 4004df: 5d pop %rbp 4004e0: e9 7b ff ff ff jmpq 400460 <register_tm_clones> 4004e5: 0f 1f 00 nopl (%rax) 4004e8: e9 73 ff ff ff jmpq 400460 <register_tm_clones> 00000000004004ed <max>: 4004ed: 55 force %rbp 4004ee: 48 89 e5 mov %rsp,%rbp 4004f1: 48 89 7d e8 mov %rdi,-0x18(%rbp) 4004f5: 48 8b 45 e8 mov -0x18(%rbp),%rax 4004f9: 8b 00 mov (%rax),%eax 4004fb: 89 45 fc mov %eax,-0x4(%rbp) 4004fe: eb 19 jmp 400519 <max+0x2c> 400500: 48 8b 45 e8 mov -0x18(%rbp),%rax 400504: 8b 00 mov (%rax),%eax 400506: 3b 45 fc cmp -0x4(%rbp),%eax 400509: 7e 09 jle 400514 <max+0x27> 40050b: 48 8b 45 e8 mov -0x18(%rbp),%rax 40050f: 8b 00 mov (%rax),%eax 400511: 89 45 fc mov %eax,-0x4(%rbp) 400514: 48 83 45 e8 04 addq $0x4,-0x18(%rbp) 400519: 48 8b 45 e8 mov -0x18(%rbp),%rax 40051d: 8b 00 mov (%rax),%eax 40051f: 85 c0 test %eax,%eax 400521: 75 dd jne 400500 <max+0x13> 400523: 8b 45 fc mov -0x4(%rbp),%eax 400526: 5d pop %rbp 400527: c3 retq 0000000000400528 <main>: 400528: 55 force %rbp 400529: 48 89 e5 mov %rsp,%rbp 40052c: bf 60 10 60 00 mov $0x601060,%edi 400531: e8 b7 ff ff ff callq 4004ed <max> 400536: b8 00 00 00 00 mov $0x0,%eax 40053b: 5d pop %rbp 40053c: c3 retq 40053d: 0f 1f 00 nopl (%rax) 0000000000400540 <__libc_csu_init>: 400540: 41 57 force %r15 400542: 41 89 ff mov %edi,%r15d 400545: 41 56 force %r14 400547: 49 89 f6 mov %rsi,%r14 40054a: 41 55 force %r13 40054c: 49 89 d5 mov %rdx,%r13 40054f: 41 54 force %r12 400551: 4c 8d 25 b8 08 20 00 lea 0x2008b8(%rip),%r12 # 600e10 <__frame_dummy_init_array_entry> 400558: 55 force %rbp 400559: 48 8d 2d b8 08 20 00 lea 0x2008b8(%rip),%rbp # 600e18 <__init_array_end> 400560: 53 force %rbx 400561: 4c 29 e5 sub %r12,%rbp 400564: 31 db xor %ebx,%ebx 400566: 48 c1 fd 03 sar $0x3,%rbp 40056a: 48 83 ec 08 sub $0x8,%rsp 40056e: e8 35 fe ff ff callq 4003a8 <_init> 400573: 48 85 ed test %rbp,%rbp 400576: 74 1e je 400596 <__libc_csu_init+0x56> 400578: 0f 1f 84 00 00 00 00 nopl 0x0(%rax,%rax,1) 40057f: 00 400580: 4c 89 ea mov %r13,%rdx 400583: 4c 89 f6 mov %r14,%rsi 400586: 44 89 ff mov %r15d,%edi 400589: 41 ff 14 dc callq *(%r12,%rbx,8) 40058d: 48 83 c3 01 add together $0x1,%rbx 400591: 48 39 eb cmp %rbp,%rbx 400594: 75 ea jne 400580 <__libc_csu_init+0x40> 400596: 48 83 c4 08 add together $0x8,%rsp 40059a: 5b pop %rbx 40059b: 5d pop %rbp 40059c: 41 5c pop %r12 40059e: 41 5d pop %r13 4005a0: 41 5e pop %r14 4005a2: 41 5f pop %r15 4005a4: c3 retq 4005a5: 66 66 2e 0f 1f 84 00 data32 nopw %cs:0x0(%rax,%rax,1) 4005ac: 00 00 00 00 00000000004005b0 <__libc_csu_fini>: 4005b0: f3 c3 repz retq disassembly of section .fini: 00000000004005b4 <_fini>: 4005b4: 48 83 ec 08 sub $0x8,%rsp 4005b8: 48 83 c4 08 add together $0x8,%rsp 4005bc: c3 retq

my question that, in main function:

40052c: bf 60 10 60 00 mov $0x601060,%edi

the address $0x601060 should address of array data_items in c code. can not find data_items array value in assemble code, it?

by way, in max function code:

4004f1: 48 89 7d e8 mov %rdi,-0x18(%rbp)

i think stack should be:

mov %rdi, -0x8(%rbp)

why compiler makes hole in stack?

my scheme ubuntu 14.04 lts.

objdump -d disassembles sections of executable there's supposed code.

use objdump -d disassemble sections, , you'll find this:

disassembly of section .data: 08049760 <__data_start>: ... 08049780 <data_items>: 8049780: 03 00 add together (%eax),%eax 8049782: 00 00 add together %al,(%eax) 8049784: 43 inc %ebx 8049785: 00 00 add together %al,(%eax) 8049787: 00 20 add together %ah,(%eax) 8049789: 00 00 add together %al,(%eax) 804978b: 00 04 00 add together %al,(%eax,%eax,1) 804978e: 00 00 add together %al,(%eax)

that's array. objdump seek disassemble if machine code, assembly isn't going create sense though).

c assembly

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -