18 Commits

Author SHA1 Message Date
lizhenlin efba194008 update version to 0.193
Signed-off-by: lizhenlin <lizhenlin2@h-partners.com>
2025-11-12 14:48:40 +08:00
unknown 705c22626b update to v0.190
Signed-off-by: unknown <zhangchun39@huawei.com>
2024-12-06 15:48:16 +08:00
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 b8d1683ce4 libdwelf: fix spelling typos in comments
algorith -> algorithm
occured -> occurred

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2020-12-12 18:06:28 +01:00
Dmitry V. Levin b43d1b48c6 libdwelf: fix spelling typos in strings returned by dwelf_elf_e_machine_string
embeded -> embedded
Semicondutor -> Semiconductor

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2020-12-12 14:57:59 +01:00
Mark Wielaard 39f22a7687 libelf: Sync elf.h from glibc.
There is now finally a PT_GNU_PROPERTY define.
Also EM_ARC_COMPACT2 got renamed to EM_ARCV2.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-06-04 16:59:52 +02:00
Mark Wielaard 7ea82243ec libdwelf: Make dwelf_elf_begin return NULL only when there is an error.
dwelf_elf_begin was slightly different from elf_begin in case the file
turned out to not be an ELF file. elf_begin would return an Elf handle
with ELF_K_NONE. But dwelf_elf_begin would return NULL. This made it
impossible to tell the difference between a file or decompression error
and a (decompressed) file not being an ELF file.

Since dwelf_elf_begin could still return different kinds of ELF files
(ELF_K_ELF or ELF_K_AR - and theoretically ELF_K_COFF) this was not
really useful anyway. So make it so that dwelf_elf_begin always returns
an Elf handle unless there was a real error reading or decompressing
the file. Otherwise return NULL to make clear there was a real error.

Make sure that the decompression function returns DWFL_E_BADELF only
when the file isn't compressed. In which case the Elf handle won't
be replaced and can be returned (as ELF_K_NONE).

Add a new version to dwelf_elf_begin so programs can rely on it
returning NULL only for real errors.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2019-08-13 12:16:18 +02:00
Mark Wielaard b323391407 libdwelf: Add dwelf_elf_e_machine_string and use it in readelf.
To print eh human readable description of the ELF e_machine header field
we used the ebl name. But this is not set for most EM constants. Introduce
a new function dwelf_elf_e_machine_string that does work for all known
EM values. Use that in eu-readelf to print a string representation of the
e_machine value.

Since this was the only usage of ebl->name, remove that from struct ebl.

Also add a testcase that makes sure dwelf_elf_e_machine_string works for
all EM values in the libelf/elf.h header so we will immediately notice
when a new value appears.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2019-07-10 14:08:33 +02:00
Mark Wielaard ecbe3120cd libdwelf: New function dwelf_elf_begin.
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 <mark@klomp.org>
2018-11-09 18:11:48 +01:00
Mark Wielaard 5199e15870 Recognize and parse GNU Property notes.
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 <mark@klomp.org>
2018-10-29 00:57:57 +01:00
Akihiko Odaki 60b2bf1b08 lib: Provide MAX and MIN in system.h
This change also creates a new header file libeu.h to provide the
prototypes for the function of libeu. That hides the definition of function
crc32, which can conflict with zlib, from libelf. It also prevents mistakes
to refer those functions from a component which doesn't link with libeu,
such as libelf.

Signed-off-by: Akihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>
2016-10-12 15:43:14 +02:00
Mark Wielaard dd906c1b48 dwelf: Add string table functions from ebl.
Move the strtab functions from libebl to libdw. Programs often want to
create ELF/DWARF string tables. We don't want (static) linking against
ebl since those are internal functions that might change.

This introduces dwelf_strtab_init, dwelf_strtab_add,
dwelf_strtab_add_len, dwelf_strtab_finalize, dwelf_strent_off,
dwelf_strent_str and dwelf_strtab_free. Documentation for each has
been added to libdwelf.h. The add fucntion got a variant that takes
the length explicitly and finalize was changed to return NULL on
out of memory instead of aborting. All code and tests now uses the
new functions.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2016-08-03 18:19:47 +02:00
Mark Wielaard 0c32b6f086 libdwelf: Add dwelf_scn_gnu_compressed_size.
Helper function to get the size of a GNU compressed zdebug section.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2016-01-06 14:27:10 +01:00
Chih-Hung Hsieh 11659f2529 Move nested functions in libdwelf.
* Move nested functions to file scope
  in libdwelf/dwelf_elf_gnu_build_id.c
  to compile with clang.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
2015-10-22 22:43:42 +02:00
Mark Wielaard 2f8e4d3383 libdwelf: Check the d_buf actually exists in dwelf_elf_gnu_debuglink.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-11-14 16:58:36 +01:00
Mark Wielaard d81d32d2a4 libdwelf: Add dwelf_elf_gnu_build_id.
Move internal function __libdwfl_find_build_id to libdwelf and use it to
add a public dwelf_elf_gnu_build_id function to extract the NT_GNU_BUILD_ID
from an ELF file using either the shdrs or phdrs. Adjust internal callers
and add a testcase.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-05-01 13:51:31 +02:00
Florian Weimer 4813dbbcb8 libdwelf: Add dwelf_dwarf_gnu_debugaltlink
Signed-off-by: Florian Weimer <fweimer@redhat.com>
2014-04-24 14:40:59 +02:00
Mark Wielaard 9380297e13 libdwelf: New DWARF ELF Low-level Functions. Add dwelf_elf_gnu_debuglink.
New public header elfutils/libdwelf.h for low-level DWARF/ELF helper
functions.  The new function dwelf_elf_gnu_debuglink returns the name and
crc as found in the .gnu_debuglink section of an ELF file.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-04-24 13:18:33 +02:00