Skip to content

src/test/ui/numbers-arithmetic/i128.rs causes pagefault in UEFI target #99750

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
Ayush1325 opened this issue Jul 26, 2022 · 1 comment
Closed
Labels
C-bug Category: This is a bug.

Comments

@Ayush1325
Copy link
Contributor

Hello everyone, I have been working on implementing Rust std for the UEFI target as a part of GSoC 2022. It is now finally possible to run Rust tests in UEFI using qemu and remote-test-server. While many tests fail for one reason or another, a few tests (mainly numeric ones) seem to cause different types of CPU exceptions rather than panics. So I thought it might be a good idea to open bugs for these issues.

The first one in this list is src/test/ui/numbers-arithmetic/i128.rs. After some testing, I have come up with a simpler example that produces a similar exception in UEFI:

fn main() {
    use std::hint::black_box as b;

    let z: i128 = b(1);
    assert!((-z as f64) < 0.0);
} 

The exception output is:

!!!! X64 Exception Type - 0E(#PF - Page-Fault)  CPU Apic ID - 00000000 !!!!
ExceptionData - 0000000000000000  I:0 R:0 U:0 W:0 P:0 PK:0 SS:0 SGX:0
RIP  - 000000000603DB60, CS  - 0000000000000038, RFLAGS - 0000000000000246
RAX  - 0000000000000000, RCX - FFFFFFFFFFFFFFFF, RDX - FFFFFFFFFFFFFFFF
RBX  - 0000000000000000, RSP - 0000000007EDF1D0, RBP - 0000000007EDF4C0
RSI  - 0000000007EDF360, RDI - 0000000007EDF3C0
R8   - 0000000000000000, R9  - 0000000000000038, R10 - 0000000000000000
R11  - 0000000000000000, R12 - 00000000060C6018, R13 - 0000000007EDF520
R14  - 0000000007EDF6A8, R15 - 0000000005FA9490
DS   - 0000000000000030, ES  - 0000000000000030, FS  - 0000000000000030
GS   - 0000000000000030, SS  - 0000000000000030
CR0  - 0000000080010033, CR2 - FFFFFFFFFFFFFFFF, CR3 - 0000000007C01000
CR4  - 0000000000000668, CR8 - 0000000000000000
DR0  - 0000000000000000, DR1 - 0000000000000000, DR2 - 0000000000000000
DR3  - 0000000000000000, DR6 - 00000000FFFF0FF0, DR7 - 0000000000000400
GDTR - 00000000079DE000 0000000000000047, LDTR - 0000000000000000
IDTR - 0000000007418018 0000000000000FFF,   TR - 0000000000000000
FXSAVE_STATE - 0000000007EDEE30
!!!! Find image based on IP(0x603DB60) /var/home/ayush/Documents/Programming/Rust/uefi/hello_world_std/target/x86_64-unknown-uefi/debug/deps/hello_world_std-338028f9369e2d42.pdb (ImageBase=000000000603C000, EntryPoint=000000000603D8C0) !!!!

From my testing, the exception only occurs when a few conditions are met.

  1. The binary is compiled in Debug mode. No error in Release mode.
  2. i128 is in a black_box. Does not occur if black_box is not present.
  3. It has to be i128. i64 or something else work fine.
  4. The cast has to be done on -z. Doing the same with +z is fine.

Some discussions about this issue have already taken place in the zulipchat and edk2 mailing list.

I have also attached an archive containing the Assembly, executable and .pdb file for the above example. Additionally, if anyone wants to try running the actual example/test themselves, you can use my blog post to try it out.

hello_world_std.zip

@Ayush1325 Ayush1325 added the C-bug Category: This is a bug. label Jul 26, 2022
@nicholasbishop
Copy link
Contributor

I believe this is now fixed by rust-lang/compiler-builtins#486, and the corresponding PR to update the compiler_builtins version in rust: #100380

I tested the i128/u128->f32/f64 conversions with rustc 1.65.0-nightly (75b7e52e9 2022-08-13) on x86_64-unknown-uefi and it seems to be working now.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants