英文:
What is NT_GNU_BUILD_ID used for?
问题
我正在为您翻译以下内容:
我正在阅读golang ld的帮助指南,其中一个选项是
-B value
在使用ELF时添加一个NT_GNU_BUILD_ID注释。该值应以0x开头,并且应为偶数个十六进制数字。
有人知道为什么要使用这个标志吗?
搜索NT_GNU_BUILD_ID
并没有提供任何有见地的答案。
英文:
I was reading the help guide for golang ld and one of the options is
-B value
Add a NT_GNU_BUILD_ID note when using ELF. The value
should start with 0x and be an even number of hex digits.
Does anyone knows why one would use that flag ?
searching for NT_GNU_BUILD_ID
does not provide any insightful answer.
答案1
得分: 8
这是来自于cmd/new5l
的大规模将C转换为Go的代码(2015年2月),翻译自src/cmd/ld/pobj.c
。
这些信息是在提交 7d507dc6e(2013年12月,用于Go 1.3)中引入的,为新的链接器结构做准备。
NT_GNU_BUILD_ID
在这里被提到作为一个唯一的构建 ID 位串。例如,在Fedora 发布构建中可以看到它的应用。
为了将 ID 嵌入到剥离了符号信息的目标文件和其.debug
文件中,我选择使用了一个 ELF 笔记(note)段。当段的类型为SHT_NOTE
时,strip
等工具可以在两个文件中保持该段的完整性。
这个新的段被规范地称为.note.gnu.build-id
,但名称并不是规范的,该段可以与其他SHT_NOTE
段合并。ELF 笔记头部为构建 ID 笔记给出了名称“GNU
”和类型 3(NT_GNU_BUILD_ID
),一个链接对象(或.ko
风格的ET_REL
文件)中只能有一个构建 ID 笔记。
你可以在这个 2007 年的补丁中看到它的引入:
这个补丁为 ELF 目标添加了一个新的选项--build-id
。它生成一个包含“唯一构建 ID”位的合成 ELF 笔记段,由ld
选择。
这样做是为了作为ld
选项,以便对每次编译都是高效和可靠的(而不是通过某个脚本将生成的对象添加到链接中)。它的实现方式可以使用确切的最终 ELF 输出位来贡献选择一个唯一 ID,既不多也不少。
这是确保确定性 ID 生成方式(如加密哈希)在重复精确重现的构建中始终产生相同结果的最佳方式。
英文:
This comes from the massive conversion from C to Go of cmd/new5l
(Feb. 2015), translated from src/cmd/ld/pobj.c
That information was introduced in commit 7d507dc6e (Dec. 2013, for Go 1.3), a preparation for the new linker structure
NT_GNU_BUILD_ID
is mentioned here as a unique build ID bitstring.
You see it employed for instance in Fedora release build
> To embed an ID into both the stripped object and its .debug
file, I've chosen to use an ELF note section.
strip
et al can keep the section intact in both files when its type is SHT_NOTE
.
> The new section is canonically called .note.gnu.build-id
, but the name is not normative, and the section can be merged with other SHT_NOTE
sections.
The ELF note headers give name "GNU
" and type 3 (NT_GNU_BUILD_ID
) for a build ID note, of which there can be only one in a linked object (or an ET_REL
file of the .ko
style).
You can see it introduced in this patch in 2007:
> This patch adds a new option to ld
for ELF targets, --build-id
.
It generates a synthetic ELF note section containing "unique build ID
" bits
chosen by ld
.
> This is done as an ld
option to be efficient and foolproof to enable for
every compilation (vs some script adding a generated object into the link).
It's done the way it is so it can use no more and no less than the exact
final ELF bits of the output to contribute to selecting a unique ID.
> This is the best way to ensure that deterministic styles of ID generation
(i.e. cryptographic hash) will always yield identical results for repeated
builds reproduced precisely.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论