770 Commits

Author SHA1 Message Date
zhanghaibo e660ab2124 upgrade to v0.188
Signed-off-by: zhanghaibo <zhanghaibo0@huawei.com>
Change-Id: I83c8756f5ce0a464b037bc963cfdce43df82921b
2023-04-25 18:45:37 +08:00
Dmitry V. Levin 940b0e7d30 elfcompress: fix exit status in case of an error
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: 92acb57eb0 ("elfcompress: New utility.")
2021-05-12 16:00:00 +00:00
Dmitry V. Levin 806c1f7a0d elfcompress: remove redundant assignment
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: ed62996def ("elfcompress: Don't rewrite file if no section data needs to be updated.")
2021-05-12 15:00:00 +00:00
Dmitry V. Levin 43ac25c2de elfcompress: fix exit status regression in case of "Nothing to do"
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: c497478390 ("elfcompress: Replace cleanup() with label")
2021-05-12 15:00:00 +00:00
Martin Liska adc201f819 Come up with startswith function.
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>
2021-05-12 11:56:57 +02:00
Mark Wielaard 879513aba0 nm: Fix file descriptor leak on dwfl_begin failure.
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>
2021-04-13 14:45:34 +02:00
Mark Wielaard 1261691acc unstrip: Fix small leak in handle_output_dir_module.
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>
2021-04-13 14:45:34 +02:00
Mark Wielaard b58516a620 ar: Always close newfd in do_oper_insert.
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>
2021-04-13 14:45:34 +02:00
Mark Wielaard 480b6fa366 readelf: Sanity check verneed and verdef offsets in handle_symtab.
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>
2021-03-03 21:44:45 +01:00
Timm Bäder c497478390 elfcompress: Replace cleanup() with label
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>
2021-03-02 10:37:32 +01:00
Timm Bäder 0df0e8e05a elfcompress: Pull get_sections() into file scope
Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
2021-03-01 23:01:29 +01:00
Timm Bäder 71b7401496 elfcompress: Pull get_section() into file scope
Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
2021-03-01 23:01:13 +01:00
Timm Bäder c9ccf7e3f0 elfcompress: Pull set_section() into file scope
Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
2021-03-01 23:00:57 +01:00
Timm Bäder d1cbce88d7 unstrip: Remove nested next() function
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>
2021-03-01 18:07:20 +01:00
Timm Bäder 93a6c36c85 unstrip: Pull warn() into file scope
Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
2021-03-01 18:07:20 +01:00
Timm Bäder 39c67b8f6c unstrip: Inline find_unalloc_section() into only caller
Get rid of an unnecessary nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
2021-03-01 18:07:10 +01:00
Timm Bäder 2daab4e766 unstrip: Pull check_match() into file scope
Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
2021-03-01 17:47:20 +01:00
Timm Bäder ec5d1a47e3 unstrip: Pull adjust_reloc() into file scope
Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
2021-03-01 17:42:29 +01:00
Timm Bäder e95d1fbb77 elflint: Pull left() in file scope
And rename it to buffer_left() to be a bit more descriptive

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
2021-03-01 17:27:08 +01:00
Timm Bäder fd1b3802a7 elflint: Pull pos() info file scope
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>
2021-03-01 17:22:58 +01:00
Mark Wielaard 4019aa8148 readelf: Type DIE offset is from start of CU.
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>
2021-02-17 16:55:53 +01:00
Mark Wielaard ce6a126b01 readelf, libdw: blocks aren't expressions for DWARF version 4
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>
2021-02-17 16:52:57 +01:00
Timm Bäder ce0944f728 ar: Pull should_truncate_fname() into file scope
Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
2021-02-05 18:46:07 +01:00
Timm Bäder f36ac0f291 readelf: Remove show_op_index variable
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.
2021-02-05 16:42:58 +01:00
Timm Bäder 92ed5f32bd readelf: Pull regname() into file scope
Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
2021-01-30 21:44:36 +01:00
Timm Bäder 839880d243 readelf: Pull left() info file scope
Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
2021-01-30 21:26:59 +01:00
Timm Bäder aaa6c3eacf readelf: Pull same_set() info file scope
Get rid of a nested function this way

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
2021-01-30 21:09:57 +01:00
Timm Bäder 4812953335 readelf: Pull add_dump_section() into file scope
Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
2021-01-30 20:52:06 +01:00
Timm Bäder 0d8cbca2c0 arlib-argp: Pull text_for_default() into file scope
Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
2021-01-29 21:57:17 +01:00
Timm Bäder f91424e7a5 addr2line: Pull show_note() and show_int() in file scope
Get rid of the nested functions

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
2021-01-29 21:22:00 +01:00
Timm Bäder e29965f401 strip: Remove no_symtab_updates() function
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>
2021-01-28 14:23:28 +01:00
Timm Bäder 541aa7d060 strip: Pull update_section_size() into file scope
Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
2021-01-28 13:55:39 +01:00
Timm Bäder d68e8151ae strip: Pull relocate() info file scope
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>
2021-01-28 13:46:57 +01:00
Timm Bäder b076d4c219 strip: Replace nested check_preserved function with loop
Signed-off-by: Timm Bäder <tbaeder@redhat.com>
2021-01-28 13:14:13 +01:00
Mark Wielaard 7024796b63 elflint: Recognize SHF_GNU_RETAIN as extra section flag.
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>
2021-01-15 11:43:01 +01:00
Sergei Trofimovich ada269939a src/elflint.c: add debug print for GNU_RETAIN and others
Signed-off-by: Mark Wielaard <mark@klomp.org>
2021-01-12 10:09:25 +01:00
Sergei Trofimovich 372b41d3ce src/elflint.c: fix printing of unknown flags
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>
2021-01-11 23:31:44 +01:00
Érico Rolim 2ad0758fdd src/readelf: use qsort instead of qsort_r.
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>
2021-01-10 16:28:34 +01:00
Dmitry V. Levin 05c232f7fd Split the top level .gitignore file
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>
2020-12-20 08:00:00 +00:00
Mark Wielaard 84f1daf129 Handle SHF_GNU_RETAIN in eu-readelf and eu-elflint.
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>
2020-12-16 19:44:47 +01:00
Dmitry V. Levin 3ddd8f9bb6 src: consistently use _(Str) instead of gettext(Str)
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>
2020-12-16 10:01:52 +00:00
Dmitry V. Levin 0a5defb64e Consistently define _(Str) using dgettext ("elfutils", Str)
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>
2020-12-16 10:01:52 +00:00
Mark Wielaard a5b95a38b7 elflint: Always print symbol name (if known) in error messages.
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>
2020-12-16 00:16:33 +01:00
Dmitry V. Levin 107b351d49 src: fix spelling typos in comments and ChangeLog
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>
2020-12-12 18:06:28 +01:00
Dmitry V. Levin adbf4bafc2 src: fix spelling typos in argp help text and error diagnostics
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>
2020-12-12 14:59:17 +01:00
Érico Rolim ced66615bd Switch from numerical to defined constants for permissions.
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>
2020-11-03 15:54:14 +01:00
Érico Rolim da855fc9cd Support building when fts and obstack aren't part of libc.
- 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>
2020-11-03 01:11:06 +01:00
Érico Rolim e7e4c92650 unstrip: Stop using strndupa.
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>
2020-10-27 22:49:33 +01:00
Mark Wielaard 82341762d7 readelf: Support showing view pairs in loclists as GNU extension.
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>
2020-10-02 23:32:49 +02:00
Mark Wielaard 5ed73d79bf libdw,readelf: Recognize DW_CFA_AARCH64_negate_ra_state
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>
2020-09-07 12:21:10 +02:00