llvm-objcopy-5.patch 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. From 17dcf25b3ade15605ca27150e4440bcc75caed65 Mon Sep 17 00:00:00 2001
  2. From: Martin Storsjo <martin@martin.st>
  3. Date: Sat, 19 Jan 2019 19:42:54 +0000
  4. Subject: [PATCH] [llvm-objcopy] [COFF] Implement --only-section
  5. Differential Revision: https://reviews.llvm.org/D56873
  6. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351663 91177308-0d34-0410-b5e6-96231b3b80d8
  7. ---
  8. .../tools/llvm-objcopy/COFF/only-section.test | 21 +++++++++++++++++++
  9. tools/llvm-objcopy/COFF/COFFObjcopy.cpp | 6 ++++++
  10. 2 files changed, 27 insertions(+)
  11. create mode 100644 test/tools/llvm-objcopy/COFF/only-section.test
  12. diff --git a/llvm/test/tools/llvm-objcopy/COFF/only-section.test b/llvm/test/tools/llvm-objcopy/COFF/only-section.test
  13. new file mode 100644
  14. index 00000000000..42492ed80ff
  15. --- /dev/null
  16. +++ b/llvm/test/tools/llvm-objcopy/COFF/only-section.test
  17. @@ -0,0 +1,21 @@
  18. +RUN: yaml2obj %p/Inputs/only-keep-sections.yaml > %t.in.exe
  19. +
  20. +RUN: llvm-objcopy --only-section .debug_discardable %t.in.exe %t.out.exe
  21. +RUN: llvm-objdump --section-headers -t %t.out.exe | FileCheck %s --check-prefixes=SECTIONS,SECTIONS-DEBUG,SYMBOLS,SYMBOLS-DEBUG
  22. +
  23. +Adding another section stripping option makes it return the intersection of
  24. +kept sections - in this case keeping only .text.
  25. +
  26. +RUN: llvm-objcopy --only-section .debug_discardable --only-section .text --strip-debug %t.in.exe %t.combination.exe
  27. +RUN: llvm-objdump --section-headers -t %t.combination.exe | FileCheck %s --check-prefixes=SECTIONS,SECTIONS-TEXT,SYMBOLS,SYMBOLS-TEXT
  28. +
  29. +SECTIONS: Sections:
  30. +SECTIONS-NEXT: Idx Name
  31. +SECTIONS-DEBUG-NEXT: .debug_discardable
  32. +SECTIONS-TEXT-NEXT: .text
  33. +SECTIONS-EMPTY:
  34. +
  35. +SYMBOLS: SYMBOL TABLE:
  36. +SYMBOLS-DEBUG-NEXT: debug_discardable_sym
  37. +SYMBOLS-TEXT-NEXT: main
  38. +SYMBOLS-EMPTY:
  39. diff --git a/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp b/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
  40. index 60afbf7bb54..99929d10a1f 100644
  41. --- a/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
  42. +++ b/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
  43. @@ -33,6 +33,12 @@ static bool isDebugSection(const Section &Sec) {
  44. static Error handleArgs(const CopyConfig &Config, Object &Obj) {
  45. // Perform the actual section removals.
  46. Obj.removeSections([&Config](const Section &Sec) {
  47. + // Contrary to --only-keep-debug, --only-section fully removes sections that
  48. + // aren't mentioned.
  49. + if (!Config.OnlySection.empty() &&
  50. + !is_contained(Config.OnlySection, Sec.Name))
  51. + return true;
  52. +
  53. if (Config.StripDebug || Config.StripAll || Config.StripAllGNU ||
  54. Config.DiscardAll || Config.StripUnneeded) {
  55. if (isDebugSection(Sec) &&
  56. --
  57. 2.17.1