- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想要解释 GCC 生成的程序集中与 .cfi_def_cfa_offset 指令一起使用的值。我隐约知道 .cfi 指令涉及调用帧和堆栈展开,但我想更详细地解释为什么,例如,在编译以下 C 程序时 GCC 输出的程序集中使用值 16 和 8在我的 64 位 Ubuntu 机器上。
C 程序:
#include <stdio.h>
int main(int argc, char** argv)
{
printf("%d", 0);
return 0;
}
我在源文件 test.c 上调用了 GCC,如下所示:gcc -S -O3 test.c
。我知道 -O3 可以实现非标准优化,但为了简洁起见,我想限制生成的程序集的大小。
生成的程序集:
.file "test.c"
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "%d"
.text
.p2align 4,,15
.globl main
.type main, @function
main:
.LFB22:
.cfi_startproc
subq $8, %rsp
.cfi_def_cfa_offset 16
xorl %edx, %edx
movl $.LC0, %esi
movl $1, %edi
xorl %eax, %eax
call __printf_chk
xorl %eax, %eax
addq $8, %rsp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE22:
.size main, .-main
.ident "GCC: (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2"
.section .note.GNU-stack,"",@progbits
为什么生成的程序集中的 .cfi_def_cfa_offset 指令使用值 16 和 8?另外,为什么局部函数开始和函数结束标签使用数字 22?
最佳答案
作为DWARF spec第 6.4 节中说:
[...] The call frame is identified by an address on the stack. We refer to this address as the Canonical Frame Address or CFA. 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).
main()
从其他地方调用(在 libc
C 运行时支持代码中),并且在执行 call
指令时执行后,%rsp
将指向堆栈顶部(这是最低地址 - 堆栈向下增长),无论它是什么(具体是什么在这里并不重要):
: : ^
| whatever | <--- %rsp | increasing addresses
+----------------+ |
此时%rsp
的值是“调用站点的堆栈指针的值”,即规范定义的CFA。
当执行call
指令时,它将把64位(8字节)返回地址压入堆栈:
: :
| whatever | <--- CFA
+----------------+
| return address | <--- %rsp == CFA - 8
+----------------+
现在我们正在 main
运行代码,它执行 subq $8, %rsp
为自己保留另外 8 个字节的堆栈:
: :
| whatever | <--- CFA
+----------------+
| return address |
+----------------+
| reserved space | <--- %rsp == CFA - 16
+----------------+
使用.cfi_def_cfa_offset
指令在调试信息中声明堆栈指针的变化,您可以看到CFA现在距离当前堆栈指针偏移16个字节。
在函数末尾,addq $8, %rsp
指令再次更改堆栈指针,因此插入另一个.cfi_def_cfa_offset
指令以指示CFA现在距堆栈指针仅偏移 8 个字节。
(标签中的数字“22”只是一个任意值。编译器将根据一些实现细节(例如基本 block 的内部编号)生成唯一的标签名称。)
关于assembly - 气体 : Explanation of . cfi_def_cfa_offset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7534420/
我想从文档属性中获取数据,将其转换为数组,然后将其推送到工作表中。该工作表恰好位于与脚本所在的电子表格不同的电子表格中,但我已经解决了这个问题。我遇到的问题是将属性中的数据转换为二维数组 [{user
我想要解释 GCC 生成的程序集中与 .cfi_def_cfa_offset 指令一起使用的值。我隐约知道 .cfi 指令涉及调用帧和堆栈展开,但我想更详细地解释为什么,例如,在编译以下 C 程序时
编译以下指令时: movl 4(%ebp), 8(%ebp) 我得到:内存引用太多。 这是怎么回事? 最佳答案 括号前的数字是字节偏移量(这会导致发生内存引用),并且 movl 中不能有两个。您需要先
编译以下指令时: movl 4(%ebp), 8(%ebp) 我得到:内存引用太多。 这是怎么回事? 最佳答案 括号前的数字是字节偏移量(这会导致内存引用发生),并且 movl 中不能有两个。您需要先
编译如下指令时: movl 4(%ebp), 8(%ebp) 我得到:过多的内存引用。 这是怎么回事? 最佳答案 括号前的数字是一个字节偏移量(这会导致内存引用发生),你不能用movl有两个。您需要先
我正在尝试组装以下程序: .text .globl _search2 _search2: pushq %rbp movq %rsp, %rbp movq
我正在尝试在 Google Apps 脚本中创建自定义对话,如下所示: function onOpen() { SpreadsheetApp.getUi() .createMenu('Cu
我如何在谷歌应用程序脚本中创建一个库,我可以在其中仅共享库 key 并且人们可以使用它,而无需正确共享代码?我正在努力寻找解决方案,但我失败了。 我不想与全世界共享图书馆。我只想在不同的谷歌驱动器中使
因此,我将一个 google 表单输入到工作表中,然后从电子表格中,我使用电子表格中的答案模板制作 google 文档。 表单能够在中途保存并稍后通过自定义问题返回,询问他们是否要保存并返回(这会提交
我有一个每天运行的脚本,每天都会将新值设置为谷歌表格。我担心的是每次脚本运行时,它都会覆盖现有数据。我想要的是工作表底部最后一行的数据集,以便有一个延续。我已尝试使用下面的代码,但它不起作用。我该怎么
考虑以下 Google Apps 脚本代码: var ui = SpreadsheetApp.getUi(); var result = ui.prompt( 'How many days in
我在几张纸上使用一个脚本。为了避免每次更改时都更改每张工作表中的脚本,我创建了一个库(顺便说一下,是否有更好的库替代品?)。所以我在其他工作表中这样调用我的函数: myFunction(){ retu
我正在尝试使用 Google Apps 脚本将文件从 Google Drive 上传到 YouTube。 我只成功上传了大约 2MB 的视频。 这样做的主要原因是互联网连接速度慢,有时上传不可靠,因此
我正在向 Amazon S3 服务器运行 URLFetchApp 请求,以提取音频文件并将其重新定位到 Google 云端硬盘。 HTTPResponse 以 XML 格式返回。 我运行以下代码来转换
我编写了一个函数,该函数从电子表格中的原始文本中提取一些所需的信息并将其放入其他列中。但我只想在该列为空时使用此函数(因为,如果它不为空,是因为它的值是手动更新的)。我尝试使用下面的代码,但我发现 s
我正在开发一个个人项目,尝试扩展 10K ft 项目管理系统 API 的限制,并且是 GAS 或 Javascript 的新手,我将不胜感激对我正在尝试执行的代码的帮助。有关此内容的 API 文档可以
使用 Google Apps 脚本,我想解码 HTML,例如: Some text & text ¢ 存储为: Some text & text ¢ 所以,类似的问题:How t
我是一名优秀的程序员,十分优秀!