llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[CSKY] segmentation fault in `__multi3`

Open Dirreke opened this issue 3 years ago • 13 comments

I have written a toolchain for csky in Rust at https://github.com/rust-lang/rust/pull/113658 before.

However, when I run a simple Rust program with u128, like this

fn main() {
    let a = 0x12345678876543219876543223456789_u128;
    println!("{a}");
}

I can compile the program successfully. However, I got a segmentation fault when I run it. It seems that -mdouble-float is not enabled. So can anyone will help to add this feature? or guide me add it?

(I'm not sure if I'm right about the above Issue, if anyone have any idea, please fell free to tell me. Thanks!)


@benshi001 @zixuan-wu I noticed that you two provide many commits to csky, so I want to know if you can give me some advice? Thanks.

Besides, contact to me If I could add your WeChat. My email is [email protected] . Thanks!

Dirreke avatar Oct 13 '23 09:10 Dirreke

Double float is not support in CSKY target. The segmentation fault is agnostic in such high level view and can't know the exact issue.

zixuan-wu avatar Oct 16 '23 02:10 zixuan-wu

I have written a toolchain for csky in Rust at rust-lang/libc#3301 before.

However, when I run a simple Rust program with u128, like this

fn main() {
    let a = 0x12345678876543219876543223456789_u128;
    println!("{a}");
}

I got a segmentation fault. It seems that -mdouble-float is not enabled. So can anyone will help to add this feature? or guide me add it?

(I'm not sure if I'm right about the above Issue, if anyone have any idea, please fell free to tell me. Thanks!)

@benshi001 @zixuan-wu I noticed that you two provide many commits to csky, so I want to know if you can give me some advice? Thanks.

Besides, contact to me If I could add your WeChat. My email is [email protected] . Thanks!

Could you please offer an .ll file and the command line options of llc ? I am not familiar with rust.

benshi001 avatar Oct 16 '23 02:10 benshi001

Could you please offer an .ll file and the command line options of llc ? I am not familiar with rust.

Yeah, I can offer a .ll file. However, It has 714 lines and I have no idea about how to make a MCVE, because I have little experience about low-level debugging.

float_cal-e4847f7eee567be8.txt

and I think using llc without any options is enough.

./llc float_cal-e4847f7eee567be8.ll

Dirreke avatar Oct 16 '23 05:10 Dirreke

Could you please offer an .ll file and the command line options of llc ? I am not familiar with rust.

Yeah, I can offer a .ll file. However, It has 714 lines and I have no idea about how to make a MCVE, because I have little experience about low-level debugging.

float_cal-e4847f7eee567be8.txt

and I think using llc without any options is enough.

./llc float_cal-e4847f7eee567be8.ll

I think it's about int128 type. It looks like a int128 num is split into 4 int32 nums in backend and to load/store with 4 times load/store in sequence. So there is no issue as I go through the .ll roughly and the seg fault may not be related to int128.

zixuan-wu avatar Oct 17 '23 09:10 zixuan-wu

I did some research on the executable file. I debug it with gdb, and I got seg fault in __multi3.

the following is the position where it crash and the registers before it crash. mmexport1697537599959.jpg

would it help?


Could you give me some direction on why it got seg fault?

Thanks!

Dirreke avatar Oct 17 '23 10:10 Dirreke

I did some research on the executable file. I debug it with gdb, and I got seg fault in __multi3.

the following is the position where it crash and the registers before it crash. mmexport1697537599959.jpg

would it help?

Could you give me some direction on why it got seg fault?

Thanks!

From your info, it triggered by loading from address( r1 + 0x8 )which is 0x23456789 + 0x8. You can check this address and see whether it's a legal address such as data or bss section.

And normally there is little possibility error occurred in __multi3 library, and it's more likely the argument passed into __multi3 got wrong.

zixuan-wu avatar Oct 18 '23 02:10 zixuan-wu

which is 0x23456789 + 0x8.

Thanks , It's what I confused. It seems that 0x23456789 is not an address, it's a part of my u128 value(which is 0x12345678876543212345678998765432)

fn main() {
    let a = 0x12345678876543219876543223456789_u128;
    println!("{a}");
}

Should my next step be to find out why 0x23456789 give to r1?

Dirreke avatar Oct 18 '23 06:10 Dirreke

which is 0x23456789 + 0x8.

Thanks , It's what I confused. It seems that 0x23456789 is not an address, it's a part of my u128 value(which is 0x12345678876543212345678998765432)

fn main() {
    let a = 0x12345678876543219876543223456789_u128;
    println!("{a}");
}

Should my next step be to find out why 0x23456789 give to r1?

Right. Normally r0,r1 consist of first argument of __multi3 because the first argument is i64 type.

zixuan-wu avatar Oct 20 '23 03:10 zixuan-wu

@EugeneZelenko Could you help to chage the label

Dirreke avatar Oct 22 '23 14:10 Dirreke

@Dirreke: To which one(s)?

EugeneZelenko avatar Oct 22 '23 15:10 EugeneZelenko

@Dirreke: To which one(s)?

Thanks! I guess it might be backend:CSKY and bug?

Dirreke avatar Oct 22 '23 16:10 Dirreke

Thanks! After some tests, I think #68971 is different from #21245 . I can not simply disable UINTTOFP_I128_FXX like __multi3 easily.

When program call the u128 related builtin functions like __multi3 and __floattidf on CSKY, the value of the parameters will be passed to the function, but the function will regard it as an address. It result a SIGSEGV.

I have no idea about how to fix it. Could you give me some advice? @zixuan-wu @benshi001

Dirreke avatar Oct 23 '23 10:10 Dirreke

there's nothing to do. It's error in codegen of rust. thank all of you

Dirreke avatar Oct 25 '23 05:10 Dirreke