diff options
| author | Benjamin Lamowski <benjamin.lamowski@kernkonzept.com> | 2021-05-31 14:34:23 +0200 |
|---|---|---|
| committer | Benjamin Lamowski <benjamin.lamowski@kernkonzept.com> | 2022-01-21 16:50:33 +0100 |
| commit | 660d993c642a2f88b84d5e1f0d8602b8136b9b4e (patch) | |
| tree | a6b843d5b483424e2838cb4b52a2e3116559bf29 /compiler/rustc_codegen_ssa | |
| parent | d98428711e6fe1b2a7f6d963d4b337beaa3dc285 (diff) | |
| download | rust-660d993c642a2f88b84d5e1f0d8602b8136b9b4e.tar.gz rust-660d993c642a2f88b84d5e1f0d8602b8136b9b4e.zip | |
adapt L4Bender implementation
- Fix style errors.
- L4-bender does not yet support dynamic linking.
- Stack unwinding is not yet supported for x86_64-unknown-l4re-uclibc.
For now, just abort on panics.
- Use GNU-style linker options where possible. As suggested by review:
- Use standard GNU-style ld syntax for relro flags.
- Use standard GNU-style optimization flags and logic.
- Use standard GNU-style ld syntax for --subsystem.
- Don't read environment variables in L4Bender linker. Thanks to
CARGO_ENCODED_RUSTFLAGS introduced in #9601, l4-bender's arguments can
now be passed from the L4Re build system without resorting to custom
parsing of environment variables.
Diffstat (limited to 'compiler/rustc_codegen_ssa')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/linker.rs | 142 |
1 files changed, 62 insertions, 80 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index e2357eae7c1..3fb56f42b8c 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -3,7 +3,6 @@ use super::command::Command; use super::symbol_export; use rustc_span::symbol::sym; -use std::env; use std::ffi::{OsStr, OsString}; use std::fs::{self, File}; use std::io::prelude::*; @@ -150,9 +149,7 @@ pub fn get_linker<'a>( LinkerFlavor::BpfLinker => Box::new(BpfLinker { cmd, sess }) as Box<dyn Linker>, - LinkerFlavor::L4Bender => { - Box::new(L4Bender::new(cmd, sess)) as Box<dyn Linker> - }, + LinkerFlavor::L4Bender => Box::new(L4Bender::new(cmd, sess)) as Box<dyn Linker>, } } @@ -1367,10 +1364,10 @@ pub struct L4Bender<'a> { } impl<'a> Linker for L4Bender<'a> { - fn link_dylib(&mut self, _lib: Symbol) { - panic!("dylibs not supported yet") + fn link_dylib(&mut self, _lib: Symbol, _verbatim: bool, _as_needed: bool) { + bug!("dylibs are not supported on L4Re"); } - fn link_staticlib(&mut self, lib: Symbol) { + fn link_staticlib(&mut self, lib: Symbol, _verbatim: bool) { self.hint_static(); self.cmd.arg(format!("-PC{}", lib)); } @@ -1382,36 +1379,44 @@ impl<'a> Linker for L4Bender<'a> { self.cmd.arg("-L").arg(path); } fn framework_path(&mut self, _: &Path) { - bug!("Frameworks are not supported on L4Re!"); - } - fn output_filename(&mut self, path: &Path) { self.cmd.arg("-o").arg(path); } - fn add_object(&mut self, path: &Path) { self.cmd.arg(path); } - // not sure about pie on L4Re - fn position_independent_executable(&mut self) { } - fn no_position_independent_executable(&mut self) { } - fn full_relro(&mut self) { self.cmd.arg("-z,relro,-z,now"); } - fn partial_relro(&mut self) { self.cmd.arg("-z,relro"); } - fn no_relro(&mut self) { self.cmd.arg("-z,norelro"); } - fn build_static_executable(&mut self) { self.cmd.arg("-static"); } + bug!("frameworks are not supported on L4Re"); + } + fn output_filename(&mut self, path: &Path) { + self.cmd.arg("-o").arg(path); + } + + fn add_object(&mut self, path: &Path) { + self.cmd.arg(path); + } + + fn full_relro(&mut self) { + self.cmd.arg("-zrelro"); + self.cmd.arg("-znow"); + } + + fn partial_relro(&mut self) { + self.cmd.arg("-zrelro"); + } + + fn no_relro(&mut self) { + self.cmd.arg("-znorelro"); + } + fn cmd(&mut self) -> &mut Command { &mut self.cmd } + fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {} + fn link_rust_dylib(&mut self, _: Symbol, _: &Path) { panic!("Rust dylibs not supported"); } - fn link_framework(&mut self, _: Symbol) { - bug!("Frameworks not supported on L4Re."); + fn link_framework(&mut self, _framework: Symbol, _as_needed: bool) { + bug!("frameworks not supported on L4Re"); } - // Here we explicitly ask that the entire archive is included into the - // result artifact. For more details see #15460, but the gist is that - // the linker will strip away any unused objects in the archive if we - // don't otherwise explicitly reference them. This can occur for - // libraries which are just providing bindings, libraries with generic - // functions, etc. - fn link_whole_staticlib(&mut self, lib: Symbol, _: &[PathBuf]) { + fn link_whole_staticlib(&mut self, lib: Symbol, _verbatim: bool, _search_path: &[PathBuf]) { self.hint_static(); self.cmd.arg("--whole-archive").arg(format!("-l{}", lib)); self.cmd.arg("--no-whole-archive"); @@ -1428,17 +1433,28 @@ impl<'a> Linker for L4Bender<'a> { } } + fn no_gc_sections(&mut self) { + self.cmd.arg("--no-gc-sections"); + } + fn optimize(&mut self) { - self.cmd.arg("-O2"); + // GNU-style linkers support optimization with -O. GNU ld doesn't + // need a numeric argument, but other linkers do. + if self.sess.opts.optimize == config::OptLevel::Default + || self.sess.opts.optimize == config::OptLevel::Aggressive + { + self.cmd.arg("-O1"); + } } - fn pgo_gen(&mut self) { } + fn pgo_gen(&mut self) {} fn debuginfo(&mut self, strip: Strip) { match strip { Strip::None => {} Strip::Debuginfo => { - self.cmd().arg("--strip-debug"); } + self.cmd().arg("--strip-debug"); + } Strip::Symbols => { self.cmd().arg("--strip-all"); } @@ -1449,72 +1465,38 @@ impl<'a> Linker for L4Bender<'a> { self.cmd.arg("-nostdlib"); } - fn build_dylib(&mut self, _: &Path) { - bug!("not implemented"); - } - - fn export_symbols(&mut self, _: &Path, _: CrateType) { + fn export_symbols(&mut self, _: &Path, _: CrateType, _: &[String]) { // ToDo, not implemented, copy from GCC + self.sess.warn("exporting symbols not implemented yet for L4Bender"); return; } fn subsystem(&mut self, subsystem: &str) { - self.cmd.arg(&format!("--subsystem,{}", subsystem)); + self.cmd.arg(&format!("--subsystem {}", subsystem)); } - fn finalize(&mut self) { + fn reset_per_library_state(&mut self) { self.hint_static(); // Reset to default before returning the composed command line. } - fn group_start(&mut self) { self.cmd.arg("--start-group"); } - fn group_end(&mut self) { self.cmd.arg("--end-group"); } - fn linker_plugin_lto(&mut self) { - // do nothing - } - fn control_flow_guard(&mut self) { - self.sess.warn("Windows Control Flow Guard is not supported by this linker."); + fn group_start(&mut self) { + self.cmd.arg("--start-group"); } - fn no_crt_objects(&mut self) { } -} + fn group_end(&mut self) { + self.cmd.arg("--end-group"); + } -impl<'a> L4Bender<'a> { - pub fn new(mut cmd: Command, sess: &'a Session) -> L4Bender<'a> { - if let Ok(l4bender_args) = env::var("L4_BENDER_ARGS") { - L4Bender::split_cmd_args(&mut cmd, &l4bender_args); - } + fn linker_plugin_lto(&mut self) {} - cmd.arg("--"); // separate direct l4-bender args from linker args + fn control_flow_guard(&mut self) {} - L4Bender { - cmd: cmd, - sess: sess, - hinted_static: false, - } - } + fn no_crt_objects(&mut self) {} +} - /// This parses a shell-escaped string and unquotes the arguments. It doesn't attempt to - /// completely understand shell, but should instead allow passing arguments like - /// `-Dlinker="ld -m x86_64"`, and a copy without quotes, but spaces preserved, is added as an - /// argument to the given Command. This means that constructs as \" are not understood, so - /// quote wisely. - fn split_cmd_args(cmd: &mut Command, shell_args: &str) { - let mut arg = String::new(); - let mut quoted = false; - for character in shell_args.chars() { - match character { - ' ' if !quoted => { - cmd.arg(&arg); - arg.clear(); - }, - '"' | '\'' => quoted = !quoted, - _ => arg.push(character), - }; - } - if arg.len() > 0 { - cmd.arg(&arg); - arg.clear(); - } +impl<'a> L4Bender<'a> { + pub fn new(cmd: Command, sess: &'a Session) -> L4Bender<'a> { + L4Bender { cmd: cmd, sess: sess, hinted_static: false } } fn hint_static(&mut self) { |
