summaryrefslogtreecommitdiffstats
path: root/libelf/elf32_updatenull.c
Commit message (Collapse)AuthorAgeFilesLines
* Use fallthrough attribute.Joshua Watt2018-02-101-1/+1
| | | | | | | | | | | | | | | Use __attribute__ ((fallthrough)) to indicate switch case fall through instead of a comment. This ensures that the fallthrough warning is not triggered even if the file is pre-processed (hence stripping the comments) before it is compiled. The actual fallback implementation is hidden behind a FALLBACK macro in case the compiler doesn't support it. Finally, the -Wimplict-fallthrough warning was upgraded to only allow the attribute to satisfy it; a comment alone is no longer sufficient. Signed-off-by: Joshua Watt <[email protected]>
* lib: Provide MAX and MIN in system.hAkihiko Odaki2016-10-121-1/+1
| | | | | | | | | | This change also creates a new header file libeu.h to provide the prototypes for the function of libeu. That hides the definition of function crc32, which can conflict with zlib, from libelf. It also prevents mistakes to refer those functions from a component which doesn't link with libeu, such as libelf. Signed-off-by: Akihiko Odaki <[email protected]>
* libelf: Allow updating phdrs for any e_type.Mark Wielaard2016-07-111-13/+2
| | | | | | | | | | | | | | | | | | | | | | | | elf[32|64]_updatenull would sanity check the e_type before allowing to update the phdrs. This prevents creating an ET_REL file with phdrs. It also prevents creating any vendor specific ELF file having phdrs. We only check this when updating/writing out the file. But we would just read such files. Don't prevent people from creating unexpected ELF files. elflint will warn for such files. While writing a new testcase for this another bug was found that prevented updating a just created phdr because elf_getphdrnum would sanity check the phdr offset in the file (which doesn't exist yet). Fix that by only doing such a sanity check if the phdrs haven't been read in or created yet. This second bug should have been found by the existing elfshphehdr test, but that test contained a typo checking elf_getphdrnum. It tested that the called failed when there were no phdrs, but then elf_getphdrnum should simply succeed and return zero. https://bugzilla.redhat.com/show_bug.cgi?id=1352232 Signed-off-by: Mark Wielaard <[email protected]>
* libelf: find 1st section instead of assumingJohn Ogness2016-06-281-2/+9
| | | | | | | | | | | | | | | | | | When getting section headers it is assumed that the first section is on the first section list. However, it is possible that the first section list only contains the zeroth section, in which case either illegal memory access occurs or elf_nextscn() erroneously returns NULL. With this patch, checks are added to avoid the illegal memory access and (if available) the second section list is looked at to find the first section. A new test emptyfile is added that tests adding a section to and "empty" ELF file 32/64 class with ELF_C_RDWR[_MMAP]. Signed-off-by: John Ogness <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Add elf_compress and elf_compress_gnu.Mark Wielaard2016-01-061-4/+19
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Always update e_version and e_shentsize in elf_update.Mark Wielaard2015-10-051-5/+8
| | | | | | | | | | | 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 <[email protected]>
* libelf: If e_phnum is zero then set e_phoff also to zero.Mark Wielaard2015-05-181-0/+8
| | | | | | | | | | 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 <[email protected]>
* libelf: More checking of valid sh_addralign values.Mark Wielaard2015-05-181-0/+5
| | | | | | | | | | | | | | | | | | | | 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 <[email protected]>
* libelf: Don't extend ELF file size with SHT_NOBITS sh_offset.Mark Wielaard2015-03-271-4/+3
| | | | | | | | | | | | | | | | | | | | | Don't explicitly extend the file size for SHT_NOBITS sections. Since that could cause a size beyond any actual file content it will cause issues when the underlying ELF file has been mmapped or will extend the file size to increase (writing fill bytes) when not mmapped. The sh_offset value is essentially meaningless for SHT_NOBITS. gabi says that a NOBITS section sh_offset member locates the "conceptual placement" in the file. But it doesn't say this cannot be beyond the enf of the file. When ELF_F_LAYOUT is set we should trust sh_offset as given is what is wanted for an SHT_NOBITS section without extending the file size. https://bugzilla.redhat.com/show_bug.cgi?id=1020842 Buggy binutils ld could generate files where SHT_NOBITS sections have sh_offset outside the file. https://sourceware.org/bugzilla/show_bug.cgi?id=12921 Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Consider sh_addralign 0 as 1Jan Kratochvil2015-02-071-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently the Koji build for arm32 fails with: extracting debug info from /builddir/build/BUILDROOT/etcd-2.0.0-0.3.rc1.fc22.arm/usr/bin/etcd Failed to write file: invalid section alignment This is because the binary etcd http://people.redhat.com/jkratoch/etcdctl.xz contains: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [11] .rel.plt REL 00459ee0 449ee0 000088 08 A 13 0 0 ^ which corresponds to golang's code: go/src/cmd/ld/elf.c case EM_X86_64: sh = elfshname(".rela.plt"); sh->addralign = RegSize; default: sh = elfshname(".rel.plt"); <nothing> ELF spec says: Values 0 and 1 mean the section has no alignment constraints. and libelf/elf32_updatenull.c really parses it that way at line 204 ElfW2(LIBELFBITS,Word) sh_align = shdr->sh_addralign ?: 1; but unfortunately the later line being patched no longer does. libelf/ 2015-02-07 Jan Kratochvil <[email protected]> * elf32_updatenull.c (__elfw2(LIBELFBITS,updatenull_wrlock)): Consider sh_addralign 0 as 1. Signed-off-by: Jan Kratochvil <[email protected]>
* Update name, license and contributor policy.Mark Wielaard2012-06-051-40/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Change name from "Red Hat elfutils" to "elfutils". * Update license of standalone tools and test from GPLv2 to GPLv3+. * Change license of libraries from GPLv2+exception to GPLv2/LGPLv3+. * Add Developer Certificate of Origin based contributor policy. top-level: - COPYING: Upgraded from GPLv2 to GPLv3. - CONTRIBUTING, COPYING-GPLv2, COPYING-LGPLv3: New files. - NEWS: Added note about new contribution and license policy. - Makefile.am: Updated to GPLv3, added new files to EXTRA_DIST. - configure.ac: Update to GPLv3, changed AC_INIT name to 'elfutils'. backends, lib, libasm, libcpu, libdw, libdwfl, libebl, libelf: - All files updated to GPLv2/LGPLv3+. Except some very small files (<5 lines) which didn't have any headers at all before, the linker .maps files and the libcpu/defs files which only contain data and libelf/elf.h which comes from glibc and is under LGPLv2+. config: - elfutils.spec.in: Add new License: headers and new %doc files. - Update all license headers to GPLv2/LGPLv3+ for files used by libs. src, tests: - All files updated to GPLv3+. Except for the test bz2 data files, the linker maps and script files and some very small files (<5 lines) that don't have any headers. Signed-off-by: Richard Fontana <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* Add elf_getphdrnum, support >65536 phdrs.Roland McGrath2010-01-071-3/+7
|
* Fix commit in updatenull_wrlock wrt to layout resulting from section headerUlrich Drepper2009-01-261-3/+4
| | | | table position and size.
* propagate from branch 'com.redhat.elfutils.roland.pending.libelf-threads' ↵Ulrich Drepper2008-12-041-1/+1
| | | | | | (head fc97c9c202b5d7d7699a3b1d5c53007a2ef37bb1) to branch 'com.redhat.elfutils' (head 67cccb9bfffc1a7fe3d8d355a2d9b6d0e489ff81)
* Fix up bogon and missing log entries from .pmachata.threads branch.Roland McGrath2008-08-251-7/+6
|
* propagate from branch 'com.redhat.elfutils.pmachata.threads' (head ↵Ulrich Drepper2008-08-161-6/+10
| | | | | | 8bd3bc10eb015c96f7bafcc6a22c973620b57dd8) to branch 'com.redhat.elfutils' (head c5a11b6b3329382f1b5ffd0020f0d93c64176f20)
* Lock down libelf and elflint a bit more after import of Roland's changes.Ulrich Drepper2006-12-181-4/+7
|
* propagate from branch 'com.redhat.elfutils' (head ↵Roland McGrath2006-12-171-3/+3
| | | | | | b4944cf70801d9dac056f4f80ef1334e5acb8bdc) to branch 'com.redhat.elfutils.roland.pending' (head e7e402c668fb0670fc5f6b6a522853ae88f32f11)
* merge of 67f3844b544f03a64b3ac896c19f94744923d76aUlrich Drepper2006-07-121-1/+1
| | | | and ba017f6b59b4ad649cf32f4eefdfecca8b31332c
* propagate from branch 'com.redhat.elfutils.roland.pending' (head ↵Ulrich Drepper2006-07-121-1/+1
| | | | | | e5cfdd13aa39dfae16b905fd57ff56ad8a131bb5) to branch 'com.redhat.elfutils' (head 60222fc1981540f15e674b6705fd7a6f628f95a4)
* Adjust for internal_function_def removal.Ulrich Drepper2006-07-121-1/+1
|
* Fix FSF address. No exception for libdwarf.Ulrich Drepper2006-04-041-1/+1
|
* propagate from branch 'com.redhat.elfutils.roland.pending' (head ↵Ulrich Drepper2006-04-041-12/+45
| | | | | | 4f8fc821345feef58624f0aa5b470d4827577d8c) to branch 'com.redhat.elfutils' (head 76e26cb54695fd3b21ee8fb5be3036bd68200633)
* Fix read/write of existing file using mmap and different layout of the ELFUlrich Drepper2006-04-041-2/+12
| | | | file.
* Adjust for monotone.Ulrich Drepper2005-07-261-0/+384