[lld] [LLD][COFF] Add -build-id flag to generate .buildid section. (PR #71433)

Zequan Wu via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 15 07:52:45 PST 2023


ZequanWu wrote:

> > 1. I feel like it's not necessary to create a separate `.buildid` section at all when not using MinGW driver. Initially, I thought if I want to find build id at runtime, I need to somehow find the program header and locate `.buildid`. With a separate section, it's easier to find it. @rnk suggested adding a synthetic `__lld_buildid` symbol to lld-link pointing to the chunk, so it's easier to locate it. I have a local patch for it. With that, it doesn't matter if buildid is in a separate section or not. So, I think just always put it in .rdata under non-MinGW mode is enough.
> 
> Hmm, if you're using a symbol, how are you locating the symbol later when inspecting things? MSVC style builds normally don't include a symbol table at all - do you build with debug info and resolve it from the PDB file somehow? Or do you use `-debug:symtab`?

By using symbol, I meant to let lld-link add a synthetic symbol `__lld_buildid` if `/build-id` is passed. That points the the chunk contains build id, just like `__CTOR_LIST__` symbol https://github.com/llvm/llvm-project/blob/ebb8ffde94476333cb2e95aacfd2e023d7112efb/lld/COFF/Driver.cpp#L2373. 

At the source that references `__lld_buildid`, it can use `extern "C" __declspec(selectany) uint8_t __lld_buildid[24];` to read the build id.
For tools like `llvm-readobj`, it is already able to read build id even if it's inside `.rdata` by looking through the program header.

https://github.com/llvm/llvm-project/pull/71433


More information about the llvm-commits mailing list