Comments (7)
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.
I also tried to patch unstripped binary. Still shows zsh: exec format error: /tmp/tig
, although nm shows full list of symbols.
from patchelf.
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.
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.
Does the version from the ports work?
from patchelf.
I have no idea, didn't use ports.
from patchelf.
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 filemc' 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)
- patchelf: cannot find section '.interp'. The input file is most likely statically linked
- Test regression in 0.18.0: repeated-updates.sh, replace-add-needed.sh HOT 5
- patchelf breaks dylibs from recent Firefox Nightly builds HOT 11
- repeated-updates.sh fails on mips64el HOT 1
- What versions support redhat6
- `patchelf --set-interpreter` and `patchelf --set-rpath` depend on the order (at least on i686-linux) HOT 3
- Allow --rename-dynamic-symbols to change the version tag.
- Regression in 0.18.0: --set-rpath creates broken header alignment HOT 3
- `patchefd --set-rpath ... nodejs` broken since ~0.17.2 (0.15.0 works) HOT 3
- when I use zsh plugins zsh-autosuggestions, it something wrong HOT 1
- Program header editing features HOT 5
- SEGV when ELF has a malformed .dynamic section
- Relocatable binaries not handled
- Patchelf 0.18.0 Build failure on s390x with "span : out of range error"
- build failed for NetBSD
- rename-dynamic-symbols produces unusable binary
- Need help for cross-compliling libc.so.6
- patchelf: cannot normalize PT_NOTE segment: non-contiguous SHT_NOTE sections HOT 1
- _arguments:463: command not found: dynamic HOT 6
- `replace-needed.sh` test fails on 32-bit arm
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from patchelf.