Solve the haunting i386 data layout in Linux legacy boot

This commit is contained in:
Zhang Junyang
2024-06-20 15:05:05 +00:00
committed by Tate, Hongliang Tian
parent 68793d28c5
commit f703d915cd
2 changed files with 2 additions and 18 deletions

View File

@ -1,6 +1,6 @@
{
"llvm-target": "i386-unknown-none",
"data-layout": "e-m:e-i32:32-f80:128-n8:16:32-S128-p:32:32",
"data-layout": "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i128:128-f64:32:64-f80:32-n8:16:32-S128",
"cpu": "i386",
"arch": "x86",
"dynamic-linking": false,

View File

@ -15,23 +15,7 @@ fn get_rela_array() -> &'static [Elf64Rela] {
}
let start = __rela_dyn_start as *const Elf64Rela;
let end = __rela_dyn_end as *const Elf64Rela;
// FIXME: 2023/11/29
// There should be a Rust compiler bug that makes the calculation of len incorrect.
// The most sound implementation only works in debug mode.
// let len = unsafe { end.offset_from(start) } as usize;
// The inline asm solution is a workaround.
let len = unsafe {
let len: usize;
core::arch::asm!("
mov {len}, {end}
sub {len}, {start}
",
len = out(reg) len,
end = in(reg) end,
start = in(reg) start,
);
len / core::mem::size_of::<Elf64Rela>()
};
let len = unsafe { end.offset_from(start) } as usize;
#[cfg(feature = "debug_print")]
unsafe {
use crate::console::{print_hex, print_str};