You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Upgrade to LLVM 12 caused AArch64 bare metal program run incorrectly #83335
I'm not saying the errors about feature gates that compiler throwing, I fixed that. And it complied successfully, but run incorrectly.
The correct behaviour of the leos-kernel in the project is like this:
But when using nightly-2021-03-05 version rustc, the kernel prints nothing. And I believe it's not related to those feature gates or the restriction of naked function, because my own os kernel project without these features has the same situation.
@songzhi for us to frame the issue, we need a way to reproduce it, ideally with a small piece of code (possibly without external libraries) that shows the incorrect behaviour you described.
Also, can you report if you can reproduce on other toolchains (example beta and stable)?
#![no_std]#![no_main]#![feature(global_asm)]#![feature(asm)]use core::ptr;global_asm!(r#".section .text.boot.globl _start_start: # read cpu affinity, start core 0, halt rest mrs x19, mpidr_el1 and x19, x19, #3 # compare and branch if non zero cbnz x19, halt adrp x0, _start sub x0, x0, x19, lsl #16 mov sp, x0 b main_starthalt: # unreachable wfe b halt"#);constUART_BASE:usize = 0x0900_0000;#[inline]fnhalt(){unsafe{asm!("wfi", options(nomem, nostack))}}#[inline]fnwfe(){unsafe{asm!("wfe", options(nomem, nostack))}}#[panic_handler]fnpanic(_:&core::panic::PanicInfo) -> ! {loop{wfe();}}extern"C"{fn_start();}#[no_mangle]pubunsafeextern"C"fnmain_start(){let x = _start asusize;// just used to prevent `x` is optimized.
ptr::write_volatile(UART_BASEas*mutu8,(x % 10 + '0'asusize)asu8);halt();}
Here's the difference of generated assembly code (based on generated ELF file), comparing nightly-2021-03-04 version to nightly-2021-03-05 version.
Actually QEMU load the kernel binary at address 0x40080000, so the adrp x8, ffff000040080000 <_start> is actually adrp x8, 40080000, then the _start we got is 0x40080000. But in later version of rustc, the _start is 0xFFFF000040080000. In this specific case, the former value is considered correct.
It's a breaking change, but I don't know if it could be considered as a bug. Maybe this usage could be considered as a undefined behaviour? I don't know what do you think about it.
My own OS kernel still runs incorrectly, I'll keep digging to find out if it related to rustc, if not I'll close this issue.
The problem is, in the nightly-2021-03-05 version code, the data_block and data_block2 pointer we got are both nullptr.
I don't know why such code is generated, but it seems like a real bug?
Here's another example.
Hey LLVM ICE-breakers! This bug has been identified as a good
"LLVM ICE-breaking candidate". In case it's useful, here are some instructions for tackling these sorts of bugs. Maybe take a look?
Thanks! <3
@jyn514 The second case is pretty common, maybe we want to initialize the data_block2, since we get a null pointer, it's not possible. In my OS kernel, I allocate and operate some pagetables like this, it's inspired by rCore.
I'm not yet sure if its a genuine bug (probably is) that we ignore the relocation-model, but I think on the user's end this could also be fixed by adjusting their linker script to correctly handle the .got section.
Activity
jyn514 commentedon Mar 21, 2021
Can you describe what you mean by "incorrectly "?
songzhi commentedon Mar 21, 2021
I'm not saying the errors about feature gates that compiler throwing, I fixed that. And it complied successfully, but run incorrectly.
The correct behaviour of the leos-kernel in the project is like this:
But when using
nightly-2021-03-05version rustc, the kernel prints nothing. And I believe it's not related to those feature gates or the restriction of naked function, because my own os kernel project without these features has the same situation.apiraino commentedon Mar 21, 2021
@songzhi for us to frame the issue, we need a way to reproduce it, ideally with a small piece of code (possibly without external libraries) that shows the incorrect behaviour you described.
Also, can you report if you can reproduce on other toolchains (example beta and stable)?
songzhi commentedon Mar 21, 2021
I just found why. Here's the minimal reproducible code:
Here's the difference of generated assembly code (based on generated ELF file), comparing
nightly-2021-03-04version tonightly-2021-03-05version.Actually QEMU load the kernel binary at address
0x40080000, so theadrp x8, ffff000040080000 <_start>is actuallyadrp x8, 40080000, then the_startwe got is0x40080000. But in later version of rustc, the_startis0xFFFF000040080000. In this specific case, the former value is considered correct.It's a breaking change, but I don't know if it could be considered as a bug. Maybe this usage could be considered as a undefined behaviour? I don't know what do you think about it.
My own OS kernel still runs incorrectly, I'll keep digging to find out if it related to rustc, if not I'll close this issue.
songzhi commentedon Mar 21, 2021
Just found another, emmm, bug? Here's the code, using
qemu-system-aarch64 -M virt -kernel $(kernel)to run it:Generated assembly code difference, comparing
nightly-2021-03-04tonightly-2021-03-05:The problem is, in the
nightly-2021-03-05version code, thedata_blockanddata_block2pointer we got are bothnullptr.I don't know why such code is generated, but it seems like a real bug?
Here's another example.
jyn514 commentedon Mar 21, 2021
@rustbot ping llvm
I don't know assembly well enough to see if this is a real bug or not - it would be helpful to figure out what the expected behavior is.
rustbot commentedon Mar 21, 2021
Hey LLVM ICE-breakers! This bug has been identified as a good
"LLVM ICE-breaking candidate". In case it's useful, here are some
instructions for tackling these sorts of bugs. Maybe take a look?
Thanks! <3
cc @camelid @comex @cuviper @DutchGhost @hdhoang @henryboisdequin @heyrutvik @higuoxing @JOE1994 @jryans @mmilenko @nagisa @nikic @Noah-Kennedy @SiavoshZarrasvand @spastorino @vertexclique
songzhi commentedon Mar 21, 2021
@jyn514 The second case is pretty common, maybe we want to initialize the data_block2, since we get a null pointer, it's not possible. In my OS kernel, I allocate and operate some pagetables like this, it's inspired by rCore.
nagisa commentedon Mar 21, 2021
Looks like with the new version the binary generated uses
picrelocation model, and attempts to specify different relocation models get ignored.Here's a more minimal reproducer:
I'm not yet sure if its a genuine bug (probably is) that we ignore the
relocation-model, but I think on the user's end this could also be fixed by adjusting their linker script to correctly handle the.gotsection.11 remaining items
apiraino commentedon Mar 31, 2021
Removing
I-prioritize, PR is on the way (Zulip thread)@rustbot label -I-prioritize
Manually set dso_local when its valid to do so
Auto merge of rust-lang#83592 - nagisa:nagisa/dso_local, r=davidtwco