Llvm-strip `-r`, `-u` and `-x` on macOS

CMake on macOS hardcodes the following logic for invoking STRIP (thanks to @tobiashieta for finding it):

  // macOS 'strip' is picky, executables need '-u -r' and dylibs need '-x'.
  if (this->Target->Target->GetMakefile()->IsOn("APPLE")) {
    if (this->Target->GetType() == cmStateEnums::SHARED_LIBRARY ||
        this->Target->GetType() == cmStateEnums::MODULE_LIBRARY) {
      stripArgs = "-x ";
    } else if (this->Target->GetType() == cmStateEnums::EXECUTABLE) {
      stripArgs = "-u -r ";
    }
  }

However, llvm-strip does not understand -u and -r, which results in silently unstripped binaries when building install-distribution-stripped. I’m saying silently, but it does log to stderr that it doesn’t understand these flags, but the target succeeds.

The man page for strip says

    -u     Save all undefined symbols.  This is intended for use with relocatable objects to save symbols referred to by external relocation entries.  Note  that  common
           symbols are also referred to by external relocation entries and this flag does not save those symbols.

    -r     Save all symbols referenced dynamically.

    -x     Remove all local symbols (saving only global symbols).

llvm-strip does have -x and the help says it’s for removing non-global symbols, I assume that’s the same as locals.

It sounds like -u could map to --keep-undefined but I don’t know if it’s the same.

I couldn’t figure out what r should map to (if such functionality is even implemented). If it’s not implemented, is it a bad thing to ignore the flag? I think that might be a better outcome than silently getting unstripped binaries.

I’m happy to contribute a patch to fix this if I can get some guidance on which way to go.