summaryrefslogtreecommitdiffstats
path: root/libelf
Commit message (Collapse)AuthorAgeFilesLines
* libelf: Only include features.h on linux.staging/lineage-15.1staging/lineage-15.0_rebase-android-8.0.0_r23lineage-15.1lineage-15.0Adnan Begovic2017-08-241-0/+2
| | | | Change-Id: I5429f63166f8e7da6b2099157fefc3f590d97719
* Convert libelf from Android.mk to Android.bpColin Cross2016-07-132-190/+163
| | | | Change-Id: I4b3859757c67e4a505c7e96b27907db47e44d106
* Revert "Disable clang for arm64 where local __thread is used."Stephen Hines2016-02-241-3/+0
| | | | | | | | Bug: http://b/25642296 This reverts commit e223eb95c4f3df36a7c24c3b9a4dfdeec06ac15d. Change-Id: I727eefee8e4edb8d85528999698b82b14855d615
* Merge upstream 0.165 SHA '203f0a3'Chih-Hung Hsieh2016-01-2525-35/+1361
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * git merge 203f0a3 * See all upstream changes since the previous merge in branch aosp/upstream-master: git diff 9d1e236..203f0a3 * Android relevant upstream changes: * Version number changed from 0.164 to 0.165 * libelf now depends on zlib * Changed version number in generated files: version.h, config.h * No change to generated files: libdw/known-dwarf.h * Updated libelf/Android.mk: * added new source files: gelf_getchdr.c elf{32,64}_getchdr.c elf_compress.c * added LOCAL_STATIC_LIBRARIES := libz Change-Id: Ieb306d84ffcaf680ad6e74da28fcc8efbf00592a
| * Move nested functions in elf_compress.c and elf_strptr.c.Chih-Hung Hsieh2016-01-233-26/+39
| | | | | | | | | | | | | | * elf_compress.c (__libelf_compress): do_deflate_cleanup * elf_strptr.c (elf_strptr): get_zdata Signed-off-by: Chih-Hung Hsieh <chh@google.com>
| * libelf: Add ELF compression types and defines to libelf.h for older glibc.Mark Wielaard2016-01-142-0/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | Older glibc elf.h might not define the new ELF compression defines and types. If not just define them in libelf.h directly to make the libelf headers work on older glibc systems. Also include a testcase to check the libelf headers build against the system elf.h. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=810885 Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: Make elf_strptr index correctly into compressed section data.Mark Wielaard2016-01-064-43/+120
| | | | | | | | | | | | | | | | | | elf_strptr indexes into the section data. This is defined as index into the uncompressed data of the section. If the section is compressed make sure the uncompressed data is available, but don't really decompress the section header (elf_getdata will still return compressed data). Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: Add elf_compress and elf_compress_gnu.Mark Wielaard2016-01-0613-22/+896
| | | | | | | | Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: Add elf32_getchdr, elf64_getchdr and gelf_getchdr.Mark Wielaard2016-01-0617-14/+335
| | | | | | | | | | | | | | | | | | Elf_Data of a compressed section has type ELF_T_CHDR. This type can be xlated to the file or memory representation. This will make sure the Chdr is in the correct endianess. The compressed data following the Chdr isn't translated. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* | Disable clang for arm64 where local __thread is used.Chih-Hung Hsieh2015-11-201-0/+3
| | | | | | | | | | | | | | | | | | clang/llvm for aarch64 generates relocation references to local symbols and that is not supported by Android dynamic linker. BUG: 25642296 Change-Id: If99aca50002eef4cce7735c6defef2fcb76f5a9b
* | Enable clang compiler for some modules.Chih-Hung Hsieh2015-11-161-6/+0
| | | | | | | | | | | | | | * libdwelf, libebl, libelf can compile cleanly with clang now. * libdw and libdwfl still have some nested functions only compiled by gcc. Change-Id: Id43585c6d11f521ef0ccebe9cae4db9de436cdc0
* | Merge upstream SHA 'ae09ca9'Chih-Hung Hsieh2015-11-032-1/+5
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | * git merge ae09ca9 * See all upstream changes since the previous merge: git diff 5eb3e90..ae09ca9 * Android relevant upstream changes: Move nested functions to file scope: backends/ia64_retval.c, aarch64_regs.c libdwfl/frame_unwind.c, dwfl_module.c * Other upstream changes unrelated to Android: Make zlib mandatory. * No changes to the following generated files: version.h, config.h, libdw/known-dwarf.h
| * Make zlib mandatory.Mark Wielaard2015-10-262-1/+5
| | | | | | | | | | | | Explicitly link libelf and libdw with -lz. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* | Merge upstream SHA '5eb3e90'Chih-Hung Hsieh2015-10-234-39/+85
|\| | | | | | | | | | | | | | | | | | | | | | | | | * git merge 5eb3e90 * Android relevant upstream changes: Move nested functions to file scope: libdw/cfi.c, libdwelf, libelf elf.h: Update from glibc. Add section compression constants and structures. libelf: use the right size when preading in[0].sh_size See all upstream changes since the previous merge: git diff a1e17a2..5eb3e90 * No changes to the following generated files: version.h, config.h, libdw/known-dwarf.h
| * elf.h: Update from glibc. Add section compression constants and structures.Mark Wielaard2015-10-222-0/+30
| | | | | | | | Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: use the right size when preading in[0].sh_sizeJose E. Marchesi2015-10-222-1/+6
| | | | | | | | Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
| * Move nested functions in libelf.Chih-Hung Hsieh2015-10-223-38/+49
| | | | | | | | | | | | | | | | * Move nested functions to file scope in libelf/elf_begin.c and elf32_updatefile.c to compile with clang. Signed-off-by: Chih-Hung Hsieh <chh@google.com>
* | Merge upstream 'a1e17a2', version 0.164.Chih-Hung Hsieh2015-10-195-23/+48
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * git merge a1e17a2 * Android relevant upstream changes: version number changed to 0.164 handle ELF with merged strtab/shstrtab handle missing SHF_INFO_LINK section flags open64 -> open loff_t -> int64_t conditionally include <config.h> See all upstream changes since the previous merge: git diff 86ed7f7..a1e17a2 * Manual changes (of generated files) after git merge: * version.h: new version number 164. * config.h: new version number 0.164, still keep Android #if __LP64__ * libdw/known-dwarf.h: no change Change-Id: Ieb1bfed35e76ee3a641499897863679e6d4da096
| * libelf: Use int64_t for offsets in libelf.hJosh Stone2015-10-142-6/+11
| | | | | | | | | | | | | | | | Some systems don't have loff_t, like FreeBSD where off_t always supports large files. We need a standardized 64-bit signed type for the public header, without depending on configuration... OK, just use int64_t. Signed-off-by: Josh Stone <jistone@redhat.com>
| * libelf: Only use posix_fallocate when using mmap. Ignore unsupported errors.Mark Wielaard2015-10-122-13/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Don't use posix_fallocate when not using mmap. It is enough to ftruncate the file to the right size. pwrite will report an error if there is no disk space left. And on file systems that don't support fallocate it might duplicate writes in that case. When using posix_fallocate do ignore most errors. Other libc implementations don't guarantee the call actually works always and even with glibc there might be an unexpected error from the fallback code when the file system doesn't support fallocate. That is pretty nasty since we might get a SIGBUS in that case when writing to the mmapped memory. But the chance of that happening is very small. And will normally never happen with glibc. So only report an error when posix_fallocate reports ENOSPC. Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * Trust AC_SYS_LARGEFILE to provide large file supportJosh Stone2015-10-093-4/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | AC_SYS_LARGEFILE defines _FILE_OFFSET_BITS in config.h if needed for LFS, and this automatically maps things like open to open64. But quite a few places used explicit 64-bit names, which won't work on platforms like FreeBSD where off_t is always 64-bit and there are no foo64 names. It's better to just trust that AC_SYS_LARGEFILE is doing it correctly. But we can verify this too, as some file could easily forget to include config.h. The new tests/run-lfs-symbols.sh checks all build targets against lfs-symbols (taken from lintian) to make sure everything was implicitly mapped to 64-bit variants when _FILE_OFFSET_BITS is set. Signed-off-by: Josh Stone <jistone@redhat.com>
* | Merge upstream commit '86ed7f7'.Chih-Hung Hsieh2015-10-083-11/+23
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | git merge 86ed7f7 Include upstream changes up to Thu Oct 8 00:16:03 2015. Previous clang compilation errors about union of VLA should be fixed with this merge. * Allocate exact amount of bytes for phdrs and shdrs. * Do without union of variable length arrays. * Other changes from upstream, not all used for Android: AM_SILENT_RULES coverage, sparc check_object_attribute ebl hook, Use -fPIC in PIC code. * No change of generated files such as: ./config.h, libdw/known-dwarf.h, ./version.h Change-Id: Iac63519112c4a92b57344f4a43bf0e9a6c4baa13
| * Do without union of variable length arrays.Chih-Hung Hsieh2015-10-072-8/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Prepare to compile with clang. A union like { T32 a32[n]; T64 a64[n]; } u; is expanded to size_t nbytes = n * MAX(sizeof(T32), sizeof(T64)); void *data = malloc(nbytes); T32 (*a32)[n] = data; T64 (*a64)[n] = data; Signed-off-by: Chih-Hung Hsieh <chh@google.com>
| * Improve AM_SILENT_RULES coverageJosh Stone2015-10-062-2/+6
| | | | | | | | | | | | | | | | | | | | | | Note, elfutils does not explicitly enable AM_SILENT_RULES. It's only available starting from automake 1.11, but starting from automake 1.13 silent rules are always generated, defaulting to verbose. $(AM_V_foo) additions should be no-ops on systems that don't support silent rules. To be silent, use "./configure --enable-silent-rules" or "make V=0". Signed-off-by: Josh Stone <jistone@redhat.com>
| * Use -fPIC instead of -fpic when generating PIC code.Jose E. Marchesi2015-10-062-1/+6
| | | | | | | | | | | | | | This avoids relocation overflows in sparc/sparc64 targets while linking, where the reachable data using -fpic is only 4kb. Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
* | Merge latest upstream commit 2284375.Chih-Hung Hsieh2015-10-062-5/+13
|\| | | | | | | | | | | | | | | | | | | | | | | * Four libdwfl nested functions were converted to standard C syntax, to compile with clang/llvm. * Other upstream changes since SHA d8698e5, see git log for details: sparc relocation types, update sh_info in unstrip, strtab/shstrtab string tables in strip and unstrip, update e_version and e_shentsize in elf_update, Ukrainian translation. Change-Id: Ib5871cd3873a8fdf88683c30d95effc7fdc338f5
| * libelf: Always update e_version and e_shentsize in elf_update.Mark Wielaard2015-10-052-5/+13
| | | | | | | | | | | | | | | | | | | | | | When e_version is EV_NONE we should set it to EV_CURRENT like we do for the EI_VERSION and like we set EI_DATA to the correct byte order when set to ELFDATANONE. Likewise we should always set e_shentsize like we do for e_phentsize, not just when ELF_F_LAYOUT isn't set. Add a new elfshphehdr testcase to check the above. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* | Merge in latest aosp/upstream-master d8698e55.Chih-Hung Hsieh2015-09-2995-649/+1067
|\| | | | | | | | | | | | | | | | | | | | | | | git merge d8698e55cbe95e56c3a4cbd67c320048ea4f087a Include upstream changes up to Wed Sep 23 20:44:06 2015. Update generated files: ./config.h ./libdw/known-dwarf.h ./version.h Change-Id: Ica2510edda846659a0c89703aeafe85bd62abab8
| * Properly mark all internal function definitions.Mark Wielaard2015-09-238-0/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since we banned old style function definitions GCC is able to diagnose function definitions that don't match the function declaration: elf32_getehdr.c:78: error: conflicting types for ‘__elf64_getehdr_wrlock’ libelfP.h:498: note: previous declaration of ‘__elf64_getehdr_wrlock’ This happens on i386 because there internal functions are marked with: # define internal_function __attribute__ ((regparm (3), stdcall)) Make sure all internal function declarations and definitions are marked with internal_function. Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * Remove old-style function definitions.Mark Wielaard2015-09-2386-398/+189
| | | | | | | | | | | | | | We already require -std=gnu99 and old-style function definitions might hide some compiler warnings. Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * Update dl-hash.h from glibc.Mark Wielaard2015-09-232-41/+38
| | | | | | | | | | | | | | | | | | | | Our dl-hash.h implementation originally came from, or was written at the same time as, the glibc implementation. At some point (around 9 years ago) they diverged and the elfutils version got an updated copyright header. The glibc version saw various updates/optimizations. Just treat the file like we do for elf.h and copy it whenever the glibc version is updated. Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: Don't leak memory on failure paths in elf_updatefile.Mark Wielaard2015-06-192-12/+22
| | | | | | | | | | | | | | When something goes wrong during the update make sure to always free any temporary allocated memory (shdr_data and/or scns). Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: Check symbol section header exists before use in nlist.Mark Wielaard2015-06-192-2/+10
| | | | | | | | Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: Always call ftruncate before posix_fallocate to set the right size.Mark Wielaard2015-06-192-2/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When elf_update.c (write_file) doesn't know the current maximum file length it might have to reduce the file size. posix_fallocate can only extend the file. So always call ftruncate before that to set the file size and making sure the backing store is fully there. Add test cases for checking strip in place (eu-strip without -o) actually reduces the file size. But only for non-ET_REL files. We might not be able to strip ET_REL files (except when they are kernel modules) because they might contain "dangling" symbol table entries. https://bugzilla.redhat.com/show_bug.cgi?id=1232206 Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: Make sure elf_getdata_rawchunk returns aligned data.Mark Wielaard2015-06-093-3/+34
| | | | | | | | | | | | | | | | | | | | elf_getdata_rawchunk might return an unaligned buffer for the requested ELF data type. Make sure the data is also correctly aligned when using an mmapped file. Also add some missing alignments for ELF data types for __libelf_type_align (the missing types could also make elf_getdata to return unaligned data). Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: Make sure conversion functions work on aligned data for type.Mark Wielaard2015-06-092-2/+29
| | | | | | | | | | | | | | | | | | | | | | The gelf_xlate conversion functions work on properly aligned ELF data types. If elf_get data needs to do conversion and ! ALLOW_UNALIGNED and the rawdata_base isn't aligned properly for the section type, then provide an aligned copy of the data. Found with --enable-sanitize-undefined in run-test-archive64.sh on x86_64. Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: Check e_shoff alignment before direct access of Elf(32|64)_Shdr.Mark Wielaard2015-06-082-4/+9
| | | | | | | | | | | | | | | | In get_shnum the check was whether the Elf(32|64)_Ehdr was correctly aligned, but to access the Shdr directly we need to check whether the address that points to the Elf(32|64)_Shdr structure is correctly aligned. Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: Split checks for ehdr and shdr, drop phdr check in file_read_elf.Mark Wielaard2015-06-082-65/+80
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are various places in the code that check whether mmapped structures are correctly aligned (or ALLOW_UNALIGNED is set). Some of these checks are asserts. Like the one in elf(32|64)_getshdr. We should not get into that part of the code if the shdr scn structure was cached in elf_begin because it was mmapped in and properly aligned. These asserts could trigger because in elf_begin.c file_read_elf () all alignment checks were combined. So even though only one of the ehdr, shdr or phdr structures were not properly aligned all structures would be copied. Also the phdr structure was not even read in elf_begin, so the alignment check was unnecessary. This patch splits the alignment checks and reading of ehdr and shdr structures into separate code paths. It also drops the phdr alignment checks in elf_begin. Those phdr checks are done in elf(32|64)_getphdr already. Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: Fix possible unbounded stack usage in load_shdr_wrlock.Mark Wielaard2015-06-052-4/+19
| | | | | | | | | | | | | | When a copy needs to be made of the shdrs, allocate with malloc and free after conversion instead of calling alloca. Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: Fix possible unbounded stack usage in getphdr_wrlock.Mark Wielaard2015-06-052-4/+19
| | | | | | | | | | | | | | When a copy needs to be made of the phdrs, allocate with malloc and free after conversion instead of calling alloca. Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: Fix unbounded stack usage in elf_getarsym for !ALLOW_UNALIGNED case.Mark Wielaard2015-06-052-1/+14
| | | | | | | | | | | | | | The number of entries in the index can be large, don't use alloca to read in temporary data, use malloc (which is freed after out). Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: Don't call memmove with possible NULL buffer.Mark Wielaard2015-06-052-2/+7
| | | | | | | | | | | | When size is zero the buffer src and dest buffers might be NULL. Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: Don't call mempcpy with possible NULL d_buf.Mark Wielaard2015-06-052-1/+6
| | | | | | | | | | | | | | When d_size is zero d_buf might be NULL. last_position doesn't need to be updated in that case. Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: Fix possible unbounded stack usage in updatefile.Mark Wielaard2015-05-272-3/+26
| | | | | | | | | | | | | | Allocate shdr_data and scns with malloc, not alloca. Free after writing section headers. Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: Fix possible unbounded stack usage in updatemmap.Mark Wielaard2015-05-272-8/+28
| | | | | | | | | | | | | | Allocate temporary shdr storage with malloc, not alloca. Free after writing section headers. Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: Fix possible unbounded stack usage in elf_getarsym.Mark Wielaard2015-05-272-2/+17
| | | | | | | | | | | | | | The number of entries in the index can be large, don't use alloca to read in temporary data, use malloc (and free after out). Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: Use posix_fallocate instead of ftruncate to extend ELF file.Mark Wielaard2015-05-272-3/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes an obscure SIGBUS error when using ELF_C_WRITE_MMAP on an ELF file that needs extending when the underlying file system is (nearly) full. Use posix_fallocate to make sure the file content is really there. Using ftruncate might mean the file is extended, but space isn't allocated yet. This might cause a SIGBUS once we write into the mmapped space and the disk is full. Using fallocate might fail on some file systems. posix_fallocate is required to extend the file and allocate enough space even if the underlying filesystem would normally return EOPNOTSUPP or the kernel doesn't implement the fallocate syscall. Also posix_fallocate has been in glibc since 2.1.94, while support for fallocate was only added in 2.10 and kernel 2.6.23. Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: If e_phnum is zero then set e_phoff also to zero.Mark Wielaard2015-05-182-0/+13
| | | | | | | | | | | | | | | | | | | | If phnum is zero make sure e_phoff is also zero and not some random value. That would cause trouble in update_file. This could happen when ELF_F_LAYOUT is set and the user copied over a ehdr from a bogus ELF file where the phdrs are unreadable. In that case trying to write out the new ELF image would crash trying to follow the bogus e_phdr value. Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: More checking of valid sh_addralign values.Mark Wielaard2015-05-183-0/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There were two issues with bogus sh_addralign values. First we would only check the individual Elf_Data d_align values were powerof2. But not the actual shdr addralign value. This would cause an issue if the shdr addralign was bigger than all of the individual d_align values. Then we could write out a bogus (! powerof2) shdr addralign value for the sections. Secondly when reading in the Elf_Data we would set the d_align value to the value of the shdr addralign value. But we would not check it was valid at all. In practice there are ELF files with incorrect sh_addralign values (they are a powerof2, but aren't aligned to the ELF image offset). We would try to fix that up in elf_update by adding extra padding. But this could bloat the ELF image a lot for large alignment values. So for too large alignments that are bigger than the offset in the ELF file clamp them to the offset value. This could lead us to reject to write out the data again when the offset was not a powerof2. But this will only happen for aligment values bigger than 64. Which are uncommon in practice. Signed-off-by: Mark Wielaard <mjw@redhat.com>
| * libelf: Make sure shdrs are valid before storing extended phnum in newphdr.Mark Wielaard2015-05-182-1/+17
| | | | | | | | | | | | | | | | | | Creating phdr with more than PN_XNUM phnum requires a valid section zero shdr to store the extended value. Make sure the shdrs are valid. Also fix the error when count was too big to store by setting ELF_E_INVALID_INDEX before failing. Signed-off-by: Mark Wielaard <mjw@redhat.com>