Skip to content

Commit

Permalink
Rollup merge of rust-lang#48560 - bdrewery:freebsd-struct-abi, r=este…
Browse files Browse the repository at this point in the history
…bank

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.
  • Loading branch information
kennytm committed Feb 27, 2018
2 parents 5805538 + 279e5b0 commit 4fcee2b
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/librustc_back/target/apple_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub fn opts() -> TargetOptions {
pre_link_args: LinkArgs::new(),
exe_allocation_crate: super::maybe_jemalloc(),
has_elf_tls: version >= (10, 7),
abi_return_struct_as_int: true,
.. Default::default()
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/freebsd_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub fn opts() -> TargetOptions {
eliminate_frame_pointer: false, // FIXME 43575
relro_level: RelroLevel::Full,
exe_allocation_crate: super::maybe_jemalloc(),
abi_return_struct_as_int: true,
.. Default::default()
}
}
11 changes: 5 additions & 6 deletions src/librustc_back/target/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,8 @@ pub struct TargetOptions {
pub staticlib_suffix: String,
/// OS family to use for conditional compilation. Valid options: "unix", "windows".
pub target_family: Option<String>,
/// Whether the target toolchain is like OpenBSD's.
/// Only useful for compiling against OpenBSD, for configuring abi when returning a struct.
pub is_like_openbsd: bool,
/// Whether the target toolchain's ABI supports returning small structs as an integer.
pub abi_return_struct_as_int: bool,
/// Whether the target toolchain is like macOS's. Only useful for compiling against iOS/macOS,
/// in particular running dsymutil and some other stuff like `-dead_strip`. Defaults to false.
pub is_like_osx: bool,
Expand Down Expand Up @@ -504,7 +503,7 @@ impl Default for TargetOptions {
staticlib_prefix: "lib".to_string(),
staticlib_suffix: ".a".to_string(),
target_family: None,
is_like_openbsd: false,
abi_return_struct_as_int: false,
is_like_osx: false,
is_like_solaris: false,
is_like_windows: false,
Expand Down Expand Up @@ -759,7 +758,7 @@ impl Target {
key!(staticlib_prefix);
key!(staticlib_suffix);
key!(target_family, optional);
key!(is_like_openbsd, bool);
key!(abi_return_struct_as_int, bool);
key!(is_like_osx, bool);
key!(is_like_solaris, bool);
key!(is_like_windows, bool);
Expand Down Expand Up @@ -957,7 +956,7 @@ impl ToJson for Target {
target_option_val!(staticlib_prefix);
target_option_val!(staticlib_suffix);
target_option_val!(target_family);
target_option_val!(is_like_openbsd);
target_option_val!(abi_return_struct_as_int);
target_option_val!(is_like_osx);
target_option_val!(is_like_solaris);
target_option_val!(is_like_windows);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/target/openbsd_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn opts() -> TargetOptions {
target_family: Some("unix".to_string()),
linker_is_gnu: true,
has_rpath: true,
is_like_openbsd: true,
abi_return_struct_as_int: true,
pre_link_args: args,
position_independent_executables: true,
eliminate_frame_pointer: false, // FIXME 43575
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/windows_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub fn opts() -> TargetOptions {
"rsend.o".to_string()
],
custom_unwind_resume: true,
abi_return_struct_as_int: true,

.. Default::default()
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/windows_msvc_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub fn opts() -> TargetOptions {
pre_link_args: args,
crt_static_allows_dylibs: true,
crt_static_respected: true,
abi_return_struct_as_int: true,

.. Default::default()
}
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_trans/cabi_x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ pub fn compute_abi_info<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
// http://www.angelcode.com/dev/callconv/callconv.html
// Clang's ABI handling is in lib/CodeGen/TargetInfo.cpp
let t = &cx.sess().target.target;
if t.options.is_like_osx || t.options.is_like_windows
|| t.options.is_like_openbsd {
if t.options.abi_return_struct_as_int {
// According to Clang, everyone but MSVC returns single-element
// float aggregates directly in a floating-point register.
if !t.options.is_like_msvc && is_single_fp_element(cx, fty.ret.layout) {
Expand Down

0 comments on commit 4fcee2b

Please sign in to comment.