Skip to content

Commit 1fb7eb8

Browse files
Setup for cross-platform development and support
* Import compiler builtin crate to fix issue with _umod and _udiv * Trim unnecessary Makefile variables and flags * Keep the BLOCK and ALIGN commands in linker.ld for now * Fix linking error `undefiend reference to rust_begin_unwind` * `panic_fmt` was mangled through optimization * `panic_fmt` becomes `rust_begin_unwind` * Solution: add `#[no_mangle]` before `panic_fmt` * [Rust Issue](rust-lang/rust#38281)
1 parent ffa5d3d commit 1fb7eb8

File tree

4 files changed

+18
-24
lines changed

4 files changed

+18
-24
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ authors = [ "[email protected]" ]
88
crate-type = ["staticlib"]
99

1010
[dependencies]
11+
compiler_builtins = { git = "https://github.com/rust-lang-nursery/compiler-builtins" }
1112
rlibc = "1.0.0"
1213
spin = "0.3.4"
1314
volatile = "0.1.0"

Makefile

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
# Target and build files
22
arch ?= x86
33
target ?= i386
4-
system ?= linux
54
build ?= debug
65

76
# Flags
87
CFLAGS := --target=$(target)-unknown-none-elf -ffreestanding
98
ASFLAGS := -masm=intel
10-
LDFLAGS := -n -nostdlib --gc-sections -melf_$(target)
9+
LDFLAGS := -n --gc-sections -melf_$(target)
1110

1211
# Rust target
1312
rust_arch := $(target)
1413
ifeq ($(rust_arch),i386)
1514
rust_arch := i686
16-
else
17-
CFLAGS += -mno-red-zone
1815
endif
1916

2017
# Debug flags
@@ -28,15 +25,7 @@ kernel := build/rxinu-$(arch)-$(target).bin
2825
iso := build/rxinu-$(arch)-$(target).iso
2926

3027
# Rust Binaries
31-
32-
# Target
33-
ifeq ($(system),linux)
34-
rust_target ?= $(rust_arch)-unknown-linux-gnu
35-
endif
36-
ifeq ($(system),apple)
37-
rust_target ?= $(rust_arch)-apple-darwin
38-
endif
39-
28+
rust_target ?= $(rust_arch)-unknown-linux-gnu
4029
rust_os := target/$(rust_target)/debug/librxinu.a
4130

4231
# Source files

src/arch/x86/linker.ld

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,31 @@ SECTIONS
1313
/* First put the multiboot header, as it is required to be put very early
1414
early in the image or the bootloader won't recognize the file format.
1515
Next we'll put the .text section. */
16-
.text :
16+
.text BLOCK(4K) : ALIGN(4K)
1717
{
1818
KEEP(*(.multiboot_header))
1919
*(.text .text.*)
2020
}
2121

2222
/* Read-only data. */
23-
.rodata :
23+
.rodata BLOCK(4K) : ALIGN(4K)
2424
{
2525
*(.rodata .rodata.*)
2626
}
2727

28-
.data.rel.ro :
29-
{
30-
*(.data.rel.ro.local*) *(.data.rel.ro .data.rel.ro.*)
31-
}
32-
3328
/* Read-write data (initialized) */
34-
.data :
29+
.data BLOCK(4K) : ALIGN(4K)
30+
{
31+
*(.data .data.*)
32+
}
33+
34+
.data.rel.ro BLOCK(4K) : ALIGN(4K)
3535
{
36-
*(.data)
36+
*(.data.rel.ro.local*) *(.data.rel.ro .data.rel.ro.*)
3737
}
3838

3939
/* Read-write data (uninitialized) and stack */
40-
.bss :
40+
.bss BLOCK(4K) : ALIGN(4K)
4141
{
4242
*(COMMON)
4343
*(.bss)

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#![feature(unique)]
44
#![no_std]
55

6+
#![feature(compiler_builtins_lib)]
7+
extern crate compiler_builtins;
8+
69
extern crate rlibc;
710
extern crate spin;
811
extern crate volatile;
@@ -20,7 +23,8 @@ pub extern fn rust_main() {
2023
}
2124

2225
#[lang = "eh_personality"] extern fn eh_personality() {}
23-
#[lang = "panic_fmt"] extern fn panic_fmt() -> ! {loop{}}
26+
27+
#[lang = "panic_fmt"] #[no_mangle] extern fn panic_fmt() -> ! {loop{}}
2428

2529
#[allow(non_snake_case)]
2630
#[no_mangle]

0 commit comments

Comments
 (0)