Coder Social home page Coder Social logo

Comments (7)

dmilith avatar dmilith commented on June 7, 2024

I tried changing "elf.h" to sys/elf.h, but same issue happens. There's no way to set back rpath which is longer than current one.

ng0# cp /Software/Git/bin/git /tmp/git
ng0# ldd /tmp/git
/tmp/git:
    libz.so.1 => /Software/Git/lib/libz.so.1 (0x800948000)
    libiconv.so.3 => /Software/Git/lib/libiconv.so.3 (0x800b5c000)
    libcrypto.so.1.0.0 => /Software/Git/lib/libcrypto.so.1.0.0 (0x800e57000)
    libthr.so.3 => /lib/libthr.so.3 (0x801233000)
    libc.so.7 => /lib/libc.so.7 (0x801456000)
ng0# ./patchelf --debug --set-rpath /Software /tmp/git
patching ELF file `/tmp/git'
new rpath is `/Software'
ng0# ./patchelf --debug --set-rpath /Software/Git/lib /tmp/git
patching ELF file `/tmp/git'
new rpath is `/Software/Git/lib'
rpath is too long, resizing...
replacing section `.dynstr' with size 4410
this is an executable
using replaced section `.dynstr'
last replaced is 6
looking at section `.interp'
replacing section `.interp' which is in the way
looking at section `.note.ABI-tag'
replacing section `.note.ABI-tag' which is in the way
looking at section `.hash'
replacing section `.hash' which is in the way
looking at section `.gnu.hash'
replacing section `.gnu.hash' which is in the way
looking at section `.dynsym'
replacing section `.dynsym' which is in the way
looking at section `.dynstr'
first reserved offset/addr is 0x4200/0x404200
first page is 0x400000
needed space is 16920
needed space is 16976
needed pages is 1
changing alignment of program header 2 from 2097152 to 4096
changing alignment of program header 3 from 2097152 to 4096
clearing first 20424 bytes
rewriting section `.dynstr' from offset 0x40d8 (size 4392) to offset 0x238 (size 4410)
rewriting section `.dynsym' from offset 0x2080 (size 8280) to offset 0x1378 (size 8280)
rewriting section `.gnu.hash' from offset 0x1bb8 (size 1220) to offset 0x33d0 (size 1220)
rewriting section `.hash' from offset 0x1230 (size 2440) to offset 0x3898 (size 2440)
rewriting section `.interp' from offset 0x1200 (size 21) to offset 0x4220 (size 21)
rewriting section `.note.ABI-tag' from offset 0x1218 (size 24) to offset 0x4238 (size 24)
rewriting symbol table section 2
ng0# ldd /tmp/git
/tmp/git:
ldd: /tmp/git: Exec format error
/tmp/git: exit status 1
ng0#

from patchelf.

dmilith avatar dmilith commented on June 7, 2024

I also tried to patch unstripped binary. Still shows zsh: exec format error: /tmp/tig, although nm shows full list of symbols.

from patchelf.

dmilith avatar dmilith commented on June 7, 2024

After patch (shorter rpath). Readelf info:

ng0#  readelf -d /tmp/tig

Dynamic section at offset 0x1ff90 contains 25 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libiconv.so.3]
 0x0000000000000001 (NEEDED)             Shared library: [libncursesw.so.8]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.7]
 0x000000000000000f (RPATH)              Library rpath: [/Software/Tig/lib]
 0x000000000000001d (RUNPATH)            Library runpath: [/Software/Tig/lib]
 0x000000000000000c (INIT)               0x402438
 0x000000000000000d (FINI)               0x4171c4
 0x0000000000000004 (HASH)               0x400370
 0x000000006ffffef5 (GNU_HASH)           0x400328
 0x0000000000000005 (STRTAB)             0x3ff238
 0x0000000000000006 (SYMTAB)             0x3ff6c8
 0x000000000000000a (STRSZ)              1162 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000015 (DEBUG)              0x0
 0x0000000000000003 (PLTGOT)             0x61f1d8
 0x0000000000000002 (PLTRELSZ)           2640 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x4019e8
 0x0000000000000007 (RELA)               0x4018b0
 0x0000000000000008 (RELASZ)             312 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x000000006ffffffe (VERNEED)            0x401880
 0x000000006fffffff (VERNEEDNUM)         1
 0x000000006ffffff0 (VERSYM)             0x401778
 0x0000000000000000 (NULL)               0x0

So the RPATH was correctly set back to /Software/Tig/lib .. so that worked. Interesting..

from patchelf.

dmilith avatar dmilith commented on June 7, 2024

What's even more interesting.. If I also set interpreter, tig is working:

ng0# patchelf --debug --set-rpath /Software/Tig/lib --set-interpreter /libexec/ld-elf.so.1 /tmp/tig
patching ELF file `/tmp/tig'
new rpath is `/Software/Tig/lib'
rpath is too long, resizing...
replacing section `.dynstr' with size 1180
replacing section `.interp' with size 21
this is an executable
using replaced section `.dynstr'
using replaced section `.interp'
last replaced is 2
looking at section `.dynstr'
looking at section `.interp'
first reserved offset/addr is 0x738/0x3fd738
first page is 0x3fd000
needed space is 1888
needed space is 1944
needed pages is 1
clearing first 5208 bytes
rewriting section `.dynstr' from offset 0x12a8 (size 1162) to offset 0x2e0 (size 1180)
rewriting section `.interp' from offset 0x1738 (size 21) to offset 0x780 (size 21)
rewriting symbol table section 3
rewriting symbol table section 29
ng0# /tmp/tig
tig: Not a git repository

from patchelf.

darealshinji avatar darealshinji commented on June 7, 2024

Does the version from the ports work?

from patchelf.

dmilith avatar dmilith commented on June 7, 2024

I have no idea, didn't use ports.

from patchelf.

Peter2121 avatar Peter2121 commented on June 7, 2024

The same problem with 0.9 version and ports version (both tested).
BTW, is FreeBSD binaries patching supported?
Trying to patch mc built from ports:

patchelf --set-rpath /usr/ports/
misc/mc/work/stage/usr/local/lib --set-interpreter /libexec/ld-elf.so.1 --debug mc
patching ELF file mc' new rpath is/usr/ports/misc/mc/work/stage/usr/local/lib'
rpath is too long, resizing...
DT_NULL index is 27
replacing section .dynamic' with size 544 replacing section.dynstr' with size 12186
replacing section .interp' with size 21 this is an executable using replaced section.interp'
using replaced section .dynstr' using replaced section.dynamic'
last replaced is 22
looking at section .interp' looking at section.note.tag'
replacing section .note.tag' which is in the way looking at section.hash'
replacing section .hash' which is in the way looking at section.gnu.hash'
replacing section .gnu.hash' which is in the way looking at section.dynsym'
replacing section .dynsym' which is in the way looking at section.dynstr'
looking at section .gnu.version' first reserved offset/addr is 0x9a4e/0x409a4e first page is 0x400000 needed space is 40096 needed space is 40152 needed pages is 1 changing alignment of program header 2 from 2097152 to 4096 changing alignment of program header 3 from 2097152 to 4096 clearing first 43030 bytes rewriting section.dynamic' from offset 0x10f880 (size 528) to offset 0x238 (size 544)
rewriting section .dynstr' from offset 0x7ae0 (size 12142) to offset 0x458 (size 12186) rewriting section.dynsym' from offset 0x3070 (size 19056) to offset 0x33f8 (size 19056)
rewriting section .gnu.hash' from offset 0x26e0 (size 2444) to offset 0x7e68 (size 2444) rewriting section.hash' from offset 0x1248 (size 5268) to offset 0x87f8 (size 5268)
rewriting section .interp' from offset 0x1200 (size 21) to offset 0x9c90 (size 21) rewriting section.note.tag' from offset 0x1218 (size 48) to offset 0x9ca8 (size 48)
./mc
./mc: Exec format error. Binary file not executable.

from patchelf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.