[llvm] d991aa9 - [llvm-objcopy][MachO] Remove more sections with llvm-bitcode-strip

Keith Smiley via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 22 16:09:20 PDT 2022


Author: Keith Smiley
Date: 2022-08-22T16:08:58-07:00
New Revision: d991aa91f1bd44dc0d3151db78791e0d8a6b9c6e

URL: https://github.com/llvm/llvm-project/commit/d991aa91f1bd44dc0d3151db78791e0d8a6b9c6e
DIFF: https://github.com/llvm/llvm-project/commit/d991aa91f1bd44dc0d3151db78791e0d8a6b9c6e.diff

LOG: [llvm-objcopy][MachO] Remove more sections with llvm-bitcode-strip

This adds the other potential bitcode sections that can exist and should
be stripped with `-r` from `llvm-bitcode-strip`.

Differential Revision: https://reviews.llvm.org/D132267

Added: 
    llvm/test/tools/llvm-objcopy/MachO/bitcode-strip-object.s

Modified: 
    llvm/tools/llvm-objcopy/ObjcopyOptions.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-objcopy/MachO/bitcode-strip-object.s b/llvm/test/tools/llvm-objcopy/MachO/bitcode-strip-object.s
new file mode 100644
index 0000000000000..e697669fca8ae
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/MachO/bitcode-strip-object.s
@@ -0,0 +1,29 @@
+# REQUIRES: x86-registered-target
+
+## Verify llvm-bitcode-strip removes sections from object files
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t
+# RUN: llvm-bitcode-strip -r %t -o %t2
+# RUN: llvm-readobj --macho-segment --sections %t2 | FileCheck --implicit-check-not=__LLVM %s
+
+# CHECK:      Name: __text
+# CHECK-NEXT: Segment: __TEXT
+
+.section __LLVM,__bundle
+  .asciz "test"
+
+.section __LLVM,__bitcode
+  .asciz "test"
+
+.section __LLVM,__cmdline
+  .asciz "test"
+
+.section __LLVM,__swift_cmdline
+  .asciz "test"
+
+.section __LLVM,__asm
+  .asciz "test"
+
+.text
+.globl _main
+_main:
+  ret

diff  --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
index 7db1e79f3e49a..a80ee2973d05e 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -1197,8 +1197,16 @@ objcopy::parseBitcodeStripOptions(ArrayRef<const char *> ArgsArr,
 
   // We only support -r for now, which removes all bitcode sections and
   // the __LLVM segment if it's now empty.
+  cantFail(Config.ToRemove.addMatcher(NameOrPattern::create(
+      "__LLVM,__asm", MatchStyle::Literal, ErrorCallback)));
+  cantFail(Config.ToRemove.addMatcher(NameOrPattern::create(
+      "__LLVM,__bitcode", MatchStyle::Literal, ErrorCallback)));
   cantFail(Config.ToRemove.addMatcher(NameOrPattern::create(
       "__LLVM,__bundle", MatchStyle::Literal, ErrorCallback)));
+  cantFail(Config.ToRemove.addMatcher(NameOrPattern::create(
+      "__LLVM,__cmdline", MatchStyle::Literal, ErrorCallback)));
+  cantFail(Config.ToRemove.addMatcher(NameOrPattern::create(
+      "__LLVM,__swift_cmdline", MatchStyle::Literal, ErrorCallback)));
   MachOConfig.EmptySegmentsToRemove.insert("__LLVM");
 
   DC.CopyConfigs.push_back(std::move(ConfigMgr));


        


More information about the llvm-commits mailing list