Skip to content

Commit

Permalink
Provide a minimum OS version for MachO objects (#8323)
Browse files Browse the repository at this point in the history
This gives LLVM enough information to generate a
"platform load-command" in the object file.

Fixes #7941
  • Loading branch information
alexreinking committed Jun 25, 2024
1 parent dd6c98b commit 9b703f3
Showing 1 changed file with 27 additions and 0 deletions.
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

0 comments on commit 9b703f3

Please sign in to comment.