Created
February 6, 2015 02:23
-
-
Save honux77/ffa1720c2d89dc1a9bc9 to your computer and use it in GitHub Desktop.
undefined action for c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| int main(void) { | |
| int *p = malloc(sizeof(int)); | |
| int *q = realloc(p, sizeof(int)); | |
| int *z = realloc(q, sizeof(int)); | |
| *p = 1; | |
| *q = 2; | |
| *z = 3; | |
| if (p == q) | |
| printf("%p %p %p %d %d %d\n", p, q, z, *p, *q, *z); | |
| return 0; | |
| } |
Author
Author
gcc -O2 result binary code
a.out:
(__TEXT,__text) section
_main:
0000000100000ec0 pushq %rbp
0000000100000ec1 movq %rsp, %rbp
0000000100000ec4 pushq %r14
0000000100000ec6 pushq %rbx
0000000100000ec7 subq $0x10, %rsp
0000000100000ecb movl $0x4, %edi
0000000100000ed0 callq 0x100000f42 ## symbol stub for: _malloc
0000000100000ed5 movq %rax, %r14
0000000100000ed8 movl $0x4, %esi
0000000100000edd movq %r14, %rdi
0000000100000ee0 callq 0x100000f4e ## symbol stub for: _realloc
0000000100000ee5 movq %rax, %rbx
0000000100000ee8 movl $0x4, %esi
0000000100000eed movq %rbx, %rdi
0000000100000ef0 callq 0x100000f4e ## symbol stub for: _realloc
0000000100000ef5 movq %rax, %rcx
0000000100000ef8 movl $0x1, (%r14)
0000000100000eff movl $0x2, (%rbx)
0000000100000f05 movl $0x3, (%rcx)
0000000100000f0b cmpq %rbx, %r14
0000000100000f0e jne 0x100000f37
0000000100000f10 movl $0x3, (%rsp)
0000000100000f17 leaq 0x64(%rip), %rdi ## literal pool for: "%p %p %p %d %d %d\n"
0000000100000f1e movl $0x1, %r8d
0000000100000f24 movl $0x2, %r9d
0000000100000f2a xorl %eax, %eax
0000000100000f2c movq %r14, %rdx
0000000100000f2f movq %r14, %rsi
0000000100000f32 callq 0x100000f48 ## symbol stub for: _printf
0000000100000f37 xorl %eax, %eax
0000000100000f39 addq $0x10, %rsp
0000000100000f3d popq %rbx
0000000100000f3e popq %r14
0000000100000f40 popq %rbp
0000000100000f41 retq
Author
gcc -O1 result binary code
o1.out:
(__TEXT,__text) section
_main:
0000000100000ec0 pushq %rbp
0000000100000ec1 movq %rsp, %rbp
0000000100000ec4 pushq %r14
0000000100000ec6 pushq %rbx
0000000100000ec7 subq $0x10, %rsp
0000000100000ecb movl $0x4, %edi
0000000100000ed0 callq 0x100000f3c ## symbol stub for: _malloc
0000000100000ed5 movq %rax, %r14
0000000100000ed8 movl $0x4, %esi
0000000100000edd movq %r14, %rdi
0000000100000ee0 callq 0x100000f48 ## symbol stub for: _realloc
0000000100000ee5 movq %rax, %rbx
0000000100000ee8 movl $0x4, %esi
0000000100000eed movq %rbx, %rdi
0000000100000ef0 callq 0x100000f48 ## symbol stub for: _realloc
0000000100000ef5 movq %rax, %rcx
0000000100000ef8 movl $0x1, (%r14)
0000000100000eff movl $0x2, (%rbx)
0000000100000f05 movl $0x3, (%rcx)
0000000100000f0b cmpq %rbx, %r14
0000000100000f0e jne 0x100000f31
0000000100000f10 movl (%r14), %r8d
0000000100000f13 movl (%rbx), %r9d
0000000100000f16 movl $0x3, (%rsp)
0000000100000f1d leaq 0x5a(%rip), %rdi ## literal pool for: "%p %p %p %d %d %d\n"
0000000100000f24 xorl %eax, %eax
0000000100000f26 movq %rbx, %rdx
0000000100000f29 movq %r14, %rsi
0000000100000f2c callq 0x100000f42 ## symbol stub for: _printf
0000000100000f31 xorl %eax, %eax
0000000100000f33 addq $0x10, %rsp
0000000100000f37 popq %rbx
0000000100000f38 popq %r14
0000000100000f3a popq %rbp
0000000100000f3b retq
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code Title: Trinity
x64 osx result