Closed nick96 closed 2 years ago
Would you be open to a PR changing FatArch::get
to something to the effect of:
enum FatEntry<'a> {
MachO(MachO(<'a>)),
Archive(Archive(<'a>)),
}
pub fn get(&self, index: usize) -> error::Result<FatEntry<'a>>
Hello!
I've been try to write a little toy linker for MacOS using goblin. So far it has been a great experience and thanks for all the hard work you've put in the library!
Nice! I actually began writing a linker many moons ago, but never finished (I wanted to write something like lld or mold, a cross platform linker, because it's kind of weird they didn't exist before); in any event, it's why all the Pwrite impls got added to all the structs (that and the dead https://github.com/m4b/faerie , an object file writer), so I'm glad it ended up being useful for someone!
If you ever get a chance to open source it, i'd love to see what you ended up with! Please let me know if you ever end up doing that :)
they both handle archives being present in fat mach-o binaries so I guess it's a thing
Yes, if you invoke lipo
with archives of different arches this is supported afaik, I just believe it's not implemented in goblin :)
So yes, I would definitely love to see something like this added! The tricky part, if any, would be if we can do backwards compat (doubtful, since if there are variants involved we didn't mark them non exhaustive), and secondly, if we can't do backwards compat, make the api changes as painless as possible, would be the only guiding principles here.
This would end up in the 0.6 release, which I usually like to roll up other breaking changes with, if you don't mind waiting a bit.
Okay cool! I'll take a look at adding it. Yeah, I don't think it can be a backwards compatible change because MachO
is a struct, not an enum. I guess it'd be possible to create another method and leave MultiArch::get
alone but that would create a quick confusing API.
I've been try to write a little toy linker for MacOS using goblin. So far it has been a great experience and thanks for all the hard work you've put in the library! It has helped me learn a lot about the different formats I'm trying to work with. I am running into a bit of an issue with fat Mach-o binaries though. When I try to get the arch specific binary out of the container it fails with
Invalid magic number: 0x213c6172
. From having a look around0x213c6172
is the magic number for archive files, and when I runfile
it says that each entry is an archive file:I can't find any documentation that corroborates this but looking at the
lld
andmold
linkers, they both handle archives being present in fat mach-o binaries so I guess it's a thing.I put together a little example of failing to extract entries:
When I pass
/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/lib/darwin/libclang_rt.osx.a
to the resulting binary I get: