Skip to content

[lld-macho] Fix -no_objc_category_merging flag #98238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2024

Conversation

alx32
Copy link
Contributor

@alx32 alx32 commented Jul 9, 2024

-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.

@kyulee-com
Copy link
Contributor

lgtm, btw is it still testing with a draft PR?

@alx32 alx32 marked this pull request as ready for review July 10, 2024 21:32
@llvmbot
Copy link
Member

llvmbot commented Jul 10, 2024

@llvm/pr-subscribers-lld

@llvm/pr-subscribers-lld-macho

Author: None (alx32)

Changes

-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.


Full diff: https://github.com/llvm/llvm-project/pull/98238.diff

2 Files Affected:

  • (modified) lld/MachO/Driver.cpp (+2-1)
  • (modified) lld/test/MachO/objc-category-merging-complete-test.s (+4)
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 83c92d214de31..28c28f29defd1 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1989,7 +1989,8 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
 
     // Category merging uses "->live = false" to erase old category data, so
     // it has to run after dead-stripping (markLive).
-    if (args.hasArg(OPT_objc_category_merging, OPT_no_objc_category_merging))
+    if (args.hasFlag(OPT_objc_category_merging, OPT_no_objc_category_merging,
+                     false))
       objc::mergeCategories();
 
     // ICF assumes that all literals have been folded already, so we must run
diff --git a/lld/test/MachO/objc-category-merging-complete-test.s b/lld/test/MachO/objc-category-merging-complete-test.s
index cf3e19e2f9c8b..cb112073eb871 100644
--- a/lld/test/MachO/objc-category-merging-complete-test.s
+++ b/lld/test/MachO/objc-category-merging-complete-test.s
@@ -8,9 +8,13 @@
 
 # RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o a64_file2.o a64_file2.s
 # RUN: %lld -arch arm64 -o a64_file2_no_merge.exe a64_file1.dylib a64_file2.o
+# RUN: %lld -arch arm64 -o a64_file2_no_merge_v2.exe a64_file1.dylib a64_file2.o -no_objc_category_merging
+# RUN: %lld -arch arm64 -o a64_file2_no_merge_v3.exe a64_file1.dylib a64_file2.o -objc_category_merging -no_objc_category_merging
 # RUN: %lld -arch arm64 -o a64_file2_merge.exe -objc_category_merging a64_file1.dylib a64_file2.o
 
 # RUN: llvm-objdump --objc-meta-data --macho a64_file2_no_merge.exe | FileCheck %s --check-prefixes=NO_MERGE_CATS
+# RUN: llvm-objdump --objc-meta-data --macho a64_file2_no_merge_v2.exe | FileCheck %s --check-prefixes=NO_MERGE_CATS
+# RUN: llvm-objdump --objc-meta-data --macho a64_file2_no_merge_v3.exe | FileCheck %s --check-prefixes=NO_MERGE_CATS
 # RUN: llvm-objdump --objc-meta-data --macho a64_file2_merge.exe | FileCheck %s --check-prefixes=MERGE_CATS
 
 ############ Test merging multiple categories into the base class ############

@alx32 alx32 merged commit 5cb7e49 into llvm:main Jul 10, 2024
12 checks passed
@alx32 alx32 deleted the 07_fix_cat_merging_flag branch July 11, 2024 17:57
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
`-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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants