summaryrefslogtreecommitdiffstats
path: root/libelf/elf_compress.c
Commit message (Collapse)AuthorAgeFilesLines
* libelf: Correctly setup alignment of SHF_COMPRESSED section data.Mark Wielaard2018-11-131-2/+2
| | | | | | | | | | | We didn't set the alignment of SHF_COMPRESSED sections correctly. Those sections start with an Elf(32|64)_Chdr. Make sure sh_addralign is setup to be able to read such a struct directly. Likewise don't trust the alignment set on any SHF_COMPRESSED section, but always make the (raw) compressed data aligned correctly for the reading the Elf(32|64)_Chdr directly. Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Explicitly update section data after (de)compression.Mark Wielaard2018-11-091-0/+6
| | | | | | | | | | | | | | We need to explictly trigger a section data reload after updating the ELF section rawdata to make sure it gets written out to disk on an elf_update. Doing this showed one bug/inefficiently when the underlying file has a different endianness. In that case for debug sections we would convert by allocating a new buffer and just copying over the raw data into a new buffer. This is not really necessary and would hide any relocations done on the rawdata by libdwfl. Added a couple of new ppc64 big endian testfiles that show the issue. Signed-off-by: Mark Wielaard <[email protected]>
* Recognize and parse GNU Property notes.Mark Wielaard2018-10-291-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GNU Property notes are different from normal notes because they use variable alignment/padding of their fields. They are 8 byte aligned, but use 4 byte fields. The name is aligned at 4 bytes and padded so that, the desc is aligned at 8 bytes. The whole note is padded to 8 bytes again. For normal notes all fields are both 4 bytes wide and 4 bytes aligned. To recognize these new kind of ELF Notes a new Elf_Type is introduced, ELF_T_NHDR8. This type is used in the xlate functions to determine how to align and pad the various fields. Since the fields themselves can now have different alignments we will have to keep track of the current alignement and use either NOTE_ALIGN4 or NOTE_ALIGN8 to determine the padding. To set the correct Elf_Type on the Elf_Data we use either the section sh_addralign or the segment p_align values. Assuming 8 means the section or segment contains the new style notes, otherwise normal notes. When we cannot determine the "alignment" directly, like when parsing special kernel sys files, we check the name "GNU" and type "GNU_PROPERTY_TYPE_0" fields. ebl_object_note now parses the new NT_GNU_PROPERTY_TYPE_0 and can extract the GNU_PROPERTY_STACK_SIZE, GNU_PROPERTY_NO_COPY_ON_PROTECTED and GNU_PROPERTY_X86_FEATURE_1_AND types GNU_PROPERTY_X86_FEATURE_1_IBT and GNU_PROPERTY_X86_FEATURE_1_SHSTK. Tests are added for extracting the note from sections or segments as set by gcc -fcf-protection. Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Check compression ratio before trying to allocate output buffer.Mark Wielaard2017-04-031-0/+9
| | | | | | | | | | The maximum compression factor (http://www.zlib.net/zlib_tech.html) is 1032:1. Add a sanity check for that before trying to allocate lots of memory and trying to decompress lots of bogus data. https://sourceware.org/bugzilla/show_bug.cgi?id=21301 Signed-off-by: Mark Wielaard <[email protected]>
* lib: Provide MAX and MIN in system.hAkihiko Odaki2016-10-121-5/+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: Fix memory leak in elf_compress for mmapped ELF files.Mark Wielaard2016-08-151-2/+5
| | | | | | | | | | | | | | | | The testcase added to run-strip-reloc.sh for strip-compressed.o showed a memory leak when ran under valgrind (configure --enable-valgrind). For a mmapped ELF file when existing section data was compressed elf_end would fail to release the new compressed data buffer assigned to rawdata_base. For non-mapped files rawdata_base is always freed. For decompressed data rawdata_base is released together with zdata_base. Use the Elf_Scn flag ELF_T_MALLOCED to track whether rawdata_base points to malloced memory and free it in elf_end even for mmapped ELF files. Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Fix memory leak when zlib deflateInit fails in elf_compress.Mark Wielaard2016-04-141-0/+1
| | | | | | On error we return NULL, not out_buf. So make sure to not leak it. Signed-off-by: Mark Wielaard <[email protected]>
* Move nested functions in elf_compress.c and elf_strptr.c.Chih-Hung Hsieh2016-01-231-10/+15
| | | | | | | * elf_compress.c (__libelf_compress): do_deflate_cleanup * elf_strptr.c (elf_strptr): get_zdata Signed-off-by: Chih-Hung Hsieh <[email protected]>
* libelf: Make elf_strptr index correctly into compressed section data.Mark Wielaard2016-01-061-38/+59
| | | | | | | | | 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 <[email protected]>
* libelf: Add elf_compress and elf_compress_gnu.Mark Wielaard2016-01-061-0/+490
Signed-off-by: Mark Wielaard <[email protected]>