This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Support stripping and linking output to .build-id directory
ClosedPublic

Authored by phosek on Mar 7 2019, 11:17 PM.

Details

Summary

When installing runtimes with install-runtimes-stripped, we don't want
to just strip them, we also want to preserve the debugging information
for potential debugging. To make it possible to later find the stripped
debugging information, we want to use the .build-id layout:

https://fedoraproject.org/wiki/RolandMcGrath/BuildID#Find_files_by_build_ID

That is, for libfoo.so with build ID abcdef1234, the debugging information
will be installed into lib/debug/.build-id/ab/cdef1234. llvm-objcopy
already has support for stripping files and linking the debugging
stripped output into the right location. However, CMake doesn't support
customizing strip invocation for the *-stripped targets. So instead, we
replace CMAKE_STRIP with a custom script that invokes llvm-objcopy with
the right command line flags.

Diff Detail

Repository
rC Clang

Event Timeline

phosek created this revision.Mar 7 2019, 11:17 PM
phosek marked 2 inline comments as done.Mar 7 2019, 11:20 PM
phosek added inline comments.
llvm/runtimes/CMakeLists.txt
455 ↗(On Diff #189815)

We should probably only enable this for ELF targets since that's the only one that currently supports the .build-id scheme.

llvm/runtimes/llvm-strip-link.in
14 ↗(On Diff #189815)

@jakehehrlich llvm-objcopy complains when you give it unrecognized file as an input, in our case it's libc++.so which is a linker script. Is there a better way to do this?

jakehehrlich accepted this revision.Mar 8 2019, 12:59 PM

LGTM

llvm/runtimes/llvm-strip-link.in
14 ↗(On Diff #189815)

No this is the best way I can think to do it. If a file starts with the elf magic it's highly unlikely to be anything else, and certainly it won't be a linker script so I think this is good.

This revision is now accepted and ready to land.Mar 8 2019, 12:59 PM
smeenai accepted this revision.Mar 8 2019, 1:26 PM

Build parts look good to me.

llvm/cmake/modules/LLVMExternalProjectUtils.cmake
38 ↗(On Diff #189815)

I think STRIP_TOOL or STRIP_PATH or STRIP_TOOL_PATH would be more standard, but I don't care too much.

LLVM already has LLVM_EXTERNALIZE_DEBUGINFO, btw ... idk if that could be easily extended for this use case.

smeenai added inline comments.Mar 8 2019, 1:29 PM
llvm/runtimes/CMakeLists.txt
455 ↗(On Diff #189815)

Yup.

phosek updated this revision to Diff 189949.Mar 8 2019, 3:17 PM
phosek marked 3 inline comments as done.

I've updated the patch to make the .build-id linking an option that can be set in the cache file, how does that look to you?

smeenai accepted this revision.Mar 8 2019, 3:55 PM

LGTM

llvm/runtimes/CMakeLists.txt
438 ↗(On Diff #189949)

list(APPEND)

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 8 2019, 5:28 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript