Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
126 changes: 0 additions & 126 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ pub(crate) fn get_linker<'a>(
// to the linker args construction.
assert!(cmd.get_args().is_empty() || sess.target.cfg_abi == CfgAbi::Uwp);
match flavor {
LinkerFlavor::Unix(Cc::No) if sess.target.os == Os::L4Re => {
Box::new(L4Bender::new(cmd, sess)) as Box<dyn Linker>
}
LinkerFlavor::Unix(Cc::No) if sess.target.os == Os::Aix => {
Box::new(AixLinker::new(cmd, sess)) as Box<dyn Linker>
}
Expand Down Expand Up @@ -279,7 +276,6 @@ generate_arg_methods! {
MsvcLinker<'_>
EmLinker<'_>
WasmLd<'_>
L4Bender<'_>
AixLinker<'_>
LlbcLinker<'_>
BpfLinker<'_>
Expand Down Expand Up @@ -1468,128 +1464,6 @@ impl<'a> WasmLd<'a> {
}
}

/// Linker shepherd script for L4Re (Fiasco)
struct L4Bender<'a> {
cmd: Command,
sess: &'a Session,
hinted_static: bool,
}

impl<'a> Linker for L4Bender<'a> {
fn cmd(&mut self) -> &mut Command {
&mut self.cmd
}

fn set_output_kind(
&mut self,
_output_kind: LinkOutputKind,
_crate_type: CrateType,
_out_filename: &Path,
) {
}

fn link_staticlib_by_name(&mut self, name: &str, _verbatim: bool, whole_archive: bool) {
self.hint_static();
if !whole_archive {
self.link_arg(format!("-PC{name}"));
} else {
self.link_arg("--whole-archive")
.link_or_cc_arg(format!("-l{name}"))
.link_arg("--no-whole-archive");
}
}

fn link_staticlib_by_path(&mut self, path: &Path, whole_archive: bool) {
self.hint_static();
if !whole_archive {
self.link_or_cc_arg(path);
} else {
self.link_arg("--whole-archive").link_or_cc_arg(path).link_arg("--no-whole-archive");
}
}

fn full_relro(&mut self) {
self.link_args(&["-z", "relro", "-z", "now"]);
}

fn partial_relro(&mut self) {
self.link_args(&["-z", "relro"]);
}

fn no_relro(&mut self) {
self.link_args(&["-z", "norelro"]);
}

fn gc_sections(&mut self, keep_metadata: bool) {
if !keep_metadata {
self.link_arg("--gc-sections");
}
}

fn optimize(&mut self) {
// 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::More
|| self.sess.opts.optimize == config::OptLevel::Aggressive
{
self.link_arg("-O1");
}
}

fn pgo_gen(&mut self) {}

fn debuginfo(&mut self, strip: Strip, _: &[PathBuf]) {
match strip {
Strip::None => {}
Strip::Debuginfo => {
self.link_arg("--strip-debug");
}
Strip::Symbols => {
self.link_arg("--strip-all");
}
}
}

fn no_default_libraries(&mut self) {
self.cc_arg("-nostdlib");
}

fn export_symbols(&mut self, _: &Path, _: CrateType, _: &[SymbolExport]) {
// ToDo, not implemented, copy from GCC
self.sess.dcx().emit_warn(diagnostics::L4BenderExportingSymbolsUnimplemented);
}

fn windows_subsystem(&mut self, subsystem: WindowsSubsystemKind) {
let subsystem = subsystem.as_str();
self.link_arg(&format!("--subsystem {subsystem}"));
}

fn reset_per_library_state(&mut self) {
self.hint_static(); // Reset to default before returning the composed command line.
}

fn linker_plugin_lto(&mut self) {}

fn control_flow_guard(&mut self) {}

fn ehcont_guard(&mut self) {}

fn no_crt_objects(&mut self) {}
}

