Skip to content

add Thumbs to the compiler #36874

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

Merged
merged 8 commits into from
Oct 4, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/librustc_back/target/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ mod netbsd_base;
mod solaris_base;
mod windows_base;
mod windows_msvc_base;
mod thumb_base;

pub type TargetResult = Result<Target, String>;

macro_rules! supported_targets {
( $(($triple:expr, $module:ident)),+ ) => (
( $(($triple:expr, $module:ident),)+ ) => (
$(mod $module;)*

/// List of supported targets
Expand Down Expand Up @@ -191,7 +192,12 @@ supported_targets! {

("le32-unknown-nacl", le32_unknown_nacl),
("asmjs-unknown-emscripten", asmjs_unknown_emscripten),
("wasm32-unknown-emscripten", wasm32_unknown_emscripten)
("wasm32-unknown-emscripten", wasm32_unknown_emscripten),

("thumbv6m-none-eabi", thumbv6m_none_eabi),
("thumbv7m-none-eabi", thumbv7m_none_eabi),
("thumbv7em-none-eabi", thumbv7em_none_eabi),
("thumbv7em-none-eabihf", thumbv7em_none_eabihf),
}

/// Everything `rustc` knows about how to compile for a specific target.
Expand Down Expand Up @@ -401,6 +407,9 @@ impl Default for TargetOptions {
allow_asm: true,
has_elf_tls: false,
obj_is_bitcode: false,
// NOTE 0 is *not* the real default value of max_atomic_width. The default value is
// actually the pointer_width of the target. This default is injected in the
// Target::from_json function.
max_atomic_width: 0,
panic_strategy: PanicStrategy::Unwind,
}
Expand Down Expand Up @@ -699,6 +708,10 @@ impl ToJson for Target {
target_option_val!(max_atomic_width);
target_option_val!(panic_strategy);

if self.options.max_atomic_width.to_string() != self.target_pointer_width {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcrichton this fixes the problem I was seeing where setting max_atomic_width to 0 in the Target declaration was being converted into 32 due to the JSON roundtrip. I've also added a rmake test for this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woah can't we use Option instead of magic 0 treatment or similar? Granted, I'm arriving late to this issue so apologies if that has already been ruled out for good reason.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the simplest change necessary to make this work but using Option here sounds better; I'll give it a try.

d.insert("max-atomic-width".to_string(), self.options.max_atomic_width.to_json());
}

Json::Object(d)
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/librustc_back/target/thumb_base.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use target::TargetOptions;
use std::default::Default;

pub fn opts() -> TargetOptions {
TargetOptions {
executables: true,
linker: "arm-none-eabi-gcc".to_string(),
panic_strategy: "abort".to_string(),
relocation_model: "static".to_string(),
.. Default::default()
}
}
34 changes: 34 additions & 0 deletions src/librustc_back/target/thumbv6m_none_eabi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use target::{Target, TargetOptions, TargetResult};

pub fn target() -> TargetResult {
Ok(Target {
llvm_target: "thumbv6m-none-eabi".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "32".to_string(),
data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
arch: "arm".to_string(),
target_os: "none".to_string(),
target_env: "".to_string(),
target_vendor: "".to_string(),

options: TargetOptions {
// The ARMv6-M architecture doesn't support unaligned loads/stores so we disable them
// with +strict-align.
features: "+strict-align".to_string(),
// There are no atomic instructions available in the instruction set of the ARMv6-M
// architecture
max_atomic_width: 0,
.. super::thumb_base::opts()
}
})
}
29 changes: 29 additions & 0 deletions src/librustc_back/target/thumbv7em_none_eabi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use target::{Target, TargetOptions, TargetResult};

pub fn target() -> TargetResult {
Ok(Target {
llvm_target: "thumbv7em-none-eabi".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "32".to_string(),
data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
arch: "arm".to_string(),
target_os: "none".to_string(),
target_env: "".to_string(),
target_vendor: "".to_string(),

options: TargetOptions {
max_atomic_width: 32,
.. super::thumb_base::opts()
},
})
}
31 changes: 31 additions & 0 deletions src/librustc_back/target/thumbv7em_none_eabihf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use target::{Target, TargetOptions, TargetResult};

pub fn target() -> TargetResult {
Ok(Target {
llvm_target: "thumbv7em-none-eabihf".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "32".to_string(),
data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
arch: "arm".to_string(),
target_os: "none".to_string(),
target_env: "".to_string(),
target_vendor: "".to_string(),

options: TargetOptions {
// vfp4 lowest common denominator between the Cortex-M4 (vfp4) and the Cortex-M7 (vfp5)
features: "+vfp4".to_string(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you also need +fp-only-sp

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, won't that preclude a user from enabling double precision hardware acceleration? Perhaps they'll have to pass -fp-only-sp apart from the other feature that enables DP FP ops. (I'm speculating; I haven't tried any of this)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes -fp-only-sp would work to switch it back on. +d16 should probably be added here too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Thank you @parched.

max_atomic_width: 32,
.. super::thumb_base::opts()
}
})
}
29 changes: 29 additions & 0 deletions src/librustc_back/target/thumbv7m_none_eabi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use target::{Target, TargetOptions, TargetResult};

pub fn target() -> TargetResult {
Ok(Target {
llvm_target: "thumbv7m-none-eabi".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "32".to_string(),
data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
arch: "arm".to_string(),
target_os: "none".to_string(),
target_env: "".to_string(),
target_vendor: "".to_string(),

options: TargetOptions {
max_atomic_width: 32,
.. super::thumb_base::opts()
},
})
}
5 changes: 5 additions & 0 deletions src/test/run-make/target-without-atomics/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-include ../tools.mk

# The target used below doesn't support atomic operations. Verify that's the case
all:
$(RUSTC) --print cfg --target thumbv6m-none-eabi | grep -qv target_has_atomic