Skip to content

Commit 5370eec

Browse files
committed
Reapply "[lld] enable fixup chains by default (llvm#79894)"
This reverts commit f55b79f. The known issues with chained fixups have been addressed by llvm#98913, llvm#98305, llvm#97156 and llvm#95171. Compared to the original commit, support for xrOS (which postdates chained fixups' introduction) was added and an unnecessary test change was removed. ---------- Original commit message: Enable chained fixups in lld when all platform and version criteria are met. This is an attempt at simplifying the logic used in ld 907: https://github.com/apple-oss-distributions/ld64/blob/93d74eafc37c0558b4ffb88a8bc15c17bed44a20/src/ld/Options.cpp#L5458-L5549 Some changes were made to simplify the logic: - only enable chained fixups for macOS from 13.0 to avoid the arch check - only enable chained fixups for iphonesimulator from 16.0 to avoid the arch check - don't enable chained fixups for not specifically listed platforms - don't enable chained fixups for arm64_32
1 parent 6ad2987 commit 5370eec

File tree

6 files changed

+52
-41
lines changed

6 files changed

+52
-41
lines changed

lld/MachO/Driver.cpp

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "llvm/Support/TargetSelect.h"
5050
#include "llvm/Support/TimeProfiler.h"
5151
#include "llvm/TargetParser/Host.h"
52+
#include "llvm/TextAPI/Architecture.h"
5253
#include "llvm/TextAPI/PackedVersion.h"
5354

5455
#include <algorithm>
@@ -1048,42 +1049,55 @@ static bool shouldEmitChainedFixups(const InputArgList &args) {
10481049
if (arg && arg->getOption().matches(OPT_no_fixup_chains))
10491050
return false;
10501051

1051-
bool isRequested = arg != nullptr;
1052-
1053-
// Version numbers taken from the Xcode 13.3 release notes.
1054-
static const std::array<std::pair<PlatformType, VersionTuple>, 5> minVersion =
1055-
{{{PLATFORM_MACOS, VersionTuple(11, 0)},
1056-
{PLATFORM_IOS, VersionTuple(13, 4)},
1057-
{PLATFORM_TVOS, VersionTuple(14, 0)},
1058-
{PLATFORM_WATCHOS, VersionTuple(7, 0)},
1059-
{PLATFORM_XROS, VersionTuple(1, 0)}}};
1060-
PlatformType platform = removeSimulator(config->platformInfo.target.Platform);
1061-
auto it = llvm::find_if(minVersion,
1062-
[&](const auto &p) { return p.first == platform; });
1063-
if (it != minVersion.end() &&
1064-
it->second > config->platformInfo.target.MinDeployment) {
1065-
if (!isRequested)
1066-
return false;
1052+
bool requested = arg && arg->getOption().matches(OPT_fixup_chains);
1053+
if (!config->isPic) {
1054+
if (requested)
1055+
error("-fixup_chains is incompatible with -no_pie");
10671056

1068-
warn("-fixup_chains requires " + getPlatformName(config->platform()) + " " +
1069-
it->second.getAsString() + ", which is newer than target minimum of " +
1070-
config->platformInfo.target.MinDeployment.getAsString());
1057+
return false;
10711058
}
10721059

10731060
if (!is_contained({AK_x86_64, AK_x86_64h, AK_arm64}, config->arch())) {
1074-
if (isRequested)
1061+
if (requested)
10751062
error("-fixup_chains is only supported on x86_64 and arm64 targets");
1063+
10761064
return false;
10771065
}
10781066

1079-
if (!config->isPic) {
1080-
if (isRequested)
1081-
error("-fixup_chains is incompatible with -no_pie");
1067+
if (args.hasArg(OPT_preload)) {
1068+
if (requested)
1069+
error("-fixup_chains is incompatible with -preload");
1070+
10821071
return false;
10831072
}
10841073

1085-
// TODO: Enable by default once stable.
1086-
return isRequested;
1074+
if (requested)
1075+
return true;
1076+
1077+
static const std::array<std::pair<PlatformType, VersionTuple>, 9> minVersion =
1078+
{{
1079+
{PLATFORM_IOS, VersionTuple(13, 4)},
1080+
{PLATFORM_IOSSIMULATOR, VersionTuple(16, 0)},
1081+
{PLATFORM_MACOS, VersionTuple(13, 0)},
1082+
{PLATFORM_TVOS, VersionTuple(14, 0)},
1083+
{PLATFORM_TVOSSIMULATOR, VersionTuple(15, 0)},
1084+
{PLATFORM_WATCHOS, VersionTuple(7, 0)},
1085+
{PLATFORM_WATCHOSSIMULATOR, VersionTuple(8, 0)},
1086+
{PLATFORM_XROS, VersionTuple(1, 0)},
1087+
{PLATFORM_XROS_SIMULATOR, VersionTuple(1, 0)},
1088+
}};
1089+
PlatformType platform = config->platformInfo.target.Platform;
1090+
auto it = llvm::find_if(minVersion,
1091+
[&](const auto &p) { return p.first == platform; });
1092+
1093+
// We don't know the versions for other platforms, so default to disabled.
1094+
if (it == minVersion.end())
1095+
return false;
1096+
1097+
if (it->second > config->platformInfo.target.MinDeployment)
1098+
return false;
1099+
1100+
return true;
10871101
}
10881102

10891103
static bool shouldEmitRelativeMethodLists(const InputArgList &args) {

lld/test/MachO/arm64-32-stubs.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# RUN: llvm-mc -filetype=obj -triple=arm64_32-apple-watchos %t/test.s -o %t/test.o
1111
# RUN: %lld-watchos -dylib -install_name @executable_path/libfoo.dylib %t/foo.o -o %t/libfoo.dylib
1212
# RUN: %lld-watchos -dylib -install_name @executable_path/libbar.dylib %t/bar.o -o %t/libbar.dylib
13-
# RUN: %lld-watchos -lSystem %t/libfoo.dylib %t/libbar.dylib %t/test.o -o %t/test
13+
# RUN: %lld-watchos -lSystem %t/libfoo.dylib %t/libbar.dylib %t/test.o -o %t/test -no_fixup_chains
1414

1515
# RUN: llvm-objdump --no-print-imm-hex --macho -d --no-show-raw-insn --section="__TEXT,__stubs" --section="__TEXT,__stub_helper" %t/test | FileCheck %s
1616

lld/test/MachO/arm64-stubs.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %t/test.s -o %t/test.o
66
# RUN: %lld -arch arm64 -dylib -install_name @executable_path/libfoo.dylib %t/foo.o -o %t/libfoo.dylib
77
# RUN: %lld -arch arm64 -dylib -install_name @executable_path/libbar.dylib %t/bar.o -o %t/libbar.dylib
8-
# RUN: %lld -arch arm64 -lSystem %t/libfoo.dylib %t/libbar.dylib %t/test.o -o %t/test
8+
# RUN: %lld -arch arm64 -lSystem %t/libfoo.dylib %t/libbar.dylib %t/test.o -o %t/test -no_fixup_chains
99

1010
# RUN: llvm-objdump --no-print-imm-hex --macho -d --no-show-raw-insn --section="__TEXT,__stubs" --section="__TEXT,__stub_helper" %t/test | FileCheck %s
1111

lld/test/MachO/dyld-stub-binder.s

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,27 @@
1414
# RUN: %lld -arch arm64 -lSystem -dylib %t/foo.o -o %t/libfoo.dylib
1515
# RUN: llvm-nm -m %t/libfoo.dylib | FileCheck --check-prefix=STUB %s
1616

17-
1817
## Dylibs that do lazy dynamic calls do need dyld_stub_binder.
1918
# RUN: not %no-lsystem-lld -arch arm64 -dylib %t/bar.o %t/libfoo.dylib \
20-
# RUN: -o %t/libbar.dylib 2>&1 | FileCheck --check-prefix=MISSINGSTUB %s
19+
# RUN: -o %t/libbar.dylib -no_fixup_chains 2>&1 | \
20+
# RUN: FileCheck --check-prefix=MISSINGSTUB %s
2121
# RUN: %lld -arch arm64 -lSystem -dylib %t/bar.o %t/libfoo.dylib \
22-
# RUN: -o %t/libbar.dylib
22+
# RUN: -o %t/libbar.dylib -no_fixup_chains
2323
# RUN: llvm-nm -m %t/libbar.dylib | FileCheck --check-prefix=STUB %s
2424

2525
## As do executables.
2626
# RUN: not %no-lsystem-lld -arch arm64 %t/libfoo.dylib %t/libbar.dylib %t/test.o \
27-
# RUN: -o %t/test 2>&1 | FileCheck --check-prefix=MISSINGSTUB %s
27+
# RUN: -o %t/test -no_fixup_chains 2>&1 | FileCheck --check-prefix=MISSINGSTUB %s
2828
# RUN: %lld -arch arm64 -lSystem %t/libfoo.dylib %t/libbar.dylib %t/test.o \
29-
# RUN: -o %t/test
29+
# RUN: -o %t/test -no_fixup_chains
3030
# RUN: llvm-nm -m %t/test | FileCheck --check-prefix=STUB %s
3131

3232
## Test dynamic lookup of dyld_stub_binder.
3333
# RUN: %no-lsystem-lld -arch arm64 %t/libfoo.dylib %t/libbar.dylib %t/test.o \
34-
# RUN: -o %t/test -undefined dynamic_lookup
34+
# RUN: -o %t/test -undefined dynamic_lookup -no_fixup_chains
3535
# RUN: llvm-nm -m %t/test | FileCheck --check-prefix=DYNSTUB %s
3636
# RUN: %no-lsystem-lld -arch arm64 %t/libfoo.dylib %t/libbar.dylib %t/test.o \
37-
# RUN: -o %t/test -U dyld_stub_binder
37+
# RUN: -o %t/test -U dyld_stub_binder -no_fixup_chains
3838
# RUN: llvm-nm -m %t/test | FileCheck --check-prefix=DYNSTUB %s
3939

4040
# MISSINGSTUB: error: undefined symbol: dyld_stub_binder

lld/test/MachO/invalid/chained-fixups-incompatible.s

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
33
# RUN: not %lld -lSystem -no_pie -fixup_chains %t.o -o /dev/null 2>&1 | \
44
# RUN: FileCheck %s --check-prefix=NO-PIE
5-
# RUN: %no-fatal-warnings-lld -fixup_chains %t.o -o /dev/null \
6-
# RUN: -lSystem -platform_version macos 10.15 10.15 2>&1 | \
7-
# RUN: FileCheck %s --check-prefix=VERSION
85
# RUN: llvm-mc -filetype=obj -triple=arm64_32-apple-darwin %s -o %t-arm64_32.o
96
# RUN: not %lld-watchos -lSystem -fixup_chains %t-arm64_32.o -o /dev/null 2>&1 | \
107
# RUN: FileCheck %s --check-prefix=ARCH
118

129
## Check that we emit diagnostics when -fixup_chains is explicitly specified,
1310
## but we don't support creating chained fixups for said configuration.
1411
# NO-PIE: error: -fixup_chains is incompatible with -no_pie
15-
# VERSION: warning: -fixup_chains requires macOS 11.0, which is newer than target minimum of 10.15
1612
# ARCH: error: -fixup_chains is only supported on x86_64 and arm64 targets
1713

1814
.globl _main

lld/test/MachO/objc-selrefs.s

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %t/implicit-selrefs.s -o %t/implicit-selrefs.o
77

88
# RUN: %lld -dylib -arch arm64 -lSystem -o %t/explicit-only-no-icf \
9-
# RUN: %t/explicit-selrefs-1.o %t/explicit-selrefs-2.o
9+
# RUN: %t/explicit-selrefs-1.o %t/explicit-selrefs-2.o -no_fixup_chains
1010
# RUN: llvm-otool -vs __DATA __objc_selrefs %t/explicit-only-no-icf | \
1111
# RUN: FileCheck %s --check-prefix=EXPLICIT-NO-ICF
1212

1313
## NOTE: ld64 always dedups the selrefs unconditionally, but we only do it when
1414
## ICF is enabled.
1515
# RUN: %lld -dylib -arch arm64 -lSystem -o %t/explicit-only-with-icf \
16-
# RUN: %t/explicit-selrefs-1.o %t/explicit-selrefs-2.o
16+
# RUN: %t/explicit-selrefs-1.o %t/explicit-selrefs-2.o -no_fixup_chains
1717
# RUN: llvm-otool -vs __DATA __objc_selrefs %t/explicit-only-with-icf \
1818
# RUN: | FileCheck %s --check-prefix=EXPLICIT-WITH-ICF
1919

@@ -25,7 +25,8 @@
2525
# SELREFS-EMPTY:
2626

2727
# RUN: %lld -dylib -arch arm64 -lSystem --icf=all -o %t/explicit-and-implicit \
28-
# RUN: %t/explicit-selrefs-1.o %t/explicit-selrefs-2.o %t/implicit-selrefs.o
28+
# RUN: %t/explicit-selrefs-1.o %t/explicit-selrefs-2.o %t/implicit-selrefs.o \
29+
# RUN: -no_fixup_chains
2930
# RUN: llvm-otool -vs __DATA __objc_selrefs %t/explicit-and-implicit \
3031
# RUN: | FileCheck %s --check-prefix=EXPLICIT-AND-IMPLICIT
3132

0 commit comments

Comments
 (0)