Skip to content

Commit 9a8b040

Browse files
authored
Reapply "[lld] enable fixup chains by default (#79894)" (#99255)
This reverts commit f55b79f. The known issues with chained fixups have been addressed by #98913, #98305, #97156 and #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 e09032f commit 9a8b040

File tree

7 files changed

+57
-41
lines changed

7 files changed

+57
-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>
@@ -1080,42 +1081,55 @@ static bool shouldEmitChainedFixups(const InputArgList &args) {
10801081
if (arg && arg->getOption().matches(OPT_no_fixup_chains))
10811082
return false;
10821083

1083-
bool isRequested = arg != nullptr;
1084-
1085-
// Version numbers taken from the Xcode 13.3 release notes.
1086-
static const std::array<std::pair<PlatformType, VersionTuple>, 5> minVersion =
1087-
{{{PLATFORM_MACOS, VersionTuple(11, 0)},
1088-
{PLATFORM_IOS, VersionTuple(13, 4)},
1089-
{PLATFORM_TVOS, VersionTuple(14, 0)},
1090-
{PLATFORM_WATCHOS, VersionTuple(7, 0)},
1091-
{PLATFORM_XROS, VersionTuple(1, 0)}}};
1092-
PlatformType platform = removeSimulator(config->platformInfo.target.Platform);
1093-
auto it = llvm::find_if(minVersion,
1094-
[&](const auto &p) { return p.first == platform; });
1095-
if (it != minVersion.end() &&
1096-
it->second > config->platformInfo.target.MinDeployment) {
1097-
if (!isRequested)
1098-
return false;
1084+
bool requested = arg && arg->getOption().matches(OPT_fixup_chains);
1085+
if (!config->isPic) {
1086+
if (requested)
1087+
error("-fixup_chains is incompatible with -no_pie");
10991088

1100-
warn("-fixup_chains requires " + getPlatformName(config->platform()) + " " +
1101-
it->second.getAsString() + ", which is newer than target minimum of " +
1102-
config->platformInfo.target.MinDeployment.getAsString());
1089+
return false;
11031090
}
11041091

11051092
if (!is_contained({AK_x86_64, AK_x86_64h, AK_arm64}, config->arch())) {
1106-
if (isRequested)
1093+
if (requested)
11071094
error("-fixup_chains is only supported on x86_64 and arm64 targets");
1095+
11081096
return false;
11091097
}
11101098

1111-
if (!config->isPic) {
1112-
if (isRequested)
1113-
error("-fixup_chains is incompatible with -no_pie");
1099+
if (args.hasArg(OPT_preload)) {
1100+
if (requested)
1101+
error("-fixup_chains is incompatible with -preload");
1102+
11141103
return false;
11151104
}
11161105

1117-
// TODO: Enable by default once stable.
1118-
return isRequested;
1106+
if (requested)
1107+
return true;
1108+
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;
11191133
}
11201134

11211135
static bool shouldEmitRelativeMethodLists(const InputArgList &args) {

lld/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ MinGW Improvements
102102
MachO Improvements
103103
------------------
104104

105+
* Chained fixups are now enabled by default when targeting macOS 13.0,
106+
iOS 13.4, tvOS 14.0, watchOS 7.0, and visionOS 1.0 or later.
107+
They can be disabled with the `-no_fixup_chains` flag.
108+
(`#99255 <https://github.com/llvm/llvm-project/pull/99255>`_)
109+
105110
WebAssembly Improvements
106111
------------------------
107112

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)