Skip to content

Commit bf6770c

Browse files
committed
adapt l4-bender linker support
Adapt the initial support for L4Re's "l4-bender" linker to keep up with the current linker trait and reformat the code.
1 parent 320b9be commit bf6770c

File tree

3 files changed

+57
-54
lines changed

3 files changed

+57
-54
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ impl LinkerInfo {
7878
as Box<dyn Linker>
7979
}
8080

81-
LinkerFlavor::L4Bender => {
82-
Box::new(L4Bender::new(cmd, sess)) as Box<dyn Linker>
83-
},
81+
LinkerFlavor::L4Bender => Box::new(L4Bender::new(cmd, sess)) as Box<dyn Linker>,
8482
LinkerFlavor::Lld(LldFlavor::Wasm) => {
8583
Box::new(WasmLd::new(cmd, sess, self)) as Box<dyn Linker>
8684
}
@@ -1296,10 +1294,10 @@ pub struct L4Bender<'a> {
12961294
}
12971295

12981296
impl<'a> Linker for L4Bender<'a> {
1299-
fn link_dylib(&mut self, _lib: Symbol) {
1300-
panic!("dylibs not supported yet")
1297+
fn link_dylib(&mut self, _lib: Symbol, _verbatim: bool, _as_needed: bool) {
1298+
bug!("dylibs are not supported on L4Re");
13011299
}
1302-
fn link_staticlib(&mut self, lib: Symbol) {
1300+
fn link_staticlib(&mut self, lib: Symbol, _verbatim: bool) {
13031301
self.hint_static();
13041302
self.cmd.arg(format!("-PC{}", lib));
13051303
}
@@ -1311,36 +1309,43 @@ impl<'a> Linker for L4Bender<'a> {
13111309
self.cmd.arg("-L").arg(path);
13121310
}
13131311
fn framework_path(&mut self, _: &Path) {
1314-
bug!("Frameworks are not supported on L4Re!");
1315-
}
1316-
fn output_filename(&mut self, path: &Path) { self.cmd.arg("-o").arg(path); }
1317-
fn add_object(&mut self, path: &Path) { self.cmd.arg(path); }
1318-
// not sure about pie on L4Re
1319-
fn position_independent_executable(&mut self) { }
1320-
fn no_position_independent_executable(&mut self) { }
1321-
fn full_relro(&mut self) { self.cmd.arg("-z,relro,-z,now"); }
1322-
fn partial_relro(&mut self) { self.cmd.arg("-z,relro"); }
1323-
fn no_relro(&mut self) { self.cmd.arg("-z,norelro"); }
1324-
fn build_static_executable(&mut self) { self.cmd.arg("-static"); }
1312+
bug!("frameworks are not supported on L4Re");
1313+
}
1314+
fn output_filename(&mut self, path: &Path) {
1315+
self.cmd.arg("-o").arg(path);
1316+
}
1317+
1318+
fn add_object(&mut self, path: &Path) {
1319+
self.cmd.arg(path);
1320+
}
1321+
1322+
fn full_relro(&mut self) {
1323+
self.cmd.arg("-z,relro,-z,now");
1324+
}
1325+
1326+
fn partial_relro(&mut self) {
1327+
self.cmd.arg("-z,relro");
1328+
}
1329+
1330+
fn no_relro(&mut self) {
1331+
self.cmd.arg("-z,norelro");
1332+
}
1333+
13251334
fn cmd(&mut self) -> &mut Command {
13261335
&mut self.cmd
13271336
}
13281337

1338+
fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {}
1339+
13291340
fn link_rust_dylib(&mut self, _: Symbol, _: &Path) {
13301341
panic!("Rust dylibs not supported");
13311342
}
13321343

1333-
fn link_framework(&mut self, _: Symbol) {
1334-
bug!("Frameworks not supported on L4Re.");
1344+
fn link_framework(&mut self, _framework: Symbol, _as_needed: bool) {
1345+
bug!("frameworks not supported on L4Re");
13351346
}
13361347

1337-
// Here we explicitly ask that the entire archive is included into the
1338-
// result artifact. For more details see #15460, but the gist is that
1339-
// the linker will strip away any unused objects in the archive if we
1340-
// don't otherwise explicitly reference them. This can occur for
1341-
// libraries which are just providing bindings, libraries with generic
1342-
// functions, etc.
1343-
fn link_whole_staticlib(&mut self, lib: Symbol, _: &[PathBuf]) {
1348+
fn link_whole_staticlib(&mut self, lib: Symbol, _verbatim: bool, _search_path: &[PathBuf]) {
13441349
self.hint_static();
13451350
self.cmd.arg("--whole-archive").arg(format!("-l{}", lib));
13461351
self.cmd.arg("--no-whole-archive");
@@ -1357,17 +1362,22 @@ impl<'a> Linker for L4Bender<'a> {
13571362
}
13581363
}
13591364

1365+
fn no_gc_sections(&mut self) {
1366+
self.cmd.arg("--no-gc-sections");
1367+
}
1368+
13601369
fn optimize(&mut self) {
13611370
self.cmd.arg("-O2");
13621371
}
13631372

1364-
fn pgo_gen(&mut self) { }
1373+
fn pgo_gen(&mut self) {}
13651374

13661375
fn debuginfo(&mut self, strip: Strip) {
13671376
match strip {
13681377
Strip::None => {}
13691378
Strip::Debuginfo => {
1370-
self.cmd().arg("--strip-debug"); }
1379+
self.cmd().arg("--strip-debug");
1380+
}
13711381
Strip::Symbols => {
13721382
self.cmd().arg("--strip-all");
13731383
}
@@ -1378,33 +1388,33 @@ impl<'a> Linker for L4Bender<'a> {
13781388
self.cmd.arg("-nostdlib");
13791389
}
13801390

1381-
fn build_dylib(&mut self, _: &Path) {
1382-
bug!("not implemented");
1383-
}
1384-
13851391
fn export_symbols(&mut self, _: &Path, _: CrateType) {
13861392
// ToDo, not implemented, copy from GCC
1393+
self.sess.warn("exporting symbols not implemented yet for L4Bender");
13871394
return;
13881395
}
13891396

13901397
fn subsystem(&mut self, subsystem: &str) {
13911398
self.cmd.arg(&format!("--subsystem,{}", subsystem));
13921399
}
13931400

1394-
fn finalize(&mut self) {
1401+
fn reset_per_library_state(&mut self) {
13951402
self.hint_static(); // Reset to default before returning the composed command line.
13961403
}
13971404

1398-
fn group_start(&mut self) { self.cmd.arg("--start-group"); }
1399-
fn group_end(&mut self) { self.cmd.arg("--end-group"); }
1400-
fn linker_plugin_lto(&mut self) {
1401-
// do nothing
1405+
fn group_start(&mut self) {
1406+
self.cmd.arg("--start-group");
14021407
}
1403-
fn control_flow_guard(&mut self) {
1404-
self.sess.warn("Windows Control Flow Guard is not supported by this linker.");
1408+
1409+
fn group_end(&mut self) {
1410+
self.cmd.arg("--end-group");
14051411
}
14061412

1407-
fn no_crt_objects(&mut self) { }
1413+
fn linker_plugin_lto(&mut self) {}
1414+
1415+
fn control_flow_guard(&mut self) {}
1416+
1417+
fn no_crt_objects(&mut self) {}
14081418
}
14091419

14101420
impl<'a> L4Bender<'a> {
@@ -1415,11 +1425,7 @@ impl<'a> L4Bender<'a> {
14151425

14161426
cmd.arg("--"); // separate direct l4-bender args from linker args
14171427

1418-
L4Bender {
1419-
cmd: cmd,
1420-
sess: sess,
1421-
hinted_static: false,
1422-
}
1428+
L4Bender { cmd: cmd, sess: sess, hinted_static: false }
14231429
}
14241430

14251431
/// This parses a shell-escaped string and unquotes the arguments. It doesn't attempt to
@@ -1435,7 +1441,7 @@ impl<'a> L4Bender<'a> {
14351441
' ' if !quoted => {
14361442
cmd.arg(&arg);
14371443
arg.clear();
1438-
},
1444+
}
14391445
'"' | '\'' => quoted = !quoted,
14401446
_ => arg.push(character),
14411447
};
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
use crate::spec::{LinkArgs, LinkerFlavor, PanicStrategy, TargetOptions};
1+
use crate::spec::{LinkerFlavor, PanicStrategy, TargetOptions};
22
use std::default::Default;
33

44
pub fn opts() -> TargetOptions {
55
TargetOptions {
66
os: "l4re".to_string(),
77
env: "uclibc".to_string(),
8-
linker_flavor: LinkerFlavor::Ld,
8+
linker_flavor: LinkerFlavor::L4Bender,
99
executables: true,
1010
panic_strategy: PanicStrategy::Abort,
1111
linker: Some("l4-bender".to_string()),
12-
pre_link_args: args,
13-
os_family: Some("unix".to_string()),
12+
linker_is_gnu: false,
13+
families: vec!["unix".to_string()],
1414
..Default::default()
1515
}
1616
}

compiler/rustc_target/src/spec/x86_64_unknown_l4re_uclibc.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@ pub fn target() -> Target {
44
let mut base = super::l4re_base::opts();
55
base.cpu = "x86-64".to_string();
66
base.max_atomic_width = Some(64);
7+
base.crt_static_default = true;
78

89
Target {
910
llvm_target: "x86_64-unknown-l4re-uclibc".to_string(),
1011
pointer_width: 64,
1112
data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
1213
.to_string(),
1314
arch: "x86_64".to_string(),
14-
target_os: "l4re".to_string(),
15-
target_env: "uclibc".to_string(),
16-
target_vendor: "unknown".to_string(),
17-
linker_flavor: LinkerFlavor::L4Bender,
1815
options: base,
1916
}
2017
}

0 commit comments

Comments
 (0)