Skip to content

Commit

Permalink
OpenBSD under x86 has particular ABI for returning a struct.
Browse files Browse the repository at this point in the history
It is like OSX or Windows: small structs are returned as integers.
  • Loading branch information
semarie committed Dec 4, 2016
1 parent 53ebf5a commit 6774e7a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/librustc_back/target/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ 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 is like OSX's. Only useful for compiling against iOS/OS X, in
/// particular running dsymutil and some other stuff like `-dead_strip`. Defaults to false.
pub is_like_osx: bool,
Expand Down Expand Up @@ -406,6 +409,7 @@ impl Default for TargetOptions {
staticlib_prefix: "lib".to_string(),
staticlib_suffix: ".a".to_string(),
target_family: None,
is_like_openbsd: false,
is_like_osx: false,
is_like_solaris: false,
is_like_windows: false,
Expand Down Expand Up @@ -572,6 +576,7 @@ impl Target {
key!(staticlib_prefix);
key!(staticlib_suffix);
key!(target_family, optional);
key!(is_like_openbsd, bool);
key!(is_like_osx, bool);
key!(is_like_solaris, bool);
key!(is_like_windows, bool);
Expand Down Expand Up @@ -733,6 +738,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!(is_like_osx);
target_option_val!(is_like_solaris);
target_option_val!(is_like_windows);
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/openbsd_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub fn opts() -> TargetOptions {
executables: true,
linker_is_gnu: true,
has_rpath: true,
is_like_openbsd: true,
pre_link_args: vec![
// GNU-style linkers will use this to omit linking to libraries
// which don't actually fulfill any relocations, but only for
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_trans/cabi_x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) {
// http://www.angelcode.com/dev/callconv/callconv.html
// Clang's ABI handling is in lib/CodeGen/TargetInfo.cpp
let t = &ccx.sess().target.target;
if t.options.is_like_osx || t.options.is_like_windows {
if t.options.is_like_osx || t.options.is_like_windows

This comment has been minimized.

Copy link
@dsvensson

dsvensson Dec 6, 2016

Isn't it better to name the option according to the struct-return-behavior, rather than referring to how it's implemented on a growing list of platforms? I have no recommendation on the name though.

This comment has been minimized.

Copy link
@bdrewery

bdrewery Feb 26, 2018

Contributor

Done here #48560

|| t.options.is_like_openbsd {
match llsize_of_alloc(ccx, fty.ret.ty) {
1 => fty.ret.cast = Some(Type::i8(ccx)),
2 => fty.ret.cast = Some(Type::i16(ccx)),
Expand Down

0 comments on commit 6774e7a

Please sign in to comment.