Skip to content

Commit 8e9f565

Browse files
committed
Try to link as ELF64
1 parent 34fc6d0 commit 8e9f565

File tree

13 files changed

+104
-21
lines changed

13 files changed

+104
-21
lines changed

real_mode/.cargo/config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[build]
2-
target = "x86_64-bootloader-real-mode.json"
2+
target = "x86_64-bootloader.json"

real_mode/Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

real_mode/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "real_mode"
2+
name = "bootloader"
33
version = "0.1.0"
44
authors = ["Philipp Oppermann <[email protected]>"]
55
edition = "2018"

real_mode/build.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn main() {
99
let objcopy = llvm_tools.tool(&exe("llvm-objcopy")).expect("llvm-objcopy not found");
1010

1111
build_subproject(Path::new("first_stage"), &["_start", "print_char"], &out_dir, &objcopy);
12-
build_subproject(Path::new("second_stage"), &["second_stage"], &out_dir, &objcopy);
12+
build_subproject(Path::new("real_mode"), &["second_stage"], &out_dir, &objcopy);
1313
}
1414

1515
fn build_subproject(dir: &Path, global_symbols: &[&str], out_dir: &str, objcopy: &Path) {
@@ -21,11 +21,14 @@ fn build_subproject(dir: &Path, global_symbols: &[&str], out_dir: &str, objcopy:
2121
// build
2222
let mut cmd = Command::new("cargo");
2323
cmd.arg("xbuild").arg("--release");
24+
cmd.arg("--verbose");
2425
cmd.arg(format!("--manifest-path={}", manifest_path.display()));
26+
cmd.arg(format!("--target={}", dir.join("x86_64-target.json").display()));
2527
cmd.arg("-Z").arg("unstable-options");
2628
cmd.arg("--out-dir").arg(&out_dir);
27-
cmd.arg("--target-dir").arg("target");
28-
cmd.env("XBUILD_SYSROOT_PATH", format!("target/{}-sysroot", dir_name));
29+
cmd.arg("--target-dir").arg(out_path.join("target").join(dir_name));
30+
cmd.env_remove("RUSTFLAGS");
31+
cmd.env("XBUILD_SYSROOT_PATH", out_path.join("target").join(dir_name).join("sysroot"));
2932
let status = cmd.status().unwrap();
3033
assert!(status.success());
3134

@@ -37,6 +40,13 @@ fn build_subproject(dir: &Path, global_symbols: &[&str], out_dir: &str, objcopy:
3740
cmd.arg(out_path.join(format!("lib{}.a", dir_name)));
3841
let status = cmd.status().unwrap();
3942
assert!(status.success());
43+
44+
// convert to ELF64
45+
let mut cmd = Command::new(objcopy);
46+
cmd.arg("-I").arg("elf32-i386").arg("-O").arg("elf64-x86-64");
47+
cmd.arg(out_path.join(format!("lib{}.a", dir_name)));
48+
let status = cmd.status().unwrap();
49+
assert!(status.success());
4050

4151
// emit linker flags
4252
println!("cargo:rustc-link-search=native={}", out_dir);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"arch": "x86",
3+
"cpu": "i386",
4+
"data-layout": "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128",
5+
"dynamic-linking": false,
6+
"executables": true,
7+
"linker-flavor": "ld.lld",
8+
"linker": "rust-lld",
9+
"llvm-target": "i386-unknown-none-code16",
10+
"pre-link-args": {
11+
"ld.lld": [
12+
"-Tlinker.ld"
13+
]
14+
},
15+
"max-atomic-width": 64,
16+
"position-independent-executables": false,
17+
"disable-redzone": true,
18+
"target-c-int-width": "32",
19+
"target-pointer-width": "32",
20+
"target-endian": "little",
21+
"panic-strategy": "abort",
22+
"os": "none",
23+
"vendor": "unknown",
24+
"relocation_model": "static",
25+
"eliminate_frame_pointer": true
26+
}

real_mode/linker.ld

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ SECTIONS {
3030

3131
_second_stage_start = .;
3232

33-
.second_stage_text :
33+
.real_mode_text :
3434
{
35-
*second_stage*(.text .text.*)
35+
*real_mode*(.text .text.*)
3636
}
37-
.second_stage_data :
37+
.real_mode_data :
3838
{
39-
*second_stage*(.rodata .rodata.*)
40-
*second_stage*(.data .data.*)
41-
*second_stage*(.got .got.*)
39+
*real_mode*(.rodata .rodata.*)
40+
*real_mode*(.data .data.*)
41+
*real_mode*(.got .got.*)
4242
}
4343

4444
.text :
File renamed without changes.

real_mode/second_stage/Cargo.lock renamed to real_mode/real_mode/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

real_mode/second_stage/Cargo.toml renamed to real_mode/real_mode/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
2-
name = "second_stage"
2+
name = "real_mode"
33
version = "0.1.0"
44
authors = ["Philipp Oppermann <[email protected]>"]
55
edition = "2018"
66

77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[lib]
10-
name = "second_stage"
10+
name = "real_mode"
1111
crate-type = ["staticlib"]
1212

1313
[dependencies]
File renamed without changes.

0 commit comments

Comments
 (0)