简体   繁体   中英

build-id generation during compilation-linking

Does anyone now how build-id is generated? 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. 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. So, does anybody know how build-id is generated?

Is it generated over a section of an ELF file, multiple sections or randomly?

Is it generated over a section of an ELF file, multiple sections or randomly?

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.

As Roland explains, you could use a random UUID for it, but that has a disadvantage of precluding bit-identical rebuilds. 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.

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.

Precisely which parts are important is left to linker implementers and is left as an implementation detail. If you wanted to know exactly what these parts are, you'll have to read corresponding implementation files for Gold ,BFD ld and LLD .

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.

PS The build-id.c you found in perf has nothing to do with generation of build-ids. perf records build-id's of images that it observes, so later analysis can grab correct ELF images to perform symbolization.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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