Skip to content
This repository was archived by the owner on Jul 6, 2019. It is now read-only.

Commit a59ac75

Browse files
committed
Simplify compile process
Changes to libcore means we need to do the compile in less passes. Added the three new lang items, pulled support into zinc, app is still the main entry point but it produces the .elf without a second call to ld. There has been a large size regression, the majority of it is from libcore pulling in the string formatting functions for error handling. I will submit a patch to provide a cfg flag for building libcore with simpler errors.
1 parent 3098bdf commit a59ac75

File tree

10 files changed

+67
-47
lines changed

10 files changed

+67
-47
lines changed

Rakefile

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,25 @@ compile_rust :zinc_crate, {
2626
recompile_on: [:triple, :platform, :features],
2727
}
2828

29-
# zinc runtime support lib
30-
compile_rust :zinc_support, {
31-
source: 'lib/support.rs'.in_source,
32-
produce: 'support.o'.in_intermediate,
33-
llvm_pass: :inline,
34-
lto: false,
35-
recompile_on: :triple,
29+
# dummy archives
30+
compile_ar :dummy_morestack, {
31+
produce: 'libmorestack.a'.in_intermediate,
3632
}
37-
38-
# zinc isr crate
39-
compile_rust :zinc_isr, {
40-
source: 'hal/isr.rs'.in_source,
41-
deps: :core_crate,
42-
produce: 'isr.o'.in_intermediate,
43-
recompile_on: [:triple, :features],
33+
compile_ar :dummy_compiler_rt, {
34+
produce: 'libcompiler-rt.a'.in_intermediate,
4435
}
4536

4637
# zinc scheduler assembly
4738
# TODO(farcaller): make platform-specific
4839
if features.include?(:multitasking)
49-
compile_c :zinc_isr_sched, {
40+
compile_c :zinc_isr_sched_c, {
5041
source: 'hal/cortex_m3/sched.S'.in_source,
51-
produce: 'isr_sched.o'.in_intermediate,
42+
produce: 'libisr_sched.o'.in_intermediate,
43+
recompile_on: [:triple, :features],
44+
}
45+
compile_ar :zinc_isr_sched, {
46+
source: 'libisr_sched.o'.in_intermediate,
47+
produce: 'libisr_sched.a'.in_intermediate,
5248
recompile_on: [:triple, :features],
5349
}
5450
end
@@ -65,22 +61,18 @@ app_tasks = Context.instance.applications.map do |a|
6561
recompile_on: [:triple, :platform, :features],
6662
}
6763

68-
compile_rust "app_#{a}".to_sym, {
64+
compile_rust "app_#{a}_elf".to_sym, {
65+
script: 'layout.ld'.in_platform,
6966
source: 'lib/app.rs'.in_source,
7067
deps: [
7168
:core_crate,
7269
:zinc_crate,
7370
"app_#{a}_crate".to_sym,
74-
],
75-
produce: "app_#{a}.o".in_intermediate(a),
76-
search_paths: a.in_intermediate,
77-
}
78-
79-
link_binary "app_#{a}_elf".to_sym, {
80-
script: 'layout.ld'.in_platform,
81-
deps: ["app_#{a}".to_sym, :zinc_isr, :zinc_support] +
82-
(features.include?(:multitasking) ? [:zinc_isr_sched] : []),
71+
:dummy_morestack,
72+
:dummy_compiler_rt,
73+
] + (features.include?(:multitasking) ? [:zinc_isr_sched] : []),
8374
produce: "app_#{a}.elf".in_build,
75+
search_paths: [a.in_intermediate, "intermediate".in_build],
8476
}
8577

8678
t_bin = make_binary "app_#{a}_bin".to_sym, {

src/hal/isr.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,8 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
//! This file is not part of zinc crate, it is linked separately, alongside the
1716
//! ISRs for the platform.
1817
19-
#![feature(asm, globs)]
20-
#![crate_id="isr"]
21-
#![crate_type="staticlib"]
22-
#![no_std]
23-
24-
extern crate core;
25-
2618
#[path="cortex_m3/isr.rs"] pub mod isr_cortex_m3;
2719

2820
#[cfg(mcu_lpc17xx)]

src/hal/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ and each such struct has a `setup()` method that configures the hardware
2323

2424
mod mem_init;
2525

26+
pub mod isr;
27+
2628
#[cfg(mcu_lpc17xx)] pub mod lpc17xx;
2729
#[cfg(mcu_stm32f4)] pub mod stm32f4;
2830

src/hal/stack.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
//! Stack layout information.
1717
1818
extern {
19-
static __STACK_BASE: u32;
19+
// This is called an fn in ISR so needs to be an fn here.
20+
fn __STACK_BASE();
2021
static mut __STACK_LIMIT: u32;
2122
}
2223

2324
/// Returns the address of main stack base (end of ram).
2425
pub fn stack_base() -> u32 {
25-
(&__STACK_BASE as *u32) as u32
26+
(__STACK_BASE as *u32) as u32
2627
}
2728

2829
/// Returns the current stack limit.

src/lib/app.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
//! for stack management, scheduler, ISRs and other symbols with global
1818
//! visibility.
1919
20-
#![crate_type="staticlib"]
2120
#![no_std]
21+
#![no_start]
22+
#![no_main]
2223

2324
extern crate core;
2425
extern crate zinc;
@@ -48,6 +49,6 @@ pub extern fn __morestack() {
4849
#[no_split_stack]
4950
#[no_mangle]
5051
#[cfg(cfg_multitasking)]
51-
pub unsafe fn task_scheduler() {
52+
pub unsafe extern fn task_scheduler() {
5253
zinc::os::task::task_scheduler();
5354
}

src/lib/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ pub mod strconv;
1919
pub mod volatile_cell;
2020
pub mod shared;
2121
pub mod queue;
22+
pub mod support;

src/lib/support.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,22 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
#![no_std]
17-
#![crate_type="rlib"]
18-
#![feature(asm)]
19-
20-
extern "rust-intrinsic" {
21-
fn offset<T>(dst: *T, offset: int) -> *T;
22-
}
16+
use core::intrinsics::offset;
2317

2418
#[allow(non_camel_case_types)]
2519
pub type c_int = i32;
2620

21+
#[lang = "stack_exhausted"]
22+
extern fn stack_exhausted() { /* ... */ }
23+
24+
#[lang = "eh_personality"]
25+
extern fn eh_personality() { /* ... */ }
26+
27+
#[lang = "begin_unwind"]
28+
extern fn begin_unwind() {
29+
abort()
30+
}
31+
2732
#[no_mangle]
2833
#[no_split_stack]
2934
#[inline(never)]

src/os/syscall.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This module provides syscall interface that is implemented in assembly due to
2020
current rust restrictions (see hal/cortex_m3/sched.S for actual implementation).
2121
*/
2222

23+
#[link(name = "isr_sched")]
2324
extern {
2425
pub fn syscall(f: fn(u32), arg: u32);
2526
}

support/build/context.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ def initialize_environment!
120120
"-L#{File.join(@env[:libs_path], @platform.arch.arch)}",
121121
]
122122

123+
@env[:gccflags] = [
124+
"-lgcc"
125+
]
126+
123127
@env[:cflags] = [
124128
'-mthumb',
125129
"-mcpu=#{@platform.arch.cpu}",

support/rake.rb

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def compile_rust(n, h)
3232
crate_type = h[:crate_type] ? "--crate-type #{h[:crate_type]}" : ""
3333
ignore_warnings = h[:ignore_warnings] ? h[:ignore_warnings] : []
3434
ignore_warnings = ignore_warnings.map { |w| "-A #{w}" }.join(' ')
35+
script = h[:script]
3536

3637
declared_deps = h[:deps]
3738
rust_src = h[:source]
@@ -65,7 +66,18 @@ def compile_rust(n, h)
6566
'--emit asm'
6667
else
6768
''
68-
end
69+
end
70+
71+
mapfn = Context.instance.build_dir(File.basename(t.name, File.extname(t.name)) + '.map')
72+
73+
linker = case File.extname(t.name)
74+
when '.elf'
75+
"-C linker=#{:gcc.in_toolchain} " +
76+
"-C link-args=\"-T #{script} -Wl,-Map=#{mapfn} " +
77+
:gccflags.in_env.join(' ') + '"'
78+
else
79+
''
80+
end
6981

7082
codegen = llvm_pass ? "-C passes=#{llvm_pass}" : ''
7183

@@ -79,7 +91,7 @@ def compile_rust(n, h)
7991

8092
sh "#{:rustc.in_env} #{flags} " +
8193
"#{do_lto ? '-Z lto' : ''} #{crate_type} #{emit} " +
82-
"#{search_paths} #{codegen} " +
94+
"#{search_paths} #{codegen} #{linker} " +
8395
"#{outflags} #{ignore_warnings} #{rust_src}"
8496
end
8597
end
@@ -108,6 +120,15 @@ def compile_c(n, h)
108120
end
109121
end
110122

123+
def compile_ar(n, h)
124+
h.resolve_deps!
125+
Context.instance.rules[n] = h
126+
127+
Rake::FileTask.define_task(h[:produce] => [h[:source], h[:deps]].flatten.compact) do |t|
128+
sh "#{:ar.in_toolchain} cr -o #{h[:produce]} #{h[:source]}"
129+
end
130+
end
131+
111132
def listing(n, h)
112133
Rake::FileTask.define_task(h[:produce] => h[:source]) do |t|
113134
sh "#{:objdump.in_toolchain} -D #{t.prerequisites.first} > #{t.name}"

0 commit comments

Comments
 (0)