Index: llvm/trunk/test/tools/llvm-objcopy/strip-unneeded.test =================================================================== --- llvm/trunk/test/tools/llvm-objcopy/strip-unneeded.test +++ llvm/trunk/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: llvm/trunk/tools/llvm-objcopy/StripOpts.td =================================================================== --- llvm/trunk/tools/llvm-objcopy/StripOpts.td +++ llvm/trunk/tools/llvm-objcopy/StripOpts.td @@ -41,3 +41,6 @@ HelpText<"Remove all local symbols except file and section symbols">; def x : Flag<["-"], "x">, Alias; + +def strip_unneeded : Flag<["-", "--"], "strip-unneeded">, + HelpText<"Remove all symbols not needed by relocations">; Index: llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp =================================================================== --- llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp +++ llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp @@ -583,12 +583,12 @@ Config.OutputFilename = InputArgs.getLastArgValue(STRIP_output, Positional[0]); - // Strip debug info only. Config.StripDebug = InputArgs.hasArg(STRIP_strip_debug); Config.DiscardAll = InputArgs.hasArg(STRIP_discard_all); - - if (!Config.StripDebug && !Config.DiscardAll) + Config.StripUnneeded = InputArgs.hasArg(STRIP_strip_unneeded); + + if (!Config.StripDebug && !Config.StripUnneeded && !Config.DiscardAll) Config.StripAll = true; for (auto Arg : InputArgs.filtered(STRIP_remove_section))