[llvm] r332396 - [llvm-objcopy] Add --only-keep-debug as a noop

Jake Ehrlich via llvm-commits llvm-commits at lists.llvm.org
Tue May 15 13:53:53 PDT 2018


Author: jakehehrlich
Date: Tue May 15 13:53:53 2018
New Revision: 332396

URL: http://llvm.org/viewvc/llvm-project?rev=332396&view=rev
Log:
[llvm-objcopy] Add --only-keep-debug as a noop

This option just keeps being a problem and really needs to be implemented
in some fashion. Implementing it properly requires some kind of
"replaceSectionReference" method because all the existing links need to be
maintained. The desired behavior is just for allocated sections to become
NOBITS but actually implementing that is rather tricky due to the current
design of llvm-objcopy. However converting allocated sections to NOBITS is
just an optimization and not something debuggers need. Debuggers can debug
a stripped executable and take an unstripped executable for that stripped
executable as input. Additionally allocated sections account for a very
small part of debug binaries so this optimization is quite small. I propose
that for the time being we implement this as a NOP so that people can use
llvm-objcopy where they need to, just in a sub-optimal way.

This option has already blocked a lot of people and its currently blocking me.

Added:
    llvm/trunk/test/tools/llvm-objcopy/basic-only-keep-debug.test
Modified:
    llvm/trunk/tools/llvm-objcopy/ObjcopyOpts.td
    llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp

Added: llvm/trunk/test/tools/llvm-objcopy/basic-only-keep-debug.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/basic-only-keep-debug.test?rev=332396&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/basic-only-keep-debug.test (added)
+++ llvm/trunk/test/tools/llvm-objcopy/basic-only-keep-debug.test Tue May 15 13:53:53 2018
@@ -0,0 +1,20 @@
+# NOTE: This test is only intended to be valid as long as --only-keep-debug is
+#       implemented as a NOP. This test should fail when that changes and you
+#       will need to update this test.
+
+# RUN: yaml2obj %s > %t
+# RUN: llvm-objcopy %t %t2
+# RUN: llvm-objcopy --only-keep-debug %t %t3
+# RUN: cmp %t2 %t3
+
+!ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_EXEC
+  Machine:         EM_X86_64
+Sections:
+  - Name:            .text
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    Content:         "DEADBEEF"

Modified: llvm/trunk/tools/llvm-objcopy/ObjcopyOpts.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/ObjcopyOpts.td?rev=332396&r1=332395&r2=332396&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/ObjcopyOpts.td (original)
+++ llvm/trunk/tools/llvm-objcopy/ObjcopyOpts.td Tue May 15 13:53:53 2018
@@ -88,3 +88,5 @@ defm keep_symbol : Eq<"keep-symbol">,
                        HelpText<"Do not remove symbol <symbol>">;
 def K : JoinedOrSeparate<["-"], "K">,
         Alias<keep_symbol>;
+def only_keep_debug : Flag<["-", "--"], "only-keep-debug">,
+                          HelpText<"Currently ignored. Only for compaitability with GNU objcopy.">;

Modified: llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp?rev=332396&r1=332395&r2=332396&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp Tue May 15 13:53:53 2018
@@ -160,6 +160,7 @@ struct CopyConfig {
   bool LocalizeHidden = false;
   bool Weaken = false;
   bool DiscardAll = false;
+  bool OnlyKeepDebug = false;
 };
 
 using SectionPred = std::function<bool(const SectionBase &Sec)>;
@@ -482,6 +483,7 @@ CopyConfig ParseObjcopyOptions(ArrayRef<
   Config.LocalizeHidden = InputArgs.hasArg(OBJCOPY_localize_hidden);
   Config.Weaken = InputArgs.hasArg(OBJCOPY_weaken);
   Config.DiscardAll = InputArgs.hasArg(OBJCOPY_discard_all);
+  Config.OnlyKeepDebug = InputArgs.hasArg(OBJCOPY_only_keep_debug);
   for (auto Arg : InputArgs.filtered(OBJCOPY_localize_symbol))
     Config.SymbolsToLocalize.push_back(Arg->getValue());
   for (auto Arg : InputArgs.filtered(OBJCOPY_globalize_symbol))




More information about the llvm-commits mailing list