Skip to content

Commit 4fcee2b

Browse files
committed
Rollup merge of rust-lang#48560 - bdrewery:freebsd-struct-abi, r=estebank
Fix FreeBSD struct returning ABI. FreeBSD has had a patch similar to this for a while. See https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=223047. This reworks 6774e7a to be more specific about what `compute_abi_info` is checking for per target.
2 parents 5805538 + 279e5b0 commit 4fcee2b

File tree

7 files changed

+11
-9
lines changed

7 files changed

+11
-9
lines changed

src/librustc_back/target/apple_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub fn opts() -> TargetOptions {
4646
pre_link_args: LinkArgs::new(),
4747
exe_allocation_crate: super::maybe_jemalloc(),
4848
has_elf_tls: version >= (10, 7),
49+
abi_return_struct_as_int: true,
4950
.. Default::default()
5051
}
5152
}

src/librustc_back/target/freebsd_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub fn opts() -> TargetOptions {
3636
eliminate_frame_pointer: false, // FIXME 43575
3737
relro_level: RelroLevel::Full,
3838
exe_allocation_crate: super::maybe_jemalloc(),
39+
abi_return_struct_as_int: true,
3940
.. Default::default()
4041
}
4142
}

src/librustc_back/target/mod.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,8 @@ pub struct TargetOptions {
346346
pub staticlib_suffix: String,
347347
/// OS family to use for conditional compilation. Valid options: "unix", "windows".
348348
pub target_family: Option<String>,
349-
/// Whether the target toolchain is like OpenBSD's.
350-
/// Only useful for compiling against OpenBSD, for configuring abi when returning a struct.
351-
pub is_like_openbsd: bool,
349+
/// Whether the target toolchain's ABI supports returning small structs as an integer.
350+
pub abi_return_struct_as_int: bool,
352351
/// Whether the target toolchain is like macOS's. Only useful for compiling against iOS/macOS,
353352
/// in particular running dsymutil and some other stuff like `-dead_strip`. Defaults to false.
354353
pub is_like_osx: bool,
@@ -504,7 +503,7 @@ impl Default for TargetOptions {
504503
staticlib_prefix: "lib".to_string(),
505504
staticlib_suffix: ".a".to_string(),
506505
target_family: None,
507-
is_like_openbsd: false,
506+
abi_return_struct_as_int: false,
508507
is_like_osx: false,
509508
is_like_solaris: false,
510509
is_like_windows: false,
@@ -759,7 +758,7 @@ impl Target {
759758
key!(staticlib_prefix);
760759
key!(staticlib_suffix);
761760
key!(target_family, optional);
762-
key!(is_like_openbsd, bool);
761+
key!(abi_return_struct_as_int, bool);
763762
key!(is_like_osx, bool);
764763
key!(is_like_solaris, bool);
765764
key!(is_like_windows, bool);
@@ -957,7 +956,7 @@ impl ToJson for Target {
957956
target_option_val!(staticlib_prefix);
958957
target_option_val!(staticlib_suffix);
959958
target_option_val!(target_family);
960-
target_option_val!(is_like_openbsd);
959+
target_option_val!(abi_return_struct_as_int);
961960
target_option_val!(is_like_osx);
962961
target_option_val!(is_like_solaris);
963962
target_option_val!(is_like_windows);

src/librustc_back/target/openbsd_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn opts() -> TargetOptions {
3131
target_family: Some("unix".to_string()),
3232
linker_is_gnu: true,
3333
has_rpath: true,
34-
is_like_openbsd: true,
34+
abi_return_struct_as_int: true,
3535
pre_link_args: args,
3636
position_independent_executables: true,
3737
eliminate_frame_pointer: false, // FIXME 43575

src/librustc_back/target/windows_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ pub fn opts() -> TargetOptions {
101101
"rsend.o".to_string()
102102
],
103103
custom_unwind_resume: true,
104+
abi_return_struct_as_int: true,
104105

105106
.. Default::default()
106107
}

src/librustc_back/target/windows_msvc_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub fn opts() -> TargetOptions {
3434
pre_link_args: args,
3535
crt_static_allows_dylibs: true,
3636
crt_static_respected: true,
37+
abi_return_struct_as_int: true,
3738

3839
.. Default::default()
3940
}

src/librustc_trans/cabi_x86.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ pub fn compute_abi_info<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
5252
// http://www.angelcode.com/dev/callconv/callconv.html
5353
// Clang's ABI handling is in lib/CodeGen/TargetInfo.cpp
5454
let t = &cx.sess().target.target;
55-
if t.options.is_like_osx || t.options.is_like_windows
56-
|| t.options.is_like_openbsd {
55+
if t.options.abi_return_struct_as_int {
5756
// According to Clang, everyone but MSVC returns single-element
5857
// float aggregates directly in a floating-point register.
5958
if !t.options.is_like_msvc && is_single_fp_element(cx, fty.ret.layout) {

0 commit comments

Comments
 (0)