Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement flexible target specification #16156

Merged
merged 7 commits into from Nov 4, 2014
Merged

Implement flexible target specification #16156

merged 7 commits into from Nov 4, 2014

Conversation

@emberian
Copy link
Member

@emberian emberian commented Aug 1, 2014

See commit message.

@emberian
Copy link
Member Author

@emberian emberian commented Aug 1, 2014

Still trying to figure out a bug where executables aren't getting the executable bit set...

@emberian
Copy link
Member Author

@emberian emberian commented Aug 1, 2014

Seems to have resolved itself with a rebase ¯_(ツ)_/¯

let mut paths = os::split_paths(target_path.as_slice());
// FIXME: should be relative to the prefix rustc is installed in, and do something
// different for Windows.
paths.push(Path::new("/etc/rustc"));

This comment has been minimized.

@huonw

huonw Aug 1, 2014
Member

Who installs to /etc/rustc?

This comment has been minimized.

@alexcrichton

alexcrichton Aug 1, 2014
Member

This feature may want to remain unimplemented for now due to some open questions here, but it probably doesn't matter too much.

@huonw
Copy link
Member

@huonw huonw commented Aug 1, 2014

Can you write a run-make test that checks the compiler is correctly searching for, parsing and using external specifications? (E.g. it could run rustc --target=foo-bar-baz --emit=asm ... with a custom target that disables stack checks, and then grep for stack checks.)

@emberian
Copy link
Member Author

@emberian emberian commented Aug 1, 2014

Another issue: probably needs to allow specifying target_os instead of taking it from the target triple. I'm not actually sure this is a good idea, though, and it seems MUCH more clear that the target_os comes from the triple name itself. But we'd need to rename "osx" to "darwin", which I feel is almost a lie? Not really sure. Need feedback.

@emberian
Copy link
Member Author

@emberian emberian commented Aug 1, 2014

(The RFC specifies taking it from the target)

@emberian
Copy link
Member Author

@emberian emberian commented Aug 1, 2014

@huonw how do those docs look?

@emberian
Copy link
Member Author

@emberian emberian commented Aug 1, 2014

Hm, glaringly obvious problem: linker should probably include a target triple prefix, for cross compiling. ie, x86_64-unknown-linux-gnu-cc.

@errordeveloper
Copy link
Contributor

@errordeveloper errordeveloper commented Aug 1, 2014

@farcaller we should try this with arm-none-eabi

@emberian
Copy link
Member Author

@emberian emberian commented Aug 1, 2014

Be warned that this isn't quite working yet. My current status is:

LLVM ERROR: not a number, or does not fit in an unsigned int
@emberian
Copy link
Member Author

@emberian emberian commented Aug 1, 2014

(Already fixed I think, still building..)

//! will be given. `RUST_TARGET_PATH` includes `/etc/rustc` as its last entry, to be searched by
//! default.
//!
//! Projects defining their own targets should use `--target=path/to/my-awesome-platform.json`

This comment has been minimized.

@huonw

huonw Aug 1, 2014
Member

Do we have a story for interacting with cargo?

This comment has been minimized.

@emberian

emberian Aug 1, 2014
Author Member

Not yet, no.

pub code_model: String,
/// Do not emit code that uses the "red zone", if the ABI has one. Defaults to true.
pub disable_redzone: bool,
/// String to use as the `target_endian` `cfg` variable. Must be specified.

This comment has been minimized.

@huonw

huonw Aug 1, 2014
Member

Is it crazy to reorder these so that the required fields are together at the start of the definition?

//! Targets are defined using [JSON](http://json.org/). The `Target` struct in this module defines
//! the format the JSON file should take, though each underscore in the field names should be
//! replaced with a hyphen (`-`) in the JSON file. Some fields are required in every target
//! specification, such as `data-layout`, `llvm-target`, `target-endian`, `target-word-size`, and

This comment has been minimized.

@huonw

huonw Aug 1, 2014
Member

Could you explicitly state that most fields are optional?

sess.abort_if_errors();
}
if sess.target.target.is_like_osx && sess.opts.debuginfo != NoDebugInfo {
match Command::new("dsymutil").arg(out_filename).status() {

This comment has been minimized.

@alexcrichton

alexcrichton Aug 1, 2014
Member

status => output

}
let mut v = b"-Wl,-force_load,".to_vec();
v.push_all(morestack.as_vec());
cmd.arg(v.as_slice());
}

This comment has been minimized.

@alexcrichton

alexcrichton Aug 1, 2014
Member

This seems to have lost the fall-through case?

Some(..) => false,
None => { *slot = Some(true); true }
}
}

This comment has been minimized.

@alexcrichton

alexcrichton Aug 1, 2014
Member

This seems backwards?

This comment has been minimized.

@emberian

emberian Aug 1, 2014
Author Member

Is parse_bool also backwards, then?

This comment has been minimized.

@alexcrichton

alexcrichton Aug 1, 2014
Member

Ah nevermind, I remember what this is doing now. No worries!

