--only-keep-debug is used to create separate debug files. It removes
contents of sections that are not useful for debugging purposes
(SHF_ALLOC sections that are not SHT_NOTE), by changing their section
types to SHT_NOBITS.
The intended use case is:
llvm-objcopy --only-keep-debug a a.dbg llvm-objcopy --strip-debug a b llvm-objcopy --add-gnu-debuglink=a.dbg b
The current layout algorithm is incapable of deleting contents and
shrinking segments, so it is not suitable for implementing the
functionality.
This patch adds a new algorithm which assigns sh_offset to sections
first, then modifies p_offset/p_filesz of program headers. It bears a
resemblance to lld/ELF/Writer.cpp.
I don't think "separate" should be used here, as it implies to me that the output of this operation is not the normal output file. Perhaps change this sentence to "Produce a debug file as the output that only preserves contents of sections useful for debugging purposes."