Skip to content
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

Provide a minimum OS version for MachO objects #8323

Merged
merged 2 commits into from
Jun 25, 2024
Merged
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
27 changes: 27 additions & 0 deletions src/LLVM_Runtime_Linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,25 @@ llvm::DataLayout get_data_layout_for_target(Target target) {

namespace Internal {

namespace {

std::optional<llvm::VersionTuple> get_os_version_constraint(const llvm::Triple &triple) {
if (!triple.isOSBinFormatMachO()) {
return std::nullopt;
}

if (triple.getOS() == llvm::Triple::MacOSX && triple.getArch() == llvm::Triple::x86_64) {
// At time of writing (June 2024), this is one version prior
// to the oldest version still supported by Apple.
return llvm::VersionTuple(11, 0, 0);
}

llvm::VersionTuple t = triple.getMinimumSupportedOSVersion();
return t.empty() ? std::nullopt : std::make_optional(t);
}

} // namespace

llvm::Triple get_triple_for_target(const Target &target) {
llvm::Triple triple;

Expand Down Expand Up @@ -555,6 +574,14 @@ llvm::Triple get_triple_for_target(const Target &target) {
// Return default-constructed triple. Must be set later.
}

// Setting a minimum OS version here enables LLVM to include platform
// metadata in the MachO object file. Without this, Xcode 15's ld
// issues warnings about missing the "platform load command".
if (auto version = get_os_version_constraint(triple)) {
// llvm::Triple determines the version by parsing the OSName.
triple.setOSName((triple.getOSName() + version->getAsString()).str());
}

return triple;
}

Expand Down
Loading