david942j/rbelftools

Changing RPATH and interpreter

sjackman opened this issue ยท 7 comments

Hi, David. Can rbelftools be used to change the RPATH (or RUNPATH) and interpreter to a value that is a longer string than previous? I saw your example in https://github.com/david942j/rbelftools#patch that change the interpreter to a shorter string.

I'm currently using https://github.com/NixOS/patchelf for this purpose.

Hi,
for the currently implementation of rbelftools, the answer is no.
Currently the patch feature can only modify value/attribute in original ELF (i.e. the size of input ELF will not change), though it's limited, it changes the least bytes needed.

But I think it's not hard to implement a Ruby script to support this feature.

I also have checked the source of NixOS/patchelf. To have a longer interpreter name, it will change the file/memory layout of the input ELF, and make the output ELF much larger than the original one.
BTW, IMO the binary produced by patchelf is not a really 'valid' one because it's not a traditional ELF that can be produced by compilers.

Consider it a feature request then to support increasing the size of RPATH and interpreter. Thanks for your answer, David!

I would consider create another repository to do this since rbelftools is intended to be a basic ELF parsing library.

@sjackman Glad to let you know I have started to work on patchelf.rb: https://github.com/david942j/patchelf.rb
It can be used as a Ruby library so Homebrew doesn't need to communicate with shell commands.

That's excellent news! Thanks, David! I'm writing up my thesis right now, and so don't time right at the moment to port Homebrew of to your Ruby patchelf, but it's definitely on my radar!

It looks as though it's command line interface is identical to the command line patchelf, so that we could test it now as a drop-in replacement. I may give that a shot. Eventually we'll use it as a Ruby library rather than shelling out.

I have dropped a first release of patchelf.rb,
and now it can be downloaded from RubyGems.org as well.
Feel free to file an issue on patchelf.rb if you face any obstacles or bugs.

Excellent! Thanks, David. I don't have the time for this right now, but I definitely will be looking into it once I've submitted my thesis. Thanks again for this work.