CFI,CFA

CFI(calling frame info)的作用是出现异常时stack回滚(unwind)

而回滚的过程是一级级CFA往上回退,直到异常被catch

Assembler Directives

都属于汇编的指导语。

可以看下MIT的教程:

https://web.mit.edu/rhel-doc/3/rhel-as-en-3/index.html

The call frame is identified by an address on the stack. We refer to this address as the Canonical Frame Address orCFA. Typically, the CFA is defined to be the value of the stack pointer at the call site in the previous frame (which may be different from its value on entry to the current frame).

1)    .cfi_startproc

7.10.2 .cfi startproc [simple]
.cfi startproc is used at the beginning of each function that should have an entry in .eh frame.定义入口。 lt initializes some internal data structures. Don’t forget to close the function by .cfi endproc. Unless .cfi startproc is used along with parameter simple it also emits some architecture dependent initial CFl instructions.
7.10.3 .cfi endproc
cfi endproc is used at the end of a function where it closes its unwind entry previously opened by.cfi startproc and emits it to .eh frame. 对应的,结束。

2)    .cfi_def_cfa_offset 16

7.10.11 .cfi def cfa offset offset
.cfi def cfa offset modifies a rule for computing CFA. Register remains the same, but offset is new. Note that it is the absolute offset that will be added to a defined register to compute CFA address

偏移指的是什么东西的偏移?没有太搞清楚。具体是内存中哪个位置?

3)

    .cfi_offset 15, -16

4)包括对齐什么的。就是不知道是什么意思。什么是偏移,什么是对齐,要看具体的例子。

8.3. .align abs-expr, abs-expr, abs-expr

5)百度确实搜不出什么有用的信息来,也是醉了。

6)查手册可能更好一些,但是有些道理还是不懂。

《Intel® 64 and IA-32 Architectures Software Developer’s Manual》

7)

MOVSD Move scalar double-precision floating-point value between XMM registers or between an
XMM register and memory.

到底是mov 1个还是2个Double数据?

The MOVSD (move scalar double-precision floating-point) instruction transfers a 64-bit double-precision floatingpoint
operand from memory to the low quadword of an XMM register or vice versa, or between XMM registers.
Alignment of the memory address is not required, unless alignment checking is enabled.

movsd  (%rsi), %xmm0 # 把(%rsi)地址的一个64位数据加载到xmm0的低64位。所以是加载一个标题数据到xmm0的low quadword。

8)对寄存器的介绍,这个也不错。

http://www.mokhisin.cn/c/assemble/

9)

这个编译代码调试太牛逼了

第42部分-Linux x86 64位汇编SSE指令_mb611a2e88042f6的技术博客_51CTO博客

10)

The TEST instruction performs a logical AND of two operands and sets the SF, ZF, and PF flags according to the results

jle: Jump near if less or equal (ZF=1 or SF≠ OF).

下面我将给出一段汇编代码,请分析每一行指令的作用,并解释main,p1和p2这三个函数的堆栈变化过程 .file "test.c" .text .section .rodata .LC0: .string "%c\n" .text .globl p1 .type p1, @function p1: .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 movl %edi, %eax movb %al, -4(%rbp) movsbl -4(%rbp), %eax movl %eax, %esi leaq .LC0(%rip), %rax movq %rax, %rdi movl $0, %eax call printf@PLT nop leave .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE0: .size p1, .-p1 .globl p2 .type p2, @function p2: .LFB1: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 movl %edi, -4(%rbp) movl %esi, -8(%rbp) movl -4(%rbp), %edx movl -8(%rbp), %eax addl %edx, %eax popq %rbp .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE1: .size p2, .-p2 .section .rodata .LC1: .string "%d=%d+%d\n" .text .globl main .type main, @function main: .LFB2: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 subq $16, %rsp movb $97, -1(%rbp) movl $1, -8(%rbp) movl $2, -12(%rbp) movsbl -1(%rbp), %eax movl %eax, %edi call p1 movl -12(%rbp), %edx movl -8(%rbp), %eax movl %edx, %esi movl %eax, %edi call p2 movl %eax, -16(%rbp) movl -12(%rbp), %ecx movl -8(%rbp), %edx movl -16(%rbp), %eax movl %eax, %esi leaq .LC1(%rip), %rax movq %rax, %rdi movl $0, %eax call printf@PLT movl $0, %eax leave .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE2: .size main, .-main .ident "GCC: (Debian 13.1.0-6) 13.1.0" .section .note.GNU-stack,"",@progbits
09-29
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值