Control: tags -1 + fixed-upstream I can reproduce your results with $ cat > library.c << EOF #include <stdio.h> void test_lib(void) { printf("%s\n", "Hello, shared library"); } EOF $ cc -shared -fPIC -o library.so library.c $ cp library.so library2.so
$ patchelf --add-needed library2.so library.so $ ldd library2.so library.so library2.so: linux-vdso.so.1 (0x00007ffcec554000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff2e4c5d000) /lib64/ld-linux-x86-64.so.2 (0x00007ff2e4e5c000) library.so: linux-vdso.so.1 (0x00007ffd603af000) library2.so => not found libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f62d2e07000) /lib64/ld-linux-x86-64.so.2 (0x00007f62d3007000) $ patchelf --print-rpath library2.so library.so $ ./chrpath -k library2.so library.so library2.so: no rpath or runpath tag found. library.so: no rpath or runpath tag found. $ readelf -d library*.so File: library2.so Dynamic section at offset 0x2e08 contains 24 entries: Tag Type Name/Value 0x0000000000000001 (NEEDED) Shared library: [libc.so.6] 0x000000000000000c (INIT) 0x1000 0x000000000000000d (FINI) 0x112c 0x0000000000000019 (INIT_ARRAY) 0x3df8 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes) 0x000000000000001a (FINI_ARRAY) 0x3e00 0x000000000000001c (FINI_ARRAYSZ) 8 (bytes) 0x000000006ffffef5 (GNU_HASH) 0x260 0x0000000000000005 (STRTAB) 0x330 0x0000000000000006 (SYMTAB) 0x288 0x000000000000000a (STRSZ) 123 (bytes) 0x000000000000000b (SYMENT) 24 (bytes) 0x0000000000000003 (PLTGOT) 0x3fe8 0x0000000000000002 (PLTRELSZ) 24 (bytes) 0x0000000000000014 (PLTREL) RELA 0x0000000000000017 (JMPREL) 0x488 0x0000000000000007 (RELA) 0x3e0 0x0000000000000008 (RELASZ) 168 (bytes) 0x0000000000000009 (RELAENT) 24 (bytes) 0x000000006ffffffe (VERNEED) 0x3c0 0x000000006fffffff (VERNEEDNUM) 1 0x000000006ffffff0 (VERSYM) 0x3ac 0x000000006ffffff9 (RELACOUNT) 3 0x0000000000000000 (NULL) 0x0 File: library.so Dynamic section at offset 0x4000 contains 25 entries: Tag Type Name/Value 0x0000000000000001 (NEEDED) Shared library: [library2.so] 0x0000000000000001 (NEEDED) Shared library: [libc.so.6] 0x000000000000000c (INIT) 0x1000 0x000000000000000d (FINI) 0x112c 0x0000000000000019 (INIT_ARRAY) 0x3df8 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes) 0x000000000000001a (FINI_ARRAY) 0x3e00 0x000000000000001c (FINI_ARRAYSZ) 8 (bytes) 0x000000006ffffef5 (GNU_HASH) 0x5300 0x0000000000000005 (STRTAB) 0x51d0 0x0000000000000006 (SYMTAB) 0x5258 0x000000000000000a (STRSZ) 136 (bytes) 0x000000000000000b (SYMENT) 24 (bytes) 0x0000000000000003 (PLTGOT) 0x3fe8 0x0000000000000002 (PLTRELSZ) 24 (bytes) 0x0000000000000014 (PLTREL) RELA 0x0000000000000017 (JMPREL) 0x488 0x0000000000000007 (RELA) 0x3e0 0x0000000000000008 (RELASZ) 168 (bytes) 0x0000000000000009 (RELAENT) 24 (bytes) 0x000000006ffffffe (VERNEED) 0x3c0 0x000000006fffffff (VERNEEDNUM) 1 0x000000006ffffff0 (VERSYM) 0x3ac 0x000000006ffffff9 (RELACOUNT) 3 0x0000000000000000 (NULL) 0x0 $ patchelf --set-rpath $PWD library.so $ ldd library2.so library.so library2.so: linux-vdso.so.1 (0x00007ffe879de000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5d5dc3a000) /lib64/ld-linux-x86-64.so.2 (0x00007f5d5de39000) library.so: linux-vdso.so.1 (0x00007ffc00777000) library2.so => /home/nabijaczleweli/code/chrpath/library2.so (0x00007fdb05783000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fdb0558b000) /lib64/ld-linux-x86-64.so.2 (0x00007fdb05791000) $ patchelf --print-rpath library2.so library.so /home/nabijaczleweli/code/chrpath $ ./chrpath -k library2.so library.so library2.so: no rpath or runpath tag found. library.so: RUNPATH=_array_entry $ readelf -d library*.so File: library2.so Dynamic section at offset 0x2e08 contains 24 entries: Tag Type Name/Value 0x0000000000000001 (NEEDED) Shared library: [libc.so.6] 0x000000000000000c (INIT) 0x1000 0x000000000000000d (FINI) 0x112c 0x0000000000000019 (INIT_ARRAY) 0x3df8 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes) 0x000000000000001a (FINI_ARRAY) 0x3e00 0x000000000000001c (FINI_ARRAYSZ) 8 (bytes) 0x000000006ffffef5 (GNU_HASH) 0x260 0x0000000000000005 (STRTAB) 0x330 0x0000000000000006 (SYMTAB) 0x288 0x000000000000000a (STRSZ) 123 (bytes) 0x000000000000000b (SYMENT) 24 (bytes) 0x0000000000000003 (PLTGOT) 0x3fe8 0x0000000000000002 (PLTRELSZ) 24 (bytes) 0x0000000000000014 (PLTREL) RELA 0x0000000000000017 (JMPREL) 0x488 0x0000000000000007 (RELA) 0x3e0 0x0000000000000008 (RELASZ) 168 (bytes) 0x0000000000000009 (RELAENT) 24 (bytes) 0x000000006ffffffe (VERNEED) 0x3c0 0x000000006fffffff (VERNEEDNUM) 1 0x000000006ffffff0 (VERSYM) 0x3ac 0x000000006ffffff9 (RELACOUNT) 3 0x0000000000000000 (NULL) 0x0 File: library.so Dynamic section at offset 0x5000 contains 26 entries: Tag Type Name/Value 0x000000000000001d (RUNPATH) Library runpath: [/home/nabijaczleweli/code/chrpath] 0x0000000000000001 (NEEDED) Shared library: [library2.so] 0x0000000000000001 (NEEDED) Shared library: [libc.so.6] 0x000000000000000c (INIT) 0x1000 0x000000000000000d (FINI) 0x112c 0x0000000000000019 (INIT_ARRAY) 0x3df8 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes) 0x000000000000001a (FINI_ARRAY) 0x3e00 0x000000000000001c (FINI_ARRAYSZ) 8 (bytes) 0x000000006ffffef5 (GNU_HASH) 0x5300 0x0000000000000005 (STRTAB) 0x61e0 0x0000000000000006 (SYMTAB) 0x5258 0x000000000000000a (STRSZ) 170 (bytes) 0x000000000000000b (SYMENT) 24 (bytes) 0x0000000000000003 (PLTGOT) 0x3fe8 0x0000000000000002 (PLTRELSZ) 24 (bytes) 0x0000000000000014 (PLTREL) RELA 0x0000000000000017 (JMPREL) 0x488 0x0000000000000007 (RELA) 0x3e0 0x0000000000000008 (RELASZ) 168 (bytes) 0x0000000000000009 (RELAENT) 24 (bytes) 0x000000006ffffffe (VERNEED) 0x3c0 0x000000006fffffff (VERNEEDNUM) 1 0x000000006ffffff0 (VERSYM) 0x3ac 0x000000006ffffff9 (RELACOUNT) 3 0x0000000000000000 (NULL) 0x0 $ chrpath -r /tmp library.so library.so: RUNPATH=_array_entry library.so: new RUNPATH: /tmp $ chrpath library.so library.so: RUNPATH=/tmp $ patchelf --print-rpath library.so /home/nabijaczleweli/code/chrpath $ ldd library.so linux-vdso.so.1 (0x00007ffd68ef6000) library2.so => /home/nabijaczleweli/code/chrpath/library2.so (0x00007fe3259e7000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe3257ef000) /lib64/ld-linux-x86-64.so.2 (0x00007fe3259f5000) $ readelf -d library*.so File: library2.so Dynamic section at offset 0x2e08 contains 24 entries: Tag Type Name/Value 0x0000000000000001 (NEEDED) Shared library: [libc.so.6] 0x000000000000000c (INIT) 0x1000 0x000000000000000d (FINI) 0x112c 0x0000000000000019 (INIT_ARRAY) 0x3df8 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes) 0x000000000000001a (FINI_ARRAY) 0x3e00 0x000000000000001c (FINI_ARRAYSZ) 8 (bytes) 0x000000006ffffef5 (GNU_HASH) 0x260 0x0000000000000005 (STRTAB) 0x330 0x0000000000000006 (SYMTAB) 0x288 0x000000000000000a (STRSZ) 123 (bytes) 0x000000000000000b (SYMENT) 24 (bytes) 0x0000000000000003 (PLTGOT) 0x3fe8 0x0000000000000002 (PLTRELSZ) 24 (bytes) 0x0000000000000014 (PLTREL) RELA 0x0000000000000017 (JMPREL) 0x488 0x0000000000000007 (RELA) 0x3e0 0x0000000000000008 (RELASZ) 168 (bytes) 0x0000000000000009 (RELAENT) 24 (bytes) 0x000000006ffffffe (VERNEED) 0x3c0 0x000000006fffffff (VERNEEDNUM) 1 0x000000006ffffff0 (VERSYM) 0x3ac 0x000000006ffffff9 (RELACOUNT) 3 0x0000000000000000 (NULL) 0x0 File: library.so Dynamic section at offset 0x5000 contains 26 entries: Tag Type Name/Value 0x000000000000001d (RUNPATH) Library runpath: [/home/nabijaczleweli/code/chrpath] 0x0000000000000001 (NEEDED) Shared library: [library2.so] 0x0000000000000001 (NEEDED) Shared library: [libc.so.6] 0x000000000000000c (INIT) 0x1000 0x000000000000000d (FINI) 0x112c 0x0000000000000019 (INIT_ARRAY) 0x3df8 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes) 0x000000000000001a (FINI_ARRAY) 0x3e00 0x000000000000001c (FINI_ARRAYSZ) 8 (bytes) 0x000000006ffffef5 (GNU_HASH) 0x5300 0x0000000000000005 (STRTAB) 0x61e0 0x0000000000000006 (SYMTAB) 0x5258 0x000000000000000a (STRSZ) 170 (bytes) 0x000000000000000b (SYMENT) 24 (bytes) 0x0000000000000003 (PLTGOT) 0x3fe8 0x0000000000000002 (PLTRELSZ) 24 (bytes) 0x0000000000000014 (PLTREL) RELA 0x0000000000000017 (JMPREL) 0x488 0x0000000000000007 (RELA) 0x3e0 0x0000000000000008 (RELASZ) 168 (bytes) 0x0000000000000009 (RELAENT) 24 (bytes) 0x000000006ffffffe (VERNEED) 0x3c0 0x000000006fffffff (VERNEEDNUM) 1 0x000000006ffffff0 (VERSYM) 0x3ac 0x000000006ffffff9 (RELACOUNT) 3 0x0000000000000000 (NULL) 0x0 $ nm library.so 0000000000004010 b completed.0 w __cxa_finalize@GLIBC_2.2.5 0000000000001050 t deregister_tm_clones 00000000000010c0 t __do_global_dtors_aux 0000000000003e00 d __do_global_dtors_aux_fini_array_entry 0000000000004008 d __dso_handle 0000000000003e08 d _DYNAMIC 000000000000112c t _fini 0000000000001100 t frame_dummy 0000000000003df8 d __frame_dummy_init/tmp 00000000000020b8 r __FRAME_END__ 0000000000003fe8 d _GLOBAL_OFFSET_TABLE_ w __gmon_start__ 000000000000201c r __GNU_EH_FRAME_HDR 0000000000001000 t _init w _ITM_deregisterTMCloneTable w _ITM_registerTMCloneTable U printf@GLIBC_2.2.5 0000000000001080 t register_tm_clones 0000000000001110 T test_lib 0000000000004010 d __TMC_END__ Per readelf -S the default order is There are 28 section headers, starting at offset 0x3570: Section Headers: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0 [ 1] .note.gnu.bu[...] NOTE 0000000000000238 00000238 0000000000000024 0000000000000000 A 0 0 4 [ 2] .gnu.hash GNU_HASH 0000000000000260 00000260 0000000000000024 0000000000000000 A 3 0 8 [ 3] .dynsym DYNSYM 0000000000000288 00000288 00000000000000a8 0000000000000018 A 4 1 8 [ 4] .dynstr STRTAB 0000000000000330 00000330 000000000000007b 0000000000000000 A 0 0 1 [ 5] .gnu.version VERSYM 00000000000003ac 000003ac 000000000000000e 0000000000000002 A 3 0 2 [ 6] .gnu.version_r VERNEED 00000000000003c0 000003c0 0000000000000020 0000000000000000 A 4 1 8 [ 7] .rela.dyn RELA 00000000000003e0 000003e0 00000000000000a8 0000000000000018 A 3 0 8 [ 8] .rela.plt RELA 0000000000000488 00000488 0000000000000018 0000000000000018 AI 3 21 8 [ 9] .init PROGBITS 0000000000001000 00001000 0000000000000017 0000000000000000 AX 0 0 4 [10] .plt PROGBITS 0000000000001020 00001020 0000000000000020 0000000000000010 AX 0 0 16 [11] .plt.got PROGBITS 0000000000001040 00001040 0000000000000008 0000000000000008 AX 0 0 8 [12] .text PROGBITS 0000000000001050 00001050 00000000000000db 0000000000000000 AX 0 0 16 [13] .fini PROGBITS 000000000000112c 0000112c 0000000000000009 0000000000000000 AX 0 0 4 [14] .rodata PROGBITS 0000000000002000 00002000 000000000000001a 0000000000000001 AMS 0 0 1 [15] .eh_frame_hdr PROGBITS 000000000000201c 0000201c 0000000000000024 0000000000000000 A 0 0 4 [16] .eh_frame PROGBITS 0000000000002040 00002040 000000000000007c 0000000000000000 A 0 0 8 [17] .init_array INIT_ARRAY 0000000000003df8 00002df8 0000000000000008 0000000000000008 WA 0 0 8 [18] .fini_array FINI_ARRAY 0000000000003e00 00002e00 0000000000000008 0000000000000008 WA 0 0 8 [19] .dynamic DYNAMIC 0000000000003e08 00002e08 00000000000001c0 0000000000000010 WA 4 0 8 [20] .got PROGBITS 0000000000003fc8 00002fc8 0000000000000020 0000000000000008 WA 0 0 8 [21] .got.plt PROGBITS 0000000000003fe8 00002fe8 0000000000000020 0000000000000008 WA 0 0 8 [22] .data PROGBITS 0000000000004008 00003008 0000000000000008 0000000000000000 WA 0 0 8 [23] .bss NOBITS 0000000000004010 00003010 0000000000000008 0000000000000000 WA 0 0 1 [24] .comment PROGBITS 0000000000000000 00003010 0000000000000075 0000000000000001 MS 0 0 1 [25] .symtab SYMTAB 0000000000000000 00003088 0000000000000270 0000000000000018 26 20 8 [26] .strtab STRTAB 0000000000000000 000032f8 0000000000000180 0000000000000000 0 0 1 [27] .shstrtab STRTAB 0000000000000000 00003478 00000000000000f1 0000000000000000 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), D (mbind), l (large), p (processor specific) but after patchelf --set-rpath $PWD it changes completely: There are 28 section headers, starting at offset 0x3570: Section Headers: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0 [ 1] .gnu.version VERSYM 00000000000003ac 000003ac 000000000000000e 0000000000000002 A 25 0 2 [ 2] .gnu.version_r VERNEED 00000000000003c0 000003c0 0000000000000020 0000000000000000 A 24 1 8 [ 3] .rela.dyn RELA 00000000000003e0 000003e0 00000000000000a8 0000000000000018 A 25 0 8 [ 4] .rela.plt RELA 0000000000000488 00000488 0000000000000018 0000000000000018 AI 25 16 8 [ 5] .init PROGBITS 0000000000001000 00001000 0000000000000017 0000000000000000 AX 0 0 4 [ 6] .plt PROGBITS 0000000000001020 00001020 0000000000000020 0000000000000010 AX 0 0 16 [ 7] .plt.got PROGBITS 0000000000001040 00001040 0000000000000008 0000000000000008 AX 0 0 8 [ 8] .text PROGBITS 0000000000001050 00001050 00000000000000db 0000000000000000 AX 0 0 16 [ 9] .fini PROGBITS 000000000000112c 0000112c 0000000000000009 0000000000000000 AX 0 0 4 [10] .rodata PROGBITS 0000000000002000 00002000 000000000000001a 0000000000000001 AMS 0 0 1 [11] .eh_frame_hdr PROGBITS 000000000000201c 0000201c 0000000000000024 0000000000000000 A 0 0 4 [12] .eh_frame PROGBITS 0000000000002040 00002040 000000000000007c 0000000000000000 A 0 0 8 [13] .init_array INIT_ARRAY 0000000000003df8 00002df8 0000000000000008 0000000000000008 WA 0 0 8 [14] .fini_array FINI_ARRAY 0000000000003e00 00002e00 0000000000000008 0000000000000008 WA 0 0 8 [15] .got PROGBITS 0000000000003fc8 00002fc8 0000000000000020 0000000000000008 WA 0 0 8 [16] .got.plt PROGBITS 0000000000003fe8 00002fe8 0000000000000020 0000000000000008 WA 0 0 8 [17] .data PROGBITS 0000000000004008 00003008 0000000000000008 0000000000000000 WA 0 0 8 [18] .bss NOBITS 0000000000004010 00003010 0000000000000008 0000000000000000 WA 0 0 1 [19] .comment PROGBITS 0000000000000000 00003010 0000000000000075 0000000000000001 MS 0 0 1 [20] .symtab SYMTAB 0000000000000000 00003088 0000000000000270 0000000000000018 21 20 8 [21] .strtab STRTAB 0000000000000000 000032f8 0000000000000180 0000000000000000 0 0 1 [22] .shstrtab STRTAB 0000000000000000 00003478 00000000000000f1 0000000000000000 0 0 1 [23] .dynamic DYNAMIC 0000000000005000 00004000 00000000000001d0 0000000000000010 WA 24 0 8 [24] .dynstr STRTAB 00000000000051d0 000041d0 000000000000009d 0000000000000000 A 0 0 8 [25] .dynsym DYNSYM 0000000000005270 00004270 00000000000000a8 0000000000000018 A 24 1 8 [26] .gnu.hash GNU_HASH 0000000000005318 00004318 0000000000000024 0000000000000000 A 25 0 8 [27] .note.gnu.bu[...] NOTE 0000000000005340 00004340 0000000000000024 0000000000000000 A 0 0 4 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), D (mbind), l (large), p (processor specific) Or, filtering down to STRTABs: [ 4] .dynstr STRTAB 0000000000000330 00000330 000000000000009d 0000000000000000 A 0 0 1 [26] .strtab STRTAB 0000000000000000 000032f8 0000000000000180 0000000000000000 0 0 1 [27] .shstrtab STRTAB 0000000000000000 00003478 00000000000000f1 0000000000000000 0 0 1 -> [21] .strtab STRTAB 0000000000000000 000032f8 0000000000000180 0000000000000000 0 0 1 [22] .shstrtab STRTAB 0000000000000000 00003478 00000000000000f1 0000000000000000 0 0 1 [24] .dynstr STRTAB 00000000000051d0 000041d0 000000000000009d 0000000000000000 A 0 0 8 So your diagnosis is correct. The patches are applied at the continuation (https://sr.ht/~nabijaczleweli/chrpath-ng) as https://git.sr.ht/~nabijaczleweli/chrpath-ng/commit/279cd0475d2520692cd34c0d4bce45cd9bfb20af https://git.sr.ht/~nabijaczleweli/chrpath-ng/commit/7271f67f5fa9894b9bb11455a1b31fb031aa418c and I get $ cc -shared -fPIC -o library6.so library.c $ patchelf --set-rpath $PWD library6.so $ chrpath library6.so library6.so: RUNPATH=me_dummy_init_array_entry $ ./chrpath library6.so library6.so: RUNPATH=/home/nabijaczleweli/code/chrpath $ ./chrpath -r /tmp library6.so library6.so: RUNPATH=/home/nabijaczleweli/code/chrpath library6.so: new RUNPATH: /tmp $ ./chrpath library6.so library6.so: RUNPATH=/tmp $ readelf -d library6.so | grep PATH 0x000000000000001d (RUNPATH) Library runpath: [/tmp] $ nm library6.so 0000000000004010 b completed.0 w __cxa_finalize@GLIBC_2.2.5 0000000000001050 t deregister_tm_clones 00000000000010c0 t __do_global_dtors_aux 0000000000003e00 d __do_global_dtors_aux_fini_array_entry 0000000000004008 d __dso_handle 0000000000003e08 d _DYNAMIC 000000000000112c t _fini 0000000000001100 t frame_dummy 0000000000003df8 d __frame_dummy_init_array_entry 00000000000020b8 r __FRAME_END__ 0000000000003fe8 d _GLOBAL_OFFSET_TABLE_ w __gmon_start__ 000000000000201c r __GNU_EH_FRAME_HDR 0000000000001000 t _init w _ITM_deregisterTMCloneTable w _ITM_registerTMCloneTable U printf@GLIBC_2.2.5 0000000000001080 t register_tm_clones 0000000000001110 T test_lib 0000000000004010 d __TMC_END__ which appears correct. Best, наб
signature.asc
Description: PGP signature