简体   繁体   English

编译链接期间生成 build-id

[英]build-id generation during compilation-linking

Does anyone now how build-id is generated?现在有人知道如何生成 build-id 吗? I've been looking everywhere online but I can't find an explanation.我一直在网上到处寻找,但找不到解释。 I found this, https://fedoraproject.org/wiki/RolandMcGrath/BuildID , but that doesn't tell me how it is generated.我找到了这个https://fedoraproject.org/wiki/RolandMcGrath/BuildID ,但这并没有告诉我它是如何生成的。 I also ound this, https://elixir.bootlin.com/linux/v5.8.3/source/tools/perf/util/build-id.c , but I'm not sure if this the right place to look at.我也找到了这个https://elixir.bootlin.com/linux/v5.8.3/source/tools/perf/util/build-id.c ,但我不确定这是否是正确的地方。 So, does anybody know how build-id is generated?那么,有人知道build-id是如何生成的吗?

Is it generated over a section of an ELF file, multiple sections or randomly?它是在 ELF 文件的一部分、多个部分还是随机生成的?

Is it generated over a section of an ELF file, multiple sections or randomly?它是在 ELF 文件的一部分、多个部分还是随机生成的?

The goal of Build-ID is to make it so that it's easy to associate debug info with the ELF image ( ET_EXEC or ET_DYN ) to which it belongs. Build-ID 的目标是使其易于将调试信息与其所属的 ELF 映像( ET_EXECET_DYN )相关联。

As Roland explains, you could use a random UUID for it, but that has a disadvantage of precluding bit-identical rebuilds.正如 Roland 解释的那样,您可以为其使用随机 UUID,但这样做的缺点是无法进行完全相同的重建。 You could also use md5 or sha1 checksum over the entire ELF image, but that has a risk of people misusing it as an actual checksum.您还可以对整个 ELF 图像使用md5sha1校验和,但这有可能会被人们误将其用作实际校验和。

So the implementation uses a checksum over important parts of the image, such that hash collisions (identical build-ids) over different images are highly unlikely.因此,该实现对图像的重要部分使用校验和,因此极不可能在不同图像上发生 hash 次冲突(相同的构建 ID)。

Precisely which parts are important is left to linker implementers and is left as an implementation detail.究竟哪些部分是重要的留给 linker 实施者,并作为实施细节留给。 If you wanted to know exactly what these parts are, you'll have to read corresponding implementation files for Gold ,BFD ld and LLD .如果您想确切了解这些部分是什么,则必须阅读GoldBFD ldLLD的相应实现文件。

You can also substitute your own UUID (if bit-identical rebuilds are not a concern for you) -- the --build-id flag accepts user-provided bit string and will happily put it into your ELF image.您也可以替换您自己的UUID(如果您不关心位相同的重建)——-- --build-id标志接受用户提供的位字符串,并将很乐意将其放入您的 ELF 映像中。

PS The build-id.c you found in perf has nothing to do with generation of build-ids. PS 您在perf中找到的 build-id.c 与生成build-id 无关。 perf records build-id's of images that it observes, so later analysis can grab correct ELF images to perform symbolization. perf记录它观察到的图像的构建 ID,因此以后的分析可以抓取正确的 ELF 图像来执行符号化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM