gpt4 book ai didi

c - 将数据放入 .text 时会出现汇编器警告和 gcc 警告

转载 作者:行者123 更新时间:2023-12-03 02:55:24 25 4
gpt4 key购买 nike

当我编译时

__attribute__((section(".text"))) const int x = 42;
int main(){ return x; }

使用gcc(与tinycc和clang一起使用),我得到

警告:忽略 .text 已更改的节属性

警告的原因是什么?如何消除该警告,同时仍将(始终只读)数据保留在 .text 中?

最佳答案

显然:

__attribute__((section(".text#"))) const int x = 42;

引用号:https://gcc.gnu.org/ml/gcc-help/2010-09/msg00088.html回答者解释道:

__attribute__ ((section(".text"))) will make gcc emits ,"aw",@progbits after the .text to alter the section attributes. If you use: __attribute__ ((section(".text#"))) (notice the extra '#') this suffix will be commented in the assembly and the warning will disappear

在这种情况下,相关变量不是 const,因此对于同一问题尤其不明智(如 another responder 所述)。在您的情况下,它是一个 const,因此访问是 "a" 而不是 "aw" - 但仍然可能是不明智的。

关于c - 将数据放入 .text 时会出现汇编器警告和 gcc 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58455300/

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