Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Codegen issue (endless recursion) with custom target and +soft-float #62852

Open
phil-opp opened this issue Jul 21, 2019 · 0 comments

Comments

@phil-opp
Copy link
Contributor

phil-opp commented Jul 21, 2019

The following function causes endless recursion and a stack overflow on our bare metal target, which uses the soft-float feature:

#[no_mangle]
pub extern "C" fn _start() -> ! {
    foo(1);

    loop {}
}

fn foo(x: isize) -> f64 {
    5 as f64 / x as f64
}

The target specification looks like this:

{
    "llvm-target": "x86_64-unknown-none",
    "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
    "arch": "x86_64",
    "target-endian": "little",
    "target-pointer-width": "64",
    "target-c-int-width": "32",
    "os": "none",
    "executables": true,
    "linker-flavor": "ld.lld",
    "linker": "rust-lld",
    "panic-strategy": "abort",
    "disable-redzone": true,
    "features": "-mmx,-sse,+soft-float"
  }

The following code is generated:

0000000000201000 <_start>:
  201000:	50                   	push   rax
  201001:	bf 01 00 00 00       	mov    edi,0x1
  201006:	e8 15 00 00 00       	call   201020 <_ZN10playground3foo17hf4a4b11a35677989E>
  […]  

0000000000201020 <_ZN10playground3foo17hf4a4b11a35677989E>:
  201020:	50                   	push   rax
  201021:	48 89 3c 24          	mov    QWORD PTR [rsp],rdi
  201025:	48 8b 3c 24          	mov    rdi,QWORD PTR [rsp]
  201029:	e8 22 00 00 00       	call   201050 <__floatdidf>
  […]

0000000000201050 <__floatdidf>:
  201050:	50                   	push   rax
  201051:	e8 fa ff ff ff       	call   201050 <__floatdidf>
  201056:	59                   	pop    rcx
  […]  

The __floatdidf function is just an endless recursion that leads to a stack overflow.

I tried debugging it on godbolt, but I don't know how to make it use a custom target. I created a small test project and documented the steps to reproduce at https://github.com/phil-opp/__floatdidf-issue.

cc @adeadman

@csmoe csmoe added the A-codegen label Jul 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.