`machocopy` example
Hi, we're trying to reimplement patchelf and install_name_tool with object and at least for patchelf it seems quite straightforward with the elfcopy example :)
For install_name_tool I seem to miss a way to add load_commands to the writer. Reading the MachO file works well (we're mostly interested in patching / changing the rpath to something relative), and I can read the rpath nicely.
I was wondering if you have a quick tip on how to achieve this.
There isn't a way to write MachO executables yet, so there's no machocopy. We need to add the equivalent of write::elf::Writer for MachO. This isn't a small task.
Thanks for the hint!
Do you think there is a shortcut if all we want is to rewrite an rpath in the MachO file? We're happy to contribute.
Also if you can give me any hints on how to start this endeavor, that would be cool.
If I understand correctly, rewriting the rpath is conceptually simple: you just want to change the string in the load command for LC_RPATH. The catch is that doing so may change the file offsets of other data, so you still need to parse some of the other load commands and fix the file offsets if needed.
src/write/macho.rs already has code for writing some parts of a Mach-O file. Ideally some of that code would be moved into a write::macho::Writer that can be used by both write::Object and your utility. However, starting with something that only meets your needs would be fine, and write::Object can be migrated later.
I would start by implementing something that treats all of the load commands as opaque blocks, and then progressively add support for the load commands that need further parsing.