Skip to content

Commit 0470bb4

Browse files
dmakarovLucasSte
authored andcommitted
[SOL] Temporarily patch BPF ELF file header with SBF machine code
1 parent efb837d commit 0470bb4

File tree

1 file changed

+14
-0
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+14
-0
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,9 +2064,23 @@ fn add_linked_symbol_object(
20642064
if let Err(error) = result {
20652065
sess.dcx().emit_fatal(errors::FailedToWrite { path, error });
20662066
}
2067+
if sess.target.arch == "sbf" {
2068+
patch_synthetic_object_file(sess, &path);
2069+
}
20672070
cmd.add_object(&path);
20682071
}
20692072

2073+
fn patch_synthetic_object_file(sess: &Session, path: &PathBuf) {
2074+
const EM_SBF: [u8; 2] = [0x07, 0x01];
2075+
if let Ok(mut sf) = fs::OpenOptions::new().write(true).open(path) {
2076+
if let Ok(_) = sf.seek(SeekFrom::Start(0x12)) {
2077+
sf.write(&EM_SBF).unwrap();
2078+
}
2079+
} else {
2080+
sess.fatal(&format!("failed to patch {}", path.display()));
2081+
}
2082+
}
2083+
20702084
/// Add object files containing code from the current crate.
20712085
fn add_local_crate_regular_objects(cmd: &mut dyn Linker, codegen_results: &CodegenResults) {
20722086
for obj in codegen_results.modules.iter().filter_map(|m| m.object.as_ref()) {

0 commit comments

Comments
 (0)