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

Support reading in object files for executables on macOS #87

Open
jrmuizel opened this issue Apr 16, 2018 · 9 comments
Open

Support reading in object files for executables on macOS #87

jrmuizel opened this issue Apr 16, 2018 · 9 comments

Comments

@jrmuizel
Copy link

@jrmuizel jrmuizel commented Apr 16, 2018

By default, the linker doesn't include debug info into the resulting executable. It's either left in the .o files or put in a dsym file. In the situation where it's left in the .o files there are OSO stabs entries that give the paths of the .o files. We should read those in as needed to resolve the addresses.

@jrmuizel
Copy link
Author

@jrmuizel jrmuizel commented Apr 25, 2018

There's some code to do this at https://github.com/mstange/profiler-dwarf-lookup

@philipc
Copy link
Contributor

@philipc philipc commented Apr 26, 2018

Do you think it makes sense to add something to the object crate that performs the task of Resolver in that code? I'd probably make it return Vec<(file_name, Vec<Symbol>)> (or a similar iterator) and let the caller figure out which symbols contain the addresses they want.

@jrmuizel
Copy link
Author

@jrmuizel jrmuizel commented Apr 26, 2018

@mstange
Copy link
Contributor

@mstange mstange commented Apr 26, 2018

That's a great idea!

@philipc
Copy link
Contributor

@philipc philipc commented May 1, 2018

@mstange I noticed a couple of differences in how LLVM parses the symbol entries in MachODebugMapParser:

  • It uses N_FUN with null names to terminate functions, instead of waiting for the next N_FUN with a name. It looks like using the terminating N_FUN is better because it gives the function size.
  • It doesn't handle N_SO. Did you encounter a case where the N_SO handling is required?
@mstange
Copy link
Contributor

@mstange mstange commented May 2, 2018

Oh, the terminating N_FUN comes with the size! I didn't realize that, that's great!

I did not encounter a case where N_SO handling is required. I think all N_FUN symbols are always between an N_OSO and a terminating N_SO, so we might as well treat the N_OSO as the separator and ignore the section terminator.

One important thing that the current profiler-dwarf-lookup code doesn't handle is OSOs that point to archive files: For example, you can have an OSO symbol with the string /Users/mstange/code/obj-m-opt/toolkit/library/../../js/src/build/libjs_static.a(JSAtom.o). Then you need to load libjs_static.a as a goblin::archive::Archive and extract the member with the name /Users/mstange/code/obj-m-opt/toolkit/library/../../js/src/build/libjs_static.a(JSAtom.o). This probably requires a change to your proposed API in order to be represented properly.

@philipc
Copy link
Contributor

@philipc philipc commented May 4, 2018

It's either left in the .o files or put in a dsym file. In the situation where it's left in the .o files there are OSO stabs entries that give the paths of the .o files.

I don't know much about macOS, but it appears that the OSO entries are what dsymutil uses. Can you run dsymutil to get a dsym and use that instead? Using the .o files seems like a niche use case.

@jrmuizel
Copy link
Author

@jrmuizel jrmuizel commented May 4, 2018

Running dsymutil is pretty time consuming (see rust-lang/rust#47240) so it's nice to avoid it if at all possible. Further, most tools (lldb, gdb, nm, Instruments, ...) on macOS support using the OSO entries directly without needed a dsym file.

@philipc
Copy link
Contributor

@philipc philipc commented May 10, 2018

My current thinking is to change object::SymbolMap to also include the object file name. I've done some work to start on that here, but it might be a while before I get to do the corresponding addr2line changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.