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

Fix tail call optimisation in C++ backtrace capture #468

Merged
merged 2 commits into from
May 23, 2024
Merged

Fix tail call optimisation in C++ backtrace capture #468

merged 2 commits into from
May 23, 2024

Conversation

bamx23
Copy link
Collaborator

@bamx23 bamx23 commented May 4, 2024

According to documentation there's a __attribute__((disable_tail_calls)) attribute that should work fine for our case where we need to make sure the stacktrace has predictable number of calls at the top.

@bamx23 bamx23 requested a review from GLinnik21 May 4, 2024 12:33
Copy link
Collaborator

@GLinnik21 GLinnik21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks great! But I would make sure that this attribute is not ignored and the frames really remain.

@GLinnik21 GLinnik21 linked an issue May 4, 2024 that may be closed by this pull request
@bamx23 bamx23 force-pushed the fix-tco branch 3 times, most recently from 4aa53b8 to 7f35718 Compare May 9, 2024 21:04
@naftaly
Copy link
Contributor

naftaly commented May 9, 2024

fwiw, __asm__ __volatile__(""); should also force no tail call optimization.

@GLinnik21
Copy link
Collaborator

fwiw, __asm__ __volatile__(""); should also force no tail call optimization.

The question is which of these codes is more portable across different compilers?

@naftaly
Copy link
Contributor

naftaly commented May 9, 2024

definitely the attribute if it works.

__asm__ __volatile__("");

Hard to say really. I'd expect an attribute like that to be my first choice, but the code I shared is what I found Apple does/was-doing in CF.

Base automatically changed from release-2.0 to master May 17, 2024 14:34
@bamx23 bamx23 force-pushed the fix-tco branch 2 times, most recently from dd735d7 to e268806 Compare May 18, 2024 13:57
@bamx23
Copy link
Collaborator Author

bamx23 commented May 18, 2024

I really like the idea with __asm__ __volatile__("");. Having both this and the attribute should not harm. Thanks @naftaly!

@bamx23
Copy link
Collaborator Author

bamx23 commented May 23, 2024

Tested this PR:

Static Lib Dynamic Lib
Before Screenshot 2024-05-23 at 12 33 18 Screenshot 2024-05-23 at 12 32 41
After Screenshot 2024-05-23 at 12 34 30 Screenshot 2024-05-23 at 12 34 01

See that after the fix there's an extra frame in the stacktrace.
cc @GLinnik21

@GLinnik21
Copy link
Collaborator

GLinnik21 commented May 23, 2024

See that after the fix there's an extra frame in the stacktrace.
cc @GLinnik21

Did the frame always get deleted before this fix?

@bamx23
Copy link
Collaborator Author

bamx23 commented May 23, 2024

See that after the fix there's an extra frame in the stacktrace.
cc @GLinnik21

Did the frame always get deleted before this fix?

Yes (with Release build)

Copy link
Collaborator

@GLinnik21 GLinnik21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thank you very much!

@bamx23 bamx23 merged commit b2355d4 into master May 23, 2024
19 checks passed
@GLinnik21 GLinnik21 deleted the fix-tco branch May 23, 2024 23:14
@GLinnik21 GLinnik21 removed a link to an issue May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants