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

OSX support #2

Open
gilescope opened this issue Jun 25, 2018 · 8 comments
Open

OSX support #2

gilescope opened this issue Jun 25, 2018 · 8 comments

Comments

@gilescope
Copy link

I've had a look at some of the alternatives of doing a stack walk on stack overflow and I want to try and see if I can use unwind-rs to achieve this.

Is anyone working on OSX support? Also for object loading should we use object crate or findshlibs - to my untrained eye they seem to do similar things.

I'm probably biting off more than I can chew, but rust has made me a bit more adventurous... any help / pointers on what I need to do to get it working on OSX much appreciated!

@philipc
Copy link
Contributor

philipc commented Jun 26, 2018

I haven't looked into this much, but I think that for unwinding you need to use something like findshlibs to find the call frame information that is already loaded into memory when the program is executed.

The object crate is useful for loading the DWARF debug info from the file for use in symbolication, but that's all already done by the addr2line crate (this is same as the hardliner crate in this git repo, which needs to be replaced with addr2line).

@main--
Copy link
Collaborator

main-- commented Jun 26, 2018

Is anyone working on OSX support? Also for object loading should we use object crate or findshlibs - to my untrained eye they seem to do similar things.

As @philipc said findshlibs and this unwinder implementation read the in-memory call frame information of a running process (which is also subject to relocations etc) whereas the object crate reads information from a binary object (on disk).

findshlibs explicitly supports OSX, but I haven't gotten around to implementing this in unwind-rs. You would have to replace the implementation in find_cfi.rs with calls to findshlibs. The actual unwinding should ideally "just work", the code should be able to unwind any x86_64 SysV compatible platform - worst case you would need to adjust a few register mappings.

That being said, this crate is quite immature and not very well-tested so you may be better off with a libunwind-based solution like the unwind crate on crates.io (despite sharing the name, this is a different crate!).

@gilescope
Copy link
Author

gilescope commented Jul 2, 2018 via email

@gilescope
Copy link
Author

Still chipping away. I believe I have EhFrames now which is great. I can’t figure out where or if EhFrameHdr exist in mach-o? @fitzgen can you tell me, because the EhFrameHdr doesn’t look like a loader header. I’ve done macho-viewer on some execs and can’t see a __eh_frame_hdr or some such section either. Should I make EhFrameHdr optional? Or is it essential and I am just not looking in the right place for it?

@gilescope
Copy link
Author

Finally found some decent documentation on eh_frame_hdr:
https://www.airs.com/blog/archives/462 and on eh_frame https://www.airs.com/blog/archives/460

I suspect we're not creating it by default on OS-X, but if its not added into the exec by the linker then there's nothing to stop us creating it at runtime. Just a speedbump...

@fitzgen
Copy link
Member

fitzgen commented Jul 13, 2018

@gilescope I don't believe that osx uses eh_frame_hdr. IIRC, it does have its own fast-path unwind section. I would recommend making eh_frame_hdr optional for now, and then look into the osx specific fast path stuff later.

@gilescope
Copy link
Author

Ah yes the __unwind_info section with compact unwinding. For stacktracing when a stack overflow happens, performance isn't number one priority :-) . I will have a look - it looks like I've got all the pieces to manufacture a eh_frame_hdr from the FDEs so I'm going to shoot for the moon and try that. If that doesn't work then optional it is.

@gilescope
Copy link
Author

Progress! I have a list of stack frames on OS-X :-) . That's as far as the unwinder is supposed to go. I'm going to try create an example using addr2line to dump the current stacktrace so that I can see if the addresses makes sense. The correctness test passes, but I note that under the hood backtrace::Backtrace::new_unresolved() goes to the unwind shim so it's helpful but it's not comparing against a completely different mechanism.

@bjorn3 bjorn3 mentioned this issue Apr 27, 2019
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 a pull request may close this issue.

4 participants