question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extra tail instruction corrupts stack?

See original GitHub issue

Repro steps

Clone https://github.com/kerams/repro/, open Program.fs, target either net6.0 or net7.0, run in Release mode.

Expected behavior

Byte - 53, in total 1
[|146uy; 1uy; 53uy|]

Printed 10 times.

Actual behavior

This is printed the first 2 times:

Byte - 53, in total 1
[|146uy; 1uy; 0uy|]

Byte - 53, in total 1
[|146uy; 1uy; 112uy|]

Known workarounds

Remove [<Struct>] from MyResult.

OR

Put () at the end of the writeString function. The before and after diff is here. That extra tail instruction is a bit suspicious.

Related information

dotnet --info .NET SDK: Version: 7.0.100-preview.5.22307.18 Commit: bd8b088037

Runtime Environment: OS Name: Windows OS Version: 10.0.19044 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.100-preview.5.22307.18\

global.json file: Not found

Host: Version: 7.0.0-preview.5.22301.12 Architecture: x64 Commit: 425fedc0fb

.NET SDKs installed: 6.0.400-preview.22301.10 [C:\Program Files\dotnet\sdk] 7.0.100-preview.5.22307.18 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.0-preview.5.22303.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.0-preview.5.22301.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.0-preview.5.22302.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:18 (18 by maintainers)

github_iconTop GitHub Comments

2reactions
jakobbotschcommented, Jul 7, 2022

The call is passing a Span<byte> that is pointing to local stack memory. Looks like F#'s address exposure analysis is incorrect here, it should not be marking the call as tail. when it takes byrefs that might point to the local frame.

1reaction
jakobbotschcommented, Jul 21, 2022

The same argument applies, SysV ABI (used on Intel Macs) probably does not need the portable tailcall helper for the call to writeString while windows-x64 ABI does.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tail-calls corrupted when compiled with __attribute__ ...
I was working a Lisp interpreter with a 'threaded' design, where it compiles to a VM where each instruction is a C function...
Read more >
You can corrupt the stack without VLAs just fine. What else?
VLAs make it a lot easier to corrupt the stack by accident. ... Unless you stick with tail recursion but that's just a...
Read more >
Heap Corruption Follow-up: Size, Alignment, and Crashing ...
The tail-allocated size is sufficient, but the system didn't take alignment into account. The alignment boundary we need is not at the start...
Read more >
A Modern Exploration of Windows Memory Corruption ...
The classic stack overflow is the easiest memory corruption exploit ... a stack overflow exploit from hijacking EIP via the RET instruction ......
Read more >
Using a buffer overflow to call a function
When body will finish running (by executing the RET instruction), it will essentially pop the return address from the stack and jump to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found