Skip to content

Commit 1c6645b

Browse files
committed
Remove support for building PE files from hyperlight-guest-bin build.rs
Signed-off-by: Simon Davies <[email protected]>
1 parent 04b7adb commit 1c6645b

File tree

1 file changed

+41
-83
lines changed

1 file changed

+41
-83
lines changed

src/hyperlight_guest_bin/build.rs

Lines changed: 41 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ fn cargo_main() {
6262
.include("third_party/musl/arch/x86_64");
6363
}
6464

65-
let is_pe = env::var("CARGO_CFG_WINDOWS").is_ok();
66-
6765
if cfg!(any(feature = "printf", feature = "libc")) {
6866
cfg.define("HYPERLIGHT", None); // used in certain musl files for conditional compilation
6967

@@ -78,37 +76,26 @@ fn cargo_main() {
7876
.flag("-Wno-unused-parameter")
7977
.flag("-Wno-string-plus-int");
8078

81-
if is_pe {
82-
cfg.flag("-Wno-unused-label");
83-
cfg.flag("-Wno-unused-variable");
84-
cfg.compiler("clang-cl");
85-
} else {
86-
cfg.flag("-fPIC");
87-
// This is a terrible hack, because
88-
// - we need stack clash protection, because we have put the
89-
// stack right smack in the middle of everything in the guest
90-
// - clang refuses to do stack clash protection unless it is
91-
// required by a target ABI (Windows, MacOS) or the target is
92-
// is Linux or FreeBSD (see Clang.cpp RenderSCPOptions
93-
// https://github.com/llvm/llvm-project/blob/1bb52e9/clang/lib/Driver/ToolChains/Clang.cpp#L3724).
94-
// Hopefully a flag to force stack clash protection on generic
95-
// targets will eventually show up.
96-
cfg.flag("--target=x86_64-unknown-linux-none");
97-
98-
// We don't support stack protectors at the moment, but Arch Linux clang
99-
// auto-enables them for -linux platforms, so explicitly disable them.
100-
cfg.flag("-fno-stack-protector");
101-
cfg.flag("-fstack-clash-protection");
102-
cfg.flag("-mstack-probe-size=4096");
103-
cfg.compiler("clang");
104-
}
105-
106-
if cfg!(windows) {
107-
unsafe { env::set_var("AR_x86_64_unknown_none", "llvm-ar") };
108-
} else {
109-
unsafe { env::set_var("AR_x86_64_pc_windows_msvc", "llvm-lib") };
110-
}
111-
79+
cfg.flag("-fPIC");
80+
// This is a terrible hack, because
81+
// - we need stack clash protection, because we have put the
82+
// stack right smack in the middle of everything in the guest
83+
// - clang refuses to do stack clash protection unless it is
84+
// required by a target ABI (Windows, MacOS) or the target is
85+
// is Linux or FreeBSD (see Clang.cpp RenderSCPOptions
86+
// https://github.com/llvm/llvm-project/blob/1bb52e9/clang/lib/Driver/ToolChains/Clang.cpp#L3724).
87+
// Hopefully a flag to force stack clash protection on generic
88+
// targets will eventually show up.
89+
cfg.flag("--target=x86_64-unknown-linux-none");
90+
91+
// We don't support stack protectors at the moment, but Arch Linux clang
92+
// auto-enables them for -linux platforms, so explicitly disable them.
93+
cfg.flag("-fno-stack-protector");
94+
cfg.flag("-fstack-clash-protection");
95+
cfg.flag("-mstack-probe-size=4096");
96+
cfg.compiler("clang");
97+
98+
unsafe { env::set_var("AR_x86_64_unknown_none", "llvm-ar") };
11299
cfg.compile("hyperlight_guest_bin");
113100
}
114101

@@ -183,29 +170,20 @@ fn cargo_main() {
183170
fs::create_dir_all(&binroot)
184171
.unwrap_or_else(|e| panic!("Could not create binary root {:?}: {}", &binroot, e));
185172
fs::write(binroot.join(".out_dir"), out_dir).expect("Could not write out_dir");
186-
fs::copy(&binpath, binroot.join("ml64.exe")).expect("Could not copy to ml64.exe");
187173
fs::copy(&binpath, binroot.join("clang")).expect("Could not copy to clang");
188174
fs::copy(&binpath, binroot.join("clang.exe")).expect("Could not copy to clang.exe");
189-
fs::copy(&binpath, binroot.join("clang-cl")).expect("Could not copy to clang-cl");
190-
fs::copy(&binpath, binroot.join("clang-cl.exe")).expect("Could not copy to clang-cl.exe");
191175
}
192176
}
193177

