Skip to content

Commit fda7bb2

Browse files
committed
add "Objective-C Version" LLVM module flag
1 parent c7ba4bb commit fda7bb2

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,17 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
689689
}
690690

691691
pub(crate) fn add_objc_module_flags(&self) {
692+
// Darwin-like targets only.
692693
assert!(self.tcx.sess.target.is_like_darwin);
694+
let is_x86_32_macos =
695+
self.tcx.sess.target.arch == "x86" && self.tcx.sess.target.os == "macos";
696+
697+
llvm::add_module_flag_u32(
698+
self.llmod,
699+
llvm::ModuleFlagMergeBehavior::Error,
700+
"Objective-C Version",
701+
if is_x86_32_macos { 1 } else { 2 },
702+
);
693703

694704
llvm::add_module_flag_u32(
695705
self.llmod,
@@ -702,7 +712,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
702712
self.llmod,
703713
llvm::ModuleFlagMergeBehavior::Error,
704714
"Objective-C Image Info Section",
705-
if self.tcx.sess.target.arch == "x86" && self.tcx.sess.target.os == "macos" {
715+
if is_x86_32_macos {
706716
"__OBJC,__image_info,regular"
707717
} else {
708718
"__DATA,__objc_imageinfo,regular,no_dead_strip"

tests/codegen-llvm/darwin-objc-32bit-x86-macos.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub fn get_selector() -> *mut () {
4343
// CHECK: load ptr, ptr @OBJC_CLASS_REFERENCES_.{{[0-9]+}}, align 4
4444
// CHECK: load ptr, ptr @OBJC_SELECTOR_REFERENCES_.{{[0-9]+}}, align 4
4545

46+
// CHECK: !{{[0-9]+}} = !{i32 1, !"Objective-C Version", i32 1}
4647
// CHECK: !{{[0-9]+}} = !{i32 1, !"Objective-C Image Info Version", i32 0}
4748
// CHECK: !{{[0-9]+}} = !{i32 1, !"Objective-C Image Info Section", !"__OBJC,__image_info,regular"}
4849
// CHECK-NOT: !{{[0-9]+}} = !{i32 1, !"Objective-C Is Simulated", i32 32}

tests/codegen-llvm/darwin-objc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ pub fn get_selector() -> *mut () {
8686
// aarch64_ios-SAME: align 8
8787
// aarch64_ios_sim-SAME: align 8
8888

89+
// CHECK: !{{[0-9]+}} = !{i32 1, !"Objective-C Version", i32 2}
8990
// CHECK: !{{[0-9]+}} = !{i32 1, !"Objective-C Image Info Version", i32 0}
9091
// CHECK: !{{[0-9]+}} = !{i32 1, !"Objective-C Image Info Section", !"__DATA,__objc_imageinfo,regular,no_dead_strip"}
9192

0 commit comments

Comments
 (0)