abi::Mips => ("big", "mips", "32"),
abi::Mipsel => ("little", "mipsel", "32")
};
let re = Regex::new("([^-]+)-([^-]+)-([^-]+)(-.*)?").unwrap();

This comment has been minimized.

@alexcrichton

alexcrichton Aug 1, 2014
Member

While a regex certainly makes sense here, can we avoid pulling in the entire regex crate just for this one use case?

abi::Mipsel => ("little", "mipsel", "32")
};
let re = Regex::new("([^-]+)-([^-]+)-([^-]+)(-.*)?").unwrap();
let matches = re.captures(sess.opts.target_triple.as_slice()).expect("invalid target triple!");

This comment has been minimized.

@alexcrichton

alexcrichton Aug 1, 2014
Member

This is dealing with user input so it should probably gracefully fail instead of ICE

abi::Mips => mips::get_target_strs(target_triple, os),
abi::Mipsel => mipsel::get_target_strs(target_triple, os)
let target = Target::search(sopts.target_triple.as_slice())
.expect("Couldn't find target specification, handle this better");

This comment has been minimized.

@alexcrichton

alexcrichton Aug 1, 2014
Member

Just a reminder to handle this better

}
fn dylibname(&self) -> Option<(String, String)> {
let t = &self.sess.target.target;
Some((t.dll_prefix.clone(), t.dll_suffix.clone()))
}

This comment has been minimized.

@alexcrichton

alexcrichton Aug 1, 2014
Member

This seems like a lossy transformation, why return Option when it's always Some?

"x86_64" => cabi_x86_64::compute_abi_info(ccx, atys, rty, ret_def),
"arm" => cabi_arm::compute_abi_info(ccx, atys, rty, ret_def),
"mips" => cabi_mips::compute_abi_info(ccx, atys, rty, ret_def),
a => fail!("unrecognized arch \"{}\" in target descriptor, handle this better", a)

This comment has been minimized.

@alexcrichton

alexcrichton Aug 1, 2014
Member

Reminder to handle this better

