Combining install-distribution with binary stripping

Hi all,

I want to use the LLVM_DISTRIBUTION_COMPONENTS support to create an installed
toolchain image (via the install-distribution target). I'd also like the
installed binaries to be stripped.

If you're invoking a cmake install script directly, you can pass
-DCMAKE_INSTALL_DO_STRIP=1 to cmake to request stripping. The install-*
targets set up by LLVM's build system don't seem to have any provision for
this though, as far as I can tell. I also can't figure out a way to pass cmake
this option apart from just putting it in the invocation (and the cmake
invocation here is controlled by the install-* target).

I could go ahead and change the cmake invocation in all the install-* targets
to (conditionally) enable stripping, but the creation of the various install-*
targets is spread throughout the build system (a quick grep shows at least 20
of them spread around LLVM, clang, LLD, and libcxx), so it's a bit ugly. It's
obviously not hard to do (just tedious), and I'll put up some patches for that
if I can't figure out anything better, but I wanted to ask for suggestions
before embarking down that route.

Other solutions I've considered:
* Strip the installed files manually after the installation. Also ugly.
* Abandon LLVM_DISTRIBUTION_COMPONENTS and just build the components
  individually and then invoke the installation scripts myself. The
  distribution component setup is much nicer though :frowning:

Thanks,
Shoaib

Shoaib Meenai via llvm-dev <llvm-dev@lists.llvm.org> writes:

Hi all,

I want to use the LLVM_DISTRIBUTION_COMPONENTS support to create an installed
toolchain image (via the install-distribution target). I'd also like the
installed binaries to be stripped.

If you're invoking a cmake install script directly, you can pass
-DCMAKE_INSTALL_DO_STRIP=1 to cmake to request stripping. The install-*
targets set up by LLVM's build system don't seem to have any provision for
this though, as far as I can tell. I also can't figure out a way to pass cmake
this option apart from just putting it in the invocation (and the cmake
invocation here is controlled by the install-* target).

I could go ahead and change the cmake invocation in all the install-* targets
to (conditionally) enable stripping, but the creation of the various install-*
targets is spread throughout the build system (a quick grep shows at least 20
of them spread around LLVM, clang, LLD, and libcxx), so it's a bit ugly. It's
obviously not hard to do (just tedious), and I'll put up some patches for that
if I can't figure out anything better, but I wanted to ask for suggestions
before embarking down that route.

I was pretty sure this "Just Works", in that I use this and get stripped
executables already. It turns out that's because I use
-DLLVM_EXTERNALIZE_DEBUGINFO, which actually strips the binaries in the
build's bin/ before install targets even happen. Could that work for you?

Thanks for the suggestion. Unfortunately, that doesn't *quite* work, because
it doesn't perform a full strip (it does `strip -gx` instead of `strip -s`).
In my case the extra stripping is actually significant (e.g. it shaves 3 MB
off clang, and that 3 MB matters for my environment).

I'm wondering if performing a full strip for LLVM_EXTERNALIZE_DEBUGINFO would
be acceptable, since all the debug info is being split anyway.

    Shoaib Meenai via llvm-dev <llvm-dev@lists.llvm.org> writes:
    > Hi all,
    >
    > I want to use the LLVM_DISTRIBUTION_COMPONENTS support to create an installed
    > toolchain image (via the install-distribution target). I'd also like the
    > installed binaries to be stripped.
    >
    > If you're invoking a cmake install script directly, you can pass
    > -DCMAKE_INSTALL_DO_STRIP=1 to cmake to request stripping. The install-*
    > targets set up by LLVM's build system don't seem to have any provision for
    > this though, as far as I can tell. I also can't figure out a way to pass cmake
    > this option apart from just putting it in the invocation (and the cmake
    > invocation here is controlled by the install-* target).
    >
    > I could go ahead and change the cmake invocation in all the install-* targets
    > to (conditionally) enable stripping, but the creation of the various install-*
    > targets is spread throughout the build system (a quick grep shows at least 20
    > of them spread around LLVM, clang, LLD, and libcxx), so it's a bit ugly. It's
    > obviously not hard to do (just tedious), and I'll put up some patches for that
    > if I can't figure out anything better, but I wanted to ask for suggestions
    > before embarking down that route.
    
    I was pretty sure this "Just Works", in that I use this and get stripped
    executables already. It turns out that's because I use
    -DLLVM_EXTERNALIZE_DEBUGINFO, which actually strips the binaries in the
    build's bin/ before install targets even happen. Could that work for you?