<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">The install_name_tool command is one of many tools that simply rewrite load commands. They are all exactly the same except for the non-trivial matter of user interface:<div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">1) read a file,</div><div class="">2) rebuild some or all of the load-command buffer,</div><div class="">3) write out a file.</div></blockquote><div class=""><div><br class=""></div><div>They all have the same limitations in that the location of the segments in a non-relocatable image cannot be moved.</div><div><br class=""></div><div>Ideally all of the logic for doing this operation is somewhere central that’s easy to maintain and easy to reuse. Then people could work out the user interface problem of “how to specify what the tool should do” in some way that makes sense. While a tool like install_name_tool isn’t that interesting to me, a tool (or a toolkit, library, framework, ...) that rewrites all load commands is a lot more interesting. </div><div><br class=""></div><div>MDT</div><div><br class=""></div><div><br class=""></div><div><blockquote type="cite" class=""><div class="">On Oct 14, 2019, at 10:34 AM, Alexander Shaposhnikov <<a href="mailto:alexander.v.shaposhnikov@gmail.com" class="">alexander.v.shaposhnikov@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">"There are a few different approaches to implementing this, and I am not particularly tied to one.  I think that selecting the one that is in the best interest of the project and the most maintainable long term would be best"<div class=""><br class=""><div class="">- I agree.  </div><div class=""><br class=""></div><div class="">Regarding the implementation I can imagine different options here, but need to take a closer look / play with the code a little bit to see how things work. Hypothetical approaches: (A) build a standalone tool (similarly to llvm-lipo) (B) extend llvm-objcopy & add a new "driver" (similarly to how llvm-strip is implemented on top of llvm-objcopy) (in particular, llvm-install-name-tool would be a symbolic link to llvm-objcopy).  As I've mentioned above - I need to take a closer look at the code before making a decision / proposing a solution, there are different considerations on my mind here, e.g. install-name-tool appears to be simpler than objcopy is, and probably doesn't require the full power of the mutable model of an object file (implemented inside llvm-objcopy).</div></div><div class=""><br class=""></div><div class="">Kind regards,</div><div class="">Alex</div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Oct 14, 2019 at 10:21 AM Saleem Abdulrasool <<a href="mailto:compnerd@compnerd.org" class="">compnerd@compnerd.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class=""><div dir="auto" class="">Hey Michael,</div></div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">I completely agree that setting the rpath properly the first time around is much preferred.  But, changes to the binary, particularly during development is much quicker.<br class=""></div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">Prebuilt libraries which are being repackaged is one use case that is missed.<br class=""></div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">In the past, I’ve even used it to repair am incorrectly built library which was missing the library name.</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">There are a few different approaches to implementing this, and I am not particularly tied to one.  I think that selecting the one that is in the best interest of the project and the most maintainable long term would be best.</div><div class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Oct 11, 2019 at 10:12 PM Michael Trent <<a href="mailto:mtrent@apple.com" target="_blank" class="">mtrent@apple.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;" class="">Hi there,<div class=""><br class=""></div><div class="">This tool has been around for a long time. Originally it gave people a way to move a dylib to a new location without rebuilding, and then as a way to make an existing dylib embeddable (@rpath). I wonder if this tool is really necessary. It’s always better to make the dylib with the correct install name at build time, including @rpath, etc.. Most dylibs we see any more are either installed in fixed file system locations by OS vendors (i.e., Apple) or are embedded @rpath dylibs installed by everyone else. </div><div class=""><br class=""></div><div class="">Is there a use-case for install_name_tool that I have overlooked?</div><div class=""><br class=""></div><div class="">Or Is that small set of dylibs meant to be installed in fixed file system locations large / complex enough that people really need to install them in many different locations without simply relinking the files? </div><div class=""><br class=""></div><div class="">Turning to practical matters, is your intent to have the load-command rewriting code live in the tool? Or are you proposing adding support for building/swapping/rewriting Object files to libObject?</div><div class=""><br class=""></div><div class="">MDT</div></div><div style="overflow-wrap: break-word;" class=""><div class=""><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Oct 11, 2019, at 10:31 AM, Alexander Shaposhnikov <<a href="mailto:alexander.v.shaposhnikov@gmail.com" target="_blank" class="">alexander.v.shaposhnikov@gmail.com</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class=""><span style="margin:0px;padding:0px;border:0px;font-size:13px;white-space:pre-wrap" class="">Hey everyone!</span><span style="font-size:13px" class=""> </span> <div class="">Recently there has been some progress on LLVM-based tools for manipulating MachO binaries: llvm-objcopy has been gaining a lot of important bits to support MachO (it's relatively close to the point where one can implement the strip-like functionality), llvm-lipo is functional and supports most of cctools' lipo options (<a href="https://llvm.org/docs/CommandGuide/llvm-lipo.html" target="_blank" class="">https://llvm.org/docs/CommandGuide/llvm-lipo.html</a>). </div><div class="">There is another useful utility called install_name_tool (see e.g. <a href="https://www.unix.com/man-page/osx/1/install_name_tool/" target="_blank" class="">https://www.unix.com/man-page/osx/1/install_name_tool/</a> ),</div><div class="">this tool is capable of changing the rpaths, the names of the dependent shared libraries, etc. The way it works -  install-name-tool (from cctools) generates the new list of MachO load commands and the new MachO header, the other parts of the binary are copied over (in particular, if I'm not mistaken, it assumes that the new "prefix" (MachO header + load commands) fits into the binary so the offsets don't need to be recalculated, otherwise suggests to relink the binary with -headerpad / -headerpad_max_install_names / reports an error).  One possible (and simple) approach is to implement llvm-install-name-tool in a similar fashion: use libObject to parse the input binary and rebuild the list of load commands (analogously to what cctools' install_name_tool does (and with the same limitations)). I'd like to ask for your general feedback / thoughts / suggestions on contributing llvm-install-name-tool to LLVM with the goal to be a drop-in replacement for cctools' install_name_tool. </div><div class="">Thanks,</div><div class="">Alex</div></div>
</div></blockquote></div><br class=""></div></div></blockquote></div></div>-- <br class=""><div dir="ltr" class="">Saleem Abdulrasool<br class="">compnerd (at) compnerd (dot) org</div>
</blockquote></div>
</div></blockquote></div><br class=""></div></body></html>