Skip to content

[clang][driver][darwin] use the deployment target version as the SDK … #2905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions clang/lib/Driver/ToolChains/Darwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2764,8 +2764,16 @@ void Darwin::addPlatformVersionArgs(const llvm::opt::ArgList &Args,
}
CmdArgs.push_back(Args.MakeArgString(SDKVersion.getAsString()));
} else {
// Use a blank SDK version if it's not present.
CmdArgs.push_back("0.0.0");
// Use an SDK version that's matching the deployment target if the SDK
// version is missing. This is preferred over an empty SDK version (0.0.0)
// as the system's runtime might expect the linked binary to contain a
// valid SDK version in order for the binary to work correctly. It's
// reasonable to use the deployment target version as a proxy for the
// SDK version because older SDKs don't guarantee support for deployment
// targets newer than the SDK versions, so that rules out using some
// predetermined older SDK version, which leaves the deployment target
// version as the only reasonable choice.
CmdArgs.push_back(Args.MakeArgString(TargetVersion.getAsString()));
}
};
EmitPlatformVersionArg(getOSTargetVersion(), TargetPlatform,
Expand Down
5 changes: 4 additions & 1 deletion clang/test/Driver/darwin-ld-platform-version-macos.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@
// RUN: %clang -target x86_64-apple-macos10.13 -mlinker-version=520 \
// RUN: -### %t.o 2>&1 \
// RUN: | FileCheck --check-prefix=NOSDK %s
// NOSDK: "-platform_version" "macos" "10.13.0" "0.0.0"
// RUN: %clang -target x86_64-apple-darwin17 -mlinker-version=520 \
// RUN: -### %t.o 2>&1 \
// RUN: | FileCheck --check-prefix=NOSDK %s
// NOSDK: "-platform_version" "macos" "10.13.0" "10.13.0"