summaryrefslogtreecommitdiff
path: root/libelf/libelfP.h
Commit message (Collapse)AuthorAgeFilesLines
* support ZSTD compression algorithmMartin Liska2022-12-231-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | config/ChangeLog: * libelf.pc.in: Add LIBLZSTD to Requires.private. ChangeLog: * configure.ac: Detect ZSTD streaming API. libelf/ChangeLog: * Makefile.am: Use zstd_LIBS. * elf_compress.c: (__libelf_compress): Split into ... (__libelf_compress_zlib): ... this. (do_zstd_cleanup): New. (zstd_cleanup): New. (__libelf_compress_zstd): New. (__libelf_decompress): Switch in between zlib and zstd. (__libelf_decompress_zlib): Renamed from __libelf_decompress. (__libelf_decompress_zstd): New. (__libelf_decompress_elf): Dispatch in between compression algorithms. (elf_compress): Likewise. * elf_compress_gnu.c (elf_compress_gnu): Call with ELFCOMPRESS_ZLIB. * libelfP.h (__libelf_compress): Add new argument. (__libelf_decompress): Add chtype argument. src/ChangeLog: * elfcompress.c (enum ch_type): Add ZSTD. (parse_opt): Parse "zstd". (get_section_chtype): New. (process_file): Support zstd compression. (main): Add zstd to help. * readelf.c (elf_ch_type_name): Rewrite with switch. tests/ChangeLog: * Makefile.am: Add ELFUTILS_ZSTD if zstd is enabled. * run-compress-test.sh: Test zstd compression algorithm for debug sections.
* move platform depended include into system.h of libelfYonggang Luo2022-10-161-0/+1
| | | | | | | | All of these files either #include <system.h> directly or #include "libelfP.h" And now "libelfP.h also #include <system.h>, so the platform depended include can be moved to system.h safely Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
* libelf: Return already gotten Elf_Data from elf_getdata_rawchunkMark Wielaard2022-04-051-0/+1
| | | | | | | | | | | | | | | | | | | | | | 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>
* libdwfl: Make sure note data is properly aligned.Mark Wielaard2021-12-181-2/+2
| | | | | | | | | | | 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>
* Consistently define _(Str) using dgettext ("elfutils", Str)Dmitry V. Levin2020-12-161-3/+0
| | | | | | | | | | | | | | 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: fix spelling typos in commentsDmitry V. Levin2020-12-121-1/+1
| | | | | | | | | | | | | 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>
* libelf: Use GElf_Ehdr instead of Elf handle in __libelf_data_typeMark Wielaard2020-11-061-2/+3
| | | | | | | | | | | 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: Fix some 32bit offset/size issues that break updating 4G+ files.Mark Wielaard2019-06-281-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: Remove unused __elf_xfctstof.Mark Wielaard2019-02-281-2/+0
| | | | | | | __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-281-10/+0
| | | | | | | | | 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-281-25/+14
| | | | | | | | | | | | | | 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: Mark both fsize and msize with const attribute.Mark Wielaard2018-11-161-2/+2
| | | | | | | | | | GCC9 -Wmissing-attributes pointed out that although we alias the fsize and msize functions only fsize was marked as const. Fix by also marking the msize definition as const. https://sourceware.org/bugzilla/show_bug.cgi?id=23884 Signed-off-by: Mark Wielaard <mark@klomp.org>
* Recognize and parse GNU Property notes.Mark Wielaard2018-10-291-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 <mark@klomp.org>
* libelf: Don't return unaligned data returned from elf_getdata[_rawchunk].Mark Wielaard2018-06-221-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | For i386 and x86_64 we allow some unaligned data accesses. We also return unaligned data from elf_getdata[_rawchunk]. But that might go wrong if we then access the ELF types inside. When build with gcc -O3 for example the compiler might vectorize loops accessing ELF words or types. The instructions used do require the data is naturally aligned. If the function returnes unaligned data the program will segfault and crash. This happens for example with the code in dwfl_module_getdwarf.c that tries to iterate over the hash buckets gotten through elf_getdata_rawchunk based on the DT_[GNU]_HASH value. This only happens when the underlying ELF file is mmapped, and it is meant as optimization so that we don't have to copy data first so that it is correctly aligned. In most cases the data is already naturally aligned though. But it might not be for non-native ELF files. Given that it might even happen in our own code base and these are public functions that can be used by code that might rely on the data returned being correctly aligned for the ELF data type requested just always return correctly aligned data. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Add ELF_E_INVALID_ELF error value.Mark Wielaard2017-10-131-0/+1
| | | | | | | | Add ELF_E_INVALID_ELF which is set when the ELF file data is bad. This is different from ELF_E_INVALID_FILE which is set when the file could not be read. Signed-off-by: Mark Wielaard <mark@klomp.org>
* Check if gcc complains about __attribute__ (visibility(..))Ulf Hermann2017-08-181-1/+1
| | | | | | | | | | | | | | | If so, define attribute_hidden to be empty. Also, use attribute_hidden in all places where we hide symbols. If this attribute is missing, it simply means that we cannot hide private symbols in the binary using attributes. This disables some optimizations and may increase the risk of symbol name clashes with other libraries, but is not fatal. However, we still employ linker version scripts to explicitly define the exported symbols. This serves much of the same purpose. Also, as all our symbols are prefixed with the library name, and "__" for private ones, the chance of clashes is low anyway. Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
* Avoid double-including config.hUlf Hermann2017-05-021-4/+0
| | | | | | | | | | | | | | | | config.h doesn't have include guards, so including it twice is bad. We deal with this by checking for PACKAGE_NAME, but only in some places. Once we start using gnulib, we will need to include config.h before any gnulib-generated headers. This is problematic if we include it transitively through our own private headers. In order to set a clear rule about inclusion of config.h, it is now included in every .c file as first header, but not in any header. This will definitely avoid double-inclusion and satisfy the condition that it has to be included before gnulib headers. It comes at the price of adding some redundancy, but there is no clean way to avoid this. Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
* libelf: Fix memory leak in elf_compress for mmapped ELF files.Mark Wielaard2016-08-151-2/+8
| | | | | | | | | | | | | | | | 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 <mjw@redhat.com>
* libelf: Make elf_strptr index correctly into compressed section data.Mark Wielaard2016-01-061-0/+6
| | | | | | | | | 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-061-0/+24
| | | | Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libelf: Add elf32_getchdr, elf64_getchdr and gelf_getchdr.Mark Wielaard2016-01-061-1/+4
| | | | | | | | | 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>
* Trust AC_SYS_LARGEFILE to provide large file supportJosh Stone2015-10-091-3/+3
| | | | | | | | | | | | | | | 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>
* libelf: Make __libelf_set_data_list_rdlock an internal_function.Mark Wielaard2015-02-191-1/+1
| | | | | | | | | | __libelf_set_data_list_rdlock from elf_getdata.c is marked as an internal_function in the implementation, but not in libelfP.h when it is declared. Add internal_function to the declaration. This broke the i686 build. Reported-by: Alexander Cherepanov <ch3root@openwall.com> Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libelf: Fix elf_newdata when raw ELF file/image data is available.Mark Wielaard2015-02-061-0/+6
| | | | | | | | | | | | | | | When ELF data for a section has been read by elf_rawdata, data_read and rawdata_base are set, but data_list_rear will not be set until the data will be converted (by elf_getdata). elf_newdata would overwrite the existing data in that case. Both elf_getdata and elf_update rely on the fact that when data_list_rear is set they don't have to look at the raw data anymore. So make sure we update the data list properly before adding any new data and raw data is available in elf_newdata. Add newdata test that calls elf_newdata before and after elf_rawdata and elf_getdata and checks the new size and contents of the section. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libelf: gelf_getphdr should check phdr index is valid.Mark Wielaard2015-01-151-0/+2
| | | | | | | | | | | | elf_getphdrnum does checks the phdrnum makes sense. But gelf_getphdr checked the given index against the "raw" e_phnum or internal __elf_getphdrnum_rdlock result without checking. Extract the checking code into a new internal __elf_getphdrnum_chk_rdlock function and use that. Found by afl-fuzz. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* robustify: libelf gelf define INVALID_NDX macro.Jakub Jelinek2014-01-231-0/+4
| | | | Signed-off-by: Mark Wielaard <mjw@redhat.com>
* 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 <rfontana@redhat.com> Signed-off-by: Mark Wielaard <mjw@redhat.com>
* Fix doubled words.Marek Polacek2011-04-161-1/+1
|
* Add elf_getphdrnum, support >65536 phdrs.Roland McGrath2010-01-071-1/+3
|
* Reorder Elf struct members for optimal packing.Roland McGrath2009-07-081-26/+20
|
* Add aliases for elf_getshnum and elf_getshstrndx.Ulrich Drepper2009-06-131-4/+5
| | | | | | | | | | Sun in their implementation messed up the semantics of these functions. To get back to source code compatibility they asked for a solution. We simply add aliases for the two affected functions, named elf_getshdrnum and elf_getshdrstrndx. The semantics remains the same. Users of the old interfaces receive a warning for now. In future we might make it impossible to link programs which request the old interfaces (binary compatibility will of course be maintained).
* We only have one translation domain, elfutils. Change use in libelf.Ulrich Drepper2009-01-101-2/+2
|
* propagate from branch 'com.redhat.elfutils.roland.pending.libelf-threads' ↵Ulrich Drepper2008-12-041-3/+3
| | | | | | (head fc97c9c202b5d7d7699a3b1d5c53007a2ef37bb1) to branch 'com.redhat.elfutils' (head 67cccb9bfffc1a7fe3d8d355a2d9b6d0e489ff81)
* libdwfl/Roland McGrath2008-09-301-1/+1
| | | | | | | 2008-09-29 Roland McGrath <roland@redhat.com> * segment.c (insert): Must realloc DWFL->lookup_module here too. (dwfl_report_segment): Clear DWFL->lookup_module before insert calls.
* Fix up bogon and missing log entries from .pmachata.threads branch.Roland McGrath2008-08-251-70/+25
|
* Fix build problem after merge of pmachata.threads branch when compiled withoutUlrich Drepper2008-08-161-1/+1
| | | | thread support.
* propagate from branch 'com.redhat.elfutils.pmachata.threads' (head ↵Ulrich Drepper2008-08-161-12/+72
| | | | | | 8bd3bc10eb015c96f7bafcc6a22c973620b57dd8) to branch 'com.redhat.elfutils' (head c5a11b6b3329382f1b5ffd0020f0d93c64176f20)
* propagate from branch 'com.redhat.elfutils.disasm' (head ↵Ulrich Drepper2008-01-021-1/+5
| | | | | | d15b4eb794e81e477f9896fe82a74cb5ecf4514c) to branch 'com.redhat.elfutils' (head eaacbf01f8cc89d043ec6eca9b5e35cb5c4cde06)
* src/Roland McGrath2007-10-041-0/+15
| | | | | | | | | | | | | | | | | | | | 2007-10-04 Roland McGrath <roland@redhat.com> * readelf.c (print_archive_index): New variable. (options, parse_opt): Accept -c/--archive-index to set it. (dump_archive_index): New function. (process_file): Take new arg WILL_PRINT_ARCHIVE_INDEX. Call dump_archive_index on archives if set. (main): Update caller. (any_control_option): Give it file scope, moved out of ... (parse_opt): ... here. tests/ 2007-10-04 Roland McGrath <roland@redhat.com> * run-readelf-test4.sh: New file. * Makefile.am (TESTS, EXTRA_DIST): Add it.
* 2007-09-27 Roland McGrath <roland@redhat.com>Roland McGrath2007-09-271-0/+3
| | | | | | | | | | | | * alpha_retval.c: Use dwarf_attr_integrate and dwarf_hasattr_integrate. * i386_retval.c: Likewise. * ia64_retval.c: Likewise. * ppc64_retval.c: Likewise. * ppc_retval.c: Likewise. * s390_retval.c: Likewise. * sparc_retval.c: Likewise. * x86_64_retval.c: Likewise.
* propagate from branch 'com.redhat.elfutils.roland.pending' (head ↵Ulrich Drepper2007-03-301-1/+17
| | | | | | b584b7056d679db0fc272b47667047d07737ca55) to branch 'com.redhat.elfutils' (head 5f150a0b2f07e8c60913d4e6ad833ef026ccd26e)
* merge of 2043b4a4bc8f0359b8c216306758ab5900533fdeUlrich Drepper2006-06-101-14/+3
| | | | and fde883376d5d9573d47686c91400d14495518411
* * i386_ld.c (elf_i386_finalize_plt): Don't change symbol table entriesUlrich Drepper2006-06-101-3/+14
| | | | | | | | | | | for PLT entries if there is no local definition. * ld.c (parse_option): Handle -z ignore like --as-needed and -z record like --no-as-needed. * ld.h (struct ld_state): Remove ignore_unused_dsos field. * ldgeneric.c (new_generated_scn): Always compute ndt_needed by looping over DSOs. When deciding about adding DT_NEEDED entries use ->as_needed instead of ignore_unused_dsos.
* merge of 74ebb3c081458a7d19c744b155c767262efc47cbUlrich Drepper2006-06-041-14/+3
| | | | and cb87c403367a928f441c3dab11f1ed989884a7f7
* Handle as-needed options.Ulrich Drepper2006-05-311-3/+14
|
* No need for non-gcc support.Ulrich Drepper2006-05-281-14/+3
|
* 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)
* Add several more elflint tests:Ulrich Drepper2005-08-031-0/+5
| | | | | | | - check whether dynamic section matches PT_DYNAMIC program header entry - make sure text relocation flag is used correctly libelf needed one extension for this.
* Adjust for monotone.Ulrich Drepper2005-07-261-0/+534