| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
|
|
|
|
| |
SHF_INFO_LINK is not consistently set when sh_info is actually a section
index reference. Use SH_INFO_LINK_P to check whether to update the sh_info
value. SH_INFO_LINK_P also checks the section type to know whether or not
sh_info is meant to as section index.
Found by run-strip-strmerge.sh test with older binutils.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
ELF files can share the section header string table (e_shstrndx) with
the symtab .strtab section. That might in some cases save a bit of space
since symbols and sections might share some (sub)strings. To handle that
eu-strip just needs to not unconditionally remove the .shstrtab section
(it will be properly marked as used/unused as needed). eu-unstrip needs
to make sure the section names are added to the strtab if it decides to
rewrite that section. Also makes sure that eu-strip won't move around
a SHT_NOBITS section that has SHF_ALLOC set. Although it is allowed to
move such sections around, there is no benefit. And some tools might
expect no allocated section to move around, not even a nobits section.
It also makes it harder to do "roundtripping" sanity checks that make
sure splitting a file with eu-strip and then reconstructed with eu-unstrip
produce the same ELF file (as is done in the new run-strip-strmerge.sh).
Introduces a somewhat large test generator elfstrmerge.c that will
hopefully turn into a more generic string table merger program.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
| |
When e_version is EV_NONE we should set it to EV_CURRENT like we do for
the EI_VERSION and like we set EI_DATA to the correct byte order when set
to ELFDATANONE. Likewise we should always set e_shentsize like we do for
e_phentsize, not just when ELF_F_LAYOUT isn't set.
Add a new elfshphehdr testcase to check the above.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Since we banned old style function definitions GCC is able to diagnose
function definitions that don't match the function declaration:
elf32_getehdr.c:78: error: conflicting types for ‘__elf64_getehdr_wrlock’
libelfP.h:498: note: previous declaration of ‘__elf64_getehdr_wrlock’
This happens on i386 because there internal functions are marked with:
# define internal_function __attribute__ ((regparm (3), stdcall))
Make sure all internal function declarations and definitions are marked
with internal_function.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
| |
We already require -std=gnu99 and old-style function definitions might
hide some compiler warnings.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
| |
Our dl-hash.h implementation originally came from, or was written at the
same time as, the glibc implementation. At some point (around 9 years ago)
they diverged and the elfutils version got an updated copyright header.
The glibc version saw various updates/optimizations. Just treat the file
like we do for elf.h and copy it whenever the glibc version is updated.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
GCC6 will warn about the reassignement of the nonnull result pointer.
The reassignment is indeed a little questionable. The compiler cannot
see that the pointer will not actually be reassigned since the function
will just return the same pointer value except when the dwarf_formref_die
function fails. In which case we don't use the result anymore. So the
compiler has to pessimistically assume the pointer will need to be
reloaded in the loop every time. Help the compiler generate slightly
better code by just checking whether the function fails directly instead
of reusing the pointer value for this.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
| |
GCC6 and Clang give warnings on redundant NULL tests of parameters
that are declared with __nonnull_attribute__.
Signed-off-by: Chih-Hung Hsieh <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
| |
dwfl_linux_proc_attach depended on a Dwfl_Module with the correct
ELF header already being available. That isn't really necessary since
when we attach we have the main exe ELF file available. Just use that
to make dwfl_linux_proc_attach always work.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
| |
Some compiler does not know that error function never returns.
Signed-off-by: Chih-Hung Hsieh <[email protected]>
|
| |
|
|
|
| |
Signed-off-by: Chih-Hung Hsieh <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
| |
clang compiler static analysis failed.
Signed-off-by: Chih-Hung Hsieh <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
| |
Signed-off-by: Chih-Hung Hsieh <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
| |
And change K&R C function definition to ansi, which prevented GCC from
seeing that callers passed in const arguments.
Signed-off-by: Chih-Hung Hsieh <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
| |
Signed-off-by: Chih-Hung Hsieh <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
| |
%Z is a GNU extension predating the ISO C99 %z modifier supported by
libc5 and no longer recommended.
Signed-off-by: Chih-Hung Hsieh <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
| |
sparc_init would check the ELF class to register to correct core_note
handler. But sparc_register_info would check the ELF machine to determine
whether the register set was 32 or 64 bits. This caused some confusion
and assertion failures in readelf when printing core notes where the
sparc machine and class didn't seem to match up. Check the ELF class
in both sparc_unit and sparc_register_info to give consistent results.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The problem is this:
int n = ffs (w);
w >>= n;
The intent is to shift away up to (and including) the first least
significant bit in w. But w is an unsigned int, so 32 bits. And the
least significant bit could be bit 32 (ffs counts from 1). Unfortunately
a right shift equal to (or larger than) the length in bits of the left
hand operand is undefined behaviour. We expect w to be zero afterwards.
Which would terminate the while loop in the function. But since it is
undefined behaviour anything can happen. In this case, what will actually
happen is that w is unchanged, causing an infinite loop...
gcc -fsanitize=undefined will catch and warn about this when w = 0x80000000
https://bugzilla.redhat.com/show_bug.cgi?id=1259259
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
| |
See http://www.dwarfstd.org/ShowIssue.php?issue=120218.1
GHC emits this language code (0x18).
Also updated https://fedorahosted.org/elfutils/wiki/DwarfExtensions
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
|
| |
gnuld has a really bad bug where it can place a NOBITS section inside
a PT_LOAD segment. Normally that would not work. But it also makes sure
that the contents of the file is all zeros. So in practice it is actually
a PROGBITS section with all zero data. Except that other tools will think
there is an unused gap in the ELF file after the NOBITS section.
Recognize and check this pattern in elflint when --gnu is given.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
| |
Reuse the run-addr2line-i-test.sh testfile-inlines testfile, but
first strip the debuginfo and put the binary and separate debuginfo
file in different roots. Check that --debuginfo-path still finds
the debug file.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
[This bug has been found by using elfutils in the context of
libabigail. The initial bug report is
https://sourceware.org/bugzilla/show_bug.cgi?id=18792. The
interesting comments start at is
https://sourceware.org/bugzilla/show_bug.cgi?id=18792#c4]
suppose we have a debug info file that is located at a
/prefix1/usr/lib/debug/prefix2/libfoo.so. Suppose also that the debug
info describes a binary that is located at /prefix1/prefix2/libfoo.so
Suppose the debug_link property inside the binary
/prefix1/prefix2/libfoo.so correctly contains the string "libfoo.so"
that designates the name of the debug info file.
The problem is, when find_debuginfo_in_path() is called with its
file_name parameter set to "/prefix1/prefix2/libfoo.so" and
mod->dwfl->callbacks->debuginfo_path set to
"/prefix1/lib/debug/", it fails to locate the debug
info file libfoo.so under "/prefix1/usr/lib/debug/prefix2/".
This patch fixes the issue by making find_debuginfo_in_path() try all
the sub-strings of "/prefix1/prefix2/libfoo.so "under"
"/prefix1/usr/lib/debug/", to find libfoo.so. That is, it tries, in
order:
- /prefix1/usr/lib/debug/prefix1/prefix2/libfoo.so
- /prefix1/usr/lib/debug/prefix2/libfoo.so <-- and boom, it finds it!
Note that the patch tries the variations between the two candidates
above too.
The patch uses a goto. I dislike gotos like anyone else, but then
here, not using this would imply a bigger change of the logic of that
function. So I am proposing the scheme based on the goto instead.
* libdwfl/find-debuginfo.c (find_debuginfo_in_path): Try to locate
the debug info file named debuglink_file under
mod->dwfl->callbacks->debuginfo_path, by looking at the set of
sub-trees under mod->dwfl->callbacks->debuginfo_path which is
common to the set of non-absolute parent trees of file_name.
https://bugzilla.redhat.com/show_bug.cgi?id=1253367
Signed-off-by: Dodji Seketeli <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
When yama is enabled in the kernel it might be used to filter any user
space access which requires PTRACE_MODE_ATTACH like ptrace attach, access
to /proc/PID/{mem,personality,stack,syscall}, and the syscalls
process_vm_readv and process_vm_writev which are used for interprocess
services, communication and introspection (like synchronisation, signaling,
debugging, tracing and profiling) of processes.
These are precisely the things that libdw dwfl and ebl backends rely on.
So make sure they don't mysteriously fail in such cases by providing the
default yama scope sysctl value.
This is implemented as a separate subpackage that just provides this
functionality so other packages that don't directly rely on elfutils-libs
can also just Requires: default-yama-scope to function properly.
https://bugzilla.redhat.com/show_bug.cgi?id=1209492#c69
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
With GCC 5 there might be a .rela.plt section with SHF_INFO_LINK set.
Buggy binutils objdump might strip it from the section in the debug file.
Ignore such differences for relocation sections and put the flag back
if necessary.
Also improve the error message a little by only discarding the already
matched sections if there is an prelink undo section. Otherwise we will
report all sections as not matching if the file wasn't prelinked instead
of just the non-matching sections.
New testfiles generated by gcc5 and binutils objdump added.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
| |
Signed-off-by: Mike Frysinger <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Fill the .gitignore with more generated files, such as:
- test executables
- results of the automake testing framework (*.log and *.trs)
- sources generated by flex and bison
- generated *.mnemonics files in libcpu
- the helper libcpu/i386_gendis tool
- *.so.1 symlinks
Also, anchor existing filenames to their location when
builddir==srcdir.
Signed-off-by: Pino Toscano <[email protected]>
|
| |
|
|
|
|
|
|
| |
If the current OS does not implement dwfl_linux_proc_attach (which
currently only Linux does) then skip this test, as "stack" uses that
API for attaching to a running process.
Signed-off-by: Pino Toscano <[email protected]>
|
| |
|
|
|
|
| |
Do not crash if there is no module for the given address.
Signed-off-by: Pino Toscano <[email protected]>
|
| |
|
|
|
|
| |
Currently it is available on Linux only, and it is more an hint.
Signed-off-by: Pino Toscano <[email protected]>
|
| |
|
|
|
|
|
|
| |
This catches bogus data early before we might try to allocate giant
amounts of memory.
Reported-by: Hanno Böck <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
| |
Signed-off-by: Pino Toscano <[email protected]>
|
| |
|
|
|
|
|
|
| |
Use some includes only according to the #ifdef block of the respective
code, or matching the fact they are Linux-only. This way, includes
potentially unportable are not unconditionally used.
Signed-off-by: Pino Toscano <[email protected]>
|
| |
|
|
| |
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
|
| |
When a files do contain textrels we fail to release the segments searched
and valgrind will show:
2,560 bytes in 16 blocks are definitely lost in loss record 1 of 1
at 0x40281B5: malloc (in vgpreload_memcheck-x86-linux.so)
by 0x804AE63: process_file (findtextrel.c:322)
by 0x804909B: main (findtextrel.c:149)
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
| |
We dont' want GCC to dispose or reuse phdr2_mem stack memory while phdr2
is pointing to it.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
| |
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
| |
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
| |
When something goes wrong during the update make sure to always free any
temporary allocated memory (shdr_data and/or scns).
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
| |
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
| |
Just assert early that the page size isn't unreasonable small instead of
corrupting memory later.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
| |
We allocate GElf_SymX entries, which are larger than plain GElf_Sym structs.
The check to see whether we could use stack allocation used the correct
sizeof (GElf_SymX), but the check to see if we needed to free was using
the incorrect sizeof (GElf_Sym). Which could cause us to leak memory.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
| |
If there is something wrong with getting the section data it is likely
we won't be able to get the actual section name because the file is
somehow corrupted. Try to get the name, but handle failure gracefully.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
| |
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
| |
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
| |
When there is an error with the first entry we might already have allocated
the memory but not yet set cnt to 1. Just always free the memory on error.
free (NULL) is a nop anyway and doesn't matter on a failure path.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
| |
dwarf_formudata can return an error for bad DWARF. Don't ignore it.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
When elf_update.c (write_file) doesn't know the current maximum file length
it might have to reduce the file size. posix_fallocate can only extend the
file. So always call ftruncate before that to set the file size and making
sure the backing store is fully there. Add test cases for checking strip
in place (eu-strip without -o) actually reduces the file size. But only
for non-ET_REL files. We might not be able to strip ET_REL files (except
when they are kernel modules) because they might contain "dangling" symbol
table entries.
https://bugzilla.redhat.com/show_bug.cgi?id=1232206
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
| |
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
| |
Signed-off-by: Piotr Drąg <[email protected]>
|
| |
|
|
| |
Signed-off-by: Piotr Drąg <[email protected]>
|