Skip to content

Commit dd251b0

Browse files
1 parent aae7c38 commit dd251b0

6 files changed

+64
-96
lines changed

lld/MachO/Driver.cpp

Lines changed: 43 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,36 +1042,20 @@ static bool shouldAdhocSignByDefault(Architecture arch, PlatformType platform) {
10421042
platform == PLATFORM_XROS_SIMULATOR;
10431043
}
10441044

1045-
template <std::size_t N>
1046-
using MinVersions = std::array<std::pair<PlatformType, VersionTuple>, N>;
1047-
1048-
/// Returns true if the platform is greater than the min version.
1049-
/// Returns false if the platform does not exist.
1050-
template <std::size_t N>
1051-
static bool greaterEqMinVersion(const MinVersions<N> &minVersions,
1052-
bool ignoreSimulator) {
1053-
PlatformType platform = config->platformInfo.target.Platform;
1054-
if (ignoreSimulator)
1055-
platform = removeSimulator(platform);
1056-
auto it = llvm::find_if(minVersions,
1057-
[&](const auto &p) { return p.first == platform; });
1058-
if (it != minVersions.end())
1059-
if (config->platformInfo.target.MinDeployment >= it->second)
1060-
return true;
1061-
return false;
1062-
}
1063-
10641045
static bool dataConstDefault(const InputArgList &args) {
1065-
static const MinVersions<6> minVersion = {{
1066-
{PLATFORM_MACOS, VersionTuple(10, 15)},
1067-
{PLATFORM_IOS, VersionTuple(13, 0)},
1068-
{PLATFORM_TVOS, VersionTuple(13, 0)},
1069-
{PLATFORM_WATCHOS, VersionTuple(6, 0)},
1070-
{PLATFORM_XROS, VersionTuple(1, 0)},
1071-
{PLATFORM_BRIDGEOS, VersionTuple(4, 0)},
1072-
}};
1073-
if (!greaterEqMinVersion(minVersion, true))
1074-
return false;
1046+
static const std::array<std::pair<PlatformType, VersionTuple>, 6> minVersion =
1047+
{{{PLATFORM_MACOS, VersionTuple(10, 15)},
1048+
{PLATFORM_IOS, VersionTuple(13, 0)},
1049+
{PLATFORM_TVOS, VersionTuple(13, 0)},
1050+
{PLATFORM_WATCHOS, VersionTuple(6, 0)},
1051+
{PLATFORM_XROS, VersionTuple(1, 0)},
1052+
{PLATFORM_BRIDGEOS, VersionTuple(4, 0)}}};
1053+
PlatformType platform = removeSimulator(config->platformInfo.target.Platform);
1054+
auto it = llvm::find_if(minVersion,
1055+
[&](const auto &p) { return p.first == platform; });
1056+
if (it != minVersion.end())
1057+
if (config->platformInfo.target.MinDeployment < it->second)
1058+
return false;
10751059

10761060
switch (config->outputType) {
10771061
case MH_EXECUTE:
@@ -1122,18 +1106,30 @@ static bool shouldEmitChainedFixups(const InputArgList &args) {
11221106
if (requested)
11231107
return true;
11241108

1125-
static const MinVersions<9> minVersion = {{
1126-
{PLATFORM_IOS, VersionTuple(13, 4)},
1127-
{PLATFORM_IOSSIMULATOR, VersionTuple(16, 0)},
1128-
{PLATFORM_MACOS, VersionTuple(13, 0)},
1129-
{PLATFORM_TVOS, VersionTuple(14, 0)},
1130-
{PLATFORM_TVOSSIMULATOR, VersionTuple(15, 0)},
1131-
{PLATFORM_WATCHOS, VersionTuple(7, 0)},
1132-
{PLATFORM_WATCHOSSIMULATOR, VersionTuple(8, 0)},
1133-
{PLATFORM_XROS, VersionTuple(1, 0)},
1134-
{PLATFORM_XROS_SIMULATOR, VersionTuple(1, 0)},
1135-
}};
1136-
return greaterEqMinVersion(minVersion, false);
1109+
static const std::array<std::pair<PlatformType, VersionTuple>, 9> minVersion =
1110+
{{
1111+
{PLATFORM_IOS, VersionTuple(13, 4)},
1112+
{PLATFORM_IOSSIMULATOR, VersionTuple(16, 0)},
1113+
{PLATFORM_MACOS, VersionTuple(13, 0)},
1114+
{PLATFORM_TVOS, VersionTuple(14, 0)},
1115+
{PLATFORM_TVOSSIMULATOR, VersionTuple(15, 0)},
1116+
{PLATFORM_WATCHOS, VersionTuple(7, 0)},
1117+
{PLATFORM_WATCHOSSIMULATOR, VersionTuple(8, 0)},
1118+
{PLATFORM_XROS, VersionTuple(1, 0)},
1119+
{PLATFORM_XROS_SIMULATOR, VersionTuple(1, 0)},
1120+
}};
1121+
PlatformType platform = config->platformInfo.target.Platform;
1122+
auto it = llvm::find_if(minVersion,
1123+
[&](const auto &p) { return p.first == platform; });
1124+
1125+
// We don't know the versions for other platforms, so default to disabled.
1126+
if (it == minVersion.end())
1127+
return false;
1128+
1129+
if (it->second > config->platformInfo.target.MinDeployment)
1130+
return false;
1131+
1132+
return true;
11371133
}
11381134

11391135
static bool shouldEmitRelativeMethodLists(const InputArgList &args) {
@@ -1144,20 +1140,12 @@ static bool shouldEmitRelativeMethodLists(const InputArgList &args) {
11441140
if (arg && arg->getOption().getID() == OPT_no_objc_relative_method_lists)
11451141
return false;
11461142

1147-
// If no flag is specified, enable this on newer versions by default.
1148-
// The min versions is taken from
1149-
// ld64(https://github.com/apple-oss-distributions/ld64/blob/47f477cb721755419018f7530038b272e9d0cdea/src/ld/ld.hpp#L310)
1150-
// to mimic to operation of ld64
1151-
// [here](https://github.com/apple-oss-distributions/ld64/blob/47f477cb721755419018f7530038b272e9d0cdea/src/ld/Options.cpp#L6085-L6101)
1152-
static const MinVersions<6> minVersion = {{
1153-
{PLATFORM_MACOS, VersionTuple(10, 16)},
1154-
{PLATFORM_IOS, VersionTuple(14, 0)},
1155-
{PLATFORM_WATCHOS, VersionTuple(7, 0)},
1156-
{PLATFORM_TVOS, VersionTuple(14, 0)},
1157-
{PLATFORM_BRIDGEOS, VersionTuple(5, 0)},
1158-
{PLATFORM_XROS, VersionTuple(1, 0)},
1159-
}};
1160-
return greaterEqMinVersion(minVersion, true);
1143+
// TODO: If no flag is specified, don't default to false, but instead:
1144+
// - default false on < ios14
1145+
// - default true on >= ios14
1146+
// For now, until this feature is confirmed stable, default to false if no
1147+
// flag is explicitly specified
1148+
return false;
11611149
}
11621150

11631151
void SymbolPatterns::clear() {

lld/test/MachO/objc-category-conflicts.s

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# `-no_objc_relative_method_lists` needs to be explicitly added to this test to avoid crashing after `-objc_relative_method_lists` was made default.
2-
# TODO: Make this test compatible with default `-objc_relative_method_lists` and remove the `-no_objc_relative_method_lists` flag. Issue #101419
3-
41
# REQUIRES: x86
52
# RUN: rm -rf %t; split-file %s %t
63
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos11.0 -I %t %t/cat1.s -o %t/cat1.o
@@ -13,31 +10,31 @@
1310
# 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
1411
# 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
1512
# 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
16-
# RUN: %lld -no_objc_relative_method_lists -dylib -lobjc %t/klass.o -o %t/libklass.dylib
13+
# RUN: %lld -dylib -lobjc %t/klass.o -o %t/libklass.dylib
1714

18-
# 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 \
15+
# RUN: %no-fatal-warnings-lld --check-category-conflicts -dylib -lobjc %t/klass.o %t/cat1.o %t/cat2.o -o \
1916
# RUN: /dev/null 2>&1 | FileCheck %s --check-prefixes=CATCLS,CATCAT
20-
# RUN: %no-fatal-warnings-lld -no_objc_relative_method_lists --check-category-conflicts -dylib -lobjc %t/libklass.dylib %t/cat1.o \
17+
# RUN: %no-fatal-warnings-lld --check-category-conflicts -dylib -lobjc %t/libklass.dylib %t/cat1.o \
2118
# RUN: %t/cat2.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=CATCAT
2219

23-
# 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 \
20+
# 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 \
2421
# RUN: /dev/null 2>&1 | FileCheck %s --check-prefixes=CATCLS_W_SYM,CATCAT_W_SYM
25-
# RUN: %no-fatal-warnings-lld -no_objc_relative_method_lists --check-category-conflicts -dylib -lobjc %t/libklass.dylib %t/cat1_w_sym.o \
22+
# RUN: %no-fatal-warnings-lld --check-category-conflicts -dylib -lobjc %t/libklass.dylib %t/cat1_w_sym.o \
2623
# RUN: %t/cat2_w_sym.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=CATCAT_W_SYM
2724

2825
## Check that we don't emit spurious warnings around the +load method while
2926
## still emitting the other warnings. Note that we have made separate
3027
## `*-with-load.s` files for ease of comparison with ld64; ld64 will not warn
3128
## at all if multiple +load methods are present.
32-
# RUN: %no-fatal-warnings-lld -no_objc_relative_method_lists --check-category-conflicts -dylib -lobjc %t/klass-with-load.o \
29+
# RUN: %no-fatal-warnings-lld --check-category-conflicts -dylib -lobjc %t/klass-with-load.o \
3330
# RUN: %t/cat1-with-load.o %t/cat2-with-load.o -o /dev/null 2>&1 | \
3431
# RUN: FileCheck %s --check-prefixes=CATCLS,CATCAT --implicit-check-not '+load'
3532

3633
## Regression test: Check that we don't crash.
37-
# RUN: %no-fatal-warnings-lld -no_objc_relative_method_lists --check-category-conflicts -dylib -lobjc %t/klass-with-no-rodata.o -o /dev/null
34+
# RUN: %no-fatal-warnings-lld --check-category-conflicts -dylib -lobjc %t/klass-with-no-rodata.o -o /dev/null
3835

3936
## Check that we don't emit any warnings without --check-category-conflicts.
40-
# RUN: %no-fatal-warnings-lld -no_objc_relative_method_lists -dylib -lobjc %t/klass.o %t/cat1.o %t/cat2.o -o \
37+
# RUN: %no-fatal-warnings-lld -dylib -lobjc %t/klass.o %t/cat1.o %t/cat2.o -o \
4138
# RUN: /dev/null 2>&1 | FileCheck %s --implicit-check-not 'warning' --allow-empty
4239

4340
# CATCLS: warning: method '+s1' has conflicting definitions:

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# `-no_objc_relative_method_lists` needs to be explicitly added to this test to avoid crashing after `-objc_relative_method_lists` was made default.
2-
# TODO: Make this test compatible with default `-objc_relative_method_lists` and remove the `-no_objc_relative_method_lists` flag. Issue #101419
3-
41
# REQUIRES: aarch64
52
# RUN: rm -rf %t; split-file %s %t && cd %t
63

@@ -10,18 +7,18 @@
107
# RUN: %lld -arch arm64 a64_file1.o -o a64_file1.dylib -dylib
118

129
# RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o a64_file2.o a64_file2.s
13-
# RUN: %lld -no_objc_relative_method_lists -arch arm64 -o a64_file2_no_merge.exe a64_file1.dylib a64_file2.o
14-
# 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
15-
# 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
16-
# RUN: %lld -no_objc_relative_method_lists -arch arm64 -o a64_file2_merge.exe -objc_category_merging a64_file1.dylib a64_file2.o
10+
# 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
13+
# RUN: %lld -arch arm64 -o a64_file2_merge.exe -objc_category_merging a64_file1.dylib a64_file2.o
1714

1815
# RUN: llvm-objdump --objc-meta-data --macho a64_file2_no_merge.exe | FileCheck %s --check-prefixes=NO_MERGE_CATS
1916
# RUN: llvm-objdump --objc-meta-data --macho a64_file2_no_merge_v2.exe | FileCheck %s --check-prefixes=NO_MERGE_CATS
2017
# RUN: llvm-objdump --objc-meta-data --macho a64_file2_no_merge_v3.exe | FileCheck %s --check-prefixes=NO_MERGE_CATS
2118
# RUN: llvm-objdump --objc-meta-data --macho a64_file2_merge.exe | FileCheck %s --check-prefixes=MERGE_CATS
2219

2320
############ Test merging multiple categories into the base class ############
24-
# 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
21+
# RUN: %lld -arch arm64 -o a64_file2_merge_into_class.exe -objc_category_merging a64_file1.o a64_file2.o
2522
# RUN: llvm-objdump --objc-meta-data --macho a64_file2_merge_into_class.exe | FileCheck %s --check-prefixes=MERGE_CATS_CLS
2623

2724

lld/test/MachO/objc-category-merging-erase-objc-name-test.s

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
# `-no_objc_relative_method_lists` needs to be explicitly added to this test to avoid crashing after `-objc_relative_method_lists` was made default.
2-
# TODO: Make this test compatible with default `-objc_relative_method_lists` and remove the `-no_objc_relative_method_lists` flag. Issue #101419
3-
41
; REQUIRES: aarch64
52

63
; Here we test that if we defined a protocol MyTestProtocol and also a category MyTestProtocol
74
; then when merging the category into the base class (and deleting the category), we don't
85
; delete the 'MyTestProtocol' name
96

107
; RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o %T/erase-objc-name.o %s
11-
; RUN: %lld -no_objc_relative_method_lists -arch arm64 -dylib -o %T/erase-objc-name.dylib %T/erase-objc-name.o -objc_category_merging
8+
; RUN: %lld -arch arm64 -dylib -o %T/erase-objc-name.dylib %T/erase-objc-name.o -objc_category_merging
129
; RUN: llvm-objdump --objc-meta-data --macho %T/erase-objc-name.dylib | FileCheck %s --check-prefixes=MERGE_CATS
1310

1411
; === Check merge categories enabled ===

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# `-no_objc_relative_method_lists` needs to be explicitly added to this test to avoid crashing after `-objc_relative_method_lists` was made default.
2-
# TODO: Make this test compatible with default `-objc_relative_method_lists` and remove the `-no_objc_relative_method_lists` flag. Issue #101419
3-
41
# REQUIRES: aarch64
52
# RUN: rm -rf %t; split-file %s %t && cd %t
63

@@ -12,23 +9,23 @@
129
## Create our main testing dylib - linking against the fake dylib above
1310
# RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o merge_cat_minimal.o merge_cat_minimal.s
1411
# RUN: %lld -arch arm64 -dylib -o merge_cat_minimal_no_merge.dylib a64_fakedylib.dylib merge_cat_minimal.o
15-
# 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
12+
# RUN: %lld -arch arm64 -dylib -o merge_cat_minimal_merge.dylib -objc_category_merging a64_fakedylib.dylib merge_cat_minimal.o
1613

1714
## Now verify that the flag caused category merging to happen appropriatelly
1815
# RUN: llvm-objdump --objc-meta-data --macho merge_cat_minimal_no_merge.dylib | FileCheck %s --check-prefixes=NO_MERGE_CATS
1916
# RUN: llvm-objdump --objc-meta-data --macho merge_cat_minimal_merge.dylib | FileCheck %s --check-prefixes=MERGE_CATS
2017

2118
############ Test merging multiple categories into the base class ############
2219
# RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o merge_base_class_minimal.o merge_base_class_minimal.s
23-
# 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
20+
# 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
2421
# RUN: %lld -arch arm64 -dylib -o merge_base_class_minimal_no_merge.dylib merge_base_class_minimal.o merge_cat_minimal.o
2522

2623
# RUN: llvm-objdump --objc-meta-data --macho merge_base_class_minimal_no_merge.dylib | FileCheck %s --check-prefixes=NO_MERGE_INTO_BASE
2724
# RUN: llvm-objdump --objc-meta-data --macho merge_base_class_minimal_yes_merge.dylib | FileCheck %s --check-prefixes=YES_MERGE_INTO_BASE
2825

2926
############ Test merging swift category into the base class ############
3027
# RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o MyBaseClassSwiftExtension.o MyBaseClassSwiftExtension.s
31-
# 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
28+
# RUN: %lld -arch arm64 -dylib -o merge_base_class_swift_minimal_yes_merge.dylib -objc_category_merging MyBaseClassSwiftExtension.o merge_base_class_minimal.o
3229
# RUN: llvm-objdump --objc-meta-data --macho merge_base_class_swift_minimal_yes_merge.dylib | FileCheck %s --check-prefixes=YES_MERGE_INTO_BASE_SWIFT
3330

3431
#### Check merge categories enabled ###

lld/test/MachO/objc-relative-method-lists-simple.s

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,20 @@
33
# RUN: rm -rf %t; split-file %s %t && cd %t
44

55
## Compile a64_rel_dylib.o
6-
# RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos10.15 -o a64_rel_dylib.o a64_simple_class.s
6+
# RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o a64_rel_dylib.o a64_simple_class.s
77

88
## Test arm64 + relative method lists
9-
# RUN: %no-lsystem-lld a64_rel_dylib.o -o a64_rel_dylib.dylib -map a64_rel_dylib.map -dylib -arch arm64
9+
# 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
1010
# RUN: llvm-objdump --macho --objc-meta-data a64_rel_dylib.dylib | FileCheck %s --check-prefix=CHK_REL
1111

1212
## Test arm64 + relative method lists + dead-strip
13-
# RUN: %no-lsystem-lld a64_rel_dylib.o -o a64_rel_dylib.dylib -map a64_rel_dylib.map -dylib -arch arm64 -dead_strip
13+
# 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
1414
# RUN: llvm-objdump --macho --objc-meta-data a64_rel_dylib.dylib | FileCheck %s --check-prefix=CHK_REL
1515

1616
## Test arm64 + traditional method lists (no relative offsets)
1717
# 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
1818
# RUN: llvm-objdump --macho --objc-meta-data a64_rel_dylib.dylib | FileCheck %s --check-prefix=CHK_NO_REL
1919

20-
## Test arm64 + relative method lists by explicitly adding `-objc_relative_method_lists`.
21-
# 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
22-
# RUN: llvm-objdump --macho --objc-meta-data a64_rel_dylib.dylib | FileCheck %s --check-prefix=CHK_REL
23-
24-
## Test arm64 + no relative method lists by default.
25-
# 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
26-
# RUN: llvm-objdump --macho --objc-meta-data a64_rel_dylib.dylib | FileCheck %s --check-prefix=CHK_NO_REL
27-
2820

2921
CHK_REL: Contents of (__DATA_CONST,__objc_classlist) section
3022
CHK_REL-NEXT: _OBJC_CLASS_$_MyClass
@@ -133,7 +125,7 @@ CHK_NO_REL-NEXT: imp +[MyClass class_method_02]
133125
.include "objc-macros.s"
134126

135127
.section __TEXT,__text,regular,pure_instructions
136-
.build_version macos, 10, 15
128+
.build_version macos, 11, 0
137129

138130
.objc_selector_def "-[MyClass instance_method_00]"
139131
.objc_selector_def "-[MyClass instance_method_01]"

0 commit comments

Comments
 (0)