summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* elfcompress: fix exit status in case of an errorDmitry V. Levin2021-05-122-1/+4
| | | | | | | | Exit status of 255 in case of an error is probably not what elfcompress users expect, change it to 1. Reported-by: Vitaly Chikunov <vt@altlinux.org> Fixes: 92acb57eb046 ("elfcompress: New utility.")
* elfcompress: remove redundant assignmentDmitry V. Levin2021-05-122-1/+3
| | | | | | | | | At the point of "Nothing to do" fnew variable has not been assigned after initialization, so it does not have to be reset to NULL. Note that any reset of fnew to NULL has to preceded with free(fnew). Fixes: ed62996defc6 ("elfcompress: Don't rewrite file if no section data needs to be updated.")
* elfcompress: fix exit status regression in case of "Nothing to do"Dmitry V. Levin2021-05-122-0/+5
| | | | | | | | | When elfcompress decides that no section data needs to be updated and therefore the file does not have to be rewritten, it still has to exit with a zero status indicating success. Resolves: https://sourceware.org/bugzilla/show_bug.cgi?id=27856 Fixes: c497478390de ("elfcompress: Replace cleanup() with label")
* Come up with startswith function.Martin Liska2021-05-126-27/+32
| | | | | | | New function in system.h that returns true if a string has a given prefix, false otherwise. Use it in place of strncmp. Signed-off-by: Martin Liška <mliska@suse.cz>
* nm: Fix file descriptor leak on dwfl_begin failure.Mark Wielaard2021-04-132-0/+6
| | | | | | | If dwfl_begin fails we won't use the dwfl_fd descriptor we just dupped. Make sure to close on dwfl_begin failure to avoid the leak. Signed-off-by: Mark Wielaard <mark@klomp.org>
* unstrip: Fix small leak in handle_output_dir_module.Mark Wielaard2021-04-132-0/+6
| | | | | | | | eu-unstrip might leak a string for each module found when using the -d option. Make sure to free the output_file name when we are done with the module. Signed-off-by: Mark Wielaard <mark@klomp.org>
* ar: Always close newfd in do_oper_insert.Mark Wielaard2021-04-132-0/+7
| | | | | | | | | newfd is normally created by mkstemp given the original fd exists. Otherwise it will created by open from arfname. In the second case newfd might not get closed. Preventd this by always trying to close it after errout. Signed-off-by: Mark Wielaard <mark@klomp.org>
* readelf: Sanity check verneed and verdef offsets in handle_symtab.Mark Wielaard2021-03-032-1/+14
| | | | | | | | | | We are going through vna_next, vn_next and vd_next in a while loop. Make sure that all offsets are sane. We don't want things to wrap around so we go in cycles. https://sourceware.org/bugzilla/show_bug.cgi?id=27501 Signed-off-by: Mark Wielaard <mark@klomp.org>
* elfcompress: Replace cleanup() with labelTimm Bäder2021-03-022-109/+112
| | | | | | | This unifies the error handling with the rest of the code base and gets rid of a nested function. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* elfcompress: Pull get_sections() into file scopeTimm Bäder2021-03-012-10/+17
| | | | | | Get rid of a nested function this way. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* elfcompress: Pull get_section() into file scopeTimm Bäder2021-03-012-6/+13
| | | | | | Get rid of a nested function this way. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* elfcompress: Pull set_section() into file scopeTimm Bäder2021-03-012-7/+15
| | | | | | Get rid of a nested function this way. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* unstrip: Remove nested next() functionTimm Bäder2021-03-012-8/+12
| | | | | | | This is a simple one-liner, so inline this into the few callers. Get rid of a nested function this way. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* unstrip: Pull warn() into file scopeTimm Bäder2021-03-012-15/+26
| | | | | | Get rid of a nested function this way. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* unstrip: Inline find_unalloc_section() into only callerTimm Bäder2021-03-012-26/+27
| | | | | | Get rid of an unnecessary nested function this way. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* unstrip: Pull check_match() into file scopeTimm Bäder2021-03-012-12/+23
| | | | | | Get rid of a nested function this way. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* unstrip: Pull adjust_reloc() into file scopeTimm Bäder2021-03-012-13/+21
| | | | | | Get rid of a nested function this way. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* elflint: Pull left() in file scopeTimm Bäder2021-03-012-8/+15
| | | | | | And rename it to buffer_left() to be a bit more descriptive Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* elflint: Pull pos() info file scopeTimm Bäder2021-03-012-19/+26
| | | | | | | Rename it to buffer_pos() to be a bit more descriptive and get rid of a nested function this way. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* readelf: Type DIE offset is from start of CU.Mark Wielaard2021-02-172-1/+6
| | | | | | | | | While inspecting some type units I noticed the type offset seemed off. We were printing the offset as is, but it should include the offset of the unit. There was actually a testcase for this, run-readelf-types.sh but that had the same bug in the expected output. Fixed both. Signed-off-by: Mark Wielaard <mark@klomp.org>
* readelf, libdw: blocks aren't expressions for DWARF version 4Mark Wielaard2021-02-172-1/+8
| | | | | | | | For DWARF version 4 or higher a block form really encodes a block, not an expression location. Also constant offsets can be expressed as DW_FORM_implicit_const in DWARF version 5. Signed-off-by: Mark Wielaard <mark@klomp.org>
* ar: Pull should_truncate_fname() into file scopeTimm Bäder2021-02-052-17/+24
| | | | | | Get rid of a nested function this way. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* readelf: Remove show_op_index variableTimm Bäder2021-02-052-6/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | advance_pc() uses show_op_index to save whether the current op_index is > 0 OR the new op_index is > 0. The new op index is calculated via new_op_index = (op_index + op_advance) % max_ops_per_instr; since all of the variables involved are unsigned, new_op_index >= op_index is always true. So... if op_index > 0, then new_op_index > 0 if op_index == 0, then new_op_index >= 0 and if the new_op_index is > 0, then the old one was as well. In any case, we only need to check the new_op_index, since show_op_index used to OR the two comparisons. In other words: op_index > 0 | new_op_index > 0 || show_op_index ------------------------------------------------ true true true false true true true false true xx false false false ... but since the third line (marked with xx) is not possible, the table becomes: op_index > 0 | new_op_index > 0 || show_op_index ------------------------------------------------ true true true false true true false false false ... and show_op_index is equal to (new_op_index > 0). So, remove the show_op_index variable and simply replace it by comparing the new op_index > 0.
* readelf: Pull regname() into file scopeTimm Bäder2021-01-302-18/+30
| | | | | | Get rid of a nested function this way. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* readelf: Pull left() info file scopeTimm Bäder2021-01-302-7/+15
| | | | | | Get rid of a nested function this way. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* readelf: Pull same_set() info file scopeTimm Bäder2021-01-302-10/+21
| | | | | | Get rid of a nested function this way Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* readelf: Pull add_dump_section() into file scopeTimm Bäder2021-01-302-16/+24
| | | | | | Get rid of a nested function this way. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* arlib-argp: Pull text_for_default() into file scopeTimm Bäder2021-01-292-10/+17
| | | | | | Get rid of a nested function this way. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* addr2line: Pull show_note() and show_int() in file scopeTimm Bäder2021-01-292-21/+33
| | | | | | Get rid of the nested functions Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* strip: Remove no_symtab_updates() functionTimm Bäder2021-01-282-45/+35
| | | | | | | | | The no_symtab_updates() function was being called at the beginning of all case labels in this switch, so we can just call it once before the switch. Then it only has one call-site, so inline this short function there. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* strip: Pull update_section_size() into file scopeTimm Bäder2021-01-282-23/+35
| | | | | | Get rid of a nested function this way. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* strip: Pull relocate() info file scopeTimm Bäder2021-01-282-163/+193
| | | | | | | | Pull relocate() info file scope and get rid of a nested function this way. Refactor remove_debug_relocations() to minimize the parameters we need to pass to relocate(). Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* strip: Replace nested check_preserved function with loopTimm Bäder2021-01-282-16/+25
| | | | Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* elflint: Recognize SHF_GNU_RETAIN as extra section flag.Mark Wielaard2021-01-152-9/+20
| | | | | | | | | | SHF_GNU_RETAIN is like SHF_LINK_ORDER it can appear on any section and should be ignored by elflint. Add all such flags to a new EXTRA_SHFLAGS and use it consistently in check_sections. https://sourceware.org/bugzilla/show_bug.cgi?id=27134 Signed-off-by: Mark Wielaard <mark@klomp.org>
* src/elflint.c: add debug print for GNU_RETAIN and othersSergei Trofimovich2021-01-122-1/+9
| | | | Signed-off-by: Mark Wielaard <mark@klomp.org>
* src/elflint.c: fix printing of unknown flagsSergei Trofimovich2021-01-112-2/+11
| | | | | | | | | | | | before the change section_flags_string() ignored unknown section flags: snprintf() did write numeric value into buffer, but "*cp = '\0'" negated the effect. The change advances the 'cp' pointer'. While at it add a '|' separator between known and unknown flags. Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
* src/readelf: use qsort instead of qsort_r.Érico Rolim2021-01-102-4/+14
| | | | | | | | | This program is single threaded, so using qsort with a global variable isn't a danger. The interface for qsort_r isn't standardized (and diverges between glibc and FreeBSD, for example), which makes usage of qsort, where possible, preferrable. Signed-off-by: Érico Rolim <erico.erc@gmail.com>
* Split the top level .gitignore fileDmitry V. Levin2020-12-202-0/+21
| | | | | | | | | | Move subdirectory parts of the top level .gitignore into appropriate subdirectories. This would be consistent with ChangeLog files, currently one has to update the top level ChangeLog file when the top level .gitignore file is changed in a way that affects a specific subdirectory only. Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* Handle SHF_GNU_RETAIN in eu-readelf and eu-elflint.Mark Wielaard2020-12-163-0/+10
| | | | | | | readelf -S now shows 'R' when SHF_GNU_RETAIN is set. elflint accepts SHF_GNU_RETAIN when set on section in --gnu mode. Signed-off-by: Mark Wielaard <mark@klomp.org>
* src: consistently use _(Str) instead of gettext(Str)Dmitry V. Levin2020-12-1615-1038/+1040
| | | | | | | | | Make use of the _(Str) macro provided by <config.h>. The change was made automatically using the following command: $ git grep -l '\<gettext *(' src |xargs sed -i 's/\<gettext *(/_(/g' Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* Consistently define _(Str) using dgettext ("elfutils", Str)Dmitry V. Levin2020-12-162-4/+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>
* elflint: Always print symbol name (if known) in error messages.Mark Wielaard2020-12-162-49/+54
| | | | | | | | | | | | | Adding the symbol name associated with the symbol index number makes the error messages a little bit more useful. We used to say: section [59] '.symtab': symbol 9: st_value out of bounds But now says: section [59] '.symtab': symbol 9 (.annobin_size.c.hot): st_value out of bounds Signed-off-by: Mark Wielaard <mark@klomp.org>
* src: fix spelling typos in comments and ChangeLogDmitry V. Levin2020-12-129-17/+27
| | | | | | | | | | | | | | | | | | Indeces -> Indices adress -> address affort -> afford dont' -> don't futher -> further higest -> highest indeces -> indices interate -> iterate occured -> occurred overlow -> overflow sectin -> section succesful -> successful teminated -> terminated Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* src: fix spelling typos in argp help text and error diagnosticsDmitry V. Levin2020-12-125-5/+13
| | | | | | | | | | | | Since all these help text strings are marked for translation, apply the fixes to translation strings as well, this helps to avoid translations becoming fuzzy. lenght -> length occured -> occurred endianess -> endianness reversable -> reversible Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* Switch from numerical to defined constants for permissions.Érico Rolim2020-11-032-2/+9
| | | | | | | | | | | Use defined constants for permission values. Also add fallback definitions for them in system.h, to allow for compatibility with systems that don't provide these macros. Include system.h in all tests/ files that required it. Signed-off-by: Érico Rolim <erico.erc@gmail.com> Signed-off-by: Mark Wielaard <mark@klomp.org>
* Support building when fts and obstack aren't part of libc.Érico Rolim2020-11-032-3/+9
| | | | | | | | - Make configure.ac test for fts and obstack availability; - Add fts and obstack ldflags to all files that need them; - Add missing argp ldflags to programs in debuginfod/. Signed-off-by: Érico Rolim <erico.erc@gmail.com>
* unstrip: Stop using strndupa.Érico Rolim2020-10-272-5/+15
| | | | | | | | | | | | | | This functon has inherent safety issues, since a long enough path can lead to memory clobbering. Due to the recursive nature of make_directories(), multiple calls could also stack overflow. Instead, the string can be allocated in the heap. As a bonus, this improves musl compatibility, since musl doesn't include the strndupa macro for now. Also add braces around while loop. Signed-off-by: Érico Rolim <erico.erc@gmail.com>
* readelf: Support showing view pairs in loclists as GNU extension.Mark Wielaard2020-10-022-8/+79
| | | | | | | | | View pairs are encoded in .debug_loclists as they are encoded in .debug_locs sections by the GCC compiler. Scan for DW_AT_GNU_locviews attributes that point to the view pairs just in front of the actual location lists. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdw,readelf: Recognize DW_CFA_AARCH64_negate_ra_stateMark Wielaard2020-09-072-5/+15
| | | | | | | | | | | | | | | | | | | | DW_CFA_AARCH64_negate_ra_state is used on aarch64 to indicate whether or not the return address is mangled or not. This has the same value as the DW_CFA_GNU_window_save. So we have to pass around the e_machine value of the process or core we are inspecting to know which one to use. Note that it isn't actually implemented yet. It needs ARMv8.3 hardware. If we don't have such hardware it is enough to simply ignore the DW_CFA_AARCH64_negate_ra_state (and not confuse it with DW_CFA_GNU_window_save) to get backtraces to work on aarch64. Add a testcase for eu-readelf --debug-dump=frames to show the value is correctly recognized. Also don't warn we cannot find any DWARF if we are just dumping frames (those will come from .eh_frame if there is no .debug_frame). Signed-off-by: Mark Wielaard <mark@klomp.org>
* readelf: base address entry can be firstMark Wielaard2020-09-072-2/+20
| | | | | | | | | In both debug_ranges and debug_loc a base address entry can be the first in the range or loc list. If so print the offset and set first to false. Otherwise don't print the entry list offset, but do set first to false. Signed-off-by: Mark Wielaard <mark@klomp.org>