match fn_ty.abi.for_target(ccx.sess().targ_cfg.os,
ccx.sess().targ_cfg.arch) {
Some(Rust) | Some(RustCall) => {
match fn_ty.abi {

This comment has been minimized.

@alexcrichton

alexcrichton Aug 1, 2014
Member

How come this stopped calling for_target?

@mneumann
Copy link
Contributor

@mneumann mneumann commented Aug 1, 2014

When compiling this on DragonFly I run into these problems:

/home/mneumann/rust/src/liblibc/lib.rs:2943:47: 2943:53 error: unresolved import
 `types::os::arch::c95::c_uint`. Could not find `arch` in `types::os`.
/home/mneumann/rust/src/liblibc/lib.rs:2943             use types::os::arch::c95
::{c_int, c_uint};

          ^~~~~~
/home/mneumann/rust/src/liblibc/lib.rs:2965:17: 2965:44 error: unresolved import
 `types::os::arch::c95::c_int`. Could not find `arch` in `types::os`.
/home/mneumann/rust/src/liblibc/lib.rs:2965             use types::os::arch::c95
::c_int;
                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/mneumann/rust/src/liblibc/lib.rs:2966:17: 2966:49 error: unresolved import
 `types::os::arch::posix88::mode_t`. Could not find `arch` in `types::os`.
/home/mneumann/rust/src/liblibc/lib.rs:2966             use types::os::arch::pos
ix88::mode_t;
                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/mneumann/rust/src/liblibc/lib.rs:3209:17: 3209:44 error: unresolved import
 `types::os::arch::c95::c_int`. Could not find `arch` in `types::os`.
/home/mneumann/rust/src/liblibc/lib.rs:3209             use types::os::arch::c95
::c_int;
                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/mneumann/rust/src/liblibc/lib.rs:150:54: 150:58 error: unresolved import (
maybe you meant `stat::*`?)
/home/mneumann/rust/src/liblibc/lib.rs:150 pub use funcs::posix88::stat_::{chmod
, fstat, mkdir, stat};

                ^~~~
error: aborting due to 115 previous errors
gmake: *** [x86_64-unknown-dragonfly/stage1/lib/rustlib/x86_64-unknown-dragonfly
/lib/stamp.libc] Error 101

Maybe the target_os is incorrectly determined?


pub fn target() -> Target {
Target {
function_sections: false,

This comment has been minimized.

@alexcrichton

alexcrichton Aug 1, 2014
Member

false => true ?

This comment has been minimized.

@alexcrichton

alexcrichton Aug 1, 2014
Member

Ah nevermind, it would be nice to preserve the comments in the source code to this target specification about why this is false


pub fn target() -> Target {
Target {
function_sections: false,

This comment has been minimized.

@alexcrichton

alexcrichton Aug 1, 2014
Member

Was this disabled originally for dragonfly?


pub fn target() -> Target {
Target {
function_sections: false,

This comment has been minimized.

@alexcrichton

alexcrichton Aug 1, 2014
Member

This should be enabled for freebsd?

executables: true,
disable_stack_checking: false,
has_rpath: true,
relocation_model: "default".to_string(),

This comment has been minimized.

@alexcrichton

alexcrichton Aug 1, 2014
Member

Why is this different than "pic"?

arch: "x86".to_string(),
.. super::freebsd_base::target()
}
}

This comment has been minimized.

@alexcrichton

alexcrichton Aug 1, 2014
Member

I don't think split-stacks are supported on 32-bit freebsd, why add this triple?

@vadimcn
Copy link
Contributor

@vadimcn vadimcn commented Oct 30, 2014

Rebased, fixed, squashed: https://github.com/vadimcn/rust/tree/flextarget. Passes tests on Windows.
@cmr: Do you want me to submit it?

bors added a commit that referenced this pull request Oct 30, 2014
@aturon
Copy link
Member

@aturon aturon commented Oct 31, 2014

Revived, yay!

bors added a commit that referenced this pull request Oct 31, 2014
bors added a commit that referenced this pull request Nov 1, 2014
bors added a commit that referenced this pull request Nov 1, 2014
@@ -1100,12 +1123,15 @@ do

if [ ${do_reconfigure} -ne 0 ]
then
msg "configuring LLVM for $t"
# LLVM's configure doesn't recognize the new Windows triples yet
$gnu_t=$(to_gnu_triple $t)

This comment has been minimized.

@klutzy

klutzy Nov 1, 2014
Contributor

- $gnu_t=$(to_gnu_triple $t)
+ gnu_t=$(to_gnu_triple $t)

This comment has been minimized.

@vadimcn

vadimcn Nov 1, 2014
Contributor

Yup, @klutzy is absolutely right! I guess this doesn't break stuff unless LLVM needs to be rebuilt...

bors added a commit that referenced this pull request Nov 1, 2014
bors added a commit that referenced this pull request Nov 2, 2014
@vadimcn
Copy link
Contributor

@vadimcn vadimcn commented Nov 2, 2014

Darn it! What's going on here???

bors added a commit that referenced this pull request Nov 3, 2014
@emberian
Copy link
Member Author

@emberian emberian commented Nov 3, 2014

I can't replicate the android failure locally. @alexcrichton do you know what API level the emulators are using?

@alexcrichton
Copy link
Member

@alexcrichton alexcrichton commented Nov 3, 2014

Looks like #17448, but I think that we're using api version 19 maybe?

emberian added 6 commits Jul 23, 2014
Removes all target-specific knowledge from rustc. Some targets have changed
during this, but none of these should be very visible outside of
cross-compilation. The changes make our targets more consistent.

iX86-unknown-linux-gnu is now only available as i686-unknown-linux-gnu. We
used to accept any value of X greater than 1. i686 was released in 1995, and
should encompass the bare minimum of what Rust supports on x86 CPUs.

The only two windows targets are now i686-pc-windows-gnu and
x86_64-pc-windows-gnu.

The iOS target has been renamed from arm-apple-ios to arm-apple-darwin.

A complete list of the targets we accept now:

arm-apple-darwin
arm-linux-androideabi
arm-unknown-linux-gnueabi
arm-unknown-linux-gnueabihf

i686-apple-darwin
i686-pc-windows-gnu
i686-unknown-freebsd
i686-unknown-linux-gnu

mips-unknown-linux-gnu
mipsel-unknown-linux-gnu

x86_64-apple-darwin
x86_64-unknown-freebsd
x86_64-unknown-linux-gnu
x86_64-pc-windows-gnu

Closes #16093

[breaking-change]
@bors

This comment has been minimized.

Copy link
Contributor

@bors bors commented on 87a753e Nov 4, 2014

This comment has been minimized.

Copy link
Contributor

@bors bors replied Nov 4, 2014

merging cmr/rust/target-spec = 87a753e into auto

This comment has been minimized.

Copy link
Contributor

@bors bors replied Nov 4, 2014

cmr/rust/target-spec = 87a753e merged ok, testing candidate = cbd0b5d

bors added a commit that referenced this pull request Nov 4, 2014
@bors

This comment has been minimized.

Copy link
Contributor

@bors bors commented on 61aeab4 Nov 4, 2014

This comment has been minimized.

Copy link
Contributor

@bors bors replied Nov 4, 2014

merging cmr/rust/target-spec = 61aeab4 into auto

This comment has been minimized.

Copy link
Contributor

@bors bors replied Nov 4, 2014

cmr/rust/target-spec = 61aeab4 merged ok, testing candidate = 3a8f4ec

This comment has been minimized.

Copy link
Contributor

@bors bors replied Nov 4, 2014

fast-forwarding master to auto = 3a8f4ec

bors added a commit that referenced this pull request Nov 4, 2014
@bors bors merged commit 61aeab4 into rust-lang:master Nov 4, 2014
2 checks passed
2 checks passed
@emberian
continuous-integration/travis-ci The Travis CI build passed
Details
@bors
default all tests passed
@vadimcn
Copy link
Contributor

@vadimcn vadimcn commented Nov 4, 2014

@cmr Congrats! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet