Commit | Line | Data |
---|---|---|
2ebaa23b AM |
1 | #; $ as -o test.o gas-cfi-test.s && gcc -nostdlib -o test test.o |
2 | ||
3 | .text | |
4 | ||
5 | #; func_locvars | |
6 | #; - function with a space on the stack | |
7 | #; allocated for local variables | |
8 | ||
9 | .type func_locvars,@function | |
10 | func_locvars: | |
11 | .cfi_startproc | |
12 | ||
13 | #; alocate space for local vars | |
14 | sub $0x1234,%rsp | |
15 | .cfi_adjust_cfa_offset 0x1234 | |
16 | ||
17 | #; dummy body | |
18 | movl $1,%eax | |
19 | ||
20 | #; release space of local vars and return | |
21 | add $0x1234,%rsp | |
22 | .cfi_adjust_cfa_offset -0x1234 | |
23 | ret | |
24 | .cfi_endproc | |
25 | ||
26 | #; func_prologue | |
27 | #; - functions that begins with standard | |
28 | #; prologue: "pushq %rbp; movq %rsp,%rbp" | |
29 | ||
30 | .type func_prologue,@function | |
31 | func_prologue: | |
32 | .cfi_startproc | |
33 | ||
34 | #; prologue, CFI is valid after | |
35 | #; each instruction. | |
36 | pushq %rbp | |
37 | .cfi_def_cfa_offset 16 | |
38 | .cfi_offset rbp,-16 | |
39 | movq %rsp, %rbp | |
40 | .cfi_def_cfa_register rbp | |
41 | ||
42 | #; function body | |
43 | call func_locvars | |
44 | addl $3, %eax | |
45 | ||
46 | #; epilogue with valid CFI | |
47 | #; (we're better than gcc :-) | |
48 | leaveq | |
49 | .cfi_def_cfa rsp,8 | |
50 | ret | |
51 | .cfi_endproc | |
52 | ||
53 | #; func_otherreg | |
54 | #; - function that moves frame pointer to | |
55 | #; another register (r12) and then allocates | |
56 | #; a space for local variables | |
57 | ||
58 | .type func_otherreg,@function | |
59 | func_otherreg: | |
60 | .cfi_startproc | |
61 | ||
62 | #; save frame pointer to r12 | |
63 | movq %rsp,%r12 | |
64 | .cfi_def_cfa_register r12 | |
65 | ||
66 | #; alocate space for local vars | |
67 | #; (no .cfi_{def,adjust}_cfa_offset here, | |
68 | #; because CFA is computed from r12!) | |
69 | sub $100,%rsp | |
70 | ||
71 | #; function body | |
72 | call func_prologue | |
73 | addl $2, %eax | |
74 | ||
75 | #; restore frame pointer from r12 | |
76 | movq %r12,%rsp | |
77 | .cfi_def_cfa_register rsp | |
78 | ret | |
79 | .cfi_endproc | |
80 | ||
81 | #; main | |
82 | #; - typical function | |
83 | .type main,@function | |
84 | main: | |
85 | .cfi_startproc | |
86 | ||
87 | #; only function body that doesn't | |
88 | #; touch the stack at all. | |
89 | call func_otherreg | |
90 | ||
91 | #; return | |
92 | ret | |
93 | .cfi_endproc | |
94 | ||
95 | #; _start | |
96 | #; - standard entry point | |
97 | ||
98 | .type _start,@function | |
99 | .globl _start | |
100 | _start: | |
101 | .cfi_startproc | |
102 | call main | |
103 | movq %rax,%rdi | |
104 | movq $0x3c,%rax | |
105 | syscall | |
106 | hlt | |
107 | .cfi_endproc |