impl<'a> L4Bender<'a> {
fn new(cmd: Command, sess: &'a Session) -> L4Bender<'a> {
L4Bender { cmd, sess, hinted_static: false }
}

fn hint_static(&mut self) {
if !self.hinted_static {
self.link_or_cc_arg("-static");
self.hinted_static = true;
}
}
}

/// Linker for AIX.
struct AixLinker<'a> {
cmd: Command,
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_codegen_ssa/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ pub(crate) struct Ld64UnimplementedModifier;
#[diag("`as-needed` modifier not supported for current linker")]
pub(crate) struct LinkerUnsupportedModifier;

#[derive(Diagnostic)]
#[diag("exporting symbols not implemented yet for L4Bender")]
pub(crate) struct L4BenderExportingSymbolsUnimplemented;

#[derive(Diagnostic)]
#[diag("error enumerating natvis directory: {$error}")]
pub(crate) struct NoNatvisDirectory {
Expand Down
55 changes: 50 additions & 5 deletions compiler/rustc_target/src/spec/base/l4re.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,59 @@
use crate::spec::{Cc, Env, LinkerFlavor, Os, PanicStrategy, RelocModel, TargetOptions, cvs};
use crate::spec::{
Cc, Env, LinkOutputKind, LinkSelfContainedComponents, LinkSelfContainedDefault, LinkerFlavor,
Os, /*PanicStrategy, */ TargetOptions, add_link_args, crt_objects, cvs,
};

pub(crate) fn opts() -> TargetOptions {
// add ld- and cc-style args
macro_rules! prepare_args {
($($val:expr),+) => {{
let ld_args = &[$($val),+];
let cc_args = &[$(concat!("-Wl,", $val)),+];

let mut ret = TargetOptions::link_args(LinkerFlavor::Unix(Cc::No), ld_args);
add_link_args(&mut ret, LinkerFlavor::Unix(Cc::Yes), cc_args);
ret
}};
}

let pre_link_args = prepare_args!("-nostdlib", "-dynamic-linker=rom/libld-l4.so");

let late_link_args = prepare_args!("-lc", "-lgcc_eh");

let pre_link_objects_self_contained = crt_objects::new(&[
(LinkOutputKind::StaticNoPicExe, &["crt1.o", "crti.o", "crtbeginT.o"]),
(LinkOutputKind::StaticPicExe, &["crt1.p.o", "crti.o", "crtbegin.o"]),
(LinkOutputKind::DynamicNoPicExe, &["crt1.o", "crti.o", "crtbegin.o"]),
(LinkOutputKind::DynamicPicExe, &["crt1.s.o", "crti.o", "crtbeginS.o"]),
(LinkOutputKind::DynamicDylib, &["crti.s.o", "crtbeginS.o"]),
(LinkOutputKind::StaticDylib, &["crti.s.o", "crtbeginS.o"]),
]);

let post_link_objects_self_contained = crt_objects::new(&[
(LinkOutputKind::StaticNoPicExe, &["crtendT.o", "crtn.o"]),
(LinkOutputKind::StaticPicExe, &["crtend.o", "crtn.o"]),
(LinkOutputKind::DynamicNoPicExe, &["crtend.o", "crtn.o"]),
(LinkOutputKind::DynamicPicExe, &["crtendS.o", "crtn.o"]),
(LinkOutputKind::DynamicDylib, &["crtendS.o", "crtn.s.o"]),
(LinkOutputKind::StaticDylib, &["crtendS.o", "crtn.s.o"]),
]);

TargetOptions {
os: Os::L4Re,
env: Env::Uclibc,
linker_flavor: LinkerFlavor::Unix(Cc::No),
panic_strategy: PanicStrategy::Abort,
linker: Some("l4-bender".into()),
families: cvs!["unix"],
relocation_model: RelocModel::Static,
//panic_strategy: PanicStrategy::Abort,
linker_flavor: LinkerFlavor::Unix(Cc::No),
dynamic_linking: true,
position_independent_executables: true,
has_thread_local: true,
pre_link_args,
late_link_args,
pre_link_objects_self_contained,
post_link_objects_self_contained,
link_self_contained: LinkSelfContainedDefault::WithComponents(
LinkSelfContainedComponents::LIBC | LinkSelfContainedComponents::CRT_OBJECTS,
),
..Default::default()
}
}
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,7 @@ supported_targets! {

("avr-none", avr_none),

("aarch64-unknown-l4re-uclibc", aarch64_unknown_l4re_uclibc),
("x86_64-unknown-l4re-uclibc", x86_64_unknown_l4re_uclibc),

("aarch64-unknown-redox", aarch64_unknown_redox),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use crate::spec::{Arch, Cc, LinkerFlavor, Target, TargetOptions, base};

pub(crate) fn target() -> Target {
let mut base = base::l4re::opts();

let extra_link_args = &["-zmax-page-size=0x1000", "-zcommon-page-size=0x1000"];
base.add_pre_link_args(LinkerFlavor::Unix(Cc::Yes), extra_link_args);
base.add_pre_link_args(LinkerFlavor::Unix(Cc::No), extra_link_args);

Target {
llvm_target: "aarch64-unknown-l4re-uclibc".into(),
metadata: crate::spec::TargetMetadata {
description: Some("Arm64 L4Re".into()),
tier: Some(3),
host_tools: Some(false),
std: Some(true),
},
pointer_width: 64,
data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32".into(),
arch: Arch::AArch64,
options: TargetOptions {
features: "+v8a".into(),
mcount: "__mcount".into(),
max_atomic_width: Some(128),
..base
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use crate::spec::{Arch, PanicStrategy, Target, TargetMetadata, base};
use crate::spec::{Arch, Cc, LinkerFlavor, Target, TargetMetadata, base};

pub(crate) fn target() -> Target {
let mut base = base::l4re::opts();
base.cpu = "x86-64".into();
base.plt_by_default = false;
base.max_atomic_width = Some(64);
base.panic_strategy = PanicStrategy::Abort;
let extra_link_args = &["-zmax-page-size=0x1000", "-zcommon-page-size=0x1000"];
base.add_pre_link_args(LinkerFlavor::Unix(Cc::Yes), extra_link_args);
base.add_pre_link_args(LinkerFlavor::Unix(Cc::No), extra_link_args);

Target {
llvm_target: "x86_64-unknown-l4re-gnu".into(),
Expand Down
5 changes: 0 additions & 5 deletions library/panic_unwind/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ cfg_select! {
#[path = "hermit.rs"]
mod imp;
}
target_os = "l4re" => {
// L4Re is unix family but does not yet support unwinding.
#[path = "dummy.rs"]
mod imp;
}
any(
all(target_family = "windows", target_env = "gnu"),
target_os = "psp",
Expand Down
1 change: 1 addition & 0 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
target_env = "sgx",
target_os = "xous",
target_os = "trusty",
target_os = "l4re",
))
))]
mod tests;
Expand Down
8 changes: 7 additions & 1 deletion library/std/src/fs/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,10 @@ fn recursive_mkdir_slash() {
}

#[test]
#[cfg_attr(
target_os = "l4re",
ignore = "Path '.' in the file system root can not be resolved in L4Re"
)]
fn recursive_mkdir_dot() {
check!(fs::create_dir_all(Path::new(".")));
}
Expand Down Expand Up @@ -1991,6 +1995,7 @@ fn rename_directory() {
}

#[test]
#[cfg_attr(target_os = "l4re", ignore = "futimens")]
fn test_file_times() {
#[cfg(target_vendor = "apple")]
use crate::os::darwin::fs::FileTimesExt;
Expand Down Expand Up @@ -2019,7 +2024,8 @@ fn test_file_times() {
target_os = "android",
target_os = "redox",
target_os = "espidf",
target_os = "horizon"
target_os = "horizon",
target_os = "l4re",
))
)
)))]
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/io/copy/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ mod io_benches {
use crate::io::prelude::*;

#[bench]
#[cfg_attr(target_os = "emscripten", ignore)] // no /dev
#[cfg_attr(any(target_os = "emscripten", target_os = "l4re"), ignore)] // no /dev
fn bench_copy_buf_reader(b: &mut Bencher) {
let mut file_in = File::open("/dev/zero").expect("opening /dev/zero failed");
// use dyn to avoid specializations unrelated to readbuf
Expand Down
9 changes: 8 additions & 1 deletion library/std/src/net/ip_addr.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// Tests for this module
#[cfg(all(test, not(any(target_os = "emscripten", all(target_os = "wasi", target_env = "p1")))))]
#[cfg(all(
test,
not(any(
target_os = "emscripten",
all(target_os = "wasi", target_env = "p1"),
target_os = "l4re"
))
))]
mod tests;

