summaryrefslogtreecommitdiffstats
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* strip: Close debug file before unlinking it on errorQtCreator4.9.2QtCreator4.9.1QtCreator4.9.0-rc1QtCreator4.9.0-beta2QtCreator4.9.0-beta1QtCreator4.9.0QtCreator4.10.2QtCreator4.10.1QtCreator4.10.0-rc1QtCreator4.10.0-beta2QtCreator4.10.0-beta1QtCreator4.10.04.94.10Ulf Hermann2019-01-181-2/+2
| | | | | | | On some platforms, notably windows, you cannot unlink open files. Change-Id: Ifd73520005b3c233c112baf0b72fd8cf2f57c671 Reviewed-by: Christian Kandeler <[email protected]>
* strip: unlink() debug file before rename()ing into itUlf Hermann2019-01-181-0/+1
| | | | | | | On windows you cannot rename into an existing file. Change-Id: I07ad0b42260e98579b00d828c96bd47db006840c Reviewed-by: Christian Kandeler <[email protected]>
* Merge tag 'elfutils-0.175'Ulf Hermann2019-01-0910-394/+982
|\ | | | | | | | | | | elfutils 0.175 release Change-Id: I409f41767af349d0521351dd733879ad31c65aab
| * elflint: Allow PT_GNU_EH_FRAME segment to match SHT_X86_64_UNWIND section.Mark Wielaard2018-11-132-2/+9
| | | | | | | | | | | | | | The gold linker might generate an .eh_frame_hdr with a SHT_X86_64_UNWIND type instead of a SHT_PROGBITS type. Signed-off-by: Mark Wielaard <[email protected]>
| * strip: Also handle gnu compressed debug sections with --reloc-debug-sectionsMark Wielaard2018-11-132-6/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | Check whether a section was gnu compressed and decompress it first before trying to resolve relocations. Recompress it afterwards. This found a bug in elf_compress_gnu which would use the "raw" file contents even if the user had just created the section (copying over the section from the original input file). Add compressed ET_REL tests to run-strip-reloc.sh testcase. Signed-off-by: Mark Wielaard <[email protected]>
| * Handle GNU Build Attribute ELF Notes.Mark Wielaard2018-11-133-2/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GNU Build Attribute ELF Notes are generated by the GCC annobin plugin and described at https://fedoraproject.org/wiki/Toolchain/Watermark Unfortunately the constants aren't yet described in the standard glibc elf.h so they have been added to the elfutils specific elf-knowledge.h. The notes abuse the name owner field to encode some data not in the description. This makes it a bit hard to parse. We have to match the note owner name prefix (to "GA") to be sure the type is valid. We also cannot rely on the owner name being a valid C string since the attribute name and value can contain zero (terminators). So pass around namesz to the ebl note parsing functions. eu-elflint will recognize and eu-readelf -n will now show the notes: Note section [27] '.gnu.build.attributes' of 56080 bytes at offset 0x114564: Owner Data size Type GA 16 GNU Build Attribute OPEN Address Range: 0x2f30f - 0x2f30f VERSION: "3p8" GA 0 GNU Build Attribute OPEN TOOL: "gcc 8.2.1 20180801" GA 0 GNU Build Attribute OPEN "GOW": 45 GA 0 GNU Build Attribute OPEN STACK_PROT: 0 GA 0 GNU Build Attribute OPEN "stack_clash": TRUE GA 0 GNU Build Attribute OPEN "cf_protection": 0 GA 0 GNU Build Attribute OPEN "GLIBCXX_ASSERTIONS": TRUE GA 0 GNU Build Attribute OPEN "FORTIFY": 0 GA 0 GNU Build Attribute OPEN PIC: 3 GA 0 GNU Build Attribute OPEN SHORT_ENUM: FALSE GA 0 GNU Build Attribute OPEN ABI: c001100000012 GA 0 GNU Build Attribute OPEN "stack_realign": FALSE A new test was added to run-readelf -n for the existing annobin file. Signed-off-by: Mark Wielaard <[email protected]>
| * Recognize NT_VERSION notes.Mark Wielaard2018-11-133-6/+29
| | | | | | | | | | | | | | | | NT_VERSION notes are emitted by the gas .version directive. They have an empty description and (ab)use the owner name to store the version data string. Signed-off-by: Mark Wielaard <[email protected]>
| * libdwelf: New function dwelf_elf_begin.Mark Wielaard2018-11-092-5/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This introduces a new function dwelf_elf_begin which creates a (read-only) ELF handle from a possibly compressed file handle or a file that start with a linux kernel header. This can be used in eu-readelf to (re)open a (pure) ELF. eu-readelf uses libdwfl to relocate addresses in the original file in case it is ET_REL. But to show the "raw" data it might need to (re)open the file. Which could fail if the file was compressed. And produced an obscure error message: "cannot create EBL handle". This rewrites __libdw_open_file a little so that the given file handle will never be closed (whether on success or failure) and introduces a new internal function __libdw_open_elf that dwelf_elf_begin wraps. Signed-off-by: Mark Wielaard <[email protected]>
| * strip: Add --reloc-debug-sections-only option.Mark Wielaard2018-11-062-6/+160
| | | | | | | | | | | | | | | | | | | | | | This option does the same thing as --reloc-debug-sections without doing any other strip operation. This is useful when you want to remove the debug section relocations in a separate ET_REL debug file that was created without --reloc-debug-sections, or for a file (like the linux debug vmlinux) that you don't want to strip, but for which the debug section relocations can be resolved already. Signed-off-by: Mark Wielaard <[email protected]>
| * strip: Extract code to update shdrstrndx into new common function.Mark Wielaard2018-11-062-45/+54
| | | | | | | | Signed-off-by: Mark Wielaard <[email protected]>
| * strip: Split out debug section relocation into separate helper functions.Mark Wielaard2018-11-062-249/+299
| | | | | | | | | | | | | | | | Extract a couple of helper functions out of handle_elf (secndx_name, get_xndxdata and remove_debug_relocations) so they can be reused more easily in the future. Signed-off-by: Mark Wielaard <[email protected]>
| * strip: Always copy over any phdrs if there are any.Mark Wielaard2018-11-062-28/+48
| | | | | | | | | | | | | | | | Ignore the type of ELF file, just copy over any phdrs if the original file contained any. Also refuse to move around any allocated sections based on whether there are any phdrs instead of on ELF file type. Signed-off-by: Mark Wielaard <[email protected]>
| * unstrip: Add ELF_CHECK to make sure gelf_getehdr () doesn't return NULL.Mark Wielaard2018-11-022-0/+6
| | | | | | | | Signed-off-by: Mark Wielaard <[email protected]>
| * Recognize and parse GNU Property notes.Mark Wielaard2018-10-293-2/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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]>
| * addr2line: Use elf_getshdrstrndx not Ehdr field to print section name.Mark Wielaard2018-10-242-3/+8
| | | | | | | | | | | | | | Using the Ehdr field directly doesn't work when there are a large number of sections. Signed-off-by: Mark Wielaard <[email protected]>
| * readelf: Use shstrndx to lookup section names.Mark Wielaard2018-10-242-35/+68
| | | | | | | | | | | | | | | | The function section_name would use the Ehdr e_shstrndx field to find the index of the section index string table directly. But it should use elf_getshdrstrndx. Adjust all callers. Signed-off-by: Mark Wielaard <[email protected]>
| * readelf: Make sure readp is smaller than cieend in print_debug_frame_section.Mark Wielaard2018-10-201-2/+10
| | | | | | | | | | | | | | | | We could end up with a negative length in a call to memchr. https://sourceware.org/bugzilla/show_bug.cgi?id=23782 Signed-off-by: Mark Wielaard <[email protected]>
| * readelf: Make sure readp is smaller than cieend in print_debug_frame_section.Mark Wielaard2018-10-201-0/+5
| | | | | | | | | | | | | | | | We could end up with a negative length in a call to memchr. https://sourceware.org/bugzilla/show_bug.cgi?id=23782 Signed-off-by: Mark Wielaard <[email protected]>
| * Check sh_entsize is not zero.Mark Wielaard2018-10-202-1/+33
| | | | | | | | | | | | | | | | | | There were some recent bug reports where we trusted the ELF section header to be sane and divided the sh_size by the sh_entsize to get the number of objects in the section. This would cause a divide by zero if the file was corrupt and the sh_entsize was zero. Add checks for any such code. Signed-off-by: Mark Wielaard <[email protected]>
| * size: Handle recursive ELF ar files.Mark Wielaard2018-10-202-2/+8
| | | | | | | | | | | | | | | | | | | | eu-size didn't handle an ELF ar file that contained an ar file itself correctly. handle_ar would recursively call itself but close the ELF file before returning. Only close the ELF file at the top-level. https://sourceware.org/bugzilla/show_bug.cgi?id=23787 Signed-off-by: Mark Wielaard <[email protected]>
| * arlib: Check that sh_entsize isn't zero.Mark Wielaard2018-10-202-0/+7
| | | | | | | | | | | | | | | | | | A bogus ELF file could have sh_entsize as zero. Don't divide by zero, but just assume there are no symbols in the section. https://sourceware.org/bugzilla/show_bug.cgi?id=23786 Signed-off-by: Mark Wielaard <[email protected]>
| * ar: Assume epoch if ar_date is bogus.Mark Wielaard2018-10-202-2/+12
| | | | | | | | | | | | | | | | | | | | If the ar header contains a bogus ar_date then in verbose mode we would get a NULL pointer from localtime. Just assume the entry was created during the epoch. https://sourceware.org/bugzilla/show_bug.cgi?id=23754 Signed-off-by: Mark Wielaard <[email protected]>
| * findtextrel: Check that sh_entsize isn't zero.Mark Wielaard2018-10-202-10/+17
| | | | | | | | | | | | | | | | | | A bogus ELF file could have sh_entsize as zero. Don't divide by zero, but just assume there are no entries in the section. https://sourceware.org/bugzilla/show_bug.cgi?id=23755 Signed-off-by: Mark Wielaard <[email protected]>
| * readelf: Handle multiple .debug_macro sections and decode header flag.Mark Wielaard2018-10-192-3/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | In object files there could be multiple .debug_macro sections. These are COMDAT sections used as imports. Note that the output for DW_MACRO_import isn't ideal since the offset is printed against the start of the .debug_macro section, but it doesn't show which one. We currently don't have that information and no interface yet for libdw users. Also decode the macro header flag byte for convenience. Signed-off-by: Mark Wielaard <[email protected]>
| * unstrip: Renumber the group section indexes.Mark Wielaard2018-10-192-0/+18
| | | | | | | | | | | | | | When unstripping we might need to renumber the group section indexes. Just like we do when stripping. Signed-off-by: Mark Wielaard <[email protected]>
| * strip, unstrip: Handle SHT_GROUP correctly.Mark Wielaard2018-10-173-8/+76
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The usage of annobin in Fedora showed a couple of bugs when using eu-strip and eu-unstrip on ET_REL files that contain multiple group sections. When stripping we should not remove the SHF_GROUP flag from sections even if the group section itself might be removed. Either the section itself gets removed, and so the flag doesn't matter. Or it gets moved together with the group section into the debug file, and then it still needs to have the flag set. Also we would "renumber" the section group flag field (which isn't a section index, and so shouldn't be changed). Often the group sections have the exact same name (".group"), flags (none) and sometimes the same sizes. Which makes matching them hard. Extract the group signature and compare those when comparing two group sections. Signed-off-by: Mark Wielaard <[email protected]>
| * Handle ADD/SUB relocationsAndreas Schwab2018-10-132-4/+23
| | | | | | | | | | | | This adds support for ADD and SUB relocations as seen on RISC-V. Signed-off-by: Andreas Schwab <[email protected]>
* | Merge tag 'elfutils-0.174'Ulf Hermann2018-10-1118-74/+335
|\| | | | | | | | | | | elfutils 0.174 release Change-Id: Ibcbdfca61cf0b65391ab6d0ad00f18ba61027e07
| * readelf: Use elf_getshdrnum in print_shdr and print_phdr.Mark Wielaard2018-09-142-5/+25
| | | | | | | | | | | | | | | | | | print_shdr didn't print the correct number of sections if there were more than SHN_LORESERVE sections. print_phdr wouldn't match up the (allocated) sections and segements if there were more than SHN_LORESERVE sections in the ELF file. Signed-off-by: Mark Wielaard <[email protected]>
| * strip,unstrip: Use and set shdrstrndx consistently.Mark Wielaard2018-09-143-5/+66
| | | | | | | | | | | | | | | | | | | | | | In various places in strip we used e_shstrndx instead of shdrstrndx and we didn't setup the shdrstrndx for the debug file. In unstrip we forgot to copy the shdrstrndx in case the -o output option was used. Added a new testcase that adds many sections to a testfile and runs strip, elflint, unstrip and elfcmp. Signed-off-by: Mark Wielaard <[email protected]>
| * elflint: Use shnum and shstrndx instead of ehdr field directly.Mark Wielaard2018-09-142-3/+10
| | | | | | | | | | | | | | | | | | We already got the right shnum and shstrndx. But were still using e_shnum in one check for ELFCLASS64 (it was correct for ELFCLASS32). And when getting section names in check_symtab we still used e_shstrndx in two places. Signed-off-by: Mark Wielaard <[email protected]>
| * elfcmp: Get, check and shdrstrndx for section names.Mark Wielaard2018-09-132-2/+22
| | | | | | | | | | | | | | | | elfcmp would use the Ehdr e_shstrndx field to find the shdr string index table. Use elf_getshdrstrndx instead to be able to handle ELF files with more than SHN_LORESERVE sections. Signed-off-by: Mark Wielaard <[email protected]>
| * libebl: Use elf_getshdrstrndx in ebl_section_strip_p.Mark Wielaard2018-09-133-4/+9
| | | | | | | | | | | | | | | | | | | | The ebl_section_strip_p function used the Ehdr e_shstrndx field to get at the name of the (debug) sections. This is not correct if there are more than SHN_LORESERVE sections. Use elf_getshdrstrndx to get at the shstrtab section. And drop the Ehdr argument that isn't necessary anymore. Signed-off-by: Mark Wielaard <[email protected]>
| * backends: Always use elf_getshdrstrndx in check_special_symbol.Mark Wielaard2018-09-132-2/+7
| | | | | | | | | | | | | | | | | | | | The check_special_symbol backend functions used the Ehdr e_shstrndx field to get at the name of sections. This is not correct if there are more than SHN_LORESERVE sections. Always use elf_getshdrstrndx to get the shstrtab section. And drop the Ehdr argument that isn't necessary anymore. Signed-off-by: Mark Wielaard <[email protected]>
| * strip: Handle mixed allocated/non-allocated sections.Mark Wielaard2018-08-302-15/+71
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Normally in non-ET_REL files all allocated sections come before all non-allocated sections. eu-strip relies on this when stripping a file and calculating the file offsets. But recently on Fedora there are non-allocated .gnu.build.attributes NOTE sections in the middle of the allocated sections, with a sh_offset field that is larger then the next section. This confuses eu-strip so much that it might corrupt the stripped file. Work around this by calculating the sh_offset fields in two phases when detecting mixed allocated/non-allocated sections. First handle the allocated ones, then use the offset after the last allocated section to calculate the offsets of the non-allocated sections left in the stripped file. Signed-off-by: Mark Wielaard <[email protected]>
| * libdw, readelf: Make sure there is enough data to read full aranges header.Mark Wielaard2018-08-182-0/+7
| | | | | | | | | | | | | | | | | | | | dwarf_getaranges didn't check if there was enough data left to read both the address and segment size. readelf didn't check there was enough data left to read the segment size. https://sourceware.org/bugzilla/show_bug.cgi?id=23541 Signed-off-by: Mark Wielaard <[email protected]>
| * elflint: Fix check_sysv_hash[64] sanity checks to not overflow.Mark Wielaard2018-08-182-2/+12
| | | | | | | | | | | | | | | | | | The sanity checks for how many words were needed in the section could overflow causing errors. Fix the checks. https://sourceware.org/bugzilla/show_bug.cgi?id=23542 Signed-off-by: Mark Wielaard <[email protected]>
| * unstrip: Also check sh_size in compare_unalloc_sections.Mark Wielaard2018-07-272-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | compare_unalloc_sections only checked sh_flags and the section names. This would cause stripped/debug section mismatches when there were multiple sections with the same name and flags. Fix this by also checking the size of the section matches. Add a testcase that has two ".group" sections created on i386 with the gcc annobin plugin. Signed-off-by: Mark Wielaard <[email protected]>
| * unstrip: Handle SHT_GROUP sections in ET_REL files.Mark Wielaard2018-07-272-1/+9
| | | | | | | | | | | | | | | | | | SHT_GROUP sections are put in both the stripped and debug file. Handle correcting the symbol table/name entry of the group only once. The testfile was generated with the gcc annobin plugin. Signed-off-by: Mark Wielaard <[email protected]>
| * elfcompress: Don't rewrite file if no section data needs to be updated.Mark Wielaard2018-07-242-3/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the input and output file are the same and no section needs to be updated we really don't need to rewrite the file. Check whether any matching section is already compressed or decompressed. Skip the section if it doesn't need to be changed. If no section data needs updating end with success without rewriting/updating file. With --force the file will still always be updated/rewritten even if no section data needs to be (de)compressed. Acked-by: Igor Gnatenko <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
| * elfcompress: Swap fchmod and fchown calls on new file.Mark Wielaard2018-07-222-4/+11
| | | | | | | | | | | | | | | | | | | | | | Calling fchmod with a suid bit on a file might silently fail or the suid bit might be slilently cleared by a call to fchown if already set. Swap the calls so that the owner is set first and then set the suid bit. https://bugzilla.redhat.com/show_bug.cgi?id=1607044 Reported-and-tested-by: Igor Gnatenko <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
| * readelf: Don't shadow index function from string.hMark Wielaard2018-07-052-7/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | On some ancient GCC versions (4.4.7 at least) -Wshadow warns about local variables "shadowing" global function definitions. readelf.c: In function ‘print_debug_addr_section’: readelf.c:5265: error: declaration of ‘index’ shadows a global declaration /usr/include/string.h:489: error: shadowed declaration is here This is silly of course, but easy to work around. Signed-off-by: Mark Wielaard <[email protected]>
| * Consolidate error.h inclusion in system.hRoss Burton2018-07-0518-19/+24
| | | | | | | | | | | | | | | | | | error.h isn't standard and so isn't part of the musl C library. To easy future porting, consolidate the inclusion of error.h into system.h. https://sourceware.org/bugzilla/show_bug.cgi?id=21008 Signed-off-by: Ross Burton <[email protected]>
* | Deal with newer libdl on windows requiring psapi.dllUlf Hermann2018-07-231-9/+16
| | | | | | | | | | | | | | We want to link libdl statically, so we need to link psapi ourselves. Change-Id: I001bda009c58cfb39bba0733436f883bbf501b80 Reviewed-by: Christian Kandeler <[email protected]>
* | On PE platforms, set PATH rather than LD_LIBRARY_PATH for installcheckUlf Hermann2018-07-231-1/+7
| | | | | | | | | | | | | | Windows loads DLLs from PATH. Change-Id: I96ef61236a615d06f1d667e1ae25f11a10e545da Reviewed-by: Christian Kandeler <[email protected]>
* | readlink: unlink temporary files after closing them, and avoid TMPDIRUlf Hermann2018-07-231-11/+16
| | | | | | | | | | | | | | | | Windows cannot unlink open files, and there is no predefined temporary directory. Use the section name as base for the file name. Change-Id: I7e050e1ca5e5e890256b2573ca0d0c64745932fa Reviewed-by: Christian Kandeler <[email protected]>
* | ranlib: unlink only after closeUlf Hermann2018-07-231-1/+1
| | | | | | | | | | | | | | Windows won't unlink open files. Change-Id: I23f785a8463aa29a972598e1e5a25b4f92448cb8 Reviewed-by: Christian Kandeler <[email protected]>
* | Add O_BINARY to new open() callsUlf Hermann2018-07-201-1/+1
| | | | | | | | | | | | | | Windows needs that if you're not reading text. Change-Id: I923782f2c47ef16765f52d6a435f69cb33f50dfd Reviewed-by: Christian Kandeler <[email protected]>
* | ar.c: Make sure we always close any fd before unlink or renameUlf Hermann2018-07-201-15/+22
| | | | | | | | | | | | | | | | Windows doesn't unlink or rename if there are still open file handles around. Change-Id: Idddda2cf841d42fa3a5a3fee9e3fe79f2a49136b Reviewed-by: Christian Kandeler <[email protected]>
* | Eliminate trees from ar.cUlf Hermann2018-07-171-91/+41
| | | | | | | | | | | | | | | | Apparently they don't do what we want them to, and we're not interested in the (supposedly) better performance anyway. Change-Id: I0797520afbe5ba6feaccf9b99b46bbaebdd6bc37 Reviewed-by: Christian Kandeler <[email protected]>