From 5ad0103d8a04cb066dfae4fc20b0dfcd9413f4d4 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 24 Oct 2019 15:48:32 -0700 Subject: [llvm-objcopy][ELF] Implement --only-keep-debug --only-keep-debug produces a debug file as the output that only preserves contents of sections useful for debugging purposes (the binutils implementation preserves SHT_NOTE and non-SHF_ALLOC sections), by changing their section types to SHT_NOBITS and rewritting file offsets. See https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html 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. Reviewed By: jhenderson, jakehehrlich Differential Revision: https://reviews.llvm.org/D67137 --- llvm/tools/llvm-objcopy/CommonOpts.td | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'llvm/tools/llvm-objcopy/CommonOpts.td') diff --git a/llvm/tools/llvm-objcopy/CommonOpts.td b/llvm/tools/llvm-objcopy/CommonOpts.td index ea3616589f5..6481d1d1df0 100644 --- a/llvm/tools/llvm-objcopy/CommonOpts.td +++ b/llvm/tools/llvm-objcopy/CommonOpts.td @@ -86,8 +86,9 @@ def keep_file_symbols : Flag<["--"], "keep-file-symbols">, def only_keep_debug : Flag<["--"], "only-keep-debug">, - HelpText<"Clear sections that would not be stripped by --strip-debug. " - "Currently only implemented for COFF.">; + HelpText< + "Produce a debug file as the output that only preserves contents of " + "sections useful for debugging purposes">; def discard_locals : Flag<["--"], "discard-locals">, HelpText<"Remove compiler-generated local symbols, (e.g. " -- cgit v1.2.3