Permalink
Browse files

OpenBSD under x86 has particular ABI for returning a struct.

It is like OSX or Windows: small structs are returned as integers.
  • Loading branch information...
semarie committed Dec 3, 2016
1 parent 53ebf5a commit 6774e7aa92f5866657f778f08261c0fe219f01a8
Showing with 9 additions and 1 deletion.
  1. +6 −0 src/librustc_back/target/mod.rs
  2. +1 −0 src/librustc_back/target/openbsd_base.rs
  3. +2 −1 src/librustc_trans/cabi_x86.rs
@@ -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,
@@ -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,
@@ -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);
@@ -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);
@@ -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
@@ -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.

Show comment
Hide comment
@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.

@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.

Show comment
Hide comment
@bdrewery

bdrewery Feb 26, 2018

Contributor

Done here #48560

@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)),

0 comments on commit 6774e7a

Please sign in to comment.