Skip to content
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

[LLD, MachO] Default objc_relative_method_lists on MacOS11+/iOS14+ #101360

Merged
merged 4 commits into from
Aug 7, 2024

Conversation

DataCorrupted
Copy link
Member

This patch makes objc_relative_method_lists default on MacOS 11+ / iOS 14+. Manual override still work if command line argument is provided.

To test this change, many explict arguments are removed from the test files. Some explict no_objc_relative... are also added for tests that don't support this yet.

This patch makes `objc_relative_method_lists` default on MacOS 11+ / iOS 14+.
Manual override still work if command line argument is provided.

To test this change, many explict arguments are removed from the test files.
Some explict `no_objc_relative...` are also added for tests that don't support this yet.

Signed-off-by: Peter Rong <[email protected]>
@DataCorrupted DataCorrupted self-assigned this Jul 31, 2024
@DataCorrupted DataCorrupted requested a review from alx32 July 31, 2024 18:39
@DataCorrupted DataCorrupted marked this pull request as ready for review July 31, 2024 20:12
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 31, 2024

@llvm/pr-subscribers-lld

@llvm/pr-subscribers-lld-macho

Author: Peter Rong (DataCorrupted)

Changes

This patch makes objc_relative_method_lists default on MacOS 11+ / iOS 14+. Manual override still work if command line argument is provided.

To test this change, many explict arguments are removed from the test files. Some explict no_objc_relative... are also added for tests that don't support this yet.


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