#[stable(feature = "ip_addr", since = "1.7.0")]
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ mod hostname;
mod ip_addr;
mod socket_addr;
mod tcp;
#[cfg(test)]
#[cfg(all(test, not(target_os = "l4re")))]
pub(crate) mod tests;
mod udp;

Expand Down
9 changes: 8 additions & 1 deletion library/std/src/net/socket_addr.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// Tests for this module
#[cfg(all(test, not(any(target_os = "emscripten", all(target_os = "wasi", target_env = "p1")))))]
#[cfg(all(
test,
not(any(
target_os = "emscripten",
all(target_os = "wasi", target_env = "p1"),
target_os = "l4re"
))
))]
mod tests;

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
1 change: 1 addition & 0 deletions library/std/src/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
all(target_os = "wasi", target_env = "p1"),
target_os = "xous",
target_os = "trusty",
target_os = "l4re",
))
))]
mod tests;
Expand Down
1 change: 1 addition & 0 deletions library/std/src/net/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
target_env = "sgx",
target_os = "xous",
target_os = "trusty",
target_os = "l4re",
))
))]
mod tests;
Expand Down
1 change: 1 addition & 0 deletions library/std/src/os/fd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod net;
mod stdio;

#[cfg(test)]
#[cfg(not(target_os = "l4re"))]
mod tests;

// Export the types and traits for the public API.
Expand Down
Loading
Loading