diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 46 | ||||
| -rw-r--r-- | src/ar.c | 65 | ||||
| -rw-r--r-- | src/elfclassify.c | 3 | ||||
| -rw-r--r-- | src/elflint.c | 3 | ||||
| -rw-r--r-- | src/ranlib.c | 44 | ||||
| -rw-r--r-- | src/readelf.c | 37 | ||||
| -rw-r--r-- | src/stack.c | 7 | ||||
| -rw-r--r-- | src/unstrip.c | 9 |
8 files changed, 154 insertions, 60 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 512d7b54..0313d2a2 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,49 @@ +2020-09-03 Mark Wielaard <mark@klomp.org> + + * readelf.c (print_cfa_program): Take ehdr as argument. Use it to + recognize DW_CFA_AARCH64_negate_ra_state. + (print_debug_frame_section): Pass ehdr to print_cfa_program. + (print_debug): Don't warn if we dump frames, but cannot get dbg. + +2020-09-01 Mark Wielaard <mark@klomp.org> + + * readelf.c (print_debug_ranges_section): Base address entry can + be first. + (print_debug_loc_section): Likewise. + +2020-09-04 Mark Wielaard <mark@klomp.org> + + * elflint.c (special_sections): Add .debug_line_str. + +2020-08-26 Mark Wielaard <mark@klomp.org> + + * readelf.c (print_debug_line_section): It is not an error if there + are no line number statements at the end of a debug line section. + +2020-07-19 Mark Wielaard <mark@klomp.org> + + * elfclassify.c (process_current_path): Handle fwrite failing. + +2020-07-05 Mark Wielaard <mark@klomp.org> + + * stack.c (module_callback): Don't assert if dwfl_module_info fails. + * unstrip.c (adjust_relocs): Produce a proper error when HAS + section has inconsistent size or entsize. + (match_module): Don't assert if dwfl_module_info fails. + +2020-06-16 Mark Wielaard <mark@klomp.org> + + * ar.c (do_oper_extract): Split large if statement. Call fchown + before fchmod and explicitly ignore the return value. + (do_oper_delete): Likewise. + (do_oper_insert): Likewise. + * ranlib.c (handle_file): Likewise. + +2020-06-16 Mark Wielaard <mark@klomp.org> + + * elflint.c (check_elf_header): Explicitly check and ignore + any error from elf_compress. + 2020-06-07 Mark Wielaard <mark@klomp.org> * nm.c (sort_by_name_strtab): Replace by... @@ -787,26 +787,30 @@ cannot rename temporary file to %.*s"), else rest_off = SARMAG; - if ((symtab.symsnamelen != 0 + if (symtab.symsnamelen != 0 && ((write_retry (newfd, symtab.symsoff, symtab.symsofflen) != (ssize_t) symtab.symsofflen) || (write_retry (newfd, symtab.symsname, symtab.symsnamelen) != (ssize_t) symtab.symsnamelen))) - /* Even if the original file had content before the - symbol table, we write it in the correct order. */ - || (index_off != SARMAG - && copy_content (elf, newfd, SARMAG, index_off - SARMAG)) - || copy_content (elf, newfd, rest_off, st.st_size - rest_off) - /* Set the mode of the new file to the same values the - original file has. */ - || fchmod (newfd, st.st_mode & ALLPERMS) != 0 - /* Never complain about fchown failing. */ - || (({asm ("" :: "r" (fchown (newfd, st.st_uid, - st.st_gid))); }), - close (newfd) != 0) - || (newfd = -1, rename (tmpfname, arfname) != 0)) + goto nonew_unlink; + /* Even if the original file had content before the + symbol table, we write it in the correct order. */ + if ((index_off != SARMAG + && copy_content (elf, newfd, SARMAG, index_off - SARMAG)) + || copy_content (elf, newfd, rest_off, st.st_size - rest_off)) + goto nonew_unlink; + + /* Never complain about fchown failing. */ + if (fchown (newfd, st.st_uid, st.st_gid) != 0) { ; } + /* Set the mode of the new file to the same values the + original file has. */ + if (fchmod (newfd, st.st_mode & ALLPERMS) != 0 + || close (newfd) != 0) + goto nonew_unlink; + newfd = -1; + if (rename (tmpfname, arfname) != 0) goto nonew_unlink; } } @@ -1052,12 +1056,15 @@ do_oper_delete (const char *arfname, char **argv, int argc, } /* Set the mode of the new file to the same values the original file - has. */ + has. Never complain about fchown failing. But do it before + setting the mode (which might be reset/ignored if the owner is + wrong. */ + if (fchown (newfd, st.st_uid, st.st_gid) != 0) { ; } if (fchmod (newfd, st.st_mode & ALLPERMS) != 0 - /* Never complain about fchown failing. */ - || (({asm ("" :: "r" (fchown (newfd, st.st_uid, st.st_gid))); }), - close (newfd) != 0) - || (newfd = -1, rename (tmpfname, arfname) != 0)) + || close (newfd) != 0) + goto nonew_unlink; + newfd = -1; + if (rename (tmpfname, arfname) != 0) goto nonew_unlink; errout: @@ -1534,13 +1541,19 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc, /* Set the mode of the new file to the same values the original file has. */ - if (fd != -1 - && (fchmod (newfd, st.st_mode & ALLPERMS) != 0 - /* Never complain about fchown failing. */ - || (({asm ("" :: "r" (fchown (newfd, st.st_uid, st.st_gid))); }), - close (newfd) != 0) - || (newfd = -1, rename (tmpfname, arfname) != 0))) - goto nonew_unlink; + if (fd != -1) + { + /* Never complain about fchown failing. But do it before + setting the modes, or they might be reset/ignored if the + owner is wrong. */ + if (fchown (newfd, st.st_uid, st.st_gid) != 0) { ; } + if (fchmod (newfd, st.st_mode & ALLPERMS) != 0 + || close (newfd) != 0) + goto nonew_unlink; + newfd = -1; + if (rename (tmpfname, arfname) != 0) + goto nonew_unlink; + } errout: for (int cnt = 0; cnt < argc; ++cnt) diff --git a/src/elfclassify.c b/src/elfclassify.c index 535cc49f..624bb861 100644 --- a/src/elfclassify.c +++ b/src/elfclassify.c @@ -827,7 +827,8 @@ process_current_path (int *status) break; case do_print0: if (checks_passed == flag_print_matching) - fwrite (current_path, strlen (current_path) + 1, 1, stdout); + if (fwrite (current_path, strlen (current_path) + 1, 1, stdout) < 1) + issue (errno, N_("writing to standard output")); break; case no_print: if (!checks_passed) diff --git a/src/elflint.c b/src/elflint.c index 72584de0..ef3e3732 100644 --- a/src/elflint.c +++ b/src/elflint.c @@ -467,7 +467,7 @@ invalid number of section header table entries\n")); break; /* If the section wasn't compressed this does nothing, but returns an error. We don't care. */ - elf_compress (scn, 0, 0); + if (elf_compress (scn, 0, 0) < 0) { ; } } if (scnt < shnum) ERROR (gettext ("Can only check %u headers, shnum was %u\n"), scnt, shnum); @@ -3631,6 +3631,7 @@ static const struct { ".data", 6, SHT_PROGBITS, exact, SHF_ALLOC | SHF_WRITE, 0 }, { ".data1", 7, SHT_PROGBITS, exact, SHF_ALLOC | SHF_WRITE, 0 }, { ".debug_str", 11, SHT_PROGBITS, exact_or_gnuld, SHF_MERGE | SHF_STRINGS, 0 }, + { ".debug_line_str", 16, SHT_PROGBITS, exact_or_gnuld, SHF_MERGE | SHF_STRINGS, 0 }, { ".debug", 6, SHT_PROGBITS, exact, 0, 0 }, { ".dynamic", 9, SHT_DYNAMIC, atleast, SHF_ALLOC, SHF_WRITE }, { ".dynstr", 8, SHT_STRTAB, exact, SHF_ALLOC, 0 }, diff --git a/src/ranlib.c b/src/ranlib.c index b9083484..483a1b65 100644 --- a/src/ranlib.c +++ b/src/ranlib.c @@ -245,25 +245,31 @@ handle_file (const char *fname) else rest_off = SARMAG; - if ((symtab.symsnamelen != 0 - && ((write_retry (newfd, symtab.symsoff, - symtab.symsofflen) - != (ssize_t) symtab.symsofflen) - || (write_retry (newfd, symtab.symsname, - symtab.symsnamelen) - != (ssize_t) symtab.symsnamelen))) - /* Even if the original file had content before the - symbol table, we write it in the correct order. */ - || (index_off > SARMAG - && copy_content (arelf, newfd, SARMAG, index_off - SARMAG)) - || copy_content (arelf, newfd, rest_off, st.st_size - rest_off) - /* Set the mode of the new file to the same values the - original file has. */ - || fchmod (newfd, st.st_mode & ALLPERMS) != 0 - /* Never complain about fchown failing. */ - || (({asm ("" :: "r" (fchown (newfd, st.st_uid, st.st_gid))); }), - close (newfd) != 0) - || (newfd = -1, rename (tmpfname, fname) != 0)) + if (symtab.symsnamelen != 0 + && ((write_retry (newfd, symtab.symsoff, + symtab.symsofflen) + != (ssize_t) symtab.symsofflen) + || (write_retry (newfd, symtab.symsname, + symtab.symsnamelen) + != (ssize_t) symtab.symsnamelen))) + goto nonew_unlink; + + /* Even if the original file had content before the + symbol table, we write it in the correct order. */ + if ((index_off > SARMAG + && copy_content (arelf, newfd, SARMAG, index_off - SARMAG)) + || copy_content (arelf, newfd, rest_off, st.st_size - rest_off)) + goto nonew_unlink; + + /* Never complain about fchown failing. */ + if (fchown (newfd, st.st_uid, st.st_gid) != 0) { ; } + /* Set the mode of the new file to the same values the + original file has. */ + if (fchmod (newfd, st.st_mode & ALLPERMS) != 0 + || close (newfd) != 0) + goto nonew_unlink; + newfd = -1; + if (rename (tmpfname, fname) != 0) goto nonew_unlink; } } diff --git a/src/readelf.c b/src/readelf.c index 685d0b17..64067a57 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -6045,10 +6045,16 @@ print_debug_ranges_section (Dwfl_Module *dwflmod, if (begin == (Dwarf_Addr) -1l) /* Base address entry. */ { - printf (gettext (" [%6tx] base address\n "), offset); + if (first) + printf (" [%6tx] ", offset); + else + printf (" "); + puts (gettext ("base address")); + printf (" "); print_dwarf_addr (dwflmod, address_size, end, end); printf ("\n"); base = end; + first = false; } else if (begin == 0 && end == 0) /* End of list entry. */ { @@ -6176,7 +6182,7 @@ print_cfa_program (const unsigned char *readp, const unsigned char *const endp, int data_align, unsigned int version, unsigned int ptr_size, unsigned int encoding, - Dwfl_Module *dwflmod, Ebl *ebl, Dwarf *dbg) + Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr, Dwarf *dbg) { char regnamebuf[REGNAMESZ]; const char *regname (unsigned int regno) @@ -6399,8 +6405,11 @@ print_cfa_program (const unsigned char *readp, const unsigned char *const endp, printf (" MIPS_advance_loc8 %" PRIu64 " to %#" PRIx64 "\n", op1, pc += op1 * code_align); break; - case DW_CFA_GNU_window_save: - puts (" GNU_window_save"); + case DW_CFA_GNU_window_save: /* DW_CFA_AARCH64_negate_ra_state */ + if (ehdr->e_machine == EM_AARCH64) + puts (" AARCH64_negate_ra_state"); + else + puts (" GNU_window_save"); break; case DW_CFA_GNU_args_size: if ((uint64_t) (endp - readp) < 1) @@ -6930,7 +6939,7 @@ print_debug_frame_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr, else print_cfa_program (readp, cieend, vma_base, code_alignment_factor, data_alignment_factor, version, ptr_size, - fde_encoding, dwflmod, ebl, dbg); + fde_encoding, dwflmod, ebl, ehdr, dbg); readp = cieend; } } @@ -8642,7 +8651,7 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr, printf (", "); } printf ("\n"); - if (linep >= lineendp) + if (linep > lineendp) goto invalid_unit; } } @@ -8685,6 +8694,12 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr, ++linep; } + if (linep == lineendp) + { + puts (gettext ("\nNo line number statements.")); + return; + } + puts (gettext ("\nLine number statements:")); Dwarf_Word address = 0; unsigned int op_index = 0; @@ -9609,10 +9624,16 @@ print_debug_loc_section (Dwfl_Module *dwflmod, if (begin == (Dwarf_Addr) -1l) /* Base address entry. */ { - printf (gettext (" [%6tx] base address\n "), offset); + if (first) + printf (" [%6tx] ", offset); + else + printf (" "); + puts (gettext ("base address")); + printf (" "); print_dwarf_addr (dwflmod, address_size, end, end); printf ("\n"); base = end; + first = false; } else if (begin == 0 && end == 0) /* End of list entry. */ { @@ -11082,7 +11103,7 @@ print_debug (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr) }; if (dbg == NULL) { - if ((print_debug_sections & ~section_exception) != 0) + if ((print_debug_sections & ~(section_exception|section_frame)) != 0) error (0, 0, gettext ("cannot get debug context descriptor: %s"), dwfl_errmsg (-1)); dbg = &dummy_dbg; diff --git a/src/stack.c b/src/stack.c index 4daabce7..2ec7c972 100644 --- a/src/stack.c +++ b/src/stack.c @@ -143,7 +143,12 @@ module_callback (Dwfl_Module *mod, void **userdata __attribute__((unused)), const char *debugfile; const char *modname = dwfl_module_info (mod, NULL, NULL, &end, NULL, NULL, &mainfile, &debugfile); - assert (strcmp (modname, name) == 0); + if (modname == NULL || strcmp (modname, name) != 0) + { + end = start + 1; + mainfile = NULL; + debugfile = NULL; + } int width = get_addr_width (mod); printf ("0x%0*" PRIx64 "-0x%0*" PRIx64 " %s\n", diff --git a/src/unstrip.c b/src/unstrip.c index 9b8c09a1..a855038a 100644 --- a/src/unstrip.c +++ b/src/unstrip.c @@ -500,7 +500,8 @@ adjust_relocs (Elf_Scn *outscn, Elf_Scn *inscn, const GElf_Shdr *shdr, error (EXIT_FAILURE, 0, "Symbol table cannot have zero sh_entsize"); const size_t nsym = symshdr->sh_size / symshdr->sh_entsize; const size_t onent = shdr->sh_size / shdr->sh_entsize; - assert (data->d_size == shdr->sh_size); + if (data->d_size != shdr->sh_size) + error (EXIT_FAILURE, 0, "HASH section has inconsistent size"); #define CONVERT_HASH(Hash_Word) \ { \ @@ -509,7 +510,8 @@ adjust_relocs (Elf_Scn *outscn, Elf_Scn *inscn, const GElf_Shdr *shdr, const size_t nchain = old_hash[1]; \ const Hash_Word *const old_bucket = &old_hash[2]; \ const Hash_Word *const old_chain = &old_bucket[nbucket]; \ - assert (onent == 2 + nbucket + nchain); \ + if (onent != 2 + nbucket + nchain) \ + error (EXIT_FAILURE, 0, "HASH section has inconsistent entsize"); \ \ const size_t nent = 2 + nbucket + nsym; \ Hash_Word *const new_hash = xcalloc (nent, sizeof new_hash[0]); \ @@ -2469,8 +2471,7 @@ match_module (Dwfl_Module *mod, const char *file; const char *check = dwfl_module_info (mod, NULL, NULL, NULL, NULL, NULL, &file, NULL); - assert (check == name); - if (file == NULL) + if (check == NULL || strcmp (check, name) != 0 || file == NULL) return DWARF_CB_OK; name = file; |
