Skip to content

Commit 9b703f3

Browse files
authored
Provide a minimum OS version for MachO objects (#8323)
This gives LLVM enough information to generate a "platform load-command" in the object file. Fixes #7941
1 parent dd6c98b commit 9b703f3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/LLVM_Runtime_Linker.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,25 @@ llvm::DataLayout get_data_layout_for_target(Target target) {
422422

423423
namespace Internal {
424424

425+
namespace {
426+
427+
std::optional<llvm::VersionTuple> get_os_version_constraint(const llvm::Triple &triple) {
428+
if (!triple.isOSBinFormatMachO()) {
429+
return std::nullopt;
430+
}
431+
432+
if (triple.getOS() == llvm::Triple::MacOSX && triple.getArch() == llvm::Triple::x86_64) {
433+
// At time of writing (June 2024), this is one version prior
434+
// to the oldest version still supported by Apple.
435+
return llvm::VersionTuple(11, 0, 0);
436+
}
437+
438+
llvm::VersionTuple t = triple.getMinimumSupportedOSVersion();
439+
return t.empty() ? std::nullopt : std::make_optional(t);
440+
}
441+
442+
} // namespace
443+
425444
llvm::Triple get_triple_for_target(const Target &target) {
426445
llvm::Triple triple;
427446

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

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

0 commit comments

Comments
 (0)