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 --- /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 --- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp +++ b/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));