Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--replace-needed messes with --set-rpath/--set-interpreter #193

Closed
bakhtiyarneyman opened this issue Feb 12, 2020 · 7 comments
Closed

--replace-needed messes with --set-rpath/--set-interpreter #193

bakhtiyarneyman opened this issue Feb 12, 2020 · 7 comments
Labels

Comments

@bakhtiyarneyman
Copy link

bakhtiyarneyman commented Feb 12, 2020

Compare two invocations.
1)
Command:

patchelf --debug \
      --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
      --set-rpath "${libPath}" \
      $out/bin/swift

Log:

nwlnjb-util-linux-2.33.2/lib:/nix/store/7jmsjdvvaihqb9nvi1y7c4567sq09bsf-ncurses-6.1-20190112-abi5-compat/lib:/nix/store/xvxsbvbi7ckccz4pz2j6np7czadgjy2x-zlib-1.2.11/lib
patching ELF file `/nix/store/9wpzyi9143dba2ahjx951i026m5hsqqr-swift-for-tensorflow-0.7/bin/swift'
Kernel page size is 4096 bytes
new rpath is `/nix/store/mxnvr0yx4q59v2ych4kfbcafjpaypr8f-libedit-20190324-3.1/lib:/nix/store/784rh7jrfhagbkydjfrv68h9x3g4gqmk-gcc-8.3.0-lib/lib:/nix/store/hiyxbvn39cp4gjppdqyvl7h30ma04zk9-blocksruntime-20140624/lib:/nix/store/pnwhp55w4lx69lxz21x02maqhgnwlnjb-util-linux-2.33.2/lib:/nix/store/7jmsjdvvaihqb9nvi1y7c4567sq09bsf-ncurses-6.1-20190112-abi5-compat/lib:/nix/store/xvxsbvbi7ckccz4pz2j6np7czadgjy2x-zlib-1.2.11/lib'
rpath is too long, resizing...
replacing section `.dynstr' with size 9830
replacing section `.interp' with size 80
this is an executable
using replaced section `.interp'
using replaced section `.dynstr'
last replaced is 4
looking at section `.interp'
looking at section `.note.ABI-tag'
replacing section `.note.ABI-tag' 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 0x4c88/0x404c88
first page is 0x400000
needed space is 20048
needed space is 20104
needed pages is 1
clearing first 23008 bytes
rewriting section `.dynstr' from offset 0x37b8 (size 9421) to offset 0x2a8 (size 9830)
rewriting section `.dynsym' from offset 0x12b0 (size 9480) to offset 0x2910 (size 9480)
rewriting section `.interp' from offset 0x1270 (size 28) to offset 0x4e18 (size 80)
rewriting section `.note.ABI-tag' from offset 0x128c (size 32) to offset 0x4e68 (size 32)
rewriting symbol table section 2
rewriting symbol table section 29

End result:

/nix/store/9wpzyi9143dba2ahjx951i026m5hsqqr-swift-for-tensorflow-0.7/bin/swift: /nix/store/7jmsjdvvaihqb9nvi1y7c4567sq09bsf-ncurses-6.1-20190112-abi5-compat/lib/libtinfo.so.5: no version information available (required by /nix/store/9wpzyi9143dba2ahjx951i026m5hsqqr-swift-for-tensorflow-0.7/bin/swift)
	linux-vdso.so.1 (0x00007ffedc1ca000)
	libpthread.so.0 => /nix/store/wx1vk75bpdr65g6xwxbj4rw0pk04v5j3-glibc-2.27/lib/libpthread.so.0 (0x00007f2e1f25c000)
	libatomic.so.1 => /nix/store/784rh7jrfhagbkydjfrv68h9x3g4gqmk-gcc-8.3.0-lib/lib/libatomic.so.1 (0x00007f2e1f252000)
	libdl.so.2 => /nix/store/wx1vk75bpdr65g6xwxbj4rw0pk04v5j3-glibc-2.27/lib/libdl.so.2 (0x00007f2e1f24d000)
	libedit.so.2 => not found
	libuuid.so.1 => /nix/store/pnwhp55w4lx69lxz21x02maqhgnwlnjb-util-linux-2.33.2/lib/libuuid.so.1 (0x00007f2e1f244000)
	libz.so.1 => /nix/store/xvxsbvbi7ckccz4pz2j6np7czadgjy2x-zlib-1.2.11/lib/libz.so.1 (0x00007f2e1f223000)
	librt.so.1 => /nix/store/wx1vk75bpdr65g6xwxbj4rw0pk04v5j3-glibc-2.27/lib/librt.so.1 (0x00007f2e1f219000)
	libtinfo.so.5 => /nix/store/7jmsjdvvaihqb9nvi1y7c4567sq09bsf-ncurses-6.1-20190112-abi5-compat/lib/libtinfo.so.5 (0x00007f2e1f1b3000)
	libm.so.6 => /nix/store/wx1vk75bpdr65g6xwxbj4rw0pk04v5j3-glibc-2.27/lib/libm.so.6 (0x00007f2e1f01d000)
	libstdc++.so.6 => /nix/store/784rh7jrfhagbkydjfrv68h9x3g4gqmk-gcc-8.3.0-lib/lib/libstdc++.so.6 (0x00007f2e1ee92000)
	libgcc_s.so.1 => /nix/store/784rh7jrfhagbkydjfrv68h9x3g4gqmk-gcc-8.3.0-lib/lib/libgcc_s.so.1 (0x00007f2e1ee78000)
	libc.so.6 => /nix/store/wx1vk75bpdr65g6xwxbj4rw0pk04v5j3-glibc-2.27/lib/libc.so.6 (0x00007f2e1ecc0000)
	/nix/store/wx1vk75bpdr65g6xwxbj4rw0pk04v5j3-glibc-2.27/lib/ld-linux-x86-64.so.2 => /nix/store/wx1vk75bpdr65g6xwxbj4rw0pk04v5j3-glibc-2.27/lib64/ld-linux-x86-64.so.2 (0x00007f2e1f27f000)
  1. Command:
patchelf --debug \
      --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
      --set-rpath "${libPath}" \
      --replace-needed libedit.so.2 libedit.so.0 \
      $out/bin/swift

Log:

/nix/store/mxnvr0yx4q59v2ych4kfbcafjpaypr8f-libedit-20190324-3.1/lib:/nix/store/784rh7jrfhagbkydjfrv68h9x3g4gqmk-gcc-8.3.0-lib/lib:/nix/store/hiyxbvn39cp4gjppdqyvl7h30ma04zk9-blocksruntime-20140624/lib:/nix/store/pnwhp55w4lx69lxz21x02maqhgnwlnjb-util-linux-2.33.2/lib:/nix/store/7jmsjdvvaihqb9nvi1y7c4567sq09bsf-ncurses-6.1-20190112-abi5-compat/lib:/nix/store/xvxsbvbi7ckccz4pz2j6np7czadgjy2x-zlib-1.2.11/lib
patching ELF file `/nix/store/cldsfkz241qrr4hliw8p0km6ilh36kcv-swift-for-tensorflow-0.7/bin/swift'
Kernel page size is 4096 bytes
new rpath is `/nix/store/mxnvr0yx4q59v2ych4kfbcafjpaypr8f-libedit-20190324-3.1/lib:/nix/store/784rh7jrfhagbkydjfrv68h9x3g4gqmk-gcc-8.3.0-lib/lib:/nix/store/hiyxbvn39cp4gjppdqyvl7h30ma04zk9-blocksruntime-20140624/lib:/nix/store/pnwhp55w4lx69lxz21x02maqhgnwlnjb-util-linux-2.33.2/lib:/nix/store/7jmsjdvvaihqb9nvi1y7c4567sq09bsf-ncurses-6.1-20190112-abi5-compat/lib:/nix/store/xvxsbvbi7ckccz4pz2j6np7czadgjy2x-zlib-1.2.11/lib'
rpath is too long, resizing...
keeping DT_NEEDED entry `libpthread.so.0'
keeping DT_NEEDED entry `libatomic.so.1'
keeping DT_NEEDED entry `libdl.so.2'
replacing DT_NEEDED entry `libedit.so.2' with `libedit.so.0'
resizing .dynstr ...keeping DT_NEEDED entry `libuuid.so.1'
keeping DT_NEEDED entry `libz.so.1'
keeping DT_NEEDED entry `librt.so.1'
keeping DT_NEEDED entry `libtinfo.so.5'
keeping DT_NEEDED entry `libm.so.6'
keeping DT_NEEDED entry `libstdc++.so.6'
keeping DT_NEEDED entry `libgcc_s.so.1'
keeping DT_NEEDED entry `libc.so.6'
keeping DT_NEEDED entry `ld-linux-x86-64.so.2'
replacing section `.dynstr' with size 9434
replacing section `.interp' with size 80
this is an executable
using replaced section `.interp'
using replaced section `.dynstr'
last replaced is 4
looking at section `.interp'
looking at section `.note.ABI-tag'
replacing section `.note.ABI-tag' 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 0x4c88/0x404c88
first page is 0x400000
needed space is 19656
needed space is 19712
needed pages is 1
clearing first 23008 bytes
rewriting section `.dynstr' from offset 0x37b8 (size 9421) to offset 0x2a8 (size 9434)
rewriting section `.dynsym' from offset 0x12b0 (size 9480) to offset 0x2788 (size 9480)
rewriting section `.interp' from offset 0x1270 (size 28) to offset 0x4c90 (size 80)
rewriting section `.note.ABI-tag' from offset 0x128c (size 32) to offset 0x4ce0 (size 32)
rewriting symbol table section 2
rewriting symbol table section 29

