dwarflint allow strange combinations of attribute/form in gnu mode
by Mark Wielaard
Hi,
I came across a strange combination of new attribute with old form for
gcc. When gcc isn't using -gstrict-dwarf, it allows attributes from
newer versions, but doesn't use new forms, even if such an attribute
would need that. So this patch allows that (in particular for
DW_AT_ranges for dwarf2), but only in gnu mode. Does this look like a
sane solution?
Thanks,
Mark
11 years, 12 months
[2/3, ppc64, elfutils patch] eu-strip vs. func addresses for GDB inferior calls
by Jan Kratochvil
Hi,
the elfutils part.
before the fix:
binary:
[11] .text PROGBITS 00000000100003e0 0003e0 000410 00 AX 0 0 16
[22] .opd PROGBITS 0000000010010ad8 000ad8 0000b8 00 WA 0 0 8
[28] .gnu_debuglink PROGBITS 0000000000000000 000c2c 00001c 00 0 0 4
.debug:
[11] .text NOBITS 00000000100003e0 000250 000410 00 AX 0 0 16
[22] .opd NOBITS 0000000010010ad8 000250 0000b8 00 WA 0 0 8
^^^^^^^^
[30] .debug_info PROGBITS 0000000000000000 0002b1 0000b1 00 0 0 1
after the fix:
binary:
[11] .text PROGBITS 00000000100003e0 0003e0 000410 00 AX 0 0 16
[22] .opd PROGBITS 0000000010010ad8 000ad8 0000b8 00 WA 0 0 8
[28] .gnu_debuglink PROGBITS 0000000000000000 000c2c 00001c 00 0 0 4
.debug:
[11] .text NOBITS 00000000100003e0 000250 000410 00 AX 0 0 16
[22] .opd PROGBITS 0000000010010ad8 000250 0000b8 00 WA 0 0 8
^^^^^^^^
[30] .debug_info PROGBITS 0000000000000000 000369 0000b1 00 0 0 1
The patch has been regression tested on x86_64-fedora14-linux-gnu,
ppc64-rhel61-linux-gnu.
Thanks,
Jan
src/
2011-03-23 Jan Kratochvil <jan.kratochvil(a)redhat.com>
* strip.c (handle_elf): Provide `.opd' copy for the .debug file.
--- a/src/strip.c
+++ b/src/strip.c
@@ -883,7 +883,8 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
bool discard_section = (shdr_info[cnt].idx > 0
&& shdr_info[cnt].debug_data == NULL
&& shdr_info[cnt].shdr.sh_type != SHT_NOTE
- && cnt != ehdr->e_shstrndx);
+ && cnt != ehdr->e_shstrndx
+ && strcmp (shdr_info[cnt].name, ".opd") != 0);
/* Set the section header in the new file. */
GElf_Shdr debugshdr = shdr_info[cnt].shdr;
11 years, 12 months
dwarlint: check_range_out_of_scope only check location of pc_contained_dies
by Mark Wielaard
Hi,
I was seeing lots of warnings from dwarflint saying a location attribute
was outside containing scope. This was for things like the
DW_AT_location of a DW_TAG_formal_parameter. I think these shouldn't be
checked. In fact the first check in recursively_validate () already only
looked at code describing dies. So I made the second check for the
location address ranges use the same logic. Does this look OK, or is it
more subtle than that?
diff -w attached, full patch on mjw/location-range branch (since it is
mostly whitespace).
Thanks,
Mark
12 years
Some more libdw/c++ support for GNU_call_site
by Mark Wielaard
Hi,
I pushed some slightly higher level support for DW_TAG_GNU_call_site and
friends to the dwarf branch. Should have posted here. dwarflint doesn't
really check the requirements, but at least should not complain too
loudly when it encounters these new tags and attributes now.
Cheers,
Mark
12 years
elf_clone test
by Marek Polacek
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Here's an attempt to cover elf_clone. I've tried to memcmp elf and cloned
elf, but this way it didn't work so I've used just manual comparison of
values. Tested on x86_64. Ok?
Signed-off-by: Marek Polacek <mpolacek(a)redhat.com>
- ---
tests/ChangeLog | 7 ++++
tests/Makefile.am | 7 ++--
tests/elf-clone.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++
tests/run-elf-clone.sh | 30 +++++++++++++++++++
4 files changed, 115 insertions(+), 3 deletions(-)
create mode 100644 tests/elf-clone.c
create mode 100755 tests/run-elf-clone.sh
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 674fe96..3c51b13 100644
- --- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,10 @@
+2011-03-31 Marek Polacek <mpolacek(a)redhat.com>
+
+ * elf-clone.c: New file.
+ * run-elf-clone.sh: Use it.
+ * Makefile.am (TESTS, EXTRA_DIST, noinst_PROGRAMS): Add files.
+ (elf_clone_LDADD): New variable.
+
2011-03-28 Marek Polacek <mpolacek(a)redhat.com>
* alldts.c: New file.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 35f55e3..83d6b25 100644
- --- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -58,7 +58,7 @@ noinst_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \
dwfl-addr-sect dwfl-bug-report early-offscn \
dwfl-bug-getmodules dwarf-getmacros addrcfi \
test-flag-nobits dwarf-getstring rerequest_tag \
- - alldts
+ alldts elf-clone
asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \
asm-tst6 asm-tst7 asm-tst8 asm-tst9
@@ -80,7 +80,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
run-readelf-test4.sh run-readelf-twofiles.sh \
run-native-test.sh run-bug1-test.sh \
dwfl-bug-addr-overflow run-addrname-test.sh \
- - dwfl-bug-fd-leak dwfl-bug-report \
+ dwfl-bug-fd-leak dwfl-bug-report run-elf-clone.sh \
run-dwfl-bug-offline-rel.sh run-dwfl-addr-sect.sh \
run-disasm-x86.sh run-disasm-x86-64.sh \
run-early-offscn.sh run-dwarf-getmacros.sh \
@@ -119,7 +119,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
run-addrname-test.sh run-dwfl-bug-offline-rel.sh \
run-dwfl-addr-sect.sh run-early-offscn.sh \
run-dwarf-getmacros.sh run-test-flag-nobits.sh \
- - run-dwarf-getstring.sh run-alldts.sh \
+ run-dwarf-getstring.sh run-alldts.sh run-elf-clone.sh \
testfile15.bz2 testfile15.debug.bz2 \
testfile16.bz2 testfile16.debug.bz2 \
testfile17.bz2 testfile17.debug.bz2 \
@@ -255,6 +255,7 @@ addrcfi_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
test_flag_nobits_LDADD = $(libelf) $(libmudflap)
rerequest_tag_LDADD = $(libdw) $(libmudflap)
alldts_LDADD = $(libebl) $(libelf) $(libmudflap)
+elf_clone_LDADD = $(libelf) $(libmudflap)
if GCOV
check: check-am coverage
diff --git a/tests/elf-clone.c b/tests/elf-clone.c
new file mode 100644
index 0000000..a5d9b4b
- --- /dev/null
+++ b/tests/elf-clone.c
@@ -0,0 +1,74 @@
+/* Test for elf_clone.
+ Copyright (C) 2011 Red Hat, Inc.
+ This file is part of Red Hat elfutils.
+ Written by Marek Polacek <mpolacek(a)redhat.com>, 2011.
+
+ Red Hat elfutils is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by the
+ Free Software Foundation; version 2 of the License.
+
+ Red Hat elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Red Hat elfutils; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+ Red Hat elfutils is an included package of the Open Invention Network.
+ An included package of the Open Invention Network is a package for which
+ Open Invention Network licensees cross-license their patents. No patent
+ license is granted, either expressly or impliedly, by designation as an
+ included package. Should you wish to participate in the Open Invention
+ Network licensing program, please visit www.openinventionnetwork.com
+ <http://www.openinventionnetwork.com>. */
+
+#include <elf.h>
+#include <fcntl.h>
+#include <libelf.h>
+#include <libelfP.h>
+#include <stdio.h>
+
+
+int
+main (int argc __attribute__ ((unused)), char *argv[])
+{
+ /* Open ourselves for reading. */
+ int fd = open64 (argv[0], O_RDONLY);
+ if (fd == -1)
+ {
+ printf ("cannot open `%s': %m\n", argv[0]);
+ return 1;
+ }
+
+ /* Tell the library which version are we expecting. */
+ elf_version (EV_CURRENT);
+
+ /* Get an ELF descriptor. */
+ struct Elf *elf = elf_begin (fd, ELF_C_RDWR, NULL);
+ if (elf == NULL)
+ {
+ printf ("cannot create ELF descriptor: %s\n", elf_errmsg (-1));
+ return 1;
+ }
+
+ /* This should return NULL. */
+ Elf *newelf = elf_clone (NULL, ELF_C_EMPTY);
+ if (newelf != NULL)
+ return 1;
+
+ /* Clone our descriptor. */
+ newelf = elf_clone (elf, ELF_C_EMPTY);
+
+ return !(elf->fildes == newelf->fildes
+ && elf->map_address == newelf->map_address
+ && elf->kind == newelf->kind
+ && elf->parent == newelf->parent
+ && elf->class == newelf->class
+ && elf->cmd == newelf->cmd
+ && elf->start_offset == newelf->start_offset
+ && elf->maximum_size == newelf->maximum_size
+ && newelf->ref_count == 1
+ && newelf->flags == ELF_F_DIRTY);
+}
diff --git a/tests/run-elf-clone.sh b/tests/run-elf-clone.sh
new file mode 100755
index 0000000..b2ac8e3
- --- /dev/null
+++ b/tests/run-elf-clone.sh
@@ -0,0 +1,30 @@
+#! /bin/sh
+# Copyright (C) 2011 Red Hat, Inc.
+# This file is part of Red Hat elfutils.
+#
+# Red Hat elfutils is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by the
+# Free Software Foundation; version 2 of the License.
+#
+# Red Hat elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Red Hat elfutils; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+#
+# Red Hat elfutils is an included package of the Open Invention Network.
+# An included package of the Open Invention Network is a package for which
+# Open Invention Network licensees cross-license their patents. No patent
+# license is granted, either expressly or impliedly, by designation as an
+# included package. Should you wish to participate in the Open Invention
+# Network licensing program, please visit www.openinventionnetwork.com
+# <http://www.openinventionnetwork.com>.
+
+. $srcdir/test-subr.sh
+
+testrun ./elf-clone
+
+exit 0
- --
1.7.3.4
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)
iF4EAREIAAYFAk2UyOMACgkQt3gKtVPE8IKNzAEAhFRChFRXxTwdz+YzIo0WeVev
hnWD3rlcUkjDfEQMz/sA/3Q4di0qKYuJa9UdoeTJ/VkyI+7x4ode1mKL+oFY2ZJr
=LeGe
-----END PGP SIGNATURE-----
12 years
mpolacek/ebl_dynamic_tag_name
by Marek Polacek
I've just pushed another test for function ebl_dynamic_tag_name. This
function is used mainly in elflint, but also in readelf. Test is quite
simple--just print all the possible strings the function can return. Now
the ebl_dynamic_tag_name is fully covered.
I've also fixed last ChangeLog entry which contained wrong month number.
All is available in branch mpolacek/ebl_dynamic_tag_name.
Please review. Thanks,
Marek
12 years
Improvements to the output of readelf -wline
by Petr Machata
Hi there,
I'd like to make -wline output more regular and useful. Currently lines
describing opcodes are formatted inconsistently either with or without
initial space. That's probably an aesthetic nit, I don't think that
there is a pattern to it.
Second, more important change is that I'd like to prefix opcode lines
with their offset. This should aid debugging and reviewing dwarflint
citations.
Both changes are on the branch pmachata/readelf.
PM
12 years
[dwarflint] low-level call_site and entry_value support
by Mark Wielaard
Hi,
This patch adds support to the low-level dwarflint checks for the new
GNU extensions for call_site and entry_value support. Also on
mjw/call_site branch.
OK to merge to dwarf branch and push?
Thanks,
Mark
12 years
Various SIGFPEs on sh_entsize == 0
by Petr Machata
Hi there,
I hit these cases during my fuzzer runs. I'm turning the patches in
after yesterday's discussion on #elfutils. My original inclination was
that we don't have to support arbitrarily broken files, but it's true
that the tools shouldn't misbehave either. It's all on the branch
pmachata/sh_entsize, and pasted here for easy review.
PM
diff --git a/libdwfl/relocate.c b/libdwfl/relocate.c
index 95206f4..64e4485 100644
--- a/libdwfl/relocate.c
+++ b/libdwfl/relocate.c
@@ -478,6 +478,9 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr,
}
}
+ if (shdr->sh_entsize == 0)
+ return DWFL_E_BADELF;
+
size_t nrels = shdr->sh_size / shdr->sh_entsize;
size_t complete = 0;
if (shdr->sh_type == SHT_REL)
diff --git a/src/elflint.c b/src/elflint.c
index c122735..1c586d0 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -1448,6 +1448,9 @@ check_rela (Ebl *ebl, GElf_Ehdr *ehdr, GElf_Shdr *shdr, int idx)
Elf_Data *symdata = elf_getdata (symscn, NULL);
enum load_state state = state_undecided;
+ if (shdr->sh_entsize == 0)
+ return;
+
for (size_t cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt)
{
GElf_Rela rela_mem;
diff --git a/src/readelf.c b/src/readelf.c
index 30c2be0..17f657a 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -1705,6 +1705,15 @@ static void
handle_relocs_rela (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, GElf_Shdr *shdr)
{
int class = gelf_getclass (ebl->elf);
+ if (shdr->sh_entsize == 0)
+ {
+ printf (gettext ("\
+\nInvalid relocation section [%2zu] at offset %#0" PRIx64 ".\n"),
+ elf_ndxscn (scn),
+ shdr->sh_offset);
+ return;
+ }
+
int nentries = shdr->sh_size / shdr->sh_entsize;
/* Get the data of the section. */
12 years