[clang] 3affbae - clang/apple: Infer simulator env from -mios-simulator-version-min= flag
Nico Weber via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 22 09:20:50 PDT 2022
Author: Nico Weber
Date: 2022-08-22T12:19:34-04:00
New Revision: 3affbae5300dcdf753c954a65ab6a96fcf65c483
URL: https://github.com/llvm/llvm-project/commit/3affbae5300dcdf753c954a65ab6a96fcf65c483
DIFF: https://github.com/llvm/llvm-project/commit/3affbae5300dcdf753c954a65ab6a96fcf65c483.diff
LOG: clang/apple: Infer simulator env from -mios-simulator-version-min= flag
Before this patch, open-source clang would consider
`-target x86_64-apple-darwin -mios-simulator-version-min=11.0` as
targeting the iOS simulator, due to the mios flag informing it
that we want to target iOS, and logic in the driver then realizing
that x86 iOS builds must be the simulator.
However, for `-target arm64-apple-darwin -mios-simulator-version-min=11.0`
that didn't work and clang thought that it's building for actual iOS,
and not for the simulator.
Due to this, building compiler-rt for arm64 iossim would lead to
all .o files in RTSanitizerCommonSymbolizer.iossim.dir being built
for iOS instead of for iOS simulator, and clang would ask ld64 to
link for iOS, but using the iPhoneSimulator sysroot. This would then
lead to many warnings from ld64 looking like:
ld: warning: building for iOS, but linking in .tbd file
(.../iPhoneSimulator.sdk/usr/lib/libc++abi.tbd) built for iOS Simulator
Worse, with ld64.lld, this diagnostic is currently an error instead
of a warning.
This patch makes it so that the presence of -mios-simulator-version-min=
now informs clang that we're building for simulator. That way, all the
.o files are built for simulator, the linker is informed that we're
building for simulator, and everything Just Works.
(Xcode's clang already behaves like this, so this makes open-source clang
match Xcode clang.)
We can now likely remove the hack to treat non-mac darwin x86 as
simulator, but doing that feels slightly risky, so I'm leaving that
for a follow-up patch.
(This patch is made necessary by the existence of arm64 macs.)
Differential Revision: https://reviews.llvm.org/D132258
Added:
Modified:
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/Driver/darwin-ld.c
clang/test/Driver/darwin-version.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index 7e3fc625d8c85..2a581a17bd099 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1655,9 +1655,12 @@ struct DarwinPlatform {
Result.setEnvironment(Environment, OSVersion, SDKInfo);
return Result;
}
- static DarwinPlatform createOSVersionArg(DarwinPlatformKind Platform,
- Arg *A) {
- return DarwinPlatform(OSVersionArg, Platform, A);
+ static DarwinPlatform createOSVersionArg(DarwinPlatformKind Platform, Arg *A,
+ bool IsSimulator) {
+ DarwinPlatform Result{OSVersionArg, Platform, A};
+ if (IsSimulator)
+ Result.Environment = DarwinEnvironmentKind::Simulator;
+ return Result;
}
static DarwinPlatform createDeploymentTargetEnv(DarwinPlatformKind Platform,
StringRef EnvVarName,
@@ -1752,23 +1755,33 @@ getDeploymentTargetFromOSVersionArg(DerivedArgList &Args,
: TvOSVersion ? TvOSVersion : WatchOSVersion)
->getAsString(Args);
}
- return DarwinPlatform::createOSVersionArg(Darwin::MacOS, macOSVersion);
+ return DarwinPlatform::createOSVersionArg(Darwin::MacOS, macOSVersion,
+ /*IsImulator=*/false);
} else if (iOSVersion) {
if (TvOSVersion || WatchOSVersion) {
TheDriver.Diag(diag::err_drv_argument_not_allowed_with)
<< iOSVersion->getAsString(Args)
<< (TvOSVersion ? TvOSVersion : WatchOSVersion)->getAsString(Args);
}
- return DarwinPlatform::createOSVersionArg(Darwin::IPhoneOS, iOSVersion);
+ return DarwinPlatform::createOSVersionArg(
+ Darwin::IPhoneOS, iOSVersion,
+ iOSVersion->getOption().getID() ==
+ options::OPT_mios_simulator_version_min_EQ);
} else if (TvOSVersion) {
if (WatchOSVersion) {
TheDriver.Diag(diag::err_drv_argument_not_allowed_with)
<< TvOSVersion->getAsString(Args)
<< WatchOSVersion->getAsString(Args);
}
- return DarwinPlatform::createOSVersionArg(Darwin::TvOS, TvOSVersion);
+ return DarwinPlatform::createOSVersionArg(
+ Darwin::TvOS, TvOSVersion,
+ TvOSVersion->getOption().getID() ==
+ options::OPT_mtvos_simulator_version_min_EQ);
} else if (WatchOSVersion)
- return DarwinPlatform::createOSVersionArg(Darwin::WatchOS, WatchOSVersion);
+ return DarwinPlatform::createOSVersionArg(
+ Darwin::WatchOS, WatchOSVersion,
+ WatchOSVersion->getOption().getID() ==
+ options::OPT_mwatchos_simulator_version_min_EQ);
return None;
}
@@ -2228,6 +2241,7 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
DarwinEnvironmentKind Environment = OSTarget->getEnvironment();
// Recognize iOS targets with an x86 architecture as the iOS simulator.
+ // FIXME: Remove this.
if (Environment == NativeEnvironment && Platform != MacOS &&
Platform != DriverKit && OSTarget->canInferSimulatorFromArch() &&
getTriple().isX86())
diff --git a/clang/test/Driver/darwin-ld.c b/clang/test/Driver/darwin-ld.c
index 3a836d4dd1f13..5be119a545a63 100644
--- a/clang/test/Driver/darwin-ld.c
+++ b/clang/test/Driver/darwin-ld.c
@@ -67,6 +67,10 @@
// LINK_IOSSIM_3_0-NOT: -lbundle1.o
// LINK_IOSSIM_3_0: -lSystem
+// RUN: %clang -target arm64-apple-darwin -fuse-ld= -mlinker-version=700 -### -arch arm64 -mios-simulator-version-min=15.0 %t.o 2>&1 | FileCheck -check-prefix=LINK_IOSSIM_ARM64 %s
+
+// LINK_IOSSIM_ARM64: "-platform_version" "ios-simulator" "15.0.0" "15.0.0"
+
// RUN: %clang -target i386-apple-darwin9 -### -fpie %t.o 2> %t.log
// RUN: FileCheck -check-prefix=LINK_EXPLICIT_PIE %s < %t.log
//
diff --git a/clang/test/Driver/darwin-version.c b/clang/test/Driver/darwin-version.c
index 8b66aef489c9b..82c6fbe556b49 100644
--- a/clang/test/Driver/darwin-version.c
+++ b/clang/test/Driver/darwin-version.c
@@ -48,6 +48,10 @@
// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS10 %s
// CHECK-VERSION-IOS10: x86_64-apple-ios11.0.0-simulator
+// RUN: %clang -target arm64-apple-darwin -mios-simulator-version-min=11.0 -c -### %s 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS10-ARM64 %s
+// CHECK-VERSION-IOS10-ARM64: arm64-apple-ios11.0.0-simulator
+
// RUN: %clang -target arm64-apple-ios11.1 -c -### %s 2>&1 | \
// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS11 %s
// CHECK-VERSION-IOS11: arm64-apple-ios11.1.0
More information about the cfe-commits
mailing list