Skip to content

Commit f55b79f

Browse files
committed
Revert "[lld] enable fixup chains by default (#79894)"
This caused links to fail with: lld/MachO/Symbols.cpp:97: virtual uint64_t lld::macho::Defined::getVA() const: Assertion `target->usesThunks()' failed. or crash when asserts are disabled. See comment on #79894 > 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 This reverts commit 775c285.
1 parent 53c0e80 commit f55b79f

File tree

7 files changed

+44
-54
lines changed

7 files changed

+44
-54
lines changed

lld/MachO/Driver.cpp

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

5554
#include <algorithm>
@@ -1043,53 +1042,41 @@ static bool shouldEmitChainedFixups(const InputArgList &args) {
10431042
if (arg && arg->getOption().matches(OPT_no_fixup_chains))
10441043
return false;
10451044

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");
1045+
bool isRequested = arg != nullptr;
10501046

1051-
return false;
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;
1060+
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());
10521064
}
10531065

10541066
if (!is_contained({AK_x86_64, AK_x86_64h, AK_arm64}, config->arch())) {
1055-
if (requested)
1067+
if (isRequested)
10561068
error("-fixup_chains is only supported on x86_64 and arm64 targets");
1057-
10581069
return false;
10591070
}
10601071

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

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;
1078+
// TODO: Enable by default once stable.
1079+
return isRequested;
10931080
}
10941081

10951082
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 -no_fixup_chains
13+
# RUN: %lld-watchos -lSystem %t/libfoo.dylib %t/libbar.dylib %t/test.o -o %t/test
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 -no_fixup_chains
8+
# RUN: %lld -arch arm64 -lSystem %t/libfoo.dylib %t/libbar.dylib %t/test.o -o %t/test
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+
1718
## Dylibs that do lazy dynamic calls do need dyld_stub_binder.
1819
# RUN: not %no-lsystem-lld -arch arm64 -dylib %t/bar.o %t/libfoo.dylib \
19-
# RUN: -o %t/libbar.dylib -no_fixup_chains 2>&1 | \
20-
# RUN: FileCheck --check-prefix=MISSINGSTUB %s
20+
# RUN: -o %t/libbar.dylib 2>&1 | FileCheck --check-prefix=MISSINGSTUB %s
2121
# RUN: %lld -arch arm64 -lSystem -dylib %t/bar.o %t/libfoo.dylib \
22-
# RUN: -o %t/libbar.dylib -no_fixup_chains
22+
# RUN: -o %t/libbar.dylib
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 -no_fixup_chains 2>&1 | FileCheck --check-prefix=MISSINGSTUB %s
27+
# RUN: -o %t/test 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 -no_fixup_chains
29+
# RUN: -o %t/test
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 -no_fixup_chains
34+
# RUN: -o %t/test -undefined dynamic_lookup
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 -no_fixup_chains
37+
# RUN: -o %t/test -U dyld_stub_binder
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 -no_fixup_chains
7-
; RUN: %lld -arch arm64 -lSystem --icf=all -dylib -o %t/icf-all.dylib %t/icf-obj.o -no_fixup_chains
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
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 -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
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
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
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
58
# RUN: llvm-mc -filetype=obj -triple=arm64_32-apple-darwin %s -o %t-arm64_32.o
69
# RUN: not %lld-watchos -lSystem -fixup_chains %t-arm64_32.o -o /dev/null 2>&1 | \
710
# RUN: FileCheck %s --check-prefix=ARCH
811

912
## Check that we emit diagnostics when -fixup_chains is explicitly specified,
1013
## but we don't support creating chained fixups for said configuration.
1114
# 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
1216
# ARCH: error: -fixup_chains is only supported on x86_64 and arm64 targets
1317

1418
.globl _main

lld/test/MachO/objc-selrefs.s

Lines changed: 3 additions & 4 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 -no_fixup_chains
9+
# RUN: %t/explicit-selrefs-1.o %t/explicit-selrefs-2.o
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 -no_fixup_chains
16+
# RUN: %t/explicit-selrefs-1.o %t/explicit-selrefs-2.o
1717
# RUN: llvm-otool -vs __DATA __objc_selrefs %t/explicit-only-with-icf \
1818
# RUN: | FileCheck %s --check-prefix=EXPLICIT-WITH-ICF
1919

@@ -25,8 +25,7 @@
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 \
29-
# RUN: -no_fixup_chains
28+
# RUN: %t/explicit-selrefs-1.o %t/explicit-selrefs-2.o %t/implicit-selrefs.o
3029
# RUN: llvm-otool -vs __DATA __objc_selrefs %t/explicit-and-implicit \
3130
# RUN: | FileCheck %s --check-prefix=EXPLICIT-AND-IMPLICIT
3231

0 commit comments

Comments
 (0)