6 Files Affected:

  • (modified) lld/MachO/Driver.cpp (+14-6)
  • (modified) lld/test/MachO/objc-category-conflicts.s (+11-8)
  • (modified) lld/test/MachO/objc-category-merging-complete-test.s (+9-6)
  • (modified) lld/test/MachO/objc-category-merging-erase-objc-name-test.s (+4-1)
  • (modified) lld/test/MachO/objc-category-merging-minimal.s (+9-6)
  • (modified) lld/test/MachO/objc-relative-method-lists-simple.s (+4-4)
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index f3d2a93914f71..bbe934d9c3887 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1140,12 +1140,20 @@ static bool shouldEmitRelativeMethodLists(const InputArgList &args) {
   if (arg && arg->getOption().getID() == OPT_no_objc_relative_method_lists)
     return false;
 
-  // TODO: If no flag is specified, don't default to false, but instead:
-  //   - default false on   <   ios14
-  //   - default true  on   >=  ios14
-  // For now, until this feature is confirmed stable, default to false if no
-  // flag is explicitly specified
-  return false;
+  // If no flag is specified:
+  //   - default true  on   >=  ios14/macos11
+  //   - default false on everything else
+  switch (config->platformInfo.target.Platform) {
+  case PLATFORM_IOS:
+  case PLATFORM_IOSSIMULATOR:
+    return config->platformInfo.target.MinDeployment >= VersionTuple(14, 0);
+  case PLATFORM_MACOS:
+    return config->platformInfo.target.MinDeployment >= VersionTuple(11, 0);
+  default:
+    return false;
+  };
+  llvm_unreachable("RelativeMethodList should default to false, control flow "
+                   "should not reach here");
 }
 
 void SymbolPatterns::clear() {
diff --git a/lld/test/MachO/objc-category-conflicts.s b/lld/test/MachO/objc-category-conflicts.s
index eb4c0adfd9e93..b7e358afe63b6 100644
--- a/lld/test/MachO/objc-category-conflicts.s
+++ b/lld/test/MachO/objc-category-conflicts.s
@@ -1,3 +1,6 @@
+# TODO: `-objc_relative_method_lists` is turned on by default.
+# Adding `-no_objc_relative_method_lists` explicitly here to avoid crashing.
+
 # REQUIRES: x86
 # RUN: rm -rf %t; split-file %s %t
 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos11.0 -I %t %t/cat1.s -o %t/cat1.o
@@ -10,31 +13,31 @@
 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos11.0 -I %t %t/cat2.s --defsym MAKE_LOAD_METHOD=1 -o %t/cat2-with-load.o
 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos11.0 -I %t %t/klass.s --defsym MAKE_LOAD_METHOD=1 -o %t/klass-with-load.o
 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos11.0 -I %t %t/klass-with-no-rodata.s -o %t/klass-with-no-rodata.o
-# RUN: %lld -dylib -lobjc %t/klass.o -o %t/libklass.dylib
+# RUN: %lld -no_objc_relative_method_lists -dylib -lobjc %t/klass.o -o %t/libklass.dylib
 
-# RUN: %no-fatal-warnings-lld --check-category-conflicts -dylib -lobjc %t/klass.o %t/cat1.o %t/cat2.o -o \
+# RUN: %no-fatal-warnings-lld -no_objc_relative_method_lists --check-category-conflicts -dylib -lobjc %t/klass.o %t/cat1.o %t/cat2.o -o \
 # RUN:   /dev/null 2>&1 | FileCheck %s --check-prefixes=CATCLS,CATCAT
-# RUN: %no-fatal-warnings-lld --check-category-conflicts -dylib -lobjc %t/libklass.dylib %t/cat1.o \
+# RUN: %no-fatal-warnings-lld -no_objc_relative_method_lists --check-category-conflicts -dylib -lobjc %t/libklass.dylib %t/cat1.o \
 # RUN:   %t/cat2.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=CATCAT
 
-# RUN: %no-fatal-warnings-lld --check-category-conflicts -dylib -lobjc %t/klass_w_sym.o %t/cat1_w_sym.o %t/cat2_w_sym.o -o \
+# RUN: %no-fatal-warnings-lld -no_objc_relative_method_lists --check-category-conflicts -dylib -lobjc %t/klass_w_sym.o %t/cat1_w_sym.o %t/cat2_w_sym.o -o \
 # RUN:   /dev/null 2>&1 | FileCheck %s --check-prefixes=CATCLS_W_SYM,CATCAT_W_SYM
-# RUN: %no-fatal-warnings-lld --check-category-conflicts -dylib -lobjc %t/libklass.dylib %t/cat1_w_sym.o \
+# RUN: %no-fatal-warnings-lld -no_objc_relative_method_lists --check-category-conflicts -dylib -lobjc %t/libklass.dylib %t/cat1_w_sym.o \
 # RUN:   %t/cat2_w_sym.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=CATCAT_W_SYM
 
 ## Check that we don't emit spurious warnings around the +load method while
 ## still emitting the other warnings. Note that we have made separate
 ## `*-with-load.s` files for ease of comparison with ld64; ld64 will not warn
 ## at all if multiple +load methods are present.
-# RUN: %no-fatal-warnings-lld --check-category-conflicts -dylib -lobjc %t/klass-with-load.o \
+# RUN: %no-fatal-warnings-lld -no_objc_relative_method_lists --check-category-conflicts -dylib -lobjc %t/klass-with-load.o \
 # RUN:   %t/cat1-with-load.o %t/cat2-with-load.o -o /dev/null 2>&1 | \
 # RUN:   FileCheck %s --check-prefixes=CATCLS,CATCAT --implicit-check-not '+load'
 
 ## Regression test: Check that we don't crash.
-# RUN: %no-fatal-warnings-lld --check-category-conflicts -dylib -lobjc %t/klass-with-no-rodata.o -o /dev/null
+# RUN: %no-fatal-warnings-lld -no_objc_relative_method_lists --check-category-conflicts -dylib -lobjc %t/klass-with-no-rodata.o -o /dev/null
 
 ## Check that we don't emit any warnings without --check-category-conflicts.
-# RUN: %no-fatal-warnings-lld -dylib -lobjc %t/klass.o %t/cat1.o %t/cat2.o -o \
+# RUN: %no-fatal-warnings-lld -no_objc_relative_method_lists -dylib -lobjc %t/klass.o %t/cat1.o %t/cat2.o -o \
 # RUN:   /dev/null 2>&1 | FileCheck %s --implicit-check-not 'warning' --allow-empty
 
 # CATCLS:      warning: method '+s1' has conflicting definitions:
diff --git a/lld/test/MachO/objc-category-merging-complete-test.s b/lld/test/MachO/objc-category-merging-complete-test.s
index cb112073eb871..403c78f04e62c 100644
--- a/lld/test/MachO/objc-category-merging-complete-test.s
+++ b/lld/test/MachO/objc-category-merging-complete-test.s
@@ -1,16 +1,19 @@
+# TODO: `-objc_relative_method_lists` is turned on by default.
+# Adding `-no_objc_relative_method_lists` explicitly here to avoid crashing.
+
 # REQUIRES: aarch64
 # RUN: rm -rf %t; split-file %s %t && cd %t
 
 ############ Test merging multiple categories into a single category ############
 ## Create a dylib to link against(a64_file1.dylib) and merge categories in the main binary (file2_merge_a64.exe)
 # RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o a64_file1.o a64_file1.s
-# RUN: %lld -arch arm64 a64_file1.o -o a64_file1.dylib -dylib
+# RUN: %lld -no_objc_relative_method_lists -arch arm64 a64_file1.o -o a64_file1.dylib -dylib
 
 # 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: %lld -no_objc_relative_method_lists -arch arm64 -o a64_file2_no_merge.exe a64_file1.dylib a64_file2.o
+# RUN: %lld -no_objc_relative_method_lists -arch arm64 -o a64_file2_no_merge_v2.exe a64_file1.dylib a64_file2.o -no_objc_category_merging
+# RUN: %lld -no_objc_relative_method_lists -arch arm64 -o a64_file2_no_merge_v3.exe a64_file1.dylib a64_file2.o -objc_category_merging -no_objc_category_merging
+# RUN: %lld -no_objc_relative_method_lists -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
@@ -18,7 +21,7 @@
 # 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 ############
-# RUN: %lld -arch arm64 -o a64_file2_merge_into_class.exe -objc_category_merging a64_file1.o a64_file2.o
+# RUN: %lld -no_objc_relative_method_lists -arch arm64 -o a64_file2_merge_into_class.exe -objc_category_merging a64_file1.o a64_file2.o
 # RUN: llvm-objdump --objc-meta-data --macho a64_file2_merge_into_class.exe | FileCheck %s --check-prefixes=MERGE_CATS_CLS
 
 
diff --git a/lld/test/MachO/objc-category-merging-erase-objc-name-test.s b/lld/test/MachO/objc-category-merging-erase-objc-name-test.s
index aeb2395b3a858..1acd3f2fce93b 100644
--- a/lld/test/MachO/objc-category-merging-erase-objc-name-test.s
+++ b/lld/test/MachO/objc-category-merging-erase-objc-name-test.s
@@ -1,3 +1,6 @@
+# TODO: `-objc_relative_method_lists` is turned on by default.
+# Adding `-no_objc_relative_method_lists` explicitly here to avoid crashing.
+
 ; REQUIRES: aarch64
 
 ; Here we test that if we defined a protocol MyTestProtocol and also a category MyTestProtocol
@@ -5,7 +8,7 @@
 ; delete the 'MyTestProtocol' name
 
 ; RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o %T/erase-objc-name.o %s
-; RUN: %lld -arch arm64 -dylib -o %T/erase-objc-name.dylib %T/erase-objc-name.o -objc_category_merging
+; RUN: %lld -no_objc_relative_method_lists -arch arm64 -dylib -o %T/erase-objc-name.dylib %T/erase-objc-name.o -objc_category_merging
 ; RUN: llvm-objdump --objc-meta-data --macho %T/erase-objc-name.dylib | FileCheck %s --check-prefixes=MERGE_CATS
 
 ; === Check merge categories enabled ===
diff --git a/lld/test/MachO/objc-category-merging-minimal.s b/lld/test/MachO/objc-category-merging-minimal.s
index 527493303c583..13a0ac9c431e4 100644
--- a/lld/test/MachO/objc-category-merging-minimal.s
+++ b/lld/test/MachO/objc-category-merging-minimal.s
@@ -1,15 +1,18 @@
+# TODO: `-objc_relative_method_lists` is turned on by default.
+# Adding `-no_objc_relative_method_lists` explicitly here to avoid crashing.
+
 # REQUIRES: aarch64
 # RUN: rm -rf %t; split-file %s %t && cd %t
 
 ############ Test merging multiple categories into a single category ############
 ## Create a dylib with a fake base class to link against in when merging between categories
 # RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o a64_fakedylib.o a64_fakedylib.s
-# RUN: %lld -arch arm64 a64_fakedylib.o -o a64_fakedylib.dylib -dylib
+# RUN: %lld -no_objc_relative_method_lists -arch arm64 a64_fakedylib.o -o a64_fakedylib.dylib -dylib
 
 ## Create our main testing dylib - linking against the fake dylib above
 # RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o merge_cat_minimal.o merge_cat_minimal.s
-# RUN: %lld -arch arm64 -dylib -o merge_cat_minimal_no_merge.dylib a64_fakedylib.dylib merge_cat_minimal.o
-# RUN: %lld -arch arm64 -dylib -o merge_cat_minimal_merge.dylib -objc_category_merging a64_fakedylib.dylib merge_cat_minimal.o
+# RUN: %lld -no_objc_relative_method_lists -arch arm64 -dylib -o merge_cat_minimal_no_merge.dylib a64_fakedylib.dylib merge_cat_minimal.o
+# RUN: %lld -no_objc_relative_method_lists -arch arm64 -dylib -o merge_cat_minimal_merge.dylib -objc_category_merging a64_fakedylib.dylib merge_cat_minimal.o
 
 ## Now verify that the flag caused category merging to happen appropriatelly
 # RUN: llvm-objdump --objc-meta-data --macho merge_cat_minimal_no_merge.dylib | FileCheck %s --check-prefixes=NO_MERGE_CATS
@@ -17,15 +20,15 @@
 
 ############ Test merging multiple categories into the base class ############
 # RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o merge_base_class_minimal.o merge_base_class_minimal.s
-# RUN: %lld -arch arm64 -dylib -o merge_base_class_minimal_yes_merge.dylib -objc_category_merging merge_base_class_minimal.o merge_cat_minimal.o
-# RUN: %lld -arch arm64 -dylib -o merge_base_class_minimal_no_merge.dylib merge_base_class_minimal.o merge_cat_minimal.o
+# RUN: %lld -no_objc_relative_method_lists -arch arm64 -dylib -o merge_base_class_minimal_yes_merge.dylib -objc_category_merging merge_base_class_minimal.o merge_cat_minimal.o
+# RUN: %lld -no_objc_relative_method_lists -arch arm64 -dylib -o merge_base_class_minimal_no_merge.dylib merge_base_class_minimal.o merge_cat_minimal.o
 
 # RUN: llvm-objdump --objc-meta-data --macho merge_base_class_minimal_no_merge.dylib  | FileCheck %s --check-prefixes=NO_MERGE_INTO_BASE
 # RUN: llvm-objdump --objc-meta-data --macho merge_base_class_minimal_yes_merge.dylib | FileCheck %s --check-prefixes=YES_MERGE_INTO_BASE
 
 ############ Test merging swift category into the base class ############
 # RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o MyBaseClassSwiftExtension.o MyBaseClassSwiftExtension.s
-# RUN: %lld -arch arm64 -dylib -o merge_base_class_swift_minimal_yes_merge.dylib -objc_category_merging MyBaseClassSwiftExtension.o merge_base_class_minimal.o
+# RUN: %lld -no_objc_relative_method_lists -arch arm64 -dylib -o merge_base_class_swift_minimal_yes_merge.dylib -objc_category_merging MyBaseClassSwiftExtension.o merge_base_class_minimal.o
 # RUN: llvm-objdump --objc-meta-data --macho merge_base_class_swift_minimal_yes_merge.dylib | FileCheck %s --check-prefixes=YES_MERGE_INTO_BASE_SWIFT
 
 #### Check merge categories enabled ###
diff --git a/lld/test/MachO/objc-relative-method-lists-simple.s b/lld/test/MachO/objc-relative-method-lists-simple.s
index 9f54b5ad828a0..171325eff77fa 100644
--- a/lld/test/MachO/objc-relative-method-lists-simple.s
+++ b/lld/test/MachO/objc-relative-method-lists-simple.s
@@ -2,15 +2,15 @@
 # UNSUPPORTED: target=arm{{.*}}-unknown-linux-gnueabihf
 # RUN: rm -rf %t; split-file %s %t && cd %t
 
-## Compile a64_rel_dylib.o
-# RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o a64_rel_dylib.o a64_simple_class.s
+## Compile a64_rel_dylib.o with MacOS 11
+# RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos11 -o a64_rel_dylib.o a64_simple_class.s
 
 ## Test arm64 + relative method lists
-# RUN: %no-lsystem-lld a64_rel_dylib.o -o a64_rel_dylib.dylib -map a64_rel_dylib.map -dylib -arch arm64 -objc_relative_method_lists
+# RUN: %no-lsystem-lld a64_rel_dylib.o -o a64_rel_dylib.dylib -map a64_rel_dylib.map -dylib -arch arm64
 # RUN: llvm-objdump --macho --objc-meta-data a64_rel_dylib.dylib  | FileCheck %s --check-prefix=CHK_REL
 
 ## Test arm64 + relative method lists + dead-strip
-# RUN: %no-lsystem-lld a64_rel_dylib.o -o a64_rel_dylib.dylib -map a64_rel_dylib.map -dylib -arch arm64 -objc_relative_method_lists -dead_strip
+# RUN: %no-lsystem-lld a64_rel_dylib.o -o a64_rel_dylib.dylib -map a64_rel_dylib.map -dylib -arch arm64 -dead_strip
 # RUN: llvm-objdump --macho --objc-meta-data a64_rel_dylib.dylib  | FileCheck %s --check-prefix=CHK_REL
 
 ## Test arm64 + traditional method lists (no relative offsets)

Comment on lines 1 to 2
# TODO: `-objc_relative_method_lists` is turned on by default.
# Adding `-no_objc_relative_method_lists` explicitly here to avoid crashing.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can make the situation clearer with something like the below.
Could you also file a github issue and link it in the comment ?

Suggested change
# TODO: `-objc_relative_method_lists` is turned on by default.
# Adding `-no_objc_relative_method_lists` explicitly here to avoid crashing.
# Adding -no_objc_relative_method_lists was needed to be explicitly added to this test to avoid it crashing after `-objc_relative_method_lists` was made default.
# TODO: Make the test compatible with default -objc_relative_method_lists and remove the -no_objc_relative_method_lists flag . Issue #FILE_AN_ISSUE

Copy link
Member

@BertalanD BertalanD Aug 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is my understanding correct that these crashes only occur when category merging (which is still off by default) is enabled alongside relative method lists?

If not, I'd like to see the crashes fixed first.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes for the cases modified here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the tests to reflect that both flags are needed to crash.

Comment on lines 1 to 2
# TODO: `-objc_relative_method_lists` is turned on by default.
# Adding `-no_objc_relative_method_lists` explicitly here to avoid crashing.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here as above

@@ -1,11 +1,14 @@
# TODO: `-objc_relative_method_lists` is turned on by default.
# Adding `-no_objc_relative_method_lists` explicitly here to avoid crashing.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here as above.

Comment on lines 1 to 3
# TODO: `-objc_relative_method_lists` is turned on by default.
# Adding `-no_objc_relative_method_lists` explicitly here to avoid crashing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here as above.

@@ -2,15 +2,15 @@
# UNSUPPORTED: target=arm{{.*}}-unknown-linux-gnueabihf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add cases to test the new logic. Specifically:

MacOS 10 => defaults to not relative
MacOS 11 => defaults to relative

MacOS 10 + -objc_relative_method_lists => relative
MacOS 12 + -no_objc_relative_method_lists=> not relative

Copy link
Member Author

@DataCorrupted DataCorrupted Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. MacOS 10 => defaults to not relative
  2. MacOS 11 => defaults to relative
  3. MacOS 10 + -objc_relative_method_lists => relative
  4. MacOS 12 + -no_objc_relative_method_lists=> not relative

(2) Should be covered by removing -objc_relative_method_lists in the tests

(4) Should be covered by unchanged -no_objc_relative_method_lists on Line 17 (on MacOS 11 tho)

I need to modify lit config to test 1 and 3 (our lit config defaults to MacOS 11 now). I tried yesterday but with no luck. Let me try it again.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

our lit config defaults to MacOS 11 now

Why change lit configs - why not manually overwrite on the command line ? Like here.

@@ -0,0 +1,244 @@
# REQUIRES: aarch64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test seems copied from objc-relative-method-lists-simple.s. Is there a reason to copy the whole thing - rather than doing it directly in objc-relative-method-lists-simple.s ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are slightly different and needs to be highlighted (minos 10 vs 11, output difference). Do you prefer to have them merged?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, better to have them merged.
If you're referring to the existing .build_version macos, 11, 0 In objc-relative-method-lists-simple.s - I think it just works removing that and having the command line flags be the determining one.

Signed-off-by: Peter Rong <[email protected]>
@@ -125,7 +136,7 @@ CHK_NO_REL-NEXT: imp +[MyClass class_method_02]
.include "objc-macros.s"

.section __TEXT,__text,regular,pure_instructions
.build_version macos, 11, 0
.build_version macos, 10, 0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build version still required or llvm-mc defaults to 11 somehow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It produces 11 output even when specifying -triple=arm64-apple-macos10 ?
Or where does it default - in this test we specificly specify either 10 or 11 triple in llvm-mc invocation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about changing the "old" target to 10.15 instead? -data_const is already the default for that version, so the change to the segment name above wouldn't be needed.

Even if we do say that our generated binaries should run on macOS 10.0 (from 2001!), they won't. Dyld opcodes -- which we use for pre-chained-fixups targets -- were introduced around the 10.9 times.

Copy link
Member Author

@DataCorrupted DataCorrupted Aug 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10.15 still generates -data, any tips? (bumping to 10.16 would enable relative method list by default and invalidate the purpose of testing)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work:

--- a/lld/test/MachO/objc-relative-method-lists-simple.s
+++ b/lld/test/MachO/objc-relative-method-lists-simple.s
@@ -2,8 +2,8 @@
 # UNSUPPORTED: target=arm{{.*}}-unknown-linux-gnueabihf
 # RUN: rm -rf %t; split-file %s %t && cd %t
 
-## Compile a64_rel_dylib.o with MacOS 11
-# RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos11 -o a64_rel_dylib.o a64_simple_class.s
+## Compile a64_rel_dylib.o
+# RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos10.15 -o a64_rel_dylib.o a64_simple_class.s
 
 ## Test arm64 + relative method lists
 # RUN: %no-lsystem-lld a64_rel_dylib.o -o a64_rel_dylib.dylib -map a64_rel_dylib.map -dylib -arch arm64
@@ -17,19 +17,16 @@
 # RUN: %no-lsystem-lld a64_rel_dylib.o -o a64_rel_dylib.dylib -map a64_rel_dylib.map -dylib -arch arm64 -no_objc_relative_method_lists
 # RUN: llvm-objdump --macho --objc-meta-data a64_rel_dylib.dylib  | FileCheck %s --check-prefix=CHK_NO_REL
 
-## Compile a64_rel_dylib.o with MacOS 10
-# RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos10 -o a64_rel_dylib.o a64_simple_class.s
-
 ## Test arm64 + relative method lists by explicitly adding `-objc_relative_method_lists`.
-# RUN: %lld a64_rel_dylib.o -o a64_rel_dylib.dylib -map a64_rel_dylib.map -dylib -arch arm64 -platform_version macOS 10.0 10.0 -objc_relative_method_lists
+# RUN: %lld a64_rel_dylib.o -o a64_rel_dylib.dylib -map a64_rel_dylib.map -dylib -arch arm64 -platform_version macOS 10.15 10.15 -objc_relative_method_lists
 # RUN: llvm-objdump --macho --objc-meta-data a64_rel_dylib.dylib  | FileCheck %s --check-prefix=CHK_REL
 
 ## Test arm64 + no relative method lists by default.
-# RUN: %lld a64_rel_dylib.o -o a64_rel_dylib.dylib -map a64_rel_dylib.map -dylib -arch arm64 -platform_version macOS 10.0 10.0
+# RUN: %lld a64_rel_dylib.o -o a64_rel_dylib.dylib -map a64_rel_dylib.map -dylib -arch arm64 -platform_version macOS 10.15 10.15
 # RUN: llvm-objdump --macho --objc-meta-data a64_rel_dylib.dylib  | FileCheck %s --check-prefix=CHK_NO_REL
 
 
-CHK_REL:       Contents of (__DATA{{(_CONST)?}},__objc_classlist) section
+CHK_REL:       Contents of (__DATA_CONST,__objc_classlist) section
 CHK_REL-NEXT:  _OBJC_CLASS_$_MyClass
 CHK_REL:       baseMethods
 CHK_REL-NEXT:  entsize 12 (relative)
@@ -62,7 +59,7 @@ CHK_REL-NEXT:    imp 0x{{[0-9a-f]*}} (0x{{[0-9a-f]*}})  +[MyClass class_method_0
 
 CHK_NO_REL-NOT: (relative)
 
-CHK_NO_REL:           Contents of (__DATA{{(_CONST)?}},__objc_classlist) section
+CHK_NO_REL:           Contents of (__DATA_CONST,__objc_classlist) section
 CHK_NO_REL-NEXT:      _OBJC_CLASS_$_MyClass
 
 CHK_NO_REL:            baseMethods 0x{{[0-9a-f]*}} (struct method_list_t *)
@@ -136,7 +133,7 @@ CHK_NO_REL-NEXT:		       imp +[MyClass class_method_02]
 .include "objc-macros.s"
 
 .section	__TEXT,__text,regular,pure_instructions
-.build_version macos, 10, 0
+.build_version macos, 10, 15
 
 .objc_selector_def "-[MyClass instance_method_00]"
 .objc_selector_def "-[MyClass instance_method_01]"
  • no need to run the assembler twice; we can link objects targeting 10.15 into macOS 11 binaries
  • had to change the version in the -platform_version flag

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh Cool! That works!

@@ -51,7 +62,7 @@ CHK_REL-NEXT: imp 0x{{[0-9a-f]*}} (0x{{[0-9a-f]*}}) +[MyClass class_method_0

CHK_NO_REL-NOT: (relative)

CHK_NO_REL: Contents of (__DATA_CONST,__objc_classlist) section
CHK_NO_REL: Contents of (__DATA{{(_CONST)?}},__objc_classlist) section
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONST doesn't show up on MacOS 10

@BertalanD BertalanD self-requested a review August 1, 2024 18:24
Comment on lines 1146 to 1154
switch (config->platformInfo.target.Platform) {
case PLATFORM_IOS:
case PLATFORM_IOSSIMULATOR:
return config->platformInfo.target.MinDeployment >= VersionTuple(14, 0);
case PLATFORM_MACOS:
return config->platformInfo.target.MinDeployment >= VersionTuple(11, 0);
default:
return false;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we can't enable it for the other platforms?

See for example what we do for chained fixups (which based on my understanding was basically introduced alongside this feature):

static const std::array<std::pair<PlatformType, VersionTuple>, 9> minVersion =
{{
{PLATFORM_IOS, VersionTuple(13, 4)},
{PLATFORM_IOSSIMULATOR, VersionTuple(16, 0)},
{PLATFORM_MACOS, VersionTuple(13, 0)},
{PLATFORM_TVOS, VersionTuple(14, 0)},
{PLATFORM_TVOSSIMULATOR, VersionTuple(15, 0)},
{PLATFORM_WATCHOS, VersionTuple(7, 0)},
{PLATFORM_WATCHOSSIMULATOR, VersionTuple(8, 0)},
{PLATFORM_XROS, VersionTuple(1, 0)},
{PLATFORM_XROS_SIMULATOR, VersionTuple(1, 0)},
}};
PlatformType platform = config->platformInfo.target.Platform;
auto it = llvm::find_if(minVersion,
[&](const auto &p) { return p.first == platform; });
// We don't know the versions for other platforms, so default to disabled.
if (it == minVersion.end())
return false;
if (it->second > config->platformInfo.target.MinDeployment)
return false;
return true;

Looks like ld64 special-cases x86, but other than that, the version2020Fall condition covers watchOS, tvOS and friends as well.

https://github.com/apple-oss-distributions/ld64/blob/47f477cb721755419018f7530038b272e9d0cdea/src/ld/Options.cpp#L6085-L6101

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can definitely add those platforms as well.

But can you shed more light how to special case x86 like the code you mentioned?

I don't find equivalence of Options::kDynamicExecutable in LLVM yet, only MH_EXECUTE.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think that part is safe to ignore, no need to special case it.

Apple might need to back-deploy executables during macOS's development process, but that is not relevant for user code.

Category merging: Change tests to reflect that both flag is needed to crash

Signed-off-by: Peter Rong <[email protected]>
@DataCorrupted DataCorrupted merged commit 6a3604e into llvm:main Aug 7, 2024
7 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 7, 2024

LLVM Buildbot has detected a new failure on builder lldb-arm-ubuntu running on linaro-lldb-arm-ubuntu while building lld at step 4 "build".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/18/builds/1902

Here is the relevant piece of the build log for the reference:

Step 4 (build) failure: build (failure)
...
50.025 [21/34/6203] Linking CXX executable bin/llvm-objdump
50.029 [20/34/6204] Linking CXX executable bin/llvm-mc
50.040 [20/33/6205] Generating ../../bin/llvm-otool
50.206 [20/32/6206] Linking CXX executable bin/llvm-jitlink
50.248 [20/31/6207] Linking CXX executable bin/clang-import-test
50.350 [20/30/6208] Linking CXX executable bin/lli
50.481 [20/29/6209] Linking CXX executable bin/llvm-exegesis
52.235 [20/28/6210] Linking CXX executable bin/clang-extdef-mapping
54.180 [20/27/6211] Linking CXX executable bin/lldb-server
56.942 [20/26/6212] Building CXX object tools/lld/MachO/CMakeFiles/lldMachO.dir/Driver.cpp.o
FAILED: tools/lld/MachO/CMakeFiles/lldMachO.dir/Driver.cpp.o 
/usr/local/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_FILE_OFFSET_BITS=64 -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lld/MachO -I/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lld/MachO -I/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lld/include -I/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lld/include -I/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/include -I/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/llvm/include -I/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/llvm/../libunwind/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT tools/lld/MachO/CMakeFiles/lldMachO.dir/Driver.cpp.o -MF tools/lld/MachO/CMakeFiles/lldMachO.dir/Driver.cpp.o.d -o tools/lld/MachO/CMakeFiles/lldMachO.dir/Driver.cpp.o -c /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lld/MachO/Driver.cpp
../llvm-project/lld/MachO/Driver.cpp:1073:8: error: no matching function for call to 'greaterEqMinVersion'
 1073 |   if (!greaterEqMinVersion(minVersion, true))
      |        ^~~~~~~~~~~~~~~~~~~
../llvm-project/lld/MachO/Driver.cpp:1051:13: note: candidate template ignored: substitution failure: deduced non-type template argument does not have the same type as the corresponding template parameter ('unsigned int' vs 'unsigned long')
 1051 | static bool greaterEqMinVersion(const MinVersions<N> &minVersions,
      |             ^
../llvm-project/lld/MachO/Driver.cpp:1136:10: error: no matching function for call to 'greaterEqMinVersion'
 1136 |   return greaterEqMinVersion(minVersion, false);
      |          ^~~~~~~~~~~~~~~~~~~
../llvm-project/lld/MachO/Driver.cpp:1051:13: note: candidate template ignored: substitution failure: deduced non-type template argument does not have the same type as the corresponding template parameter ('unsigned int' vs 'unsigned long')
 1051 | static bool greaterEqMinVersion(const MinVersions<N> &minVersions,
      |             ^
../llvm-project/lld/MachO/Driver.cpp:1160:10: error: no matching function for call to 'greaterEqMinVersion'
 1160 |   return greaterEqMinVersion(minVersion, true);
      |          ^~~~~~~~~~~~~~~~~~~
../llvm-project/lld/MachO/Driver.cpp:1051:13: note: candidate template ignored: substitution failure: deduced non-type template argument does not have the same type as the corresponding template parameter ('unsigned int' vs 'unsigned long')
 1051 | static bool greaterEqMinVersion(const MinVersions<N> &minVersions,
      |             ^
3 errors generated.
56.958 [20/25/6213] Linking CXX executable bin/llvm-gsymutil
57.138 [20/24/6214] Linking CXX executable bin/llvm-c-test
57.430 [20/23/6215] Linking CXX executable bin/llvm-dwp
58.502 [20/22/6216] Linking CXX executable bin/llvm-split
59.162 [20/21/6217] Linking CXX executable bin/llvm-dwarfutil
60.628 [20/20/6218] Linking CXX executable bin/llvm-isel-fuzzer
62.428 [20/19/6219] Linking CXX executable bin/llvm-opt-fuzzer
62.533 [20/18/6220] Linking CXX executable bin/dsymutil
63.593 [20/17/6221] Linking CXX shared library lib/libLTO.so.20.0git
64.704 [20/16/6222] Linking CXX executable bin/clang-nvlink-wrapper
67.709 [20/15/6223] Linking CXX executable bin/llvm-lto
69.570 [20/14/6224] Linking CXX executable bin/clang-linker-wrapper
70.974 [20/13/6225] Linking CXX executable bin/llc
71.426 [20/12/6226] Linking CXX executable bin/lldb-instr
71.541 [20/11/6227] Linking CXX executable bin/llvm-reduce
71.979 [20/10/6228] Linking CXX executable bin/opt
72.167 [20/9/6229] Linking CXX executable bin/llvm-lto2
74.443 [20/8/6230] Linking CXX executable bin/bugpoint

@zeroomega
Copy link
Contributor

Hi, we are seeing a LLDB test failure after this change was landed and the stack trace from the failed test looks related to this patch:

Script:
--
/Volumes/Work/s/w/ir/x/w/lldb_install/python3/bin/python3 /Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env OBJCOPY=/Volumes/Work/s/w/ir/x/w/llvm_build/./bin/llvm-objcopy --env LLVM_LIBS_DIR=/Volumes/Work/s/w/ir/x/w/llvm_build/./lib --env LLVM_INCLUDE_DIR=/Volumes/Work/s/w/ir/x/w/llvm_build/include --env LLVM_TOOLS_DIR=/Volumes/Work/s/w/ir/x/w/llvm_build/./bin --libcxx-include-dir /Volumes/Work/s/w/ir/x/w/llvm_build/include/c++/v1 --libcxx-library-dir /Volumes/Work/s/w/ir/x/w/llvm_build/lib --arch x86_64 --build-dir /Volumes/Work/s/w/ir/x/w/llvm_build/lldb-test-build.noindex --lldb-module-cache-dir /Volumes/Work/s/w/ir/x/w/llvm_build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /Volumes/Work/s/w/ir/x/w/llvm_build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /Volumes/Work/s/w/ir/x/w/llvm_build/./bin/lldb --compiler /Volumes/Work/s/w/ir/x/w/llvm_build/./bin/clang --dsymutil /Volumes/Work/s/w/ir/x/w/llvm_build/./bin/dsymutil --llvm-tools-dir /Volumes/Work/s/w/ir/x/w/llvm_build/./bin --lldb-obj-root /Volumes/Work/s/w/ir/x/w/llvm_build/tools/lldb --lldb-libs-dir /Volumes/Work/s/w/ir/x/w/llvm_build/./lib --skip-category=pexpect /Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/test/API/commands/expression/call-throws -p TestCallThatThrows.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 20.0.0git (https://llvm.googlesource.com/a/llvm-project revision 6a3604ef8592edf39fedd6af8100aefafd6d931d)
  clang revision 6a3604ef8592edf39fedd6af8100aefafd6d931d
  llvm revision 6a3604ef8592edf39fedd6af8100aefafd6d931d
Skipping the following test categories: ['pexpect', 'libstdcxx', 'dwo', 'llgs', 'fork']

--
Command Output (stderr):
--
FAIL: LLDB (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/clang-x86_64) :: test_dsym (TestCallThatThrows.ExprCommandWithThrowTestCase.test_dsym)
FAIL: LLDB (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/clang-x86_64) :: test_dwarf (TestCallThatThrows.ExprCommandWithThrowTestCase.test_dwarf)
UNSUPPORTED: LLDB (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/clang-x86_64) :: test_dwo (TestCallThatThrows.ExprCommandWithThrowTestCase.test_dwo) (test case does not fall in any category of interest for this run) 
======================================================================
ERROR: test_dsym (TestCallThatThrows.ExprCommandWithThrowTestCase.test_dsym)
   Test calling a function that throws and ObjC exception.
----------------------------------------------------------------------
Error when building test subject.

Build Command:
make VPATH=/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/test/API/commands/expression/call-throws -C /Volumes/Work/s/w/ir/x/w/llvm_build/lldb-test-build.noindex/commands/expression/call-throws/TestCallThatThrows.test_dsym -I /Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/test/API/commands/expression/call-throws -I /Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/packages/Python/lldbsuite/test/make -f /Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/test/API/commands/expression/call-throws/Makefile MAKE_DSYM=YES all ARCH=x86_64 'CC="/Volumes/Work/s/w/ir/x/w/llvm_build/bin/clang"' DSYMUTIL=/Volumes/Work/s/w/ir/x/w/llvm_build/./bin/dsymutil 'CODESIGN=codesign --entitlements /Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/packages/Python/lldbsuite/test/make/entitlements-macos.plist' CLANG_MODULE_CACHE_DIR=/Volumes/Work/s/w/ir/x/w/llvm_build/lldb-test-build.noindex/module-cache-clang/lldb-api LIBCPP_INCLUDE_DIR=/Volumes/Work/s/w/ir/x/w/llvm_build/include/c++/v1 LIBCPP_LIBRARY_DIR=/Volumes/Work/s/w/ir/x/w/llvm_build/lib LLDB_OBJ_ROOT=/Volumes/Work/s/w/ir/x/w/llvm_build/tools/lldb OS=Darwin HOST_OS=Darwin

Build Command Output:
make: Entering directory '/Volumes/Work/s/w/ir/x/w/llvm_build/lldb-test-build.noindex/commands/expression/call-throws/TestCallThatThrows.test_dsym'
"/Volumes/Work/s/w/ir/x/w/llvm_build/bin/clang" -g -O0 -isysroot "/Volumes/Work/s/w/ir/cache/macos_sdk/XCode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk" -arch x86_64  -I/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/packages/Python/lldbsuite/test/make/../../../../..//include -I/Volumes/Work/s/w/ir/x/w/llvm_build/tools/lldb/include -I/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/test/API/commands/expression/call-throws -I/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/packages/Python/lldbsuite/test/make -include /Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h -fno-limit-debug-info   -MT call-throws.o -MD -MP -MF call-throws.d -c -o call-throws.o /Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/test/API/commands/expression/call-throws/call-throws.m
"/Volumes/Work/s/w/ir/x/w/llvm_build/bin/clang" call-throws.o -g -O0 -isysroot "/Volumes/Work/s/w/ir/cache/macos_sdk/XCode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk" -arch x86_64  -I/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/packages/Python/lldbsuite/test/make/../../../../..//include -I/Volumes/Work/s/w/ir/x/w/llvm_build/tools/lldb/include -I/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/test/API/commands/expression/call-throws -I/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/packages/Python/lldbsuite/test/make -include /Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h -fno-limit-debug-info   -framework Foundation  -L/Volumes/Work/s/w/ir/x/w/llvm_build/lib -Wl,-rpath,/Volumes/Work/s/w/ir/x/w/llvm_build/lib -lc++ -lobjc --driver-mode=g++ -o "a.out"
Assertion failed: (isa<T>(*this) && "Invalid accessor called"), function get, file PointerUnion.h, line 156.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /Volumes/Work/s/w/ir/x/w/llvm_build/bin/ld64.lld -demangle -no_deduplicate -dynamic -arch x86_64 -platform_version macos 13.0.0 13.3 -syslibroot /Volumes/Work/s/w/ir/cache/macos_sdk/XCode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk -mllvm -enable-linkonceodr-outlining -o a.out -L/Volumes/Work/s/w/ir/x/w/llvm_build/lib call-throws.o -framework Foundation -rpath /Volumes/Work/s/w/ir/x/w/llvm_build/lib -lc++ -lobjc -lc++ -lSystem /Volumes/Work/s/w/ir/x/w/llvm_build/lib/clang/20/lib/darwin/libclang_rt.osx.a
 #0 0x0000000112246178 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm+0x106152178)
 #1 0x0000000112243f39 llvm::sys::RunSignalHandlers() (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm+0x10614ff39)
 #2 0x0000000112246840 SignalHandler(int) (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm+0x106152840)
 #3 0x00007ff8158575ed (/usr/lib/system/libsystem_platform.dylib+0x7ff8004265ed)
 #4 0x0000000000000000 
 #5 0x00007ff815750b45 (/usr/lib/system/libsystem_c.dylib+0x7ff80031fb45)
 #6 0x00007ff81574fe5e (/usr/lib/system/libsystem_c.dylib+0x7ff80031ee5e)
 #7 0x000000010c8454b0 lld::macho::ObjCMethListSection::setUp() (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm+0x1007514b0)
 #8 0x000000010c864d0c void lld::macho::writeResult<lld::macho::LP64>() (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm+0x100770d0c)
 #9 0x000000010c7d7219 lld::macho::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm+0x1006e3219)
#10 0x000000010c4f54e2 lld::unsafeLldMain(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, llvm::ArrayRef<lld::DriverDef>, bool) (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm+0x1004014e2)
#11 0x000000010c1a0e08 lld_main(int, char**, llvm::ToolContext const&) (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm+0x1000ace08)
#12 0x000000010c4f422f findTool(int, char**, char const*) (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm+0x10040022f)
#13 0x000000010c4f3a60 main (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm+0x1003ffa60)
#14 0x00007ff8154cf41f 
clang: error: unable to execute command: Abort trap: 6
clang: error: linker command failed due to signal (use -v to see invocation)
make: *** [Makefile.rules:571: a.out] Error 1
make: Leaving directory '/Volumes/Work/s/w/ir/x/w/llvm_build/lldb-test-build.noindex/commands/expression/call-throws/TestCallThatThrows.test_dsym'

Test Directory:
/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/test/API/commands/expression/call-throws
======================================================================
ERROR: test_dwarf (TestCallThatThrows.ExprCommandWithThrowTestCase.test_dwarf)
   Test calling a function that throws and ObjC exception.
----------------------------------------------------------------------
Error when building test subject.

Build Command:
make VPATH=/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/test/API/commands/expression/call-throws -C /Volumes/Work/s/w/ir/x/w/llvm_build/lldb-test-build.noindex/commands/expression/call-throws/TestCallThatThrows.test_dwarf -I /Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/test/API/commands/expression/call-throws -I /Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/packages/Python/lldbsuite/test/make -f /Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/test/API/commands/expression/call-throws/Makefile MAKE_DSYM=NO all ARCH=x86_64 'CC="/Volumes/Work/s/w/ir/x/w/llvm_build/bin/clang"' DSYMUTIL=/Volumes/Work/s/w/ir/x/w/llvm_build/./bin/dsymutil 'CODESIGN=codesign --entitlements /Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/packages/Python/lldbsuite/test/make/entitlements-macos.plist' CLANG_MODULE_CACHE_DIR=/Volumes/Work/s/w/ir/x/w/llvm_build/lldb-test-build.noindex/module-cache-clang/lldb-api LIBCPP_INCLUDE_DIR=/Volumes/Work/s/w/ir/x/w/llvm_build/include/c++/v1 LIBCPP_LIBRARY_DIR=/Volumes/Work/s/w/ir/x/w/llvm_build/lib LLDB_OBJ_ROOT=/Volumes/Work/s/w/ir/x/w/llvm_build/tools/lldb OS=Darwin HOST_OS=Darwin

Build Command Output:
make: Entering directory '/Volumes/Work/s/w/ir/x/w/llvm_build/lldb-test-build.noindex/commands/expression/call-throws/TestCallThatThrows.test_dwarf'
"/Volumes/Work/s/w/ir/x/w/llvm_build/bin/clang" -g -O0 -isysroot "/Volumes/Work/s/w/ir/cache/macos_sdk/XCode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk" -arch x86_64  -I/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/packages/Python/lldbsuite/test/make/../../../../..//include -I/Volumes/Work/s/w/ir/x/w/llvm_build/tools/lldb/include -I/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/test/API/commands/expression/call-throws -I/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/packages/Python/lldbsuite/test/make -include /Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h -fno-limit-debug-info   -MT call-throws.o -MD -MP -MF call-throws.d -c -o call-throws.o /Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/test/API/commands/expression/call-throws/call-throws.m
"/Volumes/Work/s/w/ir/x/w/llvm_build/bin/clang" call-throws.o -g -O0 -isysroot "/Volumes/Work/s/w/ir/cache/macos_sdk/XCode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk" -arch x86_64  -I/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/packages/Python/lldbsuite/test/make/../../../../..//include -I/Volumes/Work/s/w/ir/x/w/llvm_build/tools/lldb/include -I/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/test/API/commands/expression/call-throws -I/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/packages/Python/lldbsuite/test/make -include /Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h -fno-limit-debug-info   -framework Foundation  -L/Volumes/Work/s/w/ir/x/w/llvm_build/lib -Wl,-rpath,/Volumes/Work/s/w/ir/x/w/llvm_build/lib -lc++ -lobjc --driver-mode=g++ -o "a.out"
Assertion failed: (isa<T>(*this) && "Invalid accessor called"), function get, file PointerUnion.h, line 156.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /Volumes/Work/s/w/ir/x/w/llvm_build/bin/ld64.lld -demangle -no_deduplicate -dynamic -arch x86_64 -platform_version macos 13.0.0 13.3 -syslibroot /Volumes/Work/s/w/ir/cache/macos_sdk/XCode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk -mllvm -enable-linkonceodr-outlining -o a.out -L/Volumes/Work/s/w/ir/x/w/llvm_build/lib call-throws.o -framework Foundation -rpath /Volumes/Work/s/w/ir/x/w/llvm_build/lib -lc++ -lobjc -lc++ -lSystem /Volumes/Work/s/w/ir/x/w/llvm_build/lib/clang/20/lib/darwin/libclang_rt.osx.a
 #0 0x0000000110b92178 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm+0x106152178)
 #1 0x0000000110b8ff39 llvm::sys::RunSignalHandlers() (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm+0x10614ff39)
 #2 0x0000000110b92840 SignalHandler(int) (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm+0x106152840)
 #3 0x00007ff8158575ed (/usr/lib/system/libsystem_platform.dylib+0x7ff8004265ed)
 #4 0x0000000000000000 
 #5 0x00007ff815750b45 (/usr/lib/system/libsystem_c.dylib+0x7ff80031fb45)
 #6 0x00007ff81574fe5e (/usr/lib/system/libsystem_c.dylib+0x7ff80031ee5e)
 #7 0x000000010b1914b0 lld::macho::ObjCMethListSection::setUp() (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm+0x1007514b0)
 #8 0x000000010b1b0d0c void lld::macho::writeResult<lld::macho::LP64>() (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm+0x100770d0c)
 #9 0x000000010b123219 lld::macho::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm+0x1006e3219)
#10 0x000000010ae414e2 lld::unsafeLldMain(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, llvm::ArrayRef<lld::DriverDef>, bool) (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm+0x1004014e2)
#11 0x000000010aaece08 lld_main(int, char**, llvm::ToolContext const&) (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm+0x1000ace08)
#12 0x000000010ae4022f findTool(int, char**, char const*) (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm+0x10040022f)
#13 0x000000010ae3fa60 main (/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm+0x1003ffa60)
#14 0x00007ff8154cf41f 
clang: error: unable to execute command: Abort trap: 6
clang: error: linker command failed due to signal (use -v to see invocation)
make: *** [Makefile.rules:571: a.out] Error 1
make: Leaving directory '/Volumes/Work/s/w/ir/x/w/llvm_build/lldb-test-build.noindex/commands/expression/call-throws/TestCallThatThrows.test_dwarf'

Test Directory:
/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/lldb/test/API/commands/expression/call-throws
----------------------------------------------------------------------
Ran 3 tests in 2.297s

FAILED (errors=2, skipped=1)

--

Build task link: https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci/clang-mac-x64/b8740230069184308337/overview

We haven't yet finish a local revert and verification but looking at the blamelist, the change you landed is most likely. Could you take a look please?
And since it was a assertion error, if it is caused by this change, could you revert your change and fix it and reland it please?

@alx32
Copy link
Contributor

alx32 commented Aug 8, 2024

we are seeing a LLDB test failure

This seems to be a bug in the relative method list implementation - exposed by this change making it the default.
Do you have repro instructions for the bug - it's not clear from the link.

EDIT: This seems to be just a regular lldb test from the llvm repo - thought it's from an external project. I'll try running it locally.

@zeroomega
Copy link
Contributor

we are seeing a LLDB test failure

This seems to be a bug in the relative method list implementation - exposed by this change making it the default. Do you have repro instructions for the bug - it's not clear from the link.

The failure coming from LLDB test lldb-api :: commands/expression/call-throws/TestCallThatThrows.py . It just happened on our bot and we don't have a local reproducer yet. But the error message I posted above does have the build command steps. If you follow it with the a local built llvm/clang/lld with this patch, you probably can reproduce it.

@zeroomega
Copy link
Contributor

We had a test run with this patch as well as b3b6f7c reverted and the affected lldb test passed. Since this patch (while not directly) broke LLVM's own lldb test, can we revert it and reland it after the underlying issue with objc_relative_method_lists fixing is fixed?

DataCorrupted added a commit to DataCorrupted/llvm-project that referenced this pull request Aug 8, 2024
@DataCorrupted
Copy link
Member Author

Let's revert this for now, we will figure out how to fix this later and try to land again. See #102420

DataCorrupted added a commit that referenced this pull request Aug 8, 2024
@alx32
Copy link
Contributor

alx32 commented Aug 15, 2024

Build task link: https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci/clang-mac-x64/b8740230069184308337/overview

@zeroomega - Do you happen to know if this failure happens with Mac-x64 only ? I tried repro-ing on Mac-arm64 but the test passed for me.
I'm trying to verify weather #104081 fixed the underlying issue and we can re-commit this change.

kstoimenov pushed a commit to kstoimenov/llvm-project that referenced this pull request Aug 15, 2024
…lvm#101360)

This patch makes `objc_relative_method_lists` default on MacOS 11+ / iOS
14+. Manual override still work if command line argument is provided.

To test this change, many explicit arguments are removed from the test
files. Some explicit `no_objc_relative...` are also added for tests that
don't support this yet.

Signed-off-by: Peter Rong <[email protected]>
kstoimenov pushed a commit to kstoimenov/llvm-project that referenced this pull request Aug 15, 2024
@zeroomega
Copy link
Contributor

Build task link: https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci/clang-mac-x64/b8740230069184308337/overview

@zeroomega - Do you happen to know if this failure happens with Mac-x64 only ? I tried repro-ing on Mac-arm64 but the test passed for me. I'm trying to verify weather #104081 fixed the underlying issue and we can re-commit this change.

We currently don't build and test lldb on mac-arm64 bot due to some dependency issues. But I can try #104081 with this default objc_relative_method_lists change and see if it breaks LLDB on mac-x64

zeroomega added a commit to zeroomega/llvm-project that referenced this pull request Aug 15, 2024
@zeroomega
Copy link
Contributor

TestCallThatThrows

@alx32 my test run showed PASS: lldb-api :: commands/expression/call-throws/TestCallThatThrows.py (51 of 111)
with #104081 landed and #102420 reverted.
Passed task: https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci.shadow/clang-mac-x64/b8739505848970808785/overview

@DataCorrupted
Copy link
Member Author

Sounds good, let me revert #102420

@DataCorrupted DataCorrupted deleted the DefaultRelativeMethodList branch August 15, 2024 23:07
DataCorrupted added a commit to DataCorrupted/llvm-project that referenced this pull request Aug 15, 2024
This patch makes `-objc_relative_method_lists` default on MacOS 10.16+/iOS 14+.
Manual override still work if command line argument is provided.

To test this change, many explict arguments are removed from the test files.
Some explict `-objc_no_objc_relative_method_lists` are also added for tests that don't support this yet.

This commit tries to revive llvm#101360, which exposes a bug that breaks CI. llvm#104081 has fixed that bug.
DataCorrupted added a commit to DataCorrupted/llvm-project that referenced this pull request Aug 15, 2024
This patch makes `-objc_relative_method_lists` default on MacOS 10.16+/iOS 14+.
Manual override still work if command line argument is provided.

To test this change, many explict arguments are removed from the test files.
Some explict `-objc_no_objc_relative_method_lists` are also added for tests that don't support this yet.

This commit tries to revive llvm#101360, which exposes a bug that breaks CI. llvm#104081 has fixed that bug.
DataCorrupted added a commit that referenced this pull request Aug 16, 2024
…#104519)

This patch makes `-objc_relative_method_lists` default on MacOS
10.16+/iOS 14+. Manual override still work if command line argument is
provided.

To test this change, many explict arguments are removed from the test
files. Some explict `-objc_no_objc_relative_method_lists` are also added
for tests that don't support this yet.

This commit tries to revive #101360, which exposes a bug that breaks CI.
#104081 has fixed that bug.
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.

6 participants