c - 为什么 gcc 添加 .comment 和 .note.gnu.property 部分?

标签 c gcc ld

谁能解释为什么 gcc 在目标代码中添加 .comment 和 .note.gnu.property 部分,我如何告诉 gcc 不要添加它们,这可能吗?

谢谢。

最佳答案

why gcc is adding the .comment and .note.gnu.property sections

您可以检查 .comment 部分的内容,例如readelf -x.comment:

echo "int foo() { return 42; }" | gcc -xc - -c -o foo.o
readelf -x.comment foo.o

Hex dump of section '.comment':
  0x00000000 00474343 3a202844 65626961 6e203131 .GCC: (Debian 11
  0x00000010 2e322e30 2d313029 2031312e 322e3000 .2.0-10) 11.2.0.

显然,“为什么”是为了更容易理解生成目标文件的编译器。

我不相信有 GCcflags来抑制它,但是 objcopy --remove-section .comment foo.o bar.o 会摆脱它。

.note.gnu.property 可以是 removed以类似的方式。

这是一个discussion它可能包含的内容。

关于c - 为什么 gcc 添加 .comment 和 .note.gnu.property 部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70455981/

相关文章:

c - 我如何在这个简单的 C shell 中设置超时?

c - 信号处理程序返回段错误 :11

c - 字数统计程序 - stdin

c++ - 使用 gcc 在 C++ 中嵌入常量循环条件优化

c++ - 在 callgrind 输出中解释 _dl_runtime_resolve_xsave'2

c - 将 C 文件中的符号导入链接描述文件

gcc - 如何设置共享库的动态链接器路径?

c - 查找二维圆锥形状的网格点

c++ - 尝试在 fedora 25 上链接 SFML 应用程序

c++ - 构建共享库时 -fPIC 是什么意思?