summaryrefslogtreecommitdiffstats
path: root/libelf
Commit message (Collapse)AuthorAgeFilesLines
* Consolidate and add files to clean target variablesupstream/users/amerey/try-cleanMichael Pratt2024-11-081-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | To increase the consistency of how automatic clean targets run, define the variables together without +=, default to MOSTLYCLEANFILES when there is no need for different levels or add more clean levels to match other subdirectories, add more files that are built, remove duplication, and cleanup. Do the same for EXTRA_DIST where it is equally messy. * backends/Makefile.am: add more objects to clean, improve spacing. * debuginfod/Makefile.am: Likewise, and remove duplicates. * lib/Makefile.am: improve spacing. * libasm/Makefile.am: add more objects to clean, split similar to debuginfod. * libcpu/Makefile.am: use normal =, add more objects to clean. * libdw/Makefile.am: add more objects to clean, split similar to debuginfod. * libdwelf/Makefile.am: add more objects to clean, use lowest clean level. * libdwfl/Makefile.am: Likewise. * libebl/Makefile.am: add more objects to clean. * libelf/Makefile.am: add more objects to clean, split similar to debuginfod. * src/Makefile.am: consolidate including EXTRA_DIST, split clean levels, define with normal =, define with variables. * tests/Makefile.am: Likewise, but not including EXTRA_DIST. Signed-off-by: Michael Pratt <[email protected]>
* libelf: Only fetch shdr once in elf_compress[_gnu]Mark Wielaard2024-11-072-52/+48
| | | | | | | | | | | | | | Some compilers assume the second call to elf[32|64]_getshdr can fail and produce error: potential null pointer dereference. Just store the result of the first call and reuse (when not NULL). * libelf/elf_compress.c (elf_compress): Store getshdr result in a shdr union var. * libelf/elf_compress_gnu.c (): Likewise https://sourceware.org/bugzilla/show_bug.cgi?id=32311 Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Add libeu objects to libelf.a static archiveMark Wielaard2024-10-241-0/+3
| | | | | | | | | | | | | libelf might use some symbols from libeu.a, specifically the eu-search wrappers. But we don't ship libeu.a separately. So include the libeu objects in the libelf.a archive to facilitate static linking. * libelf/Makefile.am (libeu_objects): New variable. (libelf_a_LIBADD): New, add libeu_objects. https://sourceware.org/bugzilla/show_bug.cgi?id=32293 Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Treat elf_memory image as writableMark Wielaard2024-10-181-1/+2
| | | | | | | | | | | | | | | | | | | | | There are use cases where the Elf image created by elf_memory is manipulated, through the libelf interfaces, in place. This doesn't work anymore since we changed elf_memory to assume the memory is read-only in elfutils 0.191. commit cc44ac674 ('libelf: Treat elf_memory as if using ELF_C_READ_MMAP'). The reason for that change was that if elf_memory was given a read-only memory image then decompressing a section with elf_compress would crash. Since it directly writes the updated Shdr size. If you do want to use elf_compress on an Elf created by elf_memory you have make sure the memory is writable. You can do this for example by using mmap PROTE_WRITE and MAP_PRIVATE. * libelf/elf_memory.c (elf_memory): Call __libelf_read_mmaped_file with ELF_C_READ_MMAP_PRIVATE. * tests/elfgetzdata.c (main): Use mmap PROT_WRITE and MAP_PRIVATE. Signed-off-by: Mark Wielaard <[email protected]>
* libelf: elf_compress doesn't handle multiple elf_newdata chunks correctlyMark Wielaard2024-10-181-0/+10
| | | | | | | | | | | | | | | | | | | elf_compress would compress all (new) data chunks, but didn't reset the section data_list. This would cause extra data to be returned after decompression or create bad compressed data. Add a new testcase for this and explicitly zap the scn->data_list before resetting the elf section raw data after (de)compression. * libelf/elf_compress.c (__libelf_reset_rawdata): Cleanup scn->data_list. * tests/newzdata.c: New testcase. * tests/Makefile.am (check_PROGRAMS): Add newzdata. (TESTS): Likewise. (newzdata_LDADD): New variable. https://sourceware.org/bugzilla/show_bug.cgi?id=32102 Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Don't crash elf[32|64]_xlateto[fm] on bad arguments.Mark Wielaard2024-09-112-0/+18
| | | | | | | | | | Check that src and dest aren't NULL and that src->d_type < ELF_T_NUM. * elf32_xlatetof.c (elfw2(LIBELFBITS, xlatetof)): Check src, dest and src->d_type are valid. * elf32_xlatetom.c (elfw2(LIBELFBITS, xlatetom)): Likewise. Signed-off-by: Mark Wielaard <[email protected]>
* elf*_xlatetof: do not check ELF_T_NHDR[8] has integer number of recordsMark Wielaard2024-09-111-1/+5
| | | | | | | | | | | | commit bc0f7450c "elf*_xlatetom: do not check ELF_T_NHDR has integer number of records" fixed https://bugzilla.redhat.com/show_bug.cgi?id=835877 But only for xlatetom. Do the same for xlatetof. * elf32_xlatetof.c (elfw2(LIBELFBITS, xlatetof)): Do not check for integer number of records in case of ELF_T_NHDR[8]. Signed-off-by: Mark Wielaard <[email protected]>
* lib: Add eu_tsearch, eu_tfind, eu_tdelete and eu_tdestroyHeather McIntyre2024-08-204-15/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add struct search_tree to hold tree root and lock. Add new eu_t* functions for ensuring synchronized tree access. Replace tsearch, tfind, etc with eu_t* equivalents. lib: * Makefile.am (libeu_a_SOURCES): Add eu-search.c. (noinst_HEADERS): Add eu-search.h and locks.h. * eu-config.h: Move rwlock macros to locks.h. * eu-search.c: New file containing tree search functions with locking. * eu-search.h: New file. * locks.h: New file containing rwlock macros previously in eu-config.h. libdw: * cfi.h (struct Dwarf_CFI_s): Change type of search tree members from void * to search_tree. * cie.c: Replace tree search functions with eu-search equivalents. * dwarf_begin_elf.c (valid_p): Initialize search trees. * dwarf_end.c (cu_free): Replace tree search functions with eu-search equivalents. * dwarf_getcfi.c (dwarf_getcfi): Initialize search trees. * dwarf_getlocations.c: Replace search tree functions with eu-search equivalents. (__libdw_intern_expression): Change type of cache parameter to search_tree *. * dwarf_getmacros.c: Replace tree search functions with eu-search equivalents. * dwarf_getsrclines.c: Ditto. * fde.c: Ditto. * frame-cache.c (__libdw_destroy_frame_cache): Initialize search trees. * libdwP.h (struct Dwarf): Change type of search tree members from void * to search_tree. (struct Dwarf_CU): Ditto. (__libdw_intern_expression): Change type of cache parameter to search_tree *. * libdw_find_split_unit.c: Replace tree search functions with eu-search equivalents. * libdw_findcu.c: Ditto. libdwfl: * cu.c: Ditto. * libdwflP.h (struct Dwfl_Module): Replace void *lazy_cu_root with search_tree lazy_cu_tree. libelf: * elf_begin.c (file_read_elf): Initialize rawchunck_tree. * elf_end.c (elf_end): Replace tree search function with eu-search equivalent. * elf_getdata_rawchunck.c: Ditto. * libelfP.h (struct Elf): Replace void * rawchuncks member with search_tree rawchunk_tree. Signed-off-by: Heather S. McIntyre <[email protected]> Signed-off-by: Aaron Merey <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Fix deadlock in elf_cntlHeather McIntyre2024-08-201-11/+3
| | | | | | | | | * libelf/elf_cntl.c (elf_cntl): Move rwlock_wrlock, rwlock_unlock, inside case switch statements. Remove unnecessary early return. Signed-off-by: Heather S. McIntyre <[email protected]> Signed-off-by: Aaron Merey <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Fix deadlock in __libelf_readallHeather McIntyre2024-08-202-12/+16
| | | | | | | | Apply locking during __libelf_readall. Signed-off-by: Heather S. McIntyre <[email protected]> Signed-off-by: Aaron Merey <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Sync elf.h from glibcMark Wielaard2024-08-171-0/+4
| | | | | | * libelf/elf.h: Adds NT_ARM_{SSVE,ZA,ZT,FPRM} Signed-off-by: Mark Wielaard <[email protected]>
* libelf: elf32_getshdr might leak section header when out of memoryMark Wielaard2024-06-231-1/+1
| | | | | | | | | | | | Found by GCC -fanalyzer. When allocating the notcvt buffer fails we leak the shdr. goto free_and_out on malloc failure. * libelf/elf32_getshdr.c (load_shdr_wrlock): goto free_and_out on second malloc failure. Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Sync elf.h from glibcMark Wielaard2024-05-311-1/+11
| | | | | | | * libelf/elf.h: Adds AT_HWCAP{3,4}, NT_FDO_DLOPEN_METADATA and R_LARCH_TLS_DESC{32,64}. Signed-off-by: Mark Wielaard <[email protected]>
* Hexagon: implement machine flag checkMatheus Tavares Bernardino2024-04-041-0/+1
| | | | | | | | | | | | | This fixes the "invalid machine flag" error from eu-elflint when passing hexagon binaries. * backends/hexagon_init.c (hexagon_init): Hook machine_flag_check * backends/hexagon_symbol.c (hexagon_machine_flag_check): new function * libelf/elf-knowledge.h: add EF_HEXAGON_TINY constant Signed-off-by: Matheus Tavares Bernardino <[email protected]>
* Add support for HexagonMatheus Tavares Bernardino2024-04-041-0/+131
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This implements initial support for the Hexagon architecture. The Hexagon ABI spec can be seen at https://lists.llvm.org/pipermail/llvm-dev/attachments/20190916/21516a52/attachment-0001.pdf A hello_hexagon.ko test is also added. $ head tests/test-suite.log [...] # TOTAL: 275 # PASS: 269 # SKIP: 6 # XFAIL: 0 # FAIL: 0 # XPASS: 0 # ERROR: 0 $ cat tests/run-strip-reloc-ko.sh.log [...] runtest hello_hexagon.ko PASS run-strip-reloc-ko.sh (exit status: 0) * backends/Makefile.am (modules): Add hexagon. (hexagon_SRCS): New var for hexagon_init.c and hexagon_symbol.c. (libebl_backends_a_SOURCES): Add hexagon_SRCS. * backends/hexagon_init.c: New file. * backends/hexagon_reloc.def: Likewise. * backends/hexagon_symbol.c: Likewise. * libebl/eblopenbackend.c (hexagon_init): Declare. (machines): Add hexagon. * libelf/elf-knowledge.h: Add hexagon e_flags values, section indices and and relocs. * src/elflint.c (valid_e_machine): Add EM_QDSP6. * tests/Makefile.am (EXTRA_DIST): Add hello_hexagon.ko.bz2. * tests/hello_hexagon.ko.bz2: New test file. * tests/run-strip-reloc-ko.sh: Add hello_hexagon.ko. Signed-off-by: Matheus Tavares Bernardino <[email protected]>
* Support Mips architectureYing Huang2024-03-291-0/+3
| | | | | | | | | | | | | | * backends/Makefile.am (modules): Add mips. (mips_SRCS): New var for mips_init.c mips_symbol.c. (libebl_backends_a_SOURCES): Add mips_SRCS. * backends/mips_init.c: New file. * backends/mips_reloc.def: Likewise. * backends/mips_symbol.c: Likewise. * libebl/eblopenbackend.c (mips_init): Declare. (machines): Add mips. * libelf/libelfP.h: Add ELF64_MIPS_R_TYPE{1,2,3} Signed-off-by: Ying Huang <[email protected]>
* libelf: Sync elf.h from glibcXi Ruoyao2024-02-241-1/+30
| | | | | | Adds new LoongArch relocations. Signed-off-by: Xi Ruoyao <[email protected]>
* libelf: Treat elf_memory as if using ELF_C_READ_MMAPMark Wielaard2024-02-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | An Elf handle created through elf_memory was treated as if opened with ELF_C_READ. Which means libelf believed it had read the memory itself and could simply write to it if it wanted (because it wasn't mmaped directly on top of a file). This causes issues when that memory was actually read-only. Work around this by pretending the memory was actually read with ELF_C_READ_MMAP (so directly readable, but not writable). Add extra tests to elfgetzdata to check using elf_memory with read-only memory works as expected. * libelf/elf_memory.c (elf_memory): Call __libelf_read_mmaped_file with ELF_C_READ_MMAP. * tests/elfgetzdata.c (main): Add new "mem" option. * tests/run-elfgetzdata.sh: Also run all tests with new "mem" option. https://sourceware.org/bugzilla/show_bug.cgi?id=31225 Reported-by: Derek Bruening <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* libelf: check decompressed ZSTD sizeAleksei Vetrov2023-11-241-1/+1
| | | | | | | | | | | | | | Decompression functions like __libelf_decompress_zlib check that decompressed data has the same size as it was declared in the header (size_out argument). The same check is now added to __libelf_decompress_zstd to make sure that the whole allocated buffer is initialized. * libelf/elf_compress.c (__libelf_decompress_zstd): Use return value of ZSTD_decompress to check that decompressed data size is the same as size_out of the buffer that was allocated. Signed-off-by: Aleksei Vetrov <[email protected]>
* Minor: include <stdint.h> for uintptr_tPaul Pluzhnikov2023-11-151-0/+1
| | | | | | | | | We have a clang-tidy complaining that uintptr_t is not provided by any directly included header (it's only provided by a transitively included one). * libelf/elf_begin.c: Include <stdint.h> Signed-off-by: Paul Pluzhnikov <[email protected]>
* libelf: Fix elf_begin.c build on 32bit arches.Mark Wielaard2023-11-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | On 32bit architectures gcc produces an error: elf_begin.c: In function ‘file_read_elf’: elf_begin.c:495:30: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast] elf->state.elf64.shdr = (Elf64_Shdr *) (ehdr + e_shoff); ^ This is because we are adding an uintptr to an Elf64_Off which promotes the result to a 64bit value. Fix this by casting the e_shoff to an ptrdiff_t. This is fine since the mmap of the file would have failed if it didn't fit in the 32bit address space and we check that e_shoff fits inside the image. * libelf/elf_begin.c (file_read_elf): Cast e_shoff to ptrdiff_t before adding to ehdr. Suggested-by: Paul Pluzhnikov <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* Fix computations with (potentially) NULL pointerPaul Pluzhnikov2023-11-141-14/+10
| | | | | | | | | | | When map_address is NULL, computing map_address+offset is technically undefined behavior, and triggers Clang/LLVM warning when using -fsanitize=pointer-overflow. Fix this by using uintptr_t to perform computations. Signed-off-by: Shahriar "Nafi" Rouf <[email protected]> Signed-off-by: Paul Pluzhnikov <[email protected]>
* libelf: Fix possible memory leak in elf_getdata_rawchunkMark Wielaard2023-11-141-0/+5
| | | | | | | | | | | | If the rawchunk is not properly aligned we'll create a new buffer that is correctly aligned and put the data in that new buffer with memcpy or the conversion function. In such cases the rawchunk leaks because the new buffer is put into the Elf_Data_Chunk. * libelf/elf_getdata_rawchunk.c (elf_getdata_rawchunk): Call free on the rawchunk if new buffer was allocated. Signed-off-by: Mark Wielaard <[email protected]>
* libelf/elf_newscn.c: fix build failure against gcc-14 (-Walloc-size)upstream/masterSergei Trofimovich2023-11-031-3/+3
| | | | | | | | | | | | | | | | | | | `gcc-14` adde a new -Walloc-size warning that makes sure that size of an individual element matches size of a pointed type: https://gcc.gnu.org/PR71219 `elfutils` triggers is on `calloc()` call where member size is sued as `1`. elf_newscn.c: In function `elf_newscn`: elf_newscn.c:97:12: error: allocation of insufficient size «1» for type «Elf_ScnList» with size «16» [-Werror=alloc-size] 97 | newp = calloc (sizeof (Elf_ScnList) | ^ The change swaps arguments to pass larger value as a member size. Signed-off-by: Sergei Trofimovich <[email protected]>
* libelf: Make elf32_getchdr and elf64_getchdr thread-safeHeather McIntyre2023-10-146-44/+85
| | | | | | | | | | | | | | | * libelf/elf32_getchdr.c: Move getchdr function to elf32_getchdr.h. * libelf/elf32_getchdr.h: New file. Add macro to create getchdr_wrlock. * libelf/elf32_updatenull.c: Change call from getchdr to getchdr_wrlock. * libelf/elf_getdata.c: Add elf_getdata_wrlock. * libelf/libelfP.h: Add internal function declarations. * libelf/Makefile.am (noinst_HEADERS): Add elf32_getchdr.h. Signed-off-by: Heather S. McIntyre <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Fix elf_end deadlockHeather McIntyre2023-10-141-1/+4
| | | | | | | | * libelf/elf_end.c (elf_end): Add rwlock_unlock before early return. Signed-off-by: Heather S. McIntyre <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Make elf_version thread-safeHeather McIntyre2023-10-141-1/+10
| | | | | | | | | * elf_version.c (version_once): Define once. (initialize_version): New static function. (elf_version): Use initialize_version version_once. Signed-off-by: Heather S. McIntyre <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Sync elf.h from glibcYing Huang2023-10-131-2/+107
| | | | | MIPS add new ELF file header flags, new relocations and new section type SHT_MIPS_ABIFLAGS.
* libelf: tdelete dummy key if anything goes wrong setting up rawchunkMark Wielaard2023-09-111-2/+6
| | | | | | | | | | | | | elf_getdata_rawchunk uses a binary search tree cache. If a rawchunk is not yet in the cache we setup a new entry. But if anything went wrong setting up the new rawchunk we would leave a NULL key in the cache. This could blow up the next search. Fix this by removing the (dummy) key from the cache on any failure. * libelf/elf_getdata_rawchunk.c (elf_getdata_rawchunk): Don't assign NULL to *found. Call tdelete if anything goes wrong. Signed-off-by: Mark Wielaard <[email protected]>
* libelf: fix typos in commentCOCOCO X2023-09-102-1/+5
| | | | | | bug -> but Signed-off-by: Yanglin Xun <[email protected]>
* libelf: Sync elf.h from GlibcXi Ruoyao2023-08-291-0/+9
| | | | | | | | Adds new LoongArch relocations. * elf.h: Update from glibc. Signed-off-by: Xi Ruoyao <[email protected]>
* libelf, readelf, elflint: Add RELR supportMark Wielaard2023-08-297-2/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Handle RELR as defined here: https://groups.google.com/g/generic-abi/c/bX460iggiKg/m/YT2RrjpMAwAJ Introduce new ELF_T_RELR Elf_Type and handle it for SHT_RELR. Check various properties in elflint. Print RELR relocations in readelf. Just the entries with -U. Just the addresses with -N. And addresses plus symbol/offsets by default. Also add a test to check that gelf.h works with the system elf.h. * libebl/eblsectiontypename.c (ebl_section_type_name): Add RELR to knownstype. * libelf/elf32_updatenull.c (updatenull_wrlock): Handle sh_entsize for SHT_RELR. * libelf/gelf.h (GElf_Relr): New typedef for Elf64_Relr. * libelf/gelf_fsize.c (__libelf_type_sizes): Add ELF_T_RELR. * libelf/gelf_xlate.c (__elf_xfctstom): Likewise. * libelf/gelf_xlate.h: Add RELR as FUNDAMENTAL. * libelf/libelf.h (Elf_Type): Add ELF_T_RELR. Add RELR defines/typedefs if undefined in system elf.h. * libelf/libelfP.h: Define ELF32_FSZ_RELR and ELF64_FSZ_RELR. * src/elflint.c (check_reloc_shdr): Check she_entsize for ELF_T_RELR. (check_relr): New function. (check_dynamic): Handle DT_RELR. (special_sections): Add SHT_RELR. (check_sections): Call check_relr. * src/readelf.c (print_relocs): Also accept a Dwfl_Module. (handle_relocs_relr): New function. (print_dwarf_addr): Make static and declare early. (process_elf_file): Pass dwflmod to print_relocs. (handle_dynamic): Handle DT_RELRSZ and DTRELRENT. * system-elf-gelf-test.c: New test. * Makefile.am (TESTS): Add system-elf-gelf-test. (check_PROGRAMS): Likewise. (system_elf_gelf_test_CPPFLAGS): New variable. (system_elf_gelf_test_LDADD): Likewise. https://sourceware.org/bugzilla/show_bug.cgi?id=28495 Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Remove elf_scncnt from libelf.mapMark Wielaard2023-08-281-1/+0
| | | | | | | | | | | | | elf_scncnt was never implemented. It was probably an old name for elf_getshnum (which was the deprecated name of the elf_getshdrnum alias). Just remove it from the map file * libelf/libelf.map (ELFUTILS_1.0): Remove elf_scncnt. https://sourceware.org/bugzilla/show_bug.cgi?id=30729 Reported-by: Kostadin Shishmanov <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Free and clear rawdata_base and zdata_base consistentlyMark Wielaard2023-08-022-2/+17
| | | | | | | | | | | | | | | | | | | | There could be a leak if a program called elf_strptr on a compressed section, but the program never requests the (uncompressed) section data, but does explicitly (re)compress that same section data. Fix this by explicitly always freeing and clearing the zdata_base and rawdata_base in __libelf_reset_rawdata and elf_compress. Also clear zdata_base in elf_end so the pointer isn't indeterminate when it is being used in a later comparison against rawdata_base. * libelf/elf_compress.c (elf_compress): Explicitly free zdata_base before clearing. (__libelf_reset_rawdata): Free zdata_base if it isn't (going to be) used for rawdata_base. Explicitly clear rawdata_base and zdata_base after free. * libelf/elf_end.c (elf_end): Clear zdata_base after free. Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Replace list of elf_getdata_rawchunk results with a treeMark Wielaard2023-06-273-30/+52
| | | | | | | | | | | | | | | | | elf_getdata_rawchunks did a linear search to see if a chunk was already fetched. Replace this list with a binary search tree to make lookup faster when a lot of Elf_Data_Chunk were created. * libelf/libelfP.h (Elf_Data_Chunk): Remove next field. (struct Elf): Change the rawchunks type from Elf_Data_Chunk * to void *. * elf_getdata_rawchunk.c (chunk_compare): New static function. (elf_getdata_rawchunk): Use tsearch instead of a manual linked list. * elf_end.c (free_chunk): New static function. (elf_end): Call tdestroy instead of walking linked list. Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Sync elf.h from glibcAndreas Schwab2023-06-271-3/+10
| | | | | | | | Adds new RISC-V relocations. * elf.h: Update from glibc. Signed-off-by: Andreas Schwab <[email protected]>
* libelf: Sync elf.h from glibc.Youling Tang2023-04-072-1/+45
| | | | | | Adds R_LARCH_*. Signed-off-by: Youling Tang <[email protected]>
* libelf: Document and make ELFCOMPRESS_ZSTD usable with old system elf.hMark Wielaard2023-03-032-4/+14
| | | | | | | | Make sure that even if the system elf.h doesn't have ELF_COMPRESS_ZSTD defined it can still be used as constant. Also update libelf.h documentation and add new feature to NEWS. Signed-off-by: Mark Wielaard <[email protected]>
* libelf: memmove any extra bytes left by elf_cvt_gnuhash conversionMark Wielaard2023-02-232-2/+14
| | | | | | | | Otherwise some undefined bytes might be left in the buffer. Now they might still be not useful, but at least they are as defined in the file. Signed-off-by: Mark Wielaard <[email protected]>
* configure: Add --enable-sanitize-memoryIlya Leoshkevich2023-02-141-1/+2
| | | | | | | | | | | | | | | | | | | | Add support for clang Memory Sanitizer [1], which detects the usage of uninitialized values. While elfutils itself is already checked with valgrind, checking code that depends on elfutils requires elfutils to be built with MSan. MSan is not linked into shared libraries, and is linked into executables statically. Therefore, unlike the other sanitizers, MSan needs to be configured fairly early, since we need to drop -D_FORTIFY_SOURCE [2], -Wl,-z,defs and --no-undefined. Disable a few tests that run for more than 5 minutes due to test files being statically linked with MSan. [1] https://clang.llvm.org/docs/MemorySanitizer.html [2] https://github.com/google/sanitizers/issues/247 Signed-off-by: Ilya Leoshkevich <[email protected]>
* support ZSTD compression algorithmMartin Liska2022-12-234-57/+262
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* libelf: Sync elf.h from glibcMark Wielaard2022-12-012-7/+33
| | | | | | Adds various new ARC related declarations. Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Sync elf.h from glibcMark Wielaard2022-10-292-5/+17
| | | | | | Adds ELFCOMPRESS_ZSTD, NT_S390_PV_CPU_DATA and NT_LOONGARCH_*. Signed-off-by: Mark Wielaard <[email protected]>
* libelf/libdwfl: Remove LIB_SYSTEM_H define in lib{elf,dwfl}_crc32.cYonggang Luo2022-10-272-1/+4
| | | | | | | | | | | | | rationale: https://sourceware.org/bugzilla/show_bug.cgi?id=21001 If we don't remove this macro, when try #include <system.h> in libdw/memory-access.h wont' take effect because "#define LIB_SYSTEM_H 1" The compile error: ./../libdw/memory-access.h:390:12: error: implicit declaration of function ‘bswap_32’ [-Werror=implicit-function-declaration] Signed-off-by: Yonggang Luo <[email protected]>
* Strip __ prefix from __BYTE_ORDER __LITTLE_ENDIAN and __BIG_ENDIANYonggang Luo2022-10-175-8/+14
| | | | | | | | __BYTE_ORDER, __LITTLE_ENDIAN and __BIG_ENDIAN are defined by the gcc/clang preprocessor. BYTE_ORDER, LITTLE_ENDIAN and BIG_ENDIAN are defined in <endian.h>. Signed-off-by: Yonggang Luo <[email protected]>
* Move the #include <libintl.h> into eu-config.hYonggang Luo2022-10-161-1/+0
| | | | | | | | | | So we do not need include in each file. And indeed the macro #define _(Str) dgettext ("elfutils", Str) access libintl function dgettext, so it's make more sense #include <libintl.h> in file eu-config.h Signed-off-by: Yonggang Luo <[email protected]>
* move platform depended include into system.h of libelfYonggang Luo2022-10-1622-39/+26
| | | | | | | | 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 <[email protected]>
* libelf: Correctly decode ar_mode as octal stringMark Wielaard2022-09-142-2/+28
| | | | | | | | | ar_mode is encoded as an octal ascii string, not decimal. Add a new OCT_FIELD macro to decode it. https://sourceware.org/bugzilla/show_bug.cgi?id=28729 Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Sync elf.h from glibcAndreas Schwab2022-08-082-3/+100
| | | | | | | | | | Adds PT_RISCV_ATTRIBUTES, SHT_RISCV_ATTRIBUTES, PT_AARCH64_MEMTAG_MTE, RELR definitions, LoongArch relocations. dwelf_elf_e_machine_string was updated to handle EM_LOONGARCH, and ebl_dynamic_tag_name was updated to handle the new RELR dynamic tags. Signed-off-by: Andreas Schwab <[email protected]>
* 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 <[email protected]>