End result:

ldd (which swift)
	linux-vdso.so.1 (0x00007fff1b5c2000)
	libpthread.so.0 => /nix/store/wx1vk75bpdr65g6xwxbj4rw0pk04v5j3-glibc-2.27/lib/libpthread.so.0 (0x00007f7bd964d000)
	libatomic.so.1 => not found
	libdl.so.2 => /nix/store/wx1vk75bpdr65g6xwxbj4rw0pk04v5j3-glibc-2.27/lib/libdl.so.2 (0x00007f7bd9648000)
	libedit.so.0 => not found
	libuuid.so.1 => not found
	libz.so.1 => not found
	librt.so.1 => /nix/store/wx1vk75bpdr65g6xwxbj4rw0pk04v5j3-glibc-2.27/lib/librt.so.1 (0x00007f7bd963c000)
	libtinfo.so.5 => not found
	libm.so.6 => /nix/store/wx1vk75bpdr65g6xwxbj4rw0pk04v5j3-glibc-2.27/lib/libm.so.6 (0x00007f7bd94a6000)
	libstdc++.so.6 => not found
	libgcc_s.so.1 => /nix/store/wx1vk75bpdr65g6xwxbj4rw0pk04v5j3-glibc-2.27/lib/libgcc_s.so.1 (0x00007f7bd9290000)
	libc.so.6 => /nix/store/wx1vk75bpdr65g6xwxbj4rw0pk04v5j3-glibc-2.27/lib/libc.so.6 (0x00007f7bd90da000)

