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

Add proper CFI and other inline assembly cleanups #38

Closed
wants to merge 1 commit into from

Conversation

Amanieu
Copy link
Collaborator

@Amanieu Amanieu commented Sep 1, 2016

The most significant change is that all of the inline asm for x86 and x86_64 now has proper CFI annotations, which allows gdb to produce a correct backtrace even if the program is interrupted in the middle of a swap operations.

I didn't do this for the OR1K code because I am not familiar with the instruction set and don't have any way of testing the resulting code.

I've also added a few cleanups for the inline asm clobbers.

# Call the provided function.
call *8(%esp)
call *%ebp
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes the data flow even more complicated with no benefit that I can see.

@whitequark
Copy link
Contributor

@Amanieu Also, looks like you broke OS X. This is likely related to the DWARF encoding, I suggest looking with objdump --dwarf=frames to see which encodings are generated.

@Amanieu
Copy link
Collaborator Author

Amanieu commented Sep 2, 2016

I've addressed all the comments. I tested both x86 and x86_64 on Linux, but I haven't been able to test on OS X apart from the tests run by travis.

@@ -98,7 +140,8 @@ pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackP
let mut sp = StackPointer(stack.base() as *mut usize);
push(&mut sp, 0xdead0cfa); // CFA slot
push(&mut sp, f as usize); // function
push(&mut sp, trampoline_1 as usize);
push(&mut sp, trampoline_1 as usize + 2); // skip the 2 nops
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment here explaining that we set up the stack as-if the first trampoline has already execited.

# never actually executed.
nop

# Stack unwinding in OSX doesn't seem to like 1-byte symbols, so we add
Copy link
Contributor

Choose a reason for hiding this comment

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

s/OSX/libunwind/, since I believe this will affect anyone using libunwind (like ARTIQ)

@whitequark
Copy link
Contributor

LGTM pending inline comments and or1k port.

@Amanieu
Copy link
Collaborator Author

Amanieu commented Sep 3, 2016

I've fixed the comments. I think the or1k port is best left to a separate PR for now.

@whitequark
Copy link
Contributor

@Amanieu is there a problem with it?

@Amanieu
Copy link
Collaborator Author

Amanieu commented Sep 3, 2016

Not really, it's just that it's hard to make sure I don't accidentally break it if I have no way of testing it.

@whitequark
Copy link
Contributor

Just tell me once you have something and I'll test (and fix if something is broken).

@Amanieu
Copy link
Collaborator Author

Amanieu commented Sep 3, 2016

I reworked the trampoline code so that it is compatible with frame pointer-based unwinding. I personally feel that this approach is superior to #44 since it preserves the guarantee that a backtrace can be correctly generated at all instruction boundaries.

@Amanieu
Copy link
Collaborator Author

Amanieu commented Sep 7, 2016

This is now covered by #49.

@Amanieu Amanieu closed this Sep 7, 2016
@Amanieu
Copy link
Collaborator Author

Amanieu commented Sep 7, 2016

I'm reopening this since it seems that the approach in #44 is broken. You actually do need 2 trampolines.

@Amanieu Amanieu reopened this Sep 7, 2016
This ensures that gdb is able to generate a correct backtrace when
stopped at any instruction in the inline asm.

It also makes backtraces accessible to tools that only track frame
pointer chains, like perf or dtrace.
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.

None yet

2 participants