[PATCH] D46856: [llvm-objcopy] Add --only-keep-debug as a noop

Jake Ehrlich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 14 16:03:35 PDT 2018


jakehehrlich created this revision.
jakehehrlich added reviewers: jhenderson, paulsemel, alexshap, phosek.

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.


Repository:
  rL LLVM

https://reviews.llvm.org/D46856

Files:
  llvm/test/tools/llvm-objcopy/basic-only-keep-debug.test
  llvm/tools/llvm-objcopy/ObjcopyOpts.td
  llvm/tools/llvm-objcopy/llvm-objcopy.cpp


Index: llvm/tools/llvm-objcopy/llvm-objcopy.cpp
===================================================================
--- llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -159,6 +159,7 @@
   bool LocalizeHidden = false;
   bool Weaken = false;
   bool DiscardAll = false;
+  bool OnlyKeepDebug = false;
 };
 
 using SectionPred = std::function<bool(const SectionBase &Sec)>;
@@ -477,6 +478,7 @@
   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))
Index: llvm/tools/llvm-objcopy/ObjcopyOpts.td
===================================================================
--- llvm/tools/llvm-objcopy/ObjcopyOpts.td
+++ llvm/tools/llvm-objcopy/ObjcopyOpts.td
@@ -83,3 +83,5 @@
                        HelpText<"Remove symbol <symbol>">;
 def N : JoinedOrSeparate<["-"], "N">,
         Alias<strip_symbol>;
+def only_keep_debug : Flag<["-", "--"], "only-keep-debug">,
+                          HelpText<"Currently ignored. Only for compaitability with GNU objcopy.">;
Index: llvm/test/tools/llvm-objcopy/basic-only-keep-debug.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objcopy/basic-only-keep-debug.test
@@ -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"


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46856.146714.patch
Type: text/x-patch
Size: 2225 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180514/e7fcff52/attachment.bin>


More information about the llvm-commits mailing list