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

Keith Smiley via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 19 16:35:27 PDT 2022


keith created this revision.
keith added reviewers: alexander-shaposhnikov, rmaz.
Herald added a reviewer: rupprecht.
Herald added a reviewer: jhenderson.
Herald added a subscriber: abrachet.
Herald added a project: All.
keith requested review of this revision.
Herald added subscribers: llvm-commits, MaskRay.
Herald added a project: LLVM.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132267

Files:
  llvm/test/tools/llvm-objcopy/MachO/bitcode-strip-object.s
  llvm/tools/llvm-objcopy/ObjcopyOptions.cpp


Index: llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
===================================================================
--- llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -1197,8 +1197,16 @@
 
   // 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));
Index: llvm/test/tools/llvm-objcopy/MachO/bitcode-strip-object.s
===================================================================
--- /dev/null
+++ 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132267.454132.patch
Type: text/x-patch
Size: 1963 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220819/1340c76c/attachment.bin>


More information about the llvm-commits mailing list