Mach-O Universal Binaries #185
-
Does libdwarf support Mach-O fat/universal objects? I'm currently resolving dwarf symbols from a mach-o object. My code works for single-objects binaries but not multi-architecture objects. If libdwarf doesn't support these yet, would you accept a patch to add support? |
Beta Was this translation helpful? Give feedback.
Replies: 22 comments 9 replies
-
libdwarf reads Mach-O and has for a year or two. Uses no MacOS libraries, just does If you correctly pass an executable path (say "x') to dwarf_init_path() Read the doc about how to let that happen (let libdwarf return the path string to you , you provide Also note If you are curious, look for DSYM_SUFFIX in libdwarf source for details. |
Beta Was this translation helpful? Give feedback.
-
Of course all I said means libdwarf reads Mach-O objects placed into Win/Mingw64 or placed in Linux So, for example, on Big-Endian Ubuntu, reads all those little endian objects correctly. And vice-versa, |
Beta Was this translation helpful? Give feedback.
-
Thank you. I have been successful reading dwarf symbols with objects that look like the following:
I don't think I observed libdwarf automatically searching for a corresponding dSYM file and ended up manually checking and appending the dSYM path. I will try looking again tomorrow. However, when I produce universal binaries that look like the following I'm unable to load dwarf symbols with either method:
I've done a cursory look through the libdwarf code and I haven't found any code that seems to deal with these universal mach-o binaries, but of course I'm not familiar with the codebase so I could have missed something. I didn't see the magic numbers for fat mach-o files in the codebase either, |
Beta Was this translation helpful? Give feedback.
-
I've not had an object files with multiple architectures in hand (that I noticed) An 'ls' command in demo.dSYM/Contents/Resources/DWARF/demo Or if you can just make a tar file with the contents of demo and all its pieces that would be great. The source in libdwarf that does the finding is src/lib/libdwarf/dwarf_object_detector.c An alternative, maybe: tell me how, with MacOS command line tools (C compiler) to |
Beta Was this translation helpful? Give feedback.
-
In the libdwarf source I mentioned notice the function |
Beta Was this translation helpful? Give feedback.
-
MH_MAGIC in dwarf_macho_loader.h and so on have the magic numbers. |
Beta Was this translation helpful? Give feedback.
-
Also note DSYM_SUFFIX in dwarf_object_detector.c , the reason libdwarf works |
Beta Was this translation helpful? Give feedback.
-
Hello, here is a tar with the demo universal executable and it's .dSYM: demo.tar.gz. I built it with The fat mach-o format should be fairly easy to add support for in theory:
Each mach-o then has a cpu type and subtype that's checked during loading. Thank you for the pointers to the code. I will look at seeing if this easy to add support for in libdwarf. |
Beta Was this translation helpful? Give feedback.
-
Regarding libdwarf automatically looking for .dSYM files, I stepped through things in a debugger and realized dwarf_object_detector_path_dSYM wasn't running since I wasn't passing a |
Beta Was this translation helpful? Give feedback.
-
"The fat mach-o format should be fairly easy to add support for in theory:" Ah. I found fat.h in the command line tools. Never had a reason to notice it. That implies opening a file one needs to indicate which part of the fat format applies Oh my. |
Beta Was this translation helpful? Give feedback.
-
I've added the FAT structs into dwarf_macho_loader..h |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for your willingness to look into this and to support this!
I have no idea what the right design decision is here 😄 Figuring out the appropriate index might require the end user to parse basic mach-o information themselves which isn't the end of the world but it could be nice to benefit from the work libdwarf already odes. Maybe a callback to let the user choose based on cpu type and cpu subtype, but that'd only be for mach-o. It would be nice if all fat binary files used similar techniques to indicate their platform but it seems they don't. An index definitely would be easier and might be the right choice. |
Beta Was this translation helpful? Give feedback.
-
For an index 0 would work just fine for non universal and universal. Given the magic numbers are well defined this seems simple to implement. I'll keep existing interfaces and when index not specified will assume zero. Even given the simple functions you mention the threads |
Beta Was this translation helpful? Give feedback.
-
Thank you so much! I have been playing around with a patch locally but there's enough involved in the mach-o loading that I think I'll have to leave it to you. I look forward to support being added for this, please let me know if there's anything I can do to help! |
Beta Was this translation helpful? Give feedback.
-
Yes, I have the correct table layout in hand. So far I'm correctly reading |
Beta Was this translation helpful? Give feedback.
-
readelfobj-code's object detector now correctly reads Mach-O universal binaries (the report In addition, small changes to the reader (made already) means reading and processing a selected object in that |
Beta Was this translation helpful? Give feedback.
-
object_detector and readobjmacho now work correctly on ordinary and universal-binary Mach-O object files. |
Beta Was this translation helpful? Give feedback.
-
In spite of the inadequate output readobjmacho and object_detector print The value zero for the New libdwarf functions dwarf_init_path_a() and dwarf_init_path_dl_a() |
Beta Was this translation helpful? Give feedback.
-
Libdwarf now deals with universal binaries properly. I expect to merge into main and push to github today. |
Beta Was this translation helpful? Give feedback.
-
Documentation has been updated and is on prevanders Happy Friday! |
Beta Was this translation helpful? Give feedback.
-
I'm giving the tries a test locally. I was trying to load a dsym object directly (file reports it's a mach-o dSYM companion file), which previously worked but now I'm getting a Something minor that caught my eye while looking through the changes: Should this comment be updated or moved down? libdwarf-code/src/lib/libdwarf/dwarf_generic_init.c Lines 127 to 137 in 7b3fdd2 |
Beta Was this translation helpful? Give feedback.
-
Sometimes it can be useful to download and build the readelfobj-code project I am altering that comment to read 2023. The old comment is irrelevant and misplaced. |
Beta Was this translation helpful? Give feedback.
Sometimes it can be useful to download and build the readelfobj-code project
and try object_detector and readobmacho on the object because there
it reports issues instantly in some detail. If there are any actual issues
in the object file. Sounds now like that's not necessary.
I am altering that comment to read 2023. The old comment is irrelevant and misplaced.