Skip to content

Commit 2de8fea

Browse files
committed
L4Re: Repair build and move to rustc linking
Fixes the builds of rustc and library/std for the L4Re target OS. A major change was done in linking binaries: The need for the L4Bender tool was removed and linking parameters are now fully configured in the rustc target config.
1 parent 1b9ae9e commit 2de8fea

25 files changed

Lines changed: 141 additions & 532 deletions

File tree

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
codegen_ssa_L4Bender_exporting_symbols_unimplemented = exporting symbols not implemented yet for L4Bender
2-
31
codegen_ssa_aarch64_softfloat_neon = enabling the `neon` target feature on the current target is unsound due to ABI issues
42
53
codegen_ssa_add_native_library = failed to add native library {$library_path}: {$error}

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,6 @@ pub(crate) fn get_linker<'a>(
137137
// to the linker args construction.
138138
assert!(cmd.get_args().is_empty() || sess.target.abi == Abi::Uwp);
139139
match flavor {
140-
LinkerFlavor::Unix(Cc::No) if sess.target.os == Os::L4Re => {
141-
Box::new(L4Bender::new(cmd, sess)) as Box<dyn Linker>
142-
}
143140
LinkerFlavor::Unix(Cc::No) if sess.target.os == Os::Aix => {
144141
Box::new(AixLinker::new(cmd, sess)) as Box<dyn Linker>
145142
}
@@ -280,7 +277,6 @@ generate_arg_methods! {
280277
MsvcLinker<'_>
281278
EmLinker<'_>
282279
WasmLd<'_>
283-
L4Bender<'_>
284280
AixLinker<'_>
285281
LlbcLinker<'_>
286282
PtxLinker<'_>
@@ -1475,128 +1471,6 @@ impl<'a> WasmLd<'a> {
14751471
}
14761472
}
14771473

1478-
/// Linker shepherd script for L4Re (Fiasco)
1479-
struct L4Bender<'a> {
1480-
cmd: Command,
1481-
sess: &'a Session,
1482-
hinted_static: bool,
1483-
}
1484-
1485-
impl<'a> Linker for L4Bender<'a> {
1486-
fn cmd(&mut self) -> &mut Command {
1487-
&mut self.cmd
1488-
}
1489-
1490-
fn set_output_kind(
1491-
&mut self,
1492-
_output_kind: LinkOutputKind,
1493-
_crate_type: CrateType,
1494-
_out_filename: &Path,
1495-
) {
1496-
}
1497-
1498-
fn link_staticlib_by_name(&mut self, name: &str, _verbatim: bool, whole_archive: bool) {
1499-
self.hint_static();
1500-
if !whole_archive {
1501-
self.link_arg(format!("-PC{name}"));
1502-
} else {
1503-
self.link_arg("--whole-archive")
1504-
.link_or_cc_arg(format!("-l{name}"))
1505-
.link_arg("--no-whole-archive");
1506-
}
1507-
}
1508-
1509-
fn link_staticlib_by_path(&mut self, path: &Path, whole_archive: bool) {
1510-
self.hint_static();
1511-
if !whole_archive {
1512-
self.link_or_cc_arg(path);
1513-
} else {
1514-
self.link_arg("--whole-archive").link_or_cc_arg(path).link_arg("--no-whole-archive");
1515-
}
1516-
}
1517-
1518-
fn full_relro(&mut self) {
1519-
self.link_args(&["-z", "relro", "-z", "now"]);
1520-
}
1521-
1522-
fn partial_relro(&mut self) {
1523-
self.link_args(&["-z", "relro"]);
1524-
}
1525-
1526-
fn no_relro(&mut self) {
1527-
self.link_args(&["-z", "norelro"]);
1528-
}
1529-
1530-
fn gc_sections(&mut self, keep_metadata: bool) {
1531-
if !keep_metadata {
1532-
self.link_arg("--gc-sections");
1533-
}
1534-
}
1535-
1536-
fn optimize(&mut self) {
1537-
// GNU-style linkers support optimization with -O. GNU ld doesn't
1538-
// need a numeric argument, but other linkers do.
1539-
if self.sess.opts.optimize == config::OptLevel::More
1540-
|| self.sess.opts.optimize == config::OptLevel::Aggressive
1541-
{
1542-
self.link_arg("-O1");
1543-
}
1544-
}
1545-
1546-
fn pgo_gen(&mut self) {}
1547-
1548-
fn debuginfo(&mut self, strip: Strip, _: &[PathBuf]) {
1549-
match strip {
1550-
Strip::None => {}
1551-
Strip::Debuginfo => {
1552-
self.link_arg("--strip-debug");
1553-
}
1554-
Strip::Symbols => {
1555-
self.link_arg("--strip-all");
1556-
}
1557-
}
1558-
}
1559-
1560-
fn no_default_libraries(&mut self) {
1561-
self.cc_arg("-nostdlib");
1562-
}
1563-
1564-
fn export_symbols(&mut self, _: &Path, _: CrateType, _: &[(String, SymbolExportKind)]) {
1565-
// ToDo, not implemented, copy from GCC
1566-
self.sess.dcx().emit_warn(errors::L4BenderExportingSymbolsUnimplemented);
1567-
}
1568-
1569-
fn windows_subsystem(&mut self, subsystem: WindowsSubsystemKind) {
1570-
let subsystem = subsystem.as_str();
1571-
self.link_arg(&format!("--subsystem {subsystem}"));
1572-
}
1573-
1574-
fn reset_per_library_state(&mut self) {
1575-
self.hint_static(); // Reset to default before returning the composed command line.
1576-
}
1577-
1578-
fn linker_plugin_lto(&mut self) {}
1579-
1580-
fn control_flow_guard(&mut self) {}
1581-
1582-
fn ehcont_guard(&mut self) {}
1583-
1584-
fn no_crt_objects(&mut self) {}
1585-
}
1586-
1587-
impl<'a> L4Bender<'a> {
1588-
fn new(cmd: Command, sess: &'a Session) -> L4Bender<'a> {
1589-
L4Bender { cmd, sess, hinted_static: false }
1590-
}
1591-
1592-
fn hint_static(&mut self) {
1593-
if !self.hinted_static {
1594-
self.link_or_cc_arg("-static");
1595-
self.hinted_static = true;
1596-
}
1597-
}
1598-
}
1599-
16001474
/// Linker for AIX.
16011475
struct AixLinker<'a> {
16021476
cmd: Command,

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,6 @@ pub(crate) struct Ld64UnimplementedModifier;
113113
#[diag(codegen_ssa_linker_unsupported_modifier)]
114114
pub(crate) struct LinkerUnsupportedModifier;
115115

116-
#[derive(Diagnostic)]
117-
#[diag(codegen_ssa_L4Bender_exporting_symbols_unimplemented)]
118-
pub(crate) struct L4BenderExportingSymbolsUnimplemented;
119-
120116
#[derive(Diagnostic)]
121117
#[diag(codegen_ssa_no_natvis_directory)]
122118
pub(crate) struct NoNatvisDirectory {
Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,59 @@
1-
use crate::spec::{Cc, Env, LinkerFlavor, Os, PanicStrategy, RelocModel, TargetOptions, cvs};
1+
use crate::spec::{
2+
Cc, Env, LinkOutputKind, LinkSelfContainedComponents, LinkSelfContainedDefault, LinkerFlavor,
3+
Os, PanicStrategy, TargetOptions, add_link_args, crt_objects, cvs,
4+
};
25

36
pub(crate) fn opts() -> TargetOptions {
7+
// add ld- and cc-style args
8+
macro_rules! prepare_args {
9+
($($val:expr),+) => {{
10+
let ld_args = &[$($val),+];
11+
let cc_args = &[$(concat!("-Wl,", $val)),+];
12+
13+
let mut ret = TargetOptions::link_args(LinkerFlavor::Unix(Cc::No), ld_args);
14+
add_link_args(&mut ret, LinkerFlavor::Unix(Cc::Yes), cc_args);
15+
ret
16+
}};
17+
}
18+
19+
let pre_link_args = prepare_args!("-nostdlib", "-dynamic-linker=rom/libld-l4.so");
20+
21+
let late_link_args = prepare_args!("-lc", "-lgcc_eh");
22+
23+
let pre_link_objects_self_contained = crt_objects::new(&[
24+
(LinkOutputKind::StaticNoPicExe, &["crt1.o", "crti.o", "crtbeginT.o"]),
25+
(LinkOutputKind::StaticPicExe, &["crt1.p.o", "crti.o", "crtbegin.o"]),
26+
(LinkOutputKind::DynamicNoPicExe, &["crt1.o", "crti.o", "crtbegin.o"]),
27+
(LinkOutputKind::DynamicPicExe, &["crt1.s.o", "crti.o", "crtbeginS.o"]),
28+
(LinkOutputKind::DynamicDylib, &["crti.s.o", "crtbeginS.o"]),
29+
(LinkOutputKind::StaticDylib, &["crti.s.o", "crtbeginS.o"]),
30+
]);
31+
32+
let post_link_objects_self_contained = crt_objects::new(&[
33+
(LinkOutputKind::StaticNoPicExe, &["crtendT.o", "crtn.o"]),
34+
(LinkOutputKind::StaticPicExe, &["crtend.o", "crtn.o"]),
35+
(LinkOutputKind::DynamicNoPicExe, &["crtend.o", "crtn.o"]),
36+
(LinkOutputKind::DynamicPicExe, &["crtendS.o", "crtn.o"]),
37+
(LinkOutputKind::DynamicDylib, &["crtendS.o", "crtn.s.o"]),
38+
(LinkOutputKind::StaticDylib, &["crtendS.o", "crtn.s.o"]),
39+
]);
40+
441
TargetOptions {
542
os: Os::L4Re,
643
env: Env::Uclibc,
7-
linker_flavor: LinkerFlavor::Unix(Cc::No),
8-
panic_strategy: PanicStrategy::Abort,
9-
linker: Some("l4-bender".into()),
1044
families: cvs!["unix"],
11-
relocation_model: RelocModel::Static,
45+
panic_strategy: PanicStrategy::Abort,
46+
linker_flavor: LinkerFlavor::Unix(Cc::No),
47+
dynamic_linking: true,
48+
position_independent_executables: true,
49+
has_thread_local: true,
50+
pre_link_args,
51+
late_link_args,
52+
pre_link_objects_self_contained,
53+
post_link_objects_self_contained,
54+
link_self_contained: LinkSelfContainedDefault::WithComponents(
55+
LinkSelfContainedComponents::LIBC | LinkSelfContainedComponents::CRT_OBJECTS,
56+
),
1257
..Default::default()
1358
}
1459
}

compiler/rustc_target/src/spec/targets/x86_64_unknown_l4re_uclibc.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
use crate::spec::{Arch, PanicStrategy, Target, TargetMetadata, base};
1+
use crate::spec::{Arch, Cc, LinkerFlavor, Target, TargetMetadata, base};
22

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

1012
Target {
1113
llvm_target: "x86_64-unknown-l4re-gnu".into(),

library/Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ dependencies = [
146146

147147
[[package]]
148148
name = "libc"
149-
version = "0.2.178"
149+
version = "0.2.179"
150150
source = "registry+https://github.com/rust-lang/crates.io-index"
151-
checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091"
151+
checksum = "c5a2d376baa530d1238d133232d15e239abad80d05838b4b59354e5268af431f"
152152
dependencies = [
153153
"rustc-std-workspace-core",
154154
]

library/panic_unwind/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ cfg_select! {
4141
#[path = "hermit.rs"]
4242
mod imp;
4343
}
44-
target_os = "l4re" => {
45-
// L4Re is unix family but does not yet support unwinding.
46-
#[path = "dummy.rs"]
47-
mod imp;
48-
}
4944
any(
5045
all(target_family = "windows", target_env = "gnu"),
5146
target_os = "psp",

library/std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ miniz_oxide = { version = "0.8.0", optional = true, default-features = false }
3333
addr2line = { version = "0.25.0", optional = true, default-features = false }
3434

3535
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
36-
libc = { version = "0.2.178", default-features = false, features = [
36+
libc = { version = "0.2.179", default-features = false, features = [
3737
'rustc-dep-of-std',
3838
], public = true }
3939

library/std/src/net/tcp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
all(target_os = "wasi", target_env = "p1"),
88
target_os = "xous",
99
target_os = "trusty",
10+
target_os = "l4re",
1011
))
1112
))]
1213
mod tests;

library/std/src/net/udp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
target_env = "sgx",
77
target_os = "xous",
88
target_os = "trusty",
9+
target_os = "l4re",
910
))
1011
))]
1112
mod tests;

0 commit comments

Comments
 (0)