The libraries are gone missing in the second case.

@bakhtiyarneyman
Copy link
Author

bakhtiyarneyman commented Feb 13, 2020

Looking at the output of readelf -a -W:

...
 0x000000000000001d (RUNPATH)            Library runpath: [/nix/store/mxnvr0yx4q59v2ych4kfbcafjpaypr8f-libedit-20190324-3.1/lib:/nix/store/784rh7jrfhagbkydjfrv68h9x3g4gqmk-gcc-8.3.0-lib/lib:/nix/store/bd2wjr6xim90zvb8xqf5zyb6q8mm6rid-blocksruntime-20140624/lib:/nix/store/pnwhp55w4lx69lxz21x02maqhgnwlnjb-util-linux-2.33.2/lib:/nix/store/7jmsjdvvaihqb9nvi1y7c4567sq09bsf-ncurses-6.1-20190112-abi5-compat/lib:/nix/store/xvxsbvbi7ckccz4pz2j6np7czadgjy2x-zlib-1.2.11/lib:/nix/store/v1pll920p3smwsrzaili4kl7nnh5lw4q-swift-for-tensorflow-0.7/lib]
...
...
0x000000000000001d (RUNPATH)            Library runpath: [libedit.so.0]
...

@matthewbauer
Copy link
Member

I was seeing this with --set-rpath combined with --set-soname as well. The easy fix is to just do two separate invocations, but this definitely looks like a bug.

@domenkozar domenkozar added the bug label Jun 9, 2020
@DerDakon
Copy link
Contributor

Please check if #237 fixes the issue for you as --replace-needed was found to corrupt even itself.

@JonathonReinhart
Copy link

This seems to be closely related to #223.

@domenkozar
Copy link
Member

Could you test #237?

@fzakaria
Copy link
Contributor

I believe this is related to #359 which I have a PR to fix.
Please try it

CC @domenkozar @bakhtiyarneyman

@Mic92
Copy link
Member

Mic92 commented Dec 22, 2021

I think so too. If you still believe this is broken, please say so.

@Mic92 Mic92 closed this as completed Dec 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants