forked from M-Labs/nac3
1
0
Fork 0

nac3embedded: run linker (WIP)

This commit is contained in:
Sebastien Bourdeauducq 2021-09-23 21:30:13 +08:00
parent c4fbfeaca9
commit 14662a66dc
3 changed files with 73 additions and 3 deletions

53
nac3embedded/kernel.ld Normal file
View File

@ -0,0 +1,53 @@
/* Force ld to make the ELF header as loadable. */
PHDRS
{
headers PT_LOAD FILEHDR PHDRS ;
text PT_LOAD ;
data PT_LOAD ;
dynamic PT_DYNAMIC ;
eh_frame PT_GNU_EH_FRAME ;
}
SECTIONS
{
/* Push back .text section enough so that ld.lld not complain */
. = SIZEOF_HEADERS;
.text :
{
*(.text .text.*)
} : text
.rodata :
{
*(.rodata .rodata.*)
}
.eh_frame :
{
KEEP(*(.eh_frame))
} : text
.eh_frame_hdr :
{
KEEP(*(.eh_frame_hdr))
} : text : eh_frame
.data :
{
*(.data)
} : data
.dynamic :
{
*(.dynamic)
} : data : dynamic
.bss (NOLOAD) : ALIGN(4)
{
__bss_start = .;
*(.sbss .sbss.* .bss .bss.*);
. = ALIGN(4);
_end = .;
}
}

View File

@ -1,6 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;
use std::path::Path; use std::path::Path;
use std::process::Command;
use pyo3::prelude::*; use pyo3::prelude::*;
use pyo3::exceptions; use pyo3::exceptions;
@ -163,11 +164,20 @@ impl Nac3 {
.write_to_file(module, FileType::Object, Path::new(&format!("{}.o", module.get_name().to_str().unwrap()))) .write_to_file(module, FileType::Object, Path::new(&format!("{}.o", module.get_name().to_str().unwrap())))
.expect("couldn't write module to file"); .expect("couldn't write module to file");
}))); })));
let threads: Vec<String> = (0..4).map(|i| format!("module{}", i)).collect(); let thread_names: Vec<String> = (0..4).map(|i| format!("module{}", i)).collect();
let threads: Vec<_> = threads.iter().map(|s| s.as_str()).collect(); let threads: Vec<_> = thread_names.iter().map(|s| s.as_str()).collect();
let (registry, handles) = WorkerRegistry::create_workers(&threads, top_level.clone(), f); let (registry, handles) = WorkerRegistry::create_workers(&threads, top_level.clone(), f);
registry.add_task(task); registry.add_task(task);
registry.wait_tasks_complete(handles); registry.wait_tasks_complete(handles);
if let Ok(linker_status) = Command::new("ld.lld").args(&["-shared", "--eh-frame-hdr", "-Tkernel.ld"]).status() {
if !linker_status.success() {
return Err(exceptions::PyRuntimeError::new_err("failed to start linker"));
}
} else {
return Err(exceptions::PyRuntimeError::new_err("linker returned non-zero status code"));
}
Ok(()) Ok(())
} }
} }

View File

@ -4,6 +4,13 @@ in
pkgs.stdenv.mkDerivation { pkgs.stdenv.mkDerivation {
name = "nac3-env"; name = "nac3-env";
buildInputs = with pkgs; [ buildInputs = with pkgs; [
llvm_11 clang_11 cargo rustc libffi libxml2 clippy llvm_11
clang_11
lld_11
cargo
rustc
libffi
libxml2
clippy
]; ];
} }