Originally Posted by
Salem
> How to confirm/ verify that local variable is stored in stack memory ?
Disassemble the code (objdump -d) to see stack relative operations for local variables.
Thank you for your earlier insights. I followed your suggestion and disassembled my code using objdump -d.
I’m still unclear about where exactly the local variables are stored in memory based on the output.
Code:
objdump -d memory_layout.o
memory_layout.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <test_function>:
0: f3 0f 1e fa endbr64
4: 55 push %rbp
5: 48 89 e5 mov %rsp,%rbp
8: 48 83 ec 10 sub $0x10,%rsp
c: c7 45 fc 14 00 00 00 movl $0x14,-0x4(%rbp)
13: 8b 45 fc mov -0x4(%rbp),%eax
16: 89 c6 mov %eax,%esi
18: 48 8d 05 00 00 00 00 lea 0x0(%rip),%rax # 1f <test_function+0x1f>
1f: 48 89 c7 mov %rax,%rdi
22: b8 00 00 00 00 mov $0x0,%eax
27: e8 00 00 00 00 call 2c <test_function+0x2c>
2c: 90 nop
2d: c9 leave
2e: c3 ret
000000000000002f <main>:
2f: f3 0f 1e fa endbr64
33: 55 push %rbp
34: 48 89 e5 mov %rsp,%rbp
37: 48 83 ec 10 sub $0x10,%rsp
3b: c7 45 fc 28 00 00 00 movl $0x28,-0x4(%rbp)
42: 8b 05 00 00 00 00 mov 0x0(%rip),%eax # 48 <main+0x19>
48: 89 c6 mov %eax,%esi
4a: 48 8d 05 00 00 00 00 lea 0x0(%rip),%rax # 51 <main+0x22>
51: 48 89 c7 mov %rax,%rdi
54: b8 00 00 00 00 mov $0x0,%eax
59: e8 00 00 00 00 call 5e <main+0x2f>
5e: 8b 05 00 00 00 00 mov 0x0(%rip),%eax # 64 <main+0x35>
64: 89 c6 mov %eax,%esi
66: 48 8d 05 00 00 00 00 lea 0x0(%rip),%rax # 6d <main+0x3e>
6d: 48 89 c7 mov %rax,%rdi
70: b8 00 00 00 00 mov $0x0,%eax
75: e8 00 00 00 00 call 7a <main+0x4b>
7a: b8 00 00 00 00 mov $0x0,%eax
7f: e8 00 00 00 00 call 84 <main+0x55>
84: 8b 45 fc mov -0x4(%rbp),%eax
87: 89 c6 mov %eax,%esi
89: 48 8d 05 00 00 00 00 lea 0x0(%rip),%rax # 90 <main+0x61>
90: 48 89 c7 mov %rax,%rdi
93: b8 00 00 00 00 mov $0x0,%eax
98: e8 00 00 00 00 call 9d <main+0x6e>
9d: b8 00 00 00 00 mov $0x0,%eax
a2: c9 leave
a3: c3 ret