Repository navigation
Description
I've used patchelf with an android DSO to add new NEEDED entry.
This causes the android linker to claim about incorrect section .gnu.hash
Analysis shows this issue seems caused by incorrect code at https://github.com/NixOS/patchelf/blob/master/src/patchelf.cc#L715.
This code should replace sections that are about to be overwritten by headers but do not find any suitable section because its (ex. .gnu.hash) virtual address is greater than new header table length (see output from objdump -x for the original DSO)
This line should use 'sh_offset' instead of 'sh_addr'.
Corrected patchelf creates a DSO which passes android linker checks.
It seems impossible to create a pull request from patch/diff file and I would like to avoid forking this repo just for one-line patch. Hope someone can do this...
The objdump -x output:
`
wileyfox/porridge/proprietary/lib64/libgui_ext.so: file format elf64-little
vendor/wileyfox/porridge/proprietary/lib64/libgui_ext.so
architecture: UNKNOWN!, flags 0x00000150:
HAS_SYMS, DYNAMIC, D_PAGED
start address 0x000000000000d3c0
Program Header:
LOAD off 0x0000000000000000 vaddr 0x0000000000004000 paddr 0x0000000000004000 align 212
filesz 0x0000000000017b10 memsz 0x0000000000017b10 flags r-x
LOAD off 0x000000000001cab8 vaddr 0x000000000002cab8 paddr 0x000000000002cab8 align 216
filesz 0x0000000000003598 memsz 0x0000000000003638 flags rw-
DYNAMIC off 0x000000000001f6e0 vaddr 0x000000000002f6e0 paddr 0x000000000002f6e0 align 23
filesz 0x00000000000002b0 memsz 0x00000000000002b0 flags rw-
NOTE off 0x0000000000000200 vaddr 0x0000000000004200 paddr 0x0000000000004200 align 22
filesz 0x0000000000000020 memsz 0x0000000000000020 flags r--
NOTE off 0x0000000000017af8 vaddr 0x000000000001baf8 paddr 0x000000000001baf8 align 22
filesz 0x0000000000000018 memsz 0x0000000000000018 flags r--
EH_FRAME off 0x0000000000014910 vaddr 0x0000000000018910 paddr 0x0000000000018910 align 22
filesz 0x00000000000007cc memsz 0x00000000000007cc flags r--
STACK off 0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 24
filesz 0x0000000000000000 memsz 0x0000000000000000 flags rw-
RELRO off 0x000000000001cab8 vaddr 0x000000000002cab8 paddr 0x000000000002cab8 align 20
filesz 0x0000000000003548 memsz 0x0000000000003548 flags r--
Dynamic Section:
NEEDED libutils.so
NEEDED libcutils.so
NEEDED libbinder.so
NEEDED libhardware.so
NEEDED libhardware_legacy.so
NEEDED libgui.so
NEEDED libui.so
NEEDED libdl.so
NEEDED libion.so
NEEDED libion_mtk.so
NEEDED libgralloc_extra.so
NEEDED libui_ext.so
NEEDED libc++.so
NEEDED libc.so
NEEDED libm.so
SONAME libgui_ext.so
INIT_ARRAY 0x000000000002cab8
INIT_ARRAYSZ 0x0000000000000020
FINI_ARRAY 0x000000000002cad8
FINI_ARRAYSZ 0x0000000000000008
GNU_HASH 0x0000000000004220
STRTAB 0x0000000000006888
SYMTAB 0x0000000000004968
STRSZ 0x00000000000042a0
SYMENT 0x0000000000000018
PLTGOT 0x000000000002f990
PLTRELSZ 0x0000000000000f18
PLTREL 0x0000000000000007
JMPREL 0x000000000000ba78
0x60000011 0x000000000000ade0
0x60000012 0x0000000000000c98
RELAENT 0x0000000000000018
BIND_NOW 0x0000000000000000
FLAGS_1 0x0000000000000001
VERNEED 0x000000000000adc0
VERNEEDNUM 0x0000000000000001
VERSYM 0x000000000000ab28
RELACOUNT 0x00000000000000bb
Version References:
required from libc.so:
0x00050d63 0x00 02 LIBC
Sections:
Idx Name Size VMA LMA File off Algn
0 .note.gnu.build-id 00000020 0000000000004200 0000000000004200 00000200 22
CONTENTS, ALLOC, LOAD, READONLY, DATA
1 .gnu.hash 00000748 0000000000004220 0000000000004220 00000220 23
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .dynsym 00001f20 0000000000004968 0000000000004968 00000968 23
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .dynstr 000042a0 0000000000006888 0000000000006888 00002888 20
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .gnu.version 00000298 000000000000ab28 000000000000ab28 00006b28 21
CONTENTS, ALLOC, LOAD, READONLY, DATA
5 .gnu.version_r 00000020 000000000000adc0 000000000000adc0 00006dc0 23
CONTENTS, ALLOC, LOAD, READONLY, DATA
6 .rela.dyn 00000c98 000000000000ade0 000000000000ade0 00006de0 23
CONTENTS, ALLOC, LOAD, READONLY, DATA
7 .rela.plt 00000f18 000000000000ba78 000000000000ba78 00007a78 23
CONTENTS, ALLOC, LOAD, READONLY, DATA
8 .plt 00000a30 000000000000c990 000000000000c990 00008990 24
CONTENTS, ALLOC, LOAD, READONLY, CODE
9 .text 00009cfc 000000000000d3c0 000000000000d3c0 000093c0 22
CONTENTS, ALLOC, LOAD, READONLY, CODE
10 .rodata 00001850 00000000000170c0 00000000000170c0 000130c0 24
CONTENTS, ALLOC, LOAD, READONLY, DATA
11 .eh_frame_hdr 000007cc 0000000000018910 0000000000018910 00014910 22
CONTENTS, ALLOC, LOAD, READONLY, DATA
12 .eh_frame 00002a18 00000000000190e0 00000000000190e0 000150e0 23
CONTENTS, ALLOC, LOAD, READONLY, DATA
13 .note.android.ident 00000018 000000000001baf8 000000000001baf8 00017af8 22
CONTENTS, ALLOC, LOAD, READONLY, DATA
14 .init_array 00000020 000000000002cab8 000000000002cab8 0001cab8 23
CONTENTS, ALLOC, LOAD, DATA
15 .fini_array 00000008 000000000002cad8 000000000002cad8 0001cad8 23
CONTENTS, ALLOC, LOAD, DATA
16 .data.rel.ro 00002c00 000000000002cae0 000000000002cae0 0001cae0 24
CONTENTS, ALLOC, LOAD, DATA
17 .dynamic 000002b0 000000000002f6e0 000000000002f6e0 0001f6e0 23
CONTENTS, ALLOC, LOAD, DATA
18 .got 00000668 000000000002f990 000000000002f990 0001f990 23
CONTENTS, ALLOC, LOAD, DATA
19 .data 00000050 0000000000030000 0000000000030000 00020000 24
CONTENTS, ALLOC, LOAD, DATA
20 .bss 000000a0 0000000000030050 0000000000030050 00020050 23
ALLOC
21 .comment 0000002e 0000000000000000 0000000000000000 00020050 20
CONTENTS, READONLY
SYMBOL TABLE:
no symbols
`
Activity
domenkozar commentedon Mar 18, 2019
Ideally you'd attach the patch and give us an example binary for a test case.
divis1969 commentedon Mar 18, 2019
Binary is https://github.com/TheMuppets/proprietary_vendor_wileyfox/blob/lineage-16.0/porridge/proprietary/lib64/libgui_ext.so
Patch is attached
patchelf.txt
Test case is
patchelf --add-needed <some_name> libgui_ext.so
Error reported by android linker:
https://github.com/LineageOS/android_bionic/blob/lineage-16.0/linker/linker.cpp#L3176
domenkozar commentedon Sep 22, 2020
Fixed in master.