From f703d915cd4c0f3dc332c12a71b8013bce8e7f8b Mon Sep 17 00:00:00 2001 From: Zhang Junyang Date: Thu, 20 Jun 2024 15:05:05 +0000 Subject: [PATCH] Solve the haunting i386 data layout in Linux legacy boot --- .../builder/src/x86_64-i386_pm-none.json | 2 +- .../setup/src/x86/amd64_efi/relocation.rs | 18 +----------------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/framework/libs/linux-bzimage/builder/src/x86_64-i386_pm-none.json b/framework/libs/linux-bzimage/builder/src/x86_64-i386_pm-none.json index 4a5800775..e7ab8fa69 100644 --- a/framework/libs/linux-bzimage/builder/src/x86_64-i386_pm-none.json +++ b/framework/libs/linux-bzimage/builder/src/x86_64-i386_pm-none.json @@ -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, diff --git a/framework/libs/linux-bzimage/setup/src/x86/amd64_efi/relocation.rs b/framework/libs/linux-bzimage/setup/src/x86/amd64_efi/relocation.rs index c131fe699..cd884d381 100644 --- a/framework/libs/linux-bzimage/setup/src/x86/amd64_efi/relocation.rs +++ b/framework/libs/linux-bzimage/setup/src/x86/amd64_efi/relocation.rs @@ -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::() - }; + let len = unsafe { end.offset_from(start) } as usize; #[cfg(feature = "debug_print")] unsafe { use crate::console::{print_hex, print_str};