Skip to content

Commit 7a6229b

Browse files
committed
Do not specify an SDK version in object files
This is unnecessary, since it ends up being overwritten when linking anyhow, and it feels wrong to embed some arbitrary SDK version in here.
1 parent 4556cbd commit 7a6229b

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

compiler/rustc_codegen_ssa/src/back/metadata.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,17 @@ fn macho_object_build_version_for_target(target: &Target) -> object::write::Mach
402402
let platform =
403403
rustc_target::spec::current_apple_platform(target).expect("unknown Apple target OS");
404404
let min_os = rustc_target::spec::current_apple_deployment_target(target);
405-
let (sdk_major, sdk_minor) =
406-
rustc_target::spec::current_apple_sdk_version(platform).expect("unknown Apple target OS");
407405

408406
let mut build_version = object::write::MachOBuildVersion::default();
409407
build_version.platform = platform;
410408
build_version.minos = pack_version(min_os);
411-
build_version.sdk = pack_version((sdk_major, sdk_minor, 0));
409+
// The version here does not _really_ matter, since it is only used at runtime, and we specify
410+
// it when linking the final binary, so we will omit the version. This is also what LLVM does,
411+
// and the tooling also allows this (and shows the SDK version as `n/a`). Finally, it is the
412+
// semantically correct choice, as the SDK has not influenced the binary generated by rustc at
413+
// this point in time.
414+
build_version.sdk = 0;
415+
412416
build_version
413417
}
414418

compiler/rustc_target/src/spec/base/apple/mod.rs

-17
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,6 @@ pub(crate) fn base(
158158
(opts, llvm_target(os, arch, abi), arch.target_arch())
159159
}
160160

161-
pub fn sdk_version(platform: u32) -> Option<(u16, u8)> {
162-
// NOTE: These values are from an arbitrary point in time but shouldn't make it into the final
163-
// binary since the final link command will have the current SDK version passed to it.
164-
match platform {
165-
object::macho::PLATFORM_MACOS => Some((13, 1)),
166-
object::macho::PLATFORM_IOS
167-
| object::macho::PLATFORM_IOSSIMULATOR
168-
| object::macho::PLATFORM_TVOS
169-
| object::macho::PLATFORM_TVOSSIMULATOR
170-
| object::macho::PLATFORM_MACCATALYST => Some((16, 2)),
171-
object::macho::PLATFORM_WATCHOS | object::macho::PLATFORM_WATCHOSSIMULATOR => Some((9, 1)),
172-
// FIXME: Upgrade to `object-rs` 0.33+ implementation with visionOS platform definition
173-
11 | 12 => Some((1, 0)),
174-
_ => None,
175-
}
176-
}
177-
178161
pub fn platform(target: &Target) -> Option<u32> {
179162
Some(match (&*target.os, &*target.abi) {
180163
("macos", _) => object::macho::PLATFORM_MACOS,

compiler/rustc_target/src/spec/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub mod crt_objects;
6161
mod base;
6262
pub use base::apple::{
6363
deployment_target_for_target as current_apple_deployment_target,
64-
platform as current_apple_platform, sdk_version as current_apple_sdk_version,
64+
platform as current_apple_platform,
6565
};
6666
pub use base::avr_gnu::ef_avr_arch;
6767

tests/run-make/apple-sdk-version/rmake.rs

+9
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ fn main() {
5050
// Set to 0, which means not set or "n/a".
5151
has_sdk_version("foo.o", "n/a");
5252

53+
// Check the SDK version in the .rmeta file, as set in `create_object_file`.
54+
//
55+
// This is just to ensure that we don't set some odd version in `create_object_file`,
56+
// if the rmeta file is packed in a different way in the future, this can safely be removed.
57+
rustc().target(target()).crate_type("rlib").input("foo.rs").output("libfoo.rlib").run();
58+
// Extra .rmeta file (which is encoded as an object file).
59+
cmd("ar").arg("-x").arg("libfoo.rlib").arg("lib.rmeta").run();
60+
has_sdk_version("lib.rmeta", "n/a");
61+
5362
// Test that version makes it to the linker.
5463
for (crate_type, file_ext) in [("bin", ""), ("dylib", ".dylib")] {
5564
// Non-simulator watchOS targets don't support dynamic linking,

0 commit comments

Comments
 (0)