[PATCH] D51833: ELF: Add --build-id-link-dir=DIR switch

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 10 16:43:30 PDT 2018


phosek added a comment.

In https://reviews.llvm.org/D51833#1229002, @ruiu wrote:

> This seems like a new feature proposal, and we haven't discussed this before. It's not clear to me why you have to do this inside the linker rather than a post-processing tool. Could you please elaborate about why you want to add a new option?


The `.build-id/xx/xxx.debug` lookup protocol is already used by various tools such as debuggers (e.g. here's the logic in LLDB <https://github.com/llvm-mirror/lldb/blob/master/source/Host/common/Symbols.cpp#L251>) or Linux packagers. It's also supported by other ELF tools such as elfutils. We'd like to use it in Fuchsia as well and integrate it into our build system.

The problem is that determining the build-id after linking is done is not very straightforward, you can use a tool like `llvm-readobj`, but that tools doesn't have a machine-readable output so you need to parse the output which is error prone and adds an extra overhead. It also means that in our build system we'd need to add additional step or wrap linking in a script complicating things, especially if you want to do it in a portable fashion that's going to work on Linux, Windows and macOS.

Initially we considered adding a flag to lld that would allows writing the build-id into a file which would allow something like `ld.lld --build-id-file=>(id=$(</dev/fd/0); mkdir -p build-id/${id:0:2} && ln -f {{output}} build-id/${id:0:2}/${id:2})`, but this again is not a portable solution which won't work on Windows. So we instead tried prototyping the support for linking the output file directly into the `.build-id/xx/xxx.debug` layout to see how complicated it'd be, and turned out it's actually pretty straightforward as you see here (I have even more simplified version that eliminates the hex representation computation using `llvm::toHex` instead).

Would this be an acceptable addition? It'd simplify our build system and this solution should be working across all platforms without any extra effort. If this would be fine with you, I'm going to update the change and also write some tests.


Repository:
  rL LLVM

https://reviews.llvm.org/D51833





More information about the llvm-commits mailing list