Skip to content

Commit a8743cf

Browse files
committed
[lld] enable fixup chains by default for supported platforms
This commit enables chained fixups by default for supported platforms. This matches the logic used in ld64 907.
1 parent d133ada commit a8743cf

File tree

7 files changed

+54
-44
lines changed

7 files changed

+54
-44
lines changed

lld/MachO/Driver.cpp

Lines changed: 37 additions & 24 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>
@@ -1042,41 +1043,53 @@ static bool shouldEmitChainedFixups(const InputArgList &args) {
10421043
if (arg && arg->getOption().matches(OPT_no_fixup_chains))
10431044
return false;
10441045

1045-
bool isRequested = arg != nullptr;
1046-
1047-
// Version numbers taken from the Xcode 13.3 release notes.
1048-
static const std::array<std::pair<PlatformType, VersionTuple>, 4> minVersion =
1049-
{{{PLATFORM_MACOS, VersionTuple(11, 0)},
1050-
{PLATFORM_IOS, VersionTuple(13, 4)},
1051-
{PLATFORM_TVOS, VersionTuple(14, 0)},
1052-
{PLATFORM_WATCHOS, VersionTuple(7, 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-
it->second > config->platformInfo.target.MinDeployment) {
1058-
if (!isRequested)
1059-
return false;
1046+
bool requested = arg && arg->getOption().matches(OPT_fixup_chains);
1047+
if (!config->isPic) {
1048+
if (requested)
1049+
error("-fixup_chains is incompatible with -no_pie");
10601050

1061-
warn("-fixup_chains requires " + getPlatformName(config->platform()) + " " +
1062-
it->second.getAsString() + ", which is newer than target minimum of " +
1063-
config->platformInfo.target.MinDeployment.getAsString());
1051+
return false;
10641052
}
10651053

10661054
if (!is_contained({AK_x86_64, AK_x86_64h, AK_arm64}, config->arch())) {
1067-
if (isRequested)
1055+
if (requested)
10681056
error("-fixup_chains is only supported on x86_64 and arm64 targets");
1057+
10691058
return false;
10701059
}
10711060

1072-
if (!config->isPic) {
1073-
if (isRequested)
1074-
error("-fixup_chains is incompatible with -no_pie");
1061+
if (args.hasArg(OPT_preload)) {
1062+
if (requested)
1063+
error("-fixup_chains is incompatible with -preload");
1064+
10751065
return false;
10761066
}
10771067

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

10821095
void SymbolPatterns::clear() {

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/icf-safe.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
; RUN: rm -rf %t; mkdir %t
44

55
; RUN: llc -filetype=obj %s -O3 -o %t/icf-obj.o -enable-machine-outliner=never -mtriple arm64-apple-macos -addrsig
6-
; RUN: %lld -arch arm64 -lSystem --icf=safe -dylib -o %t/icf-safe.dylib %t/icf-obj.o
7-
; RUN: %lld -arch arm64 -lSystem --icf=all -dylib -o %t/icf-all.dylib %t/icf-obj.o
6+
; RUN: %lld -arch arm64 -lSystem --icf=safe -dylib -o %t/icf-safe.dylib %t/icf-obj.o -no_fixup_chains
7+
; RUN: %lld -arch arm64 -lSystem --icf=all -dylib -o %t/icf-all.dylib %t/icf-obj.o -no_fixup_chains
88
; RUN: llvm-objdump %t/icf-safe.dylib -d --macho | FileCheck %s --check-prefix=ICFSAFE
99
; RUN: llvm-objdump %t/icf-all.dylib -d --macho | FileCheck %s --check-prefix=ICFALL
1010

1111
; RUN: llvm-as %s -o %t/icf-bitcode.o
12-
; RUN: %lld -arch arm64 -lSystem --icf=safe -dylib -o %t/icf-safe-bitcode.dylib %t/icf-bitcode.o
13-
; RUN: %lld -arch arm64 -lSystem --icf=all -dylib -o %t/icf-all-bitcode.dylib %t/icf-bitcode.o
12+
; RUN: %lld -arch arm64 -lSystem --icf=safe -dylib -o %t/icf-safe-bitcode.dylib %t/icf-bitcode.o -no_fixup_chains
13+
; RUN: %lld -arch arm64 -lSystem --icf=all -dylib -o %t/icf-all-bitcode.dylib %t/icf-bitcode.o -no_fixup_chains
1414
; RUN: llvm-objdump %t/icf-safe-bitcode.dylib -d --macho | FileCheck %s --check-prefix=ICFSAFE
1515
; RUN: llvm-objdump %t/icf-all-bitcode.dylib -d --macho | FileCheck %s --check-prefix=ICFALL
1616

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

@@ -26,7 +26,8 @@
2626

2727
## We don't yet support dedup'ing implicitly-defined selrefs.
2828
# RUN: %lld -dylib -arch arm64 -lSystem --icf=all -o %t/explicit-and-implicit \
29-
# RUN: %t/explicit-selrefs-1.o %t/explicit-selrefs-2.o %t/implicit-selrefs.o
29+
# RUN: %t/explicit-selrefs-1.o %t/explicit-selrefs-2.o %t/implicit-selrefs.o \
30+
# RUN: -no_fixup_chains
3031
# RUN: llvm-otool -vs __DATA __objc_selrefs %t/explicit-and-implicit \
3132
# RUN: | FileCheck %s --check-prefix=EXPLICIT-AND-IMPLICIT
3233

0 commit comments

Comments
 (0)