summaryrefslogtreecommitdiff
path: root/libelf
Commit message (Collapse)AuthorAgeFilesLines
* libelf: Check for mremap, elf_update needs it for ELF_C_RDWR_MMAPMark Wielaard2022-04-242-0/+6
| | | | | | | | | | | Add a AC_CHECK_FUNCS configure check for mremap. Some systems like KFreeBSD and the Hurd don't have it. Also add a configure warning because without mremap elf_update will often fail when ELF_C_RDWR_MMAP is used. ELF_C_RDWR_MMAP is an elfutils extension to libelf. https://sourceware.org/bugzilla/show_bug.cgi?id=27337 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Return already gotten Elf_Data from elf_getdata_rawchunkMark Wielaard2022-04-053-0/+24
| | | | | | | | | | | | | | | | | | | | | | elf_getdata_rawchunk keeps a list of Elf_Data_Chunk to track which Elf_Data structures have already been requested. This allows elf_end to clean up all internal data structures and the Elf_Data d_buf if it was malloced. But it didn't check if a chunk was already requested earlier. This meant that if for example dwelf_elf_gnu_build_id was called multiple times to lookup a build-id from the phdrs a new Elf_Data_Chunk was created. This could slowly leak memory. So also keep track of the offset from which the size and type of the rawdata was requested so we can return existing data if it is requested multiple times. Note that the current cache is a simple linked list but the chain is normally not that long. It is normally used to get chunks from the phdrs, and there are normally less than 10. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Also copy/convert partial datastructures in xlate functionsMark Wielaard2022-03-302-2/+13
| | | | | | | | | | | The generated xlate functions can only convert full datastructures, dropping any trailing partial data on the floor. That means some of the data might be undefined. Just copy over the trailing bytes as is. That data isn't really usable. But at least it is defined data. https://sourceware.org/bugzilla/show_bug.cgi?id=29000 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Sync elf.h from glibc.Mark Wielaard2022-03-242-24/+87
| | | | | | | | | | | | | | Adds EM_INTELGT, NT_ARM_TAGGED_ADDR_CTRL, NT_ARM_PAC_ENABLED_KEYS, ELF_NOTE_FDO, NT_FDO_PACKAGING_METADATA and OpenRISC 1000 specific relocs. It also adds and renames some GNU_PROPERTY constants. But none of the constants the elfutils code uses was renamed or given a different constant value. dwelf_elf_e_machine_string was updated to handle EM_INTELGT. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Correct alignment of ELF_T_GNUHASH data for ELFCLASS64Mark Wielaard2022-03-232-6/+15
| | | | | | | | | | ELF_T_GNUHASH data is just 32bit words for ELFCLASS32. But for ELFCLASS64 it is a mix of 32bit and 64bit words. In the elf_cvt_gnuhash function we rely on the alignment of the whole to be 64bit word aligned, even though the first 4 words are 32bits. Otherwise we might try to convert an unaligned 64bit word. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Don't overflow offsets in elf_cvt_Verneed and elf_cvt_VerdefMark Wielaard2022-03-202-8/+55
| | | | | | | | The conversion functions for Verdef and Verneed keep offsets to the next structure. Make sure that following vd_aux, vda_next, vd_next, vn_aux, vna_next and vn_next don't overflow (and wrap around) the offsets. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Check alignment of Verdef, Verdaux, Verneed and Vernaux offsetsMark Wielaard2022-03-182-4/+19
| | | | | | | | The Verdef, Verdaux, Verneed and Vernaux structures contain fields which point to the next structures. Make sure these offsets are correctly aligned for the structures they point to. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Make sure ar_size starts with a digit before calling atol.Mark Wielaard2022-03-182-0/+9
| | | | | | | | | The ar_size field is a 10 character string, not zero terminated, of decimal digits right padded with spaces. Make sure it actually starts with a digit before calling atol on it. We already make sure it is zero terminated. Otherwise atol might produce unexpected results. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Take map offset into account for Shdr alignment check in elf_beginMark Wielaard2022-03-182-3/+10
| | | | | | | | | The sh_num function tries to get at the zero section Shdr directly. When the file is mmapped it has to make sure the offset into the file to the start of the Elf structure is taken into account when trying to cast the address to make sure the alignment is correct. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Only set shdr state when there is at least one shdrMark Wielaard2021-12-192-6/+15
| | | | | | | | The elf shdr state only needs to be set when scncnt is at least one. Otherwise e_shoff can be bogus. Also use unsigned arithmetic for checking e_shoff alignment. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Make sure note data is properly aligned.Mark Wielaard2021-12-182-2/+7
| | | | | | | | | | | In dwfl_segment_report_module the note data might not be properly aligned. Check that it is before accessing the data directly. Otherwise convert data so it is properly aligned. Also fix NOTE_ALIGN4 and NOTE_ALIGN8 to work correctly with long types. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Use offsetof to get field of unalignedMark Wielaard2021-12-162-6/+14
| | | | | | | | | | | | | | | | gcc undefined sanitizer flags: elf_begin.c:230:18: runtime error: member access within misaligned address 0xf796400a for type 'struct Elf64_Shdr', which requires 4 byte alignment struct. We aren't actually accessing the field member of the struct, but are taking the address of it. Which the compiler can take as a hint that the address is correctly aligned. But we can do the same by adding the field offsetof to the base address. Which doesn't trigger a runtime error. Signed-off-by: Mark Wielaard <mark@klomp.org>
* Remove redundant casts of memory allocating functions returning void *Dmitry V. Levin2021-09-0910-21/+33
| | | | | | | Return values of functions returning "void *", e.g. calloc, malloc, realloc, xcalloc, xmalloc, and xrealloc, do not need explicit casts. Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* libelf: Optimize elf_strptr.c validate_str by checking last char firstMark Wielaard2021-07-192-1/+8
| | | | | | | | | | | In most cases the last char of the sectio will be zero. Check that first before calling memrchr. This is a minor optimization in normal cases. But it helps asan a lot by removing the memrchr call in most cases. https://sourceware.org/bugzilla/show_bug.cgi?id=28101 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Fix unaligned d_off offsets for input sections with large alignmentsAndrei Homescu2021-07-082-1/+17
| | | | | | | | | | | | | | | | | | | | | The mkl_memory_patched.o object inside the libmkl_core.a library from the Intel Math Kernel Library version 2018.2.199 has this section with an alignment of 4096 and offset of 0xb68: [ 2] .data PROGBITS 0000000000000000 000b68 011000 00 WA 0 0 4096 Reading this file with libelf and trying to write it back to disk triggers the following sequence of events: 1) code in elf_getdata.c clamps d_align for this section's data buffer to the section's offset 2) code in elf32_updatenull.c checks if the alignment is a power of two and incorrectly returns an error This commit fixes this corner case by increasing the alignment to the next power of two after the clamping, so the check passes. A test that reproduces this bug using strip is also included. Signed-off-by: Andrei Homescu <ah@immunant.com>
* libelf: Sync elf.h from glibc.Mark Wielaard2020-12-162-6/+11
| | | | | | Adds SHF_GNU_RETAIN. Signed-off-by: Mark Wielaard <mark@klomp.org>
* Consistently define _(Str) using dgettext ("elfutils", Str)Dmitry V. Levin2020-12-162-3/+4
| | | | | | | | | | | | | | Move the definition of _(Str) macro to lib/eu-config.h which already provides a definition of N_(Str) macro. Since lib/eu-config.h is appended to config.h, it is included into every compilation unit and therefore both macros are now universally available. Remove all other definitions of N_(Str) and _(Str) macros from other files to avoid conflicts and redundancies. The next step is to replace all uses of gettext(Str) with _(Str). Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* libelf: Make sure we have at least a full ELF header available.Mark Wielaard2020-12-162-0/+11
| | | | | | | | | | | When elf_memory is called we could get a slightly too small image that doesn't contain a full ELF header (but does contain at least the e_ident values). Require the full header before even validating the rest of the ELF header fields. https://sourceware.org/bugzilla/show_bug.cgi?id=27076 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: fix spelling typos in commentsDmitry V. Levin2020-12-129-9/+20
| | | | | | | | | | | | | Auxialiary -> Auxiliary constucted -> constructed desriptor -> descriptor endianess -> endianness responsibilty -> responsibility sufficent -> sufficient elf.h comes from glibc and therefore is excluded. Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* Remove unused Makefile variable GCC_INCLUDEDmitry V. Levin2020-12-112-1/+5
| | | | | | It appears to be unused since the first commit in the revision history. Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* Fix automake warningsDmitry V. Levin2020-12-102-3/+8
| | | | | | | | | | | | | | | | | | | Apparently, commit 2f02e81510946a4c8e9157ad0b72d92894b9acd7 that removed $(EXEEXT) suffix from shared libraries was incomplete: it missed the fact that some libraries were included into noinst_PROGRAMS, resulting to the following automake warnings: libasm/Makefile.am:66: warning: deprecated feature: target 'libasm.so' overrides 'libasm.so$(EXEEXT)' libdw/Makefile.am:114: warning: deprecated feature: target 'libdw.so' overrides 'libdw.so$(EXEEXT)' libelf/Makefile.am:116: warning: deprecated feature: target 'libelf.so' overrides 'libelf.so$(EXEEXT)' Fix this by renaming noinst_PROGRAMS to noinst_DATA and removing no longer needed lib{asm,dw,elf}_so_SOURCES variables and add lib{asm,dw,elf).so to CLEANFILES. Fixes: 2f02e8151094 ("Drop $(EXEEXT) suffix from shared libraries") Signed-off-by: Dmitry V. Levin <ldv@altlinux.org> Signed-off-by: Mark Wielaard <mark@klomp.org>
* Drop $(EXEEXT) suffix from shared librariesDmitry V. Levin2020-12-062-1/+5
| | | | | | | | | According to GNU Automake documentation [1], $(EXEEXT) is the suffix that should be used for executables, it is not applicable for shared libraries. [1] https://www.gnu.org/software/automake/manual/html_node/EXEEXT.html Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* libelf: Update SH_ENTSIZE_HASH comment.Mark Wielaard2020-11-092-3/+7
| | | | | | | | | The elf-knowledge.h contains various macros to deal with specific ELF knowledge needed to interpret some ELF constructs that can be ambigious depending on architecture ABI. Update the comment of SH_ENTSIZE_HASH to add a more technical description of why it is needed. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Check header exists in elf_strptrMark Wielaard2020-11-062-1/+5
| | | | | | | | We already checked the header actually existed for ELFCLASS64 but not for the ELFCLASS32 case. It is very unlikely it is at this point in the code, but theoretically it could happen. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Set dst to zero on failure in __elf_getphdrnum_rdlockMark Wielaard2020-11-062-0/+6
| | | | | | | | | | | | GCC with -flto finds some (very) unlikely error paths. It flags callers of __elf_getphdrnum_chk_rdlock with *dst not yet set because an internal call to __elf_getphdrnum_rdlock might not initialize *dst either in one particular failure path. The sanity check that __elf_getphdrnum_chk_rdlock then performs might happen against uninitialized data. So just set *dst to zero on failure in __elf_getphdrnum_rdlock so any caller can simply check either the result/error code or whether *dst is zero or not. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Use GElf_Ehdr instead of Elf handle in __libelf_data_typeMark Wielaard2020-11-065-9/+24
| | | | | | | | | | | GCC with -flto detects some (very) unlikely issues in error paths. In theory getting the Ehdr from an Elf handle might fail. But in most cases where __libelf_data_type is used, we already have the Ehdr anyway. So simply pass that to __libelf_data_type. In the one place where we don't have it yet, get it and check for failure before calling __libelf_data_type. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Sync elf.h from glibc.Mark Wielaard2020-10-282-6/+4
| | | | | | Makes elf.h standalone and removes __BEGIN_DECLS/__END_DECLS macros. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Sync elf.h from glibc.Mark Wielaard2020-09-072-0/+6
| | | | | | Gets us DT_AARCH64_BTI_PLT and DT_AARCH64_PAC_PLT. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Fixup SHF_COMPRESSED sh_addralign in elf_update if necessary.Mark Wielaard2020-08-192-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | In elf_getdata.c we have the following to compensate for possibly bad sh_addralign values of compressed sections: /* Compressed data has a header, but then compressed data. Make sure to set the alignment of the header explicitly, don't trust the file alignment for the section, it is often wrong. */ if ((flags & SHF_COMPRESSED) != 0) { entsize = 1; align = __libelf_type_align (elf->class, ELF_T_CHDR); } Which makes sure the d_data alignment is correct for the Chdr struct at the start of the compressed section. But this means that if a user just reads such a compressed section without changing it, and then tries to write it out again using elf_update they get an error message about d_align and sh_addralign being out of sync. We already correct obviously incorrect sh_entsize fields. Do the same for the sh_addralign field of a SHF_COMPRESSED section. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Sync elf.h from glibc.Mark Wielaard2020-06-042-5/+105
| | | | | | | There is now finally a PT_GNU_PROPERTY define. Also EM_ARC_COMPACT2 got renamed to EM_ARCV2. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Check for NULL shdr in elf_strptr.Mark Wielaard2020-05-142-1/+5
| | | | | | | | GCC10 -fanalyzer with -flto notices __elf64_getshdr_rdlock can fail and because the result isn't checked in elf_strptr it can cause a dereference of NULL. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Check __gelf_getehdr_rdlock call doesn't fail in elf_getdata.Mark Wielaard2020-05-142-0/+7
| | | | | | | | GCC10 -fanalyzer with -flto notices __gelf_getehdr_rdlock can fail and that the result of the call in __libelf_set_rawdata_wrlock isn't checked, which can cause a dereference of NULL. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Fix double free in __libelf_compress on error path.Mark Wielaard2020-04-252-1/+4
| | | | | | | | | | In commit 2092865a7e589ff805caa47e69ac9630f34d4f2a "libelf: {de,}compress: ensure zlib resource cleanup" we added a call to deflate_cleanup to make sure all resources were freed. As GCC10 -fanalyzer points out that could cause a double free of out_buf. Fix by removing the free (out_buf) in __libelf_compress. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: handle PN_XNUM in elf_getphdrnum before shdr 0 is cachedOmar Sandoval2020-03-232-6/+19
| | | | | | | | | | | __elf_getphdrnum_rdlock() handles PN_XNUM by getting sh_info from elf->state.elf{32,64}.scns.data[0].shdr.e{32,64}. However, that is only a cache that may or may not have been populated by elf_begin() or elf{32,64}_getshdr(); if it hasn't been cached yet, elf_getphdrnum() returns 65535 (the value of PN_XNUM) instead. We should explicitly get the shdr if it isn't cached. Signed-off-by: Omar Sandoval <osandov@fb.com>
* libelf: {de,}compress: ensure zlib resource cleanupMatthias Maennich2020-03-202-6/+11
| | | | | | | | | | | | | | | __libelf_decompress would only cleanup zlib resources via inflateEnd() in case inflating was successful, but would leak memory if not. Fix this by calling inflateEnd() unconditionally. __libelf_decompress did this all the time already, but called deflateEnd() twice. That is not a (known) issue, but can be cleaned up by ensuring all error paths use 'return deflate_cleanup' and the success path calls deflateEnd() only once. Note, the deflate() needs to return Z_STREAM_END to indicate we are done. Hence change the condition. Fixes: 272018bba1f2 ("libelf: Add elf_compress and elf_compress_gnu.") Signed-off-by: Matthias Maennich <maennich@google.com>
* libelf: Fix some 32bit offset/size issues that break updating 4G+ files.Mark Wielaard2019-06-2811-43/+85
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some years ago, in commit b1d0b0fc "libelf: Use int64_t for offsets in libelf.h", we changed the public interface to use 64bit offsets/sizes. This wasn't really a API change, before we relied on loff_t always being 64bits on all platforms. We didn't change the implementation to use the int64_t type though. That was a little confusing, since the function definitions used a different type, int64_t, from the function implementations, off_t. Since we always build with _FILE_OFFSET_BITS=64 this should be fine. But it was a bit sloppy and confusing. Worse is that we got the translation of offset/sizes wrong in a couple of places when translating to ELF types. In various places we would use Elf32_Word or Elf64_Word. But both are 32bit (unsigned) types! As is GElf_Word. Elf32_Off is 32bits and Elf64_Off is 64bits. But we were not using those consistently. This patch introduces comments for the usage of [G]Elf(32|64)Word in libelf that are correct. And introduces Elf(32|64)_SizeWord in elf32_updatenull.c where we want to make a difference between sizes and offsets (the ELF variants are both unsigned, while int64_t/loff_t is signed). It also includes a new run-large-elf-file.sh test that creates a large ELF files (one 64bit, little endian, rel and another big endian, non-rel) and runs eu-strip, eu-elflint, eu-unstrip and eu-elfcmp. Before this patch, that test case fails and creates corrupt ELF files. The test is guarded by some checks that try to make sure there is enough disk space and memory available on the machine. The test is skipped otherwise. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Mark shdr_flags dirty if offset or size changes during update.Mark Wielaard2019-05-162-1/+9
| | | | | | | | | | | | | | | We forgot to mark the shdr_flags dirty when only the sh_size or sh_offset changed during elf_update (). This meant that if there were no other shdr changes we only wrote out the section data, but didn't write out the shdr table to the file. Add a testcase that puts some sections in the reverse order and then writes out the resulting file again without doing any other updates. This would show the issue after write out of the (re-reversed) ELF file (the .shstrtab section offset would be wrong causing all section names to be garbage). Also run a self test. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Add n_namesz offset overflow check to gelf_get_note.Mark Wielaard2019-05-042-2/+8
| | | | | | | | | | During fuzzing of the new xlate_notes testcase I noticed that gelf_get_note didn't check whether the n_namesz of a note was too big. This could lead to offset wrapping around. Causing an infinite loop going over all ELF notes. Fix by adding an overflow check before updating offset. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: If xlate can only convert the ELF note header, just do that.Mark Wielaard2019-05-042-2/+19
| | | | | | | | | | | | | | | | | When we started parsing new style ELF_T_NHDR8 notes we added extra checks on alignment and padding. When those failed we would stop converting and just return the rest of the ELF Note unconverted. In the case were we just had enough data for just the ELF Note header and the destionation and source weren't the same we would then accidentially throw away the Note header conversion we just did. Fix that by indicating we did correctly convert just the header. Adds testcase that compares parsing ELF notes with gelf_getnote and parsing the raw data by hand using elf32_xlatetom using just the Note header and ignoring the (raw) note data. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Sync elf.h from glibcMao Han2019-04-142-2/+98
| | | | Signed-off-by: Mao Han <han_mao@c-sky.com>
* libelf: Use posix_memalign instead of aligned_alloc.Mark Wielaard2019-03-072-3/+22
| | | | | | | | Older glibc might not have aligned_alloc (it is C11). Use posix_memalign instead. posix_memalign requires the alignment to be a multiple of sizeof (void *). So use malloc for smaller alignments. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Fix possible resource leak in elf[32|64]_updatefile.Mark Wielaard2019-03-062-0/+6
| | | | | | | When we cannot allocate enough memory to convert the data in updatemmap we should free the scns before returning an error. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Remove unused __elf_xfctstof.Mark Wielaard2019-02-283-6/+5
| | | | | | | __elf_xfctstof is only used in case the memory size and file size of ELF data structures are different. This is never the case. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Remove unused internal __elf[32|64]_msize functions.Mark Wielaard2019-02-283-12/+7
| | | | | | | | | Those functions were intended for ELF versions where the memory and file sizes of data structures are different. They were never used because libelf depends on the file and memory sizes being equal (otherwise using mmap wouldn't work). Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: There is just one ELF version.Mark Wielaard2019-02-2817-176/+111
| | | | | | | | | | | | | | Remove (partially defined out) code and data structures dealing with multiple ELF versions. There hasn't been a new ELF version in the last 20 years. Simplify the code a bit by just assuming there will only be one version (EV_CURRENT == 1). Simplifies elf_version, gets rid of __libelf_version_initialized. Removes one (or more) array (version) dimension from various tables and accessor functions (__elf_xfctstom, shtype_map, __libelf_data_type, __libelf_type_aligns and __libelf_type_sizes). Signed-off-by: Mark Wielaard <mark@klomp.org>`
* libelf: Handle zero size decompressed data.Mark Wielaard2019-02-192-13/+28
| | | | | | | | | | | | | | This is a corner case that will most likely never occur in practice, but we have several testcases that compress and decompress zero sized data. In that case during decompression we might malloc a buffer of size zero. It is allowed for malloc to return NULL in that case. But we do need a non-NULL buffer to return and set as result. So make sure to always at least allocate one byte. Also make sure that we don't allocate a zero sized conversion buffer for the data. https://sourceware.org/bugzilla/show_bug.cgi?id=24000 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Make sure ar_size is terminated when reading ar long names.Mark Wielaard2019-02-142-4/+23
| | | | | | | | | | The ar_size is given as a fixed size decimal string, right padded with spaces. Make sure we read it properly even if there is no terminating space. Also sanity check len early if we can. https://sourceware.org/bugzilla/show_bug.cgi?id=24085 Signed-off-by: Mark Wielaard <mark@klomp.org>
* configure: Add new --enable-install-elfh option.Mark Wielaard2019-01-312-3/+15
| | | | | | | | | | | | | | We explicitly test (with system-elf-libelf) that our include headers work with the system elf.h header. But it might be helpful to install the elf.h file for a private install. Our elf.h header really is just a copy of the latest glibc elf.h. But it might be newer and include more constants than the system installed elf.h. Add a new configure option --enable-install-elfh to install elf.h. But warn when it is enabled for the default /usr or /usr/local prefix because it might clash with the glibc/system elf.h header in that case. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Correct overflow check in note_xlate.Mark Wielaard2019-01-162-2/+7
| | | | | | | | | | We want to make sure the note_len doesn't overflow and becomes shorter than the note header. But the namesz and descsz checks got the note header size wrong). Replace the wrong constant (8) with a sizeof cvt_Nhdr (12). https://sourceware.org/bugzilla/show_bug.cgi?id=24084 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Get alignment correct when calling conversion functions.Mark Wielaard2018-11-212-5/+36
| | | | | | | | | | | | | | | | | | | | | | When writing out data that needs to be converted we have to make sure the conversion function is called on correctly aligned buffers. When using mmap this might mean we have to convert into a temporarily buffer if the user wants to write out the section at a location that is not correctly aligned for the section type. Older gas would generate misaligned ELF notes for the .version directive. When copying over such notes using mmap from files with a different endianness using mmap we would get the alignment of the conversion destination wrong. The new testcase would fail with configure --enable-sanitize-undefined on little endian systems. The GCC undefinited sanitizer caught a similar issue with testfile1 on big endian systems. gelf_xlate.h:47:1: runtime error: member access within misaligned address 0x7f8145d770d5 for type 'struct Elf32_Nhdr', which requires 4 byte alignment Signed-off-by: Mark Wielaard <mark@klomp.org>