194178
#[derive(PartialEq)]
195179
enum Tool {
196180
CargoBuildScript,
197-
Ml64,
198181
Clang,
199-
ClangCl,
200182
}
201183
impl From<&std::ffi::OsStr> for Tool {
202184
fn from(x: &std::ffi::OsStr) -> Tool {
203-
if x == "ml64.exe" {
204-
Tool::Ml64
205-
} else if x == "clang" || x == "clang.exe" {
185+
if x == "clang" {
206186
Tool::Clang
207-
} else if x == "clang-cl" || x == "clang-cl.exe" {
208-
Tool::ClangCl
209187
} else {
210188
Tool::CargoBuildScript
211189
}
@@ -252,44 +230,24 @@ fn main() -> std::process::ExitCode {
252230
let mut args = env::args();
253231
args.next(); // ignore the exe name
254232
let include_dir = <String as AsRef<Path>>::as_ref(&out_dir).join("include");
255-
match tool {
256-
Tool::Ml64 => std::process::Command::new("llvm-ml")
257-
.arg("-m64")
258-
.args(args)
259-
.status()
260-
.ok()
261-
.and_then(|x| (x.code()))
262-
.map(|x| (x as u8).into())
263-
.unwrap_or(std::process::ExitCode::FAILURE),
264-
Tool::Clang => std::process::Command::new(find_next(root_dir, "clang"))
265-
// terrible hack, see above
266-
.arg("--target=x86_64-unknown-linux-none")
267-
.args([
268-
// We don't support stack protectors at the moment, but Arch Linux clang
269-
// auto-enables them for -linux platforms, so explicitly disable them.
270-
"-fno-stack-protector",
271-
"-fstack-clash-protection",
272-
"-mstack-probe-size=4096",
273-
])
274-
.arg("-nostdinc")
275-
.arg("-isystem")
276-
.arg(include_dir)
277-
.args(args)
278-
.status()
279-
.ok()
280-
.and_then(|x| (x.code()))
281-
.map(|x| (x as u8).into())
282-
.unwrap_or(std::process::ExitCode::FAILURE),
283-
Tool::ClangCl => std::process::Command::new(find_next(root_dir, "clang-cl"))
284-
.arg("-nostdinc")
285-
.arg("/external:I")
286-
.arg(include_dir)
287-
.args(args)
288-
.status()
289-
.ok()
290-
.and_then(|x| (x.code()))
291-
.map(|x| (x as u8).into())
292-
.unwrap_or(std::process::ExitCode::FAILURE),
293-
_ => std::process::ExitCode::FAILURE,
294-
}
233+
234+
std::process::Command::new(find_next(root_dir, "clang"))
235+
// terrible hack, see above
236+
.arg("--target=x86_64-unknown-linux-none")
237+
.args([
238+
// We don't support stack protectors at the moment, but Arch Linux clang
239+
// auto-enables them for -linux platforms, so explicitly disable them.
240+
"-fno-stack-protector",
241+
"-fstack-clash-protection",
242+
"-mstack-probe-size=4096",
243+
])
244+
.arg("-nostdinc")
245+
.arg("-isystem")
246+
.arg(include_dir)
247+
.args(args)
248+
.status()
249+
.ok()
250+
.and_then(|x| (x.code()))
251+
.map(|x| (x as u8).into())
252+
.unwrap_or(std::process::ExitCode::FAILURE)
295253
}

0 commit comments

Comments
 (0)