Hi I'm trying to understand what happens here when comparing to location in memory (pointer)
fn main() -> ! {
extern "C" {
// Boundaries of the .bss section
static _ebss: u32;
static _sbss: u32;
// Boundaries of the .data section
static _edata: u32;
static _sdata: u32;
// Initial values of the .data section (stored in Flash)
static _sidata: u32;
}
let mut cons = Serial;
unsafe {
let a = &_sdata as *const u32;
let b = &_sidata as *const u32;
let c = &_sdata;
let d = &_sidata;
write!(cons, "_sdata {:p}\n", &_sdata).unwrap();
write!(cons, "_edata {:p}\n", &_edata).unwrap();
write!(cons, "_sidata {:p}\n", &_sidata).unwrap();
write!(cons, "_sbss {:p}\n", &_sbss).unwrap();
write!(cons, "_ebss {:p}\n", &_ebss).unwrap();
write!(cons, "{:?}\n", ptr::addr_of!(_sidata)).unwrap();
write!(cons, "{:?} {:?} {}\n", ptr::addr_of!(_sdata), ptr::addr_of!(_sidata), ptr::addr_of!(_sdata) == ptr::addr_of!(_sidata)).unwrap();
//write!(cons, "{:?} {:?}\n", a, b).unwrap();
write!(cons, "same1? {}\n", a == b).unwrap();
write!(cons, "same2? {}\n", ptr::eq(c, d)).unwrap();
write!(cons, "same2? {}\n", ptr::eq(&_sdata, &_sidata)).unwrap();
write!(cons, "same3? {}\n", ptr::eq(&_sdata as *const _, &_sidata as *const _)).unwrap();
}
loop { }
}
This is the output
$ qemu-system-riscv64 -nographic -machine virt -bios ./target/riscv64imac-unknown-none-elf/release/app
_sdata 0x80001740
_edata 0x80001a38
_sidata 0x80001740
_sbss 0x80001a38
_ebss 0x80001a38
0x80001740
0x80001740 0x80001740 false
same1? false
same2? false
same2? false
same3? false
If i uncomment the line: // write!(cons, "{:?} {:?}\n", a, b).unwrap(); the output change
$ qemu-system-riscv64 -nographic -machine virt -bios ./target/riscv64imac-unknown-none-elf/release/app
_sdata 0x800017e8
_edata 0x80001ae0
_sidata 0x800017e8
_sbss 0x80001ae0
_ebss 0x80001ae0
0x800017e8
0x800017e8 0x800017e8 false
0x800017e8 0x800017e8
same1? true
same2? false
same2? false
same3? false
Can someone can explain the thing ?
Thanks
-Stephane