Index: test/tools/llvm-objcopy/strip-unneeded.test =================================================================== --- test/tools/llvm-objcopy/strip-unneeded.test +++ test/tools/llvm-objcopy/strip-unneeded.test @@ -1,7 +1,14 @@ # RUN: yaml2obj %s > %t +# RUN: cp %t %t1 # RUN: llvm-objcopy --strip-unneeded %t %t2 +# Verify that llvm-objcopy has not modified the input. +# RUN: cmp %t %t1 # RUN: llvm-readobj -symbols %t2 | FileCheck %s +# Verify that llvm-strip modifies the symbol table the same way. +# RUN: llvm-strip --strip-unneeded %t +# RUN: cmp %t %t2 + !ELF FileHeader: Class: ELFCLASS64 Index: tools/llvm-objcopy/StripOpts.td =================================================================== --- tools/llvm-objcopy/StripOpts.td +++ tools/llvm-objcopy/StripOpts.td @@ -36,3 +36,5 @@ def K : JoinedOrSeparate<["-"], "K">, Alias; +def strip_unneeded : Flag<["-", "--"], "strip-unneeded">, + HelpText<"Remove all symbols not needed by relocations">; Index: tools/llvm-objcopy/llvm-objcopy.cpp =================================================================== --- tools/llvm-objcopy/llvm-objcopy.cpp +++ tools/llvm-objcopy/llvm-objcopy.cpp @@ -585,7 +585,10 @@ // Strip debug info only. Config.StripDebug = InputArgs.hasArg(STRIP_strip_debug); - if (!Config.StripDebug) + + Config.StripUnneeded = InputArgs.hasArg(STRIP_strip_unneeded); + + if (!Config.StripDebug && !Config.StripUnneeded) Config.StripAll = true; for (auto Arg : InputArgs.filtered(STRIP_remove_section))