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

Closed
jrmuizel opened this issue Apr 16, 2018 · 15 comments
Closed

Support reading in object files for executables on macOS #87

jrmuizel opened this issue Apr 16, 2018 · 15 comments

Comments

@jrmuizel
Copy link

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

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

@philipc
Copy link
Contributor

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

@mstange

@mstange
Copy link
Contributor

mstange commented Apr 26, 2018

That's a great idea!

@philipc
Copy link
Contributor

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 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 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 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 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.

@luser
Copy link

luser commented Sep 13, 2021

This got a fully-fleshed-out implementation in the fix-stacks binary:
https://github.com/mozilla/fix-stacks/blob/c30daaef43bd15486fba189b06487aa24dad3492/src/main.rs#L433-L502

@mstange
Copy link
Contributor

mstange commented Sep 13, 2021

object now exposes these references in Object::object_map. That's what I use in profiler-get-symbols: https://github.com/mstange/profiler-get-symbols/blob/3c315ba523e2c876e3de493ba36ef9fc0d01affa/lib/src/macho.rs#L317-L319

@philipc
Copy link
Contributor

philipc commented Sep 13, 2021

backtrace-rs implemented this in rust-lang/backtrace-rs#377. This needs to be handled at a higher level than the addr2line API, so closing this issue.

@philipc philipc closed this as completed Sep 13, 2021
@mstange
Copy link
Contributor

mstange commented Sep 13, 2021

@jrmuizel Did you file this issue about the addr2line crate API or about the addr2line CLI example in this repo?

@philipc
Copy link
Contributor

philipc commented Sep 13, 2021

Ah sure, that probably isn't too hard to do (rough version at philipc@65f2154). I don't currently have a macOS system to develop on though.

@philipc philipc reopened this Sep 13, 2021
@philipc
Copy link
Contributor

philipc commented Apr 12, 2024

I think https://github.com/mstange/samply/tree/main/wholesym-addr2line supports this, so hoping that is sufficient now.

@philipc philipc closed this as completed Apr 12, 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

No branches or pull requests

4 participants