|
| 1 | +extern crate llvm_tools; |
1 | 2 | extern crate target_build_utils;
|
2 | 3 | extern crate walkdir;
|
3 | 4 |
|
4 | 5 | use std::env;
|
5 | 6 | use std::fs::File;
|
6 | 7 | use std::io::Write;
|
7 | 8 | use std::path::{Path, PathBuf};
|
8 |
| -use std::process::Command; |
| 9 | +use std::process::{self, Command}; |
9 | 10 |
|
10 | 11 | use target_build_utils::TargetInfo;
|
11 | 12 | use walkdir::{DirEntry, WalkDir};
|
@@ -80,6 +81,52 @@ fn build_hermit(src_dir: &Path, target_dir_opt: Option<&Path>) {
|
80 | 81 | } else {
|
81 | 82 | panic!("Try to build for an unsupported platform");
|
82 | 83 | };
|
| 84 | + println!("Lib location: {}", lib_location.display()); |
| 85 | + |
| 86 | + // Kernel and user space has its own versions of memcpy, memset, etc, |
| 87 | + // Consequently, we rename the functions in the libos to avoid collisions. |
| 88 | + // In addition, it provides us the offer to create a optimized version of memcpy |
| 89 | + // in user space. |
| 90 | + |
| 91 | + // get access to llvm tools shipped in the llvm-tools-preview rustup component |
| 92 | + let llvm_tools = match llvm_tools::LlvmTools::new() { |
| 93 | + Ok(tools) => tools, |
| 94 | + Err(llvm_tools::Error::NotFound) => { |
| 95 | + eprintln!("Error: llvm-tools not found"); |
| 96 | + eprintln!("Maybe the rustup component `llvm-tools-preview` is missing?"); |
| 97 | + eprintln!(" Install it through: `rustup component add llvm-tools-preview`"); |
| 98 | + process::exit(1); |
| 99 | + } |
| 100 | + Err(err) => { |
| 101 | + eprintln!("Failed to retrieve llvm-tools component: {:?}", err); |
| 102 | + process::exit(1); |
| 103 | + } |
| 104 | + }; |
| 105 | + |
| 106 | + let lib = lib_location.join("libhermit.a"); |
| 107 | + |
| 108 | + let symbols: [&str; 5] = ["memcpy", "memmove", "memset", "memcmp", "bcmp"]; |
| 109 | + for symbol in symbols.iter() { |
| 110 | + // determine llvm_objcopy |
| 111 | + let llvm_objcopy = llvm_tools |
| 112 | + .tool(&llvm_tools::exe("llvm-objcopy")) |
| 113 | + .expect("llvm_objcopy not found in llvm-tools"); |
| 114 | + |
| 115 | + // rename symbols |
| 116 | + let mut cmd = Command::new(llvm_objcopy); |
| 117 | + cmd.arg("--redefine-sym") |
| 118 | + .arg(String::from(*symbol) + &String::from("=kernel") + &String::from(*symbol)) |
| 119 | + .arg(lib.display().to_string()); |
| 120 | + |
| 121 | + println!("cmd {:?}", cmd); |
| 122 | + let output = cmd.output().expect("Unable to rename symbols"); |
| 123 | + let stdout = std::string::String::from_utf8(output.stdout); |
| 124 | + let stderr = std::string::String::from_utf8(output.stderr); |
| 125 | + println!("Rename symbols output-status: {}", output.status); |
| 126 | + println!("Rename symbols output-stdout: {}", stdout.unwrap()); |
| 127 | + println!("Rename symbols output-stderr: {}", stderr.unwrap()); |
| 128 | + } |
| 129 | + |
83 | 130 | println!("cargo:rustc-link-search=native={}", lib_location.display());
|
84 | 131 | println!("cargo:rustc-link-lib=static=hermit");
|
85 | 132 |
|
|
0 commit comments