Created
January 28, 2015 14:14
-
-
Save scottt/12e81df6bf16175efe02 to your computer and use it in GitHub Desktop.
compilefunc var-arg.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
| # Grab 'compilefunc' here: | |
| # https://github.com/scottt/scottt-bin/blob/master/compilefunc | |
| $ CFLAGS='-O0' compilefunc -s -l var-arg.c main | |
| 28 { | |
| 0x0000000000400823 <+0>: push %rbp | |
| 0x0000000000400824 <+1>: mov %rsp,%rbp | |
| 29 /* See 3.5.7 Variable Arugment Lists in http://www.x86-64.org/documentation/abi.pdf | |
| 30 * "When a function taking variable-arguments is called, %rax must be set to the | |
| 31 * total number of floating point parameters passed to the function in vector registers". | |
| 32 */ | |
| 33 f1("", 1l, -1.0); | |
| 0x0000000000400827 <+4>: movsd 0xe1(%rip),%xmm0 # 0x400910 | |
| 0x000000000040082f <+12>: mov $0x1,%esi | |
| 0x0000000000400834 <+17>: mov $0x40090a,%edi | |
| 0x0000000000400839 <+22>: mov $0x1,%eax | |
| 0x000000000040083e <+27>: callq 0x400536 <f1> | |
| 34 f2("", 1l, -1.0, 0.0); | |
| 0x0000000000400843 <+32>: pxor %xmm1,%xmm1 | |
| 0x0000000000400847 <+36>: movsd 0xc1(%rip),%xmm0 # 0x400910 | |
| 0x000000000040084f <+44>: mov $0x1,%esi | |
| 0x0000000000400854 <+49>: mov $0x40090a,%edi | |
| 0x0000000000400859 <+54>: mov $0x2,%eax | |
| 0x000000000040085e <+59>: callq 0x40067b <f2> | |
| 35 return 0; | |
| 0x0000000000400863 <+64>: mov $0x0,%eax | |
| 36 } | |
| 0x0000000000400868 <+69>: pop %rbp | |
| 0x0000000000400869 <+70>: retq | |
| $ CFLAGS='-O3' compilefunc -s -l var-arg.c main | |
| 28 { | |
| 0x0000000000400440 <+0>: sub $0x8,%rsp | |
| 29 /* See 3.5.7 Variable Arugment Lists in http://www.x86-64.org/documentation/abi.pdf | |
| 30 * "When a function taking variable-arguments is called, %rax must be set to the | |
| 31 * total number of floating point parameters passed to the function in vector registers". | |
| 32 */ | |
| 33 f1("", 1l, -1.0); | |
| 0x0000000000400444 <+4>: mov $0x1,%esi | |
| 0x0000000000400449 <+9>: mov $0x400794,%edi | |
| 0x000000000040044e <+14>: movsd 0x34a(%rip),%xmm0 # 0x4007a0 | |
| 0x0000000000400456 <+22>: mov $0x1,%eax | |
| 0x000000000040045b <+27>: callq 0x400590 <f1> | |
| 34 f2("", 1l, -1.0, 0.0); | |
| 0x0000000000400460 <+32>: pxor %xmm1,%xmm1 | |
| 0x0000000000400464 <+36>: mov $0x1,%esi | |
| 0x0000000000400469 <+41>: movsd 0x32f(%rip),%xmm0 # 0x4007a0 | |
| 0x0000000000400471 <+49>: mov $0x400794,%edi | |
| 0x0000000000400476 <+54>: mov $0x2,%eax | |
| 0x000000000040047b <+59>: callq 0x400620 <f2> | |
| 35 return 0; | |
| 36 } | |
| 0x0000000000400480 <+64>: xor %eax,%eax | |
| 0x0000000000400482 <+66>: add $0x8,%rsp | |
| 0x0000000000400486 <+70>: retq | |
| $ CFLAGS='-Os' compilefunc -s -l var-arg.c main | |
| 28 { | |
| 0x0000000000400440 <+0>: push %rax | |
| 29 /* See 3.5.7 Variable Arugment Lists in http://www.x86-64.org/documentation/abi.pdf | |
| 30 * "When a function taking variable-arguments is called, %rax must be set to the | |
| 31 * total number of floating point parameters passed to the function in vector registers". | |
| 32 */ | |
| 33 f1("", 1l, -1.0); | |
| 0x0000000000400441 <+1>: mov $0x1,%esi | |
| 0x0000000000400446 <+6>: mov $0x400754,%edi | |
| 0x000000000040044b <+11>: mov $0x1,%al | |
| 0x000000000040044d <+13>: movsd 0x30b(%rip),%xmm0 # 0x400760 | |
| 0x0000000000400455 <+21>: callq 0x400576 <f1> | |
| 34 f2("", 1l, -1.0, 0.0); | |
| 0x000000000040045a <+26>: xorps %xmm1,%xmm1 | |
| 0x000000000040045d <+29>: mov $0x1,%esi | |
| 0x0000000000400462 <+34>: movsd 0x2f6(%rip),%xmm0 # 0x400760 | |
| 0x000000000040046a <+42>: mov $0x400754,%edi | |
| 0x000000000040046f <+47>: mov $0x2,%al | |
| 0x0000000000400471 <+49>: callq 0x4005f4 <f2> | |
| 35 return 0; | |
| 36 } | |
| 0x0000000000400476 <+54>: xor %eax,%eax | |
| 0x0000000000400478 <+56>: pop %rdx | |
| 0x0000000000400479 <+57>: retq |
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
| /* Demonstrate stdarg ABI */ | |
| #include <stdarg.h> | |
| #include <stdio.h> | |
| int f1(const char *fmt, ...) | |
| { | |
| va_list args; | |
| va_start(args, fmt); | |
| printf("%ld\n", va_arg(args, long)); | |
| printf("%lf\n", va_arg(args, double)); | |
| va_end(args); | |
| return 0; | |
| } | |
| int f2(const char *fmt, ...) | |
| { | |
| va_list args; | |
| va_start(args, fmt); | |
| printf("%ld\n", va_arg(args, long)); | |
| printf("%lf\n", va_arg(args, double)); | |
| printf("%lf\n", va_arg(args, double)); | |
| va_end(args); | |
| return 0; | |
| } | |
| int main() | |
| { | |
| /* See 3.5.7 Variable Arugment Lists in http://www.x86-64.org/documentation/abi.pdf | |
| * "When a function taking variable-arguments is called, %rax must be set to the | |
| * total number of floating point parameters passed to the function in vector registers". | |
| */ | |
| f1("", 1l, -1.0); | |
| f2("", 1l, -1.0, 0.0); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment