- 论坛徽章:
- 95
|
回复 1# asker160
你要是看看 gcc -S 生成的汇编的话,就会发现你的猜测是正确的:
$ cat func.c
- #include<unistd.h>
- #include<string.h>
- void a(char*s)
- {
- write(1,s,strlen(s));
- }
复制代码
$ cat func.s
- .file "func.c"
- .text
- .globl a
- .type a, @function
- a:
- .LFB0:
- .cfi_startproc
- pushq %rbp
- .cfi_def_cfa_offset 16
- .cfi_offset 6, -16
- movq %rsp, %rbp
- .cfi_def_cfa_register 6
- subq $16, %rsp
- movq %rdi, -8(%rbp)
- movq -8(%rbp), %rax
- movq %rax, %rdi
- call strlen
- movq %rax, %rdx
- movq -8(%rbp), %rax
- movq %rax, %rsi
- movl $1, %edi
- call write
- leave
- .cfi_def_cfa 7, 8
- ret
- .cfi_endproc
- .LFE0:
- .size a, .-a
- .ident "GCC: (Debian 4.9.2-10) 4.9.2"
- .section .note.GNU-stack,"",@progbits
复制代码
至于 objdump -d 给出的地址:
$ objdump -d func.o
- func.o: file format elf64-x86-64
- Disassembly of section .text:
- 0000000000000000 <a>:
- 0: 55 push %rbp
- 1: 48 89 e5 mov %rsp,%rbp
- 4: 48 83 ec 10 sub $0x10,%rsp
- 8: 48 89 7d f8 mov %rdi,-0x8(%rbp)
- c: 48 8b 45 f8 mov -0x8(%rbp),%rax
- 10: 48 89 c7 mov %rax,%rdi
- 13: e8 00 00 00 00 callq 18 <a+0x18>
- 18: 48 89 c2 mov %rax,%rdx
- 1b: 48 8b 45 f8 mov -0x8(%rbp),%rax
- 1f: 48 89 c6 mov %rax,%rsi
- 22: bf 01 00 00 00 mov $0x1,%edi
- 27: e8 00 00 00 00 callq 2c <a+0x2c>
- 2c: c9 leaveq
- 2d: c3 retq
复制代码
你仔细看看实际的机器码,就会发现跳转地址都是 0。在这里 objdump -d 给出了错误的结果。
|
|