diff options
author | 2021-01-25 02:28:10 +0000 | |
---|---|---|
committer | 2021-01-25 02:28:10 +0000 | |
commit | 2082aca42ab291981ab8c0c692d1e1d0e6d444b8 (patch) | |
tree | 74668b393bb9daa858d39adcfb54e5bf810ac001 | |
parent | 6d75b144dcc2bf6c1bd324b38e826bc4380628e1 (diff) | |
parent | 4c624da754c831cf8c17859f253e81ee4ed29c9b (diff) | |
download | cortex-m-2082aca42ab291981ab8c0c692d1e1d0e6d444b8.tar.gz cortex-m-2082aca42ab291981ab8c0c692d1e1d0e6d444b8.tar.zst cortex-m-2082aca42ab291981ab8c0c692d1e1d0e6d444b8.zip |
Merge #318
318: Use LTO instead of removing the panic handler manually. Closes #309 r=jonas-schievink a=adamgreig
Co-authored-by: Adam Greig <adam@adamgreig.com>
-rw-r--r-- | bin/thumbv6m-none-eabi-lto.a | bin | 16088 -> 11772 bytes | |||
-rw-r--r-- | bin/thumbv6m-none-eabi.a | bin | 19068 -> 16332 bytes | |||
-rw-r--r-- | bin/thumbv7em-none-eabi-lto.a | bin | 20204 -> 15916 bytes | |||
-rw-r--r-- | bin/thumbv7em-none-eabi.a | bin | 23500 -> 21524 bytes | |||
-rw-r--r-- | bin/thumbv7em-none-eabihf-lto.a | bin | 21108 -> 16880 bytes | |||
-rw-r--r-- | bin/thumbv7em-none-eabihf.a | bin | 24588 -> 22820 bytes | |||
-rw-r--r-- | bin/thumbv7m-none-eabi-lto.a | bin | 18996 -> 14892 bytes | |||
-rw-r--r-- | bin/thumbv7m-none-eabi.a | bin | 22336 -> 20180 bytes | |||
-rw-r--r-- | bin/thumbv8m.base-none-eabi-lto.a | bin | 19368 -> 15036 bytes | |||
-rw-r--r-- | bin/thumbv8m.base-none-eabi.a | bin | 22772 -> 20760 bytes | |||
-rw-r--r-- | bin/thumbv8m.main-none-eabi-lto.a | bin | 23772 -> 19536 bytes | |||
-rw-r--r-- | bin/thumbv8m.main-none-eabi.a | bin | 28156 -> 27132 bytes | |||
-rw-r--r-- | bin/thumbv8m.main-none-eabihf-lto.a | bin | 24612 -> 20508 bytes | |||
-rw-r--r-- | bin/thumbv8m.main-none-eabihf.a | bin | 29212 -> 28400 bytes | |||
-rw-r--r-- | xtask/Cargo.toml | 4 | ||||
-rw-r--r-- | xtask/src/lib.rs | 96 |
16 files changed, 4 insertions, 96 deletions
diff --git a/bin/thumbv6m-none-eabi-lto.a b/bin/thumbv6m-none-eabi-lto.a Binary files differindex be32756..6506bd8 100644 --- a/bin/thumbv6m-none-eabi-lto.a +++ b/bin/thumbv6m-none-eabi-lto.a diff --git a/bin/thumbv6m-none-eabi.a b/bin/thumbv6m-none-eabi.a Binary files differindex ea70a69..48fe997 100644 --- a/bin/thumbv6m-none-eabi.a +++ b/bin/thumbv6m-none-eabi.a diff --git a/bin/thumbv7em-none-eabi-lto.a b/bin/thumbv7em-none-eabi-lto.a Binary files differindex e5dc579..ce6bd4c 100644 --- a/bin/thumbv7em-none-eabi-lto.a +++ b/bin/thumbv7em-none-eabi-lto.a diff --git a/bin/thumbv7em-none-eabi.a b/bin/thumbv7em-none-eabi.a Binary files differindex 2da81eb..637a884 100644 --- a/bin/thumbv7em-none-eabi.a +++ b/bin/thumbv7em-none-eabi.a diff --git a/bin/thumbv7em-none-eabihf-lto.a b/bin/thumbv7em-none-eabihf-lto.a Binary files differindex c4fb488..6f7edb3 100644 --- a/bin/thumbv7em-none-eabihf-lto.a +++ b/bin/thumbv7em-none-eabihf-lto.a diff --git a/bin/thumbv7em-none-eabihf.a b/bin/thumbv7em-none-eabihf.a Binary files differindex 078295b..f25d0ef 100644 --- a/bin/thumbv7em-none-eabihf.a +++ b/bin/thumbv7em-none-eabihf.a diff --git a/bin/thumbv7m-none-eabi-lto.a b/bin/thumbv7m-none-eabi-lto.a Binary files differindex 9b4cbf5..485219b 100644 --- a/bin/thumbv7m-none-eabi-lto.a +++ b/bin/thumbv7m-none-eabi-lto.a diff --git a/bin/thumbv7m-none-eabi.a b/bin/thumbv7m-none-eabi.a Binary files differindex f64c507..d3a1213 100644 --- a/bin/thumbv7m-none-eabi.a +++ b/bin/thumbv7m-none-eabi.a diff --git a/bin/thumbv8m.base-none-eabi-lto.a b/bin/thumbv8m.base-none-eabi-lto.a Binary files differindex 791acb4..bd79b05 100644 --- a/bin/thumbv8m.base-none-eabi-lto.a +++ b/bin/thumbv8m.base-none-eabi-lto.a diff --git a/bin/thumbv8m.base-none-eabi.a b/bin/thumbv8m.base-none-eabi.a Binary files differindex abc4937..130e413 100644 --- a/bin/thumbv8m.base-none-eabi.a +++ b/bin/thumbv8m.base-none-eabi.a diff --git a/bin/thumbv8m.main-none-eabi-lto.a b/bin/thumbv8m.main-none-eabi-lto.a Binary files differindex f950f11..4be0c0d 100644 --- a/bin/thumbv8m.main-none-eabi-lto.a +++ b/bin/thumbv8m.main-none-eabi-lto.a diff --git a/bin/thumbv8m.main-none-eabi.a b/bin/thumbv8m.main-none-eabi.a Binary files differindex a334653..74a5786 100644 --- a/bin/thumbv8m.main-none-eabi.a +++ b/bin/thumbv8m.main-none-eabi.a diff --git a/bin/thumbv8m.main-none-eabihf-lto.a b/bin/thumbv8m.main-none-eabihf-lto.a Binary files differindex cca68aa..2920ea4 100644 --- a/bin/thumbv8m.main-none-eabihf-lto.a +++ b/bin/thumbv8m.main-none-eabihf-lto.a diff --git a/bin/thumbv8m.main-none-eabihf.a b/bin/thumbv8m.main-none-eabihf.a Binary files differindex 495481b..b547b0f 100644 --- a/bin/thumbv8m.main-none-eabihf.a +++ b/bin/thumbv8m.main-none-eabihf.a diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 05cfbac..06c5143 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -11,7 +11,3 @@ harness = false [dependencies] ar = "0.8.0" - -[dependencies.object] -version = "0.22.0" -features = ["write"] diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index b1e982e..a7b85e7 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -4,9 +4,6 @@ //! //! Also see the docs in `asm.rs`. -use object::read::{Object as _, ObjectSection as _}; -use object::write::{Object, Symbol, SymbolSection}; -use object::{ObjectSymbol, SymbolFlags}; use std::collections::BTreeMap; use std::env::current_dir; use std::fs::{self, File}; @@ -25,90 +22,6 @@ fn rustc() -> Command { cmd } -/// Patches an object file so that it doesn't contain a panic handler. -/// -/// The panic handler defined in `asm/lib.rs` should never get linked to the final program. -/// Unfortunately, Rust uses the same symbol for all panic handlers, and doesn't really like it if -/// that ends up with multiple ones. It also demands that we define a panic handler for the inline -/// assembly shim, even though none of that code should ever be able to panic. The result of this is -/// that the supposedly unreachable panic handler does end up getting linked into the final program, -/// unless it is built with optimizations enabled. -/// -/// To fix that, we put the never-to-be-used panic handler into its own section via -/// `#[link_section]`, and then use this function to delete that section. -fn trim_panic_handler(obj_file: &str) { - let objdata = fs::read(&obj_file).unwrap(); - let obj = object::File::parse(&objdata).unwrap(); - - let mut writer = Object::new(obj.format(), obj.architecture(), obj.endianness()); - writer.flags = obj.flags(); // Preserve flags of input file - - for (sec_index, section) in obj.sections().enumerate() { - assert_eq!(section.index().0, sec_index); - - let name = section.name().unwrap(); - if name.starts_with(".ARM") - || name.starts_with(".rel.ARM") - || name.contains("asm_panic_handler") - || name == ".strtab" - || name == ".symtab" - { - // We drop the ARM exception handling tables since they refer back to the panic handler - // symbol. They aren't used either way. We also drop `.strtab` and `.symtab` since they - // otherwise end up having the wrong section type. The object crate should rebuild any - // index tables when writing the file. - continue; - } - - let segment = section - .segment_name() - .unwrap() - .map(|s| s.as_bytes()) - .unwrap_or(&[]); - let sec_id = writer.add_section(segment.to_vec(), name.as_bytes().to_vec(), section.kind()); - - let align = if section.align() == 0 { - // Not sure why but `section.align()` can return 0. - 1 - } else { - section.align() - }; - writer.append_section_data(sec_id, section.data().unwrap(), align); - - // Import all symbols from the section. - for symbol in obj.symbols() { - if symbol.section_index() == Some(section.index()) { - writer.add_symbol(Symbol { - name: symbol.name().unwrap_or("").as_bytes().to_vec(), - value: symbol.address(), - size: symbol.size(), - kind: symbol.kind(), - scope: symbol.scope(), - weak: symbol.is_weak(), - section: match symbol.section() { - object::SymbolSection::Unknown => unimplemented!(), - object::SymbolSection::None => SymbolSection::None, - object::SymbolSection::Undefined => SymbolSection::Undefined, - object::SymbolSection::Absolute => SymbolSection::Absolute, - object::SymbolSection::Common => SymbolSection::Common, - object::SymbolSection::Section(_) => SymbolSection::Section(sec_id), - }, - flags: match symbol.flags() { - SymbolFlags::None => SymbolFlags::None, - SymbolFlags::Elf { st_info, st_other } => { - SymbolFlags::Elf { st_info, st_other } - } - _ => unimplemented!(), - }, - }); - } - } - } - - let obj = writer.write().unwrap(); - fs::write(&obj_file, obj).unwrap(); -} - fn assemble_really(target: &str, cfgs: &[&str], plugin_lto: bool) { let mut cmd = rustc(); @@ -122,6 +35,10 @@ fn assemble_really(target: &str, cfgs: &[&str], plugin_lto: bool) { // We always optimize the assembly shims. There's not really any reason not to. cmd.arg("-O"); + // We use LTO on the archive to ensure the (unused) panic handler is removed, preventing + // a linker error when the archives are linked into final crates with two panic handlers. + cmd.arg("-Clto=yes"); + // rustc will usually add frame pointers by default to aid with debugging, but that is a high // overhead for the tiny assembly routines. cmd.arg("-Cforce-frame-pointers=no"); @@ -158,11 +75,6 @@ fn assemble_really(target: &str, cfgs: &[&str], plugin_lto: bool) { let status = cmd.status().unwrap(); assert!(status.success()); - if !plugin_lto { - // Post-process the object file. - trim_panic_handler(&obj_file); - } - // Archive `target.o` -> `bin/target.a`. let mut builder = ar::Builder::new(File::create(format!("bin/{}.a", file_stub)).unwrap()); |