Skip to content

Commit 5cb7e49

Browse files
authored
[lld-macho] Fix -no_objc_category_merging flag (llvm#98238)
`-no_objc_category_merging` flag was behaving like `-objc_category_merging` - i.e. acting to enable category merging. This is because we were using `hasArg` instead of `hasFlag` to test for it. Fix this and add test to ensure it behaves as expected.
1 parent b96eb76 commit 5cb7e49

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lld/MachO/Driver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1989,7 +1989,8 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
19891989

19901990
// Category merging uses "->live = false" to erase old category data, so
19911991
// it has to run after dead-stripping (markLive).
1992-
if (args.hasArg(OPT_objc_category_merging, OPT_no_objc_category_merging))
1992+
if (args.hasFlag(OPT_objc_category_merging, OPT_no_objc_category_merging,
1993+
false))
19931994
objc::mergeCategories();
19941995

19951996
// ICF assumes that all literals have been folded already, so we must run

lld/test/MachO/objc-category-merging-complete-test.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88

99
# RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o a64_file2.o a64_file2.s
1010
# RUN: %lld -arch arm64 -o a64_file2_no_merge.exe a64_file1.dylib a64_file2.o
11+
# RUN: %lld -arch arm64 -o a64_file2_no_merge_v2.exe a64_file1.dylib a64_file2.o -no_objc_category_merging
12+
# RUN: %lld -arch arm64 -o a64_file2_no_merge_v3.exe a64_file1.dylib a64_file2.o -objc_category_merging -no_objc_category_merging
1113
# RUN: %lld -arch arm64 -o a64_file2_merge.exe -objc_category_merging a64_file1.dylib a64_file2.o
1214

1315
# RUN: llvm-objdump --objc-meta-data --macho a64_file2_no_merge.exe | FileCheck %s --check-prefixes=NO_MERGE_CATS
16+
# RUN: llvm-objdump --objc-meta-data --macho a64_file2_no_merge_v2.exe | FileCheck %s --check-prefixes=NO_MERGE_CATS
17+
# RUN: llvm-objdump --objc-meta-data --macho a64_file2_no_merge_v3.exe | FileCheck %s --check-prefixes=NO_MERGE_CATS
1418
# RUN: llvm-objdump --objc-meta-data --macho a64_file2_merge.exe | FileCheck %s --check-prefixes=MERGE_CATS
1519

1620
############ Test merging multiple categories into the base class ############

0 commit comments

Comments
 (0)