gpt4 book ai didi

c - GCC 没有重新排序堆栈变量

转载 作者:太空宇宙 更新时间:2023-11-03 23:39:40 25 4
gpt4 key购买 nike

您好,我正在尝试编译 C 代码而不对堆栈中的变量重新排序,但我做不到。

我试过使用:

__attribute__((no_reorder))

但不起作用,还尝试使用标志进行编译:

-fno-toplevel-reorder

但是没用...所以我卡住了。

实际代码:

uint8_t __attribute__((no_reorder)) first_buf[64];
uint8_t second_buf[32];

这是我的编译器版本:

gcc (Debian 7.2.0-19) 7.2.0

感谢阅读!

最佳答案

来自此处的 gcc 文档:

https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html

no_reorder

Do not reorder functions or variables marked no_reorder against each other or top level assembler statements the executable. The actual order in the program will depend on the linker command line. Static variables marked like this are also not removed. This has a similar effect as the -fno-toplevel-reorder option, but only applies to the marked symbols.

(强调我的)

因此,您似乎需要将属性应用于您希望保留的相应顺序的变量。仅将属性应用于单个变量只会保留该变量及其 itsef 的顺序,这没有任何效果。

关于c - GCC 没有重新排序堆栈变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49432465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com