Strip on mips
by Kurt Roeckx
Hi,
I'm trying to debug why strip on mips isn't working properly.
What I see is that for the debug sections, sh_type is not set to
SHT_PROGBITS but to SHT_MIPS_DWARF.
The stripped file still ends up with the debug information it it,
and the file that is supposed to have the debug symbols in it
has it set to SHT_NOBITS, and is rather small.
I'm assuming this is because of the SHT_MIPS_DWARF. I'm not sure
how to find where it's going wrong.
Kurt
11 years, 5 months
FYI: readelf.c (print_ops): Add missing DW_OP_GNU operands.
by Mark Wielaard
Pushed the following commit as obvious.
commit 716486d5a15bdfb528c5d011dc623fa0f6fdc2af
Author: Mark Wielaard <mjw(a)redhat.com>
Date: Tue Apr 24 11:56:42 2012 +0200
readelf.c (print_ops): Add missing DW_OP_GNU operands.
DW_OP_GNU_push_tls_address, DW_OP_GNU_uinit and DW_OP_GNU_encoded_addr.
diff --git a/src/ChangeLog b/src/ChangeLog
index 642df1b..cae5e6b 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2012-04-24 Mark Wielaard <mjw(a)redhat.com>
+
+ * readelf.c (print_ops): Add DW_OP_GNU_push_tls_address,
+ DW_OP_GNU_uinit and DW_OP_GNU_encoded_addr.
+
2012-03-28 Roland McGrath <roland(a)hack.frob.com>
* elflint.c (special_sections): Accept SHF_INFO_LINK for reloc sections.
diff --git a/src/readelf.c b/src/readelf.c
index b70779d..b4e9fc8 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -4065,6 +4065,9 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
[DW_OP_bit_piece] = "bit_piece",
[DW_OP_implicit_value] = "implicit_value",
[DW_OP_stack_value] = "stack_value",
+ [DW_OP_GNU_push_tls_address] = "GNU_push_tls_address",
+ [DW_OP_GNU_uninit] = "GNU_uninit",
+ [DW_OP_GNU_encoded_addr] = "GNU_encoded_addr",
[DW_OP_GNU_implicit_pointer] = "GNU_implicit_pointer",
[DW_OP_GNU_entry_value] = "GNU_entry_value",
[DW_OP_GNU_const_type] = "GNU_const_type",
11 years, 7 months
elflint: (zero sized section) alloc flag set but section not in any loaded segment
by Mark Wielaard
Hi,
Against development versions of gcc/binutils elflint gives some
complaints like:
section [24] '.tm_clone_table': alloc flag set but section not in any
loaded segment
This is because that section's size is zero. So it is somewhat
reasonable IMHO that the linker doesn't put it in any segment.
Is the following patch to elflint OK?
Thanks,
Mark
11 years, 10 months
PATCH: dwarf_highpc: Handle DW_AT_high_pc being a constant offset from DW_AT_low_pc.
by Mark Wielaard
Hi,
The DWARF spec says (since version 4) that DW_AT_high_pc can be
represented by a constant form.
If the value of the DW_AT_high_pc is of class address, it is the
relocated address of the first location past the last
instruction associated with the entity; if it is of class
constant, the value is an unsigned integer offset which when
added to the low PC gives the address of the first location past
the last instruction associated with the entity.
I have a patch for gcc to encode DW_AT_high_pc this way (which saves a
lot of relocations) and jakub has a patch for dwz to encode
DW_AT_high_pc in the smallest possible constant form, which can save ~1%
on the size of debuginfo.
The attached patch adds a testcase for this and makes dwarf_highpc ()
handle the constant form.
Does this look OK?
Thanks,
Mark
11 years, 10 months
FYI: Removed old libdwarf test show-ciefde.
by Mark Wielaard
Hi,
elfutils libdwarf was removed a long time ago and this testcase was
never actually ran anyway (which is why nobody noticed it was broken).
I just removed it.
commit bdad8e39aede889dbac95944a07eaebdebe4ad89
Author: Mark Wielaard <mjw(a)redhat.com>
Date: Thu Apr 26 12:24:33 2012 +0200
Removed old libdwarf test show-ciefde.
diff --git a/tests/ChangeLog b/tests/ChangeLog
index c38ede5..ffe61d5 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,9 @@
+2012-04-26 Mark Wielaard <mjw(a)redhat.com>
+
+ * Makefile.am (EXTRA_DIST): Remove run-show-ciefde.sh.
+ * run-show-ciefde.sh: Removed old libdwarf test.
+ * show-ciefde.c: Likewise.
11 years, 10 months
libdw patch for .debug_types iteration
by Tom Tromey
Tom
>From 1b85426f7a1fa39cfb9ff83b864e825072115847 Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey(a)redhat.com>
Date: Mon, 19 Mar 2012 11:46:45 -0600
Subject: [PATCH] Fix bug using dwarf_next_unit to iterate over .debug_types
* libdw_findcu.c (findcu_cb): Move earlier.
(__libdw_intern_next_unit): Add new CU to search tree here...
(__libdw_findcu): ... not here.
If you call dwarf_next_unit to iterate over .debug_types, then call
dwarf_offdie_types, you can see a failure if some earlier call
happened to call __libdw_intern_next_unit via dwarf_formref_die.
What happens is that __libdw_intern_next_unit updates the Dwarf's
next_tu_offset, but does not add the TU to the TU search tree. So,
the call to dwarf_offdie_types does not find the TU in the tree, and
will not search any more, causing a failure.
This fix changes __libdw_intern_next_unit to add the TU to the search
tree, rather than relying on __libdw_findcu to do it.
---
libdw/ChangeLog | 6 ++++
libdw/libdw_findcu.c | 68 ++++++++++++++++++++++++-------------------------
2 files changed, 39 insertions(+), 35 deletions(-)
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 98b67f4..f96c0d1 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,9 @@
+2012-03-19 Tom Tromey <tromey(a)redhat.com>
+
+ * libdw_findcu.c (findcu_cb): Move earlier.
+ (__libdw_intern_next_unit): Add new CU to search tree here...
+ (__libdw_findcu): ... not here.
+
2012-01-31 Mark Wielaard <mjw(a)redhat.com>
* dwarf_formudata.c (dwarf_formudata): Handle DW_FORM_sec_offset.
diff --git a/libdw/libdw_findcu.c b/libdw/libdw_findcu.c
index 8e5f9e9..83c96ba 100644
--- a/libdw/libdw_findcu.c
+++ b/libdw/libdw_findcu.c
@@ -56,6 +56,31 @@
#include <search.h>
#include "libdwP.h"
+static int
+findcu_cb (const void *arg1, const void *arg2)
+{
+ struct Dwarf_CU *cu1 = (struct Dwarf_CU *) arg1;
+ struct Dwarf_CU *cu2 = (struct Dwarf_CU *) arg2;
+
+ /* Find out which of the two arguments is the search value. It has
+ end offset 0. */
+ if (cu1->end == 0)
+ {
+ if (cu1->start < cu2->start)
+ return -1;
+ if (cu1->start >= cu2->end)
+ return 1;
+ }
+ else
+ {
+ if (cu2->start < cu1->start)
+ return 1;
+ if (cu2->start >= cu1->end)
+ return -1;
+ }
+
+ return 0;
+}
struct Dwarf_CU *
internal_function
@@ -65,6 +90,7 @@ __libdw_intern_next_unit (dbg, debug_types)
{
Dwarf_Off *const offsetp
= debug_types ? &dbg->next_tu_offset : &dbg->next_cu_offset;
+ void **tree = debug_types ? &dbg->tu_tree : &dbg->cu_tree;
Dwarf_Off oldoff = *offsetp;
uint16_t version;
@@ -105,34 +131,16 @@ __libdw_intern_next_unit (dbg, debug_types)
newp->lines = NULL;
newp->locs = NULL;
- return newp;
-}
-
-
-static int
-findcu_cb (const void *arg1, const void *arg2)
-{
- struct Dwarf_CU *cu1 = (struct Dwarf_CU *) arg1;
- struct Dwarf_CU *cu2 = (struct Dwarf_CU *) arg2;
-
- /* Find out which of the two arguments is the search value. It has
- end offset 0. */
- if (cu1->end == 0)
+ /* Add the new entry to the search tree. */
+ if (tsearch (newp, tree, findcu_cb) == NULL)
{
- if (cu1->start < cu2->start)
- return -1;
- if (cu1->start >= cu2->end)
- return 1;
- }
- else
- {
- if (cu2->start < cu1->start)
- return 1;
- if (cu2->start >= cu1->end)
- return -1;
+ /* Something went wrong. Undo the operation. */
+ *offsetp = oldoff;
+ __libdw_seterrno (DWARF_E_NOMEM);
+ return NULL;
}
- return 0;
+ return newp;
}
struct Dwarf_CU *
@@ -160,20 +168,10 @@ __libdw_findcu (dbg, start, debug_types)
/* No. Then read more CUs. */
while (1)
{
- Dwarf_Off oldoff = *next_offset;
struct Dwarf_CU *newp = __libdw_intern_next_unit (dbg, debug_types);
if (newp == NULL)
return NULL;
- /* Add the new entry to the search tree. */
- if (tsearch (newp, tree, findcu_cb) == NULL)
- {
- /* Something went wrong. Undo the operation. */
- *next_offset = oldoff;
- __libdw_seterrno (DWARF_E_NOMEM);
- return NULL;
- }
-
/* Is this the one we are looking for? */
if (start < *next_offset)
// XXX Match exact offset.
--
1.7.7.6
11 years, 11 months
Elfutils 0.153 build problem
by Zachary McGrew
I'm trying (and failing) to build elfutils 0.153 on my i686 Linux box.
The lines around the error are:
gcc -std=gnu99 -Wall -Wshadow -Werror -Wunused -Wextra -Wformat=2
-g -O2 -o libdw.so -shared -o libdw.so
-Wl,--soname,libdw.so.1,-z,defs \
-Wl,--enable-new-dtags,-rpath,/usr/lib/elfutils \
-Wl,--version-script,libdw.map,--no-undefined \
-Wl,--whole-archive libdw_pic.a ../libdwfl/libdwfl_pic.a
../libebl/libebl.a ../libelf/libelf.so -Wl,--no-whole-archive\
-ldl -llzma -lbz2 -lz
if readelf -d libdw.so | fgrep -q TEXTREL; then exit 1; fi
make[1]: *** [libdw.so] Error 1
For good measure I ran "readelf -d | fgrep TEXTREL" on libdl.so,
liblzma.so, libbz2.so, and libz.so, but they all come back clean.
Running readelf -d libdw.so gets me:
Dynamic section at offset 0x49a60 contains 32 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libelf.so.1]
0x00000001 (NEEDED) Shared library: [libdl.so.2]
0x00000001 (NEEDED) Shared library: [liblzma.so.5]
0x00000001 (NEEDED) Shared library: [libbz2.so.1.0]
0x00000001 (NEEDED) Shared library: [libc.so.6]
0x00000001 (NEEDED) Shared library: [ld-linux.so.2]
0x0000000e (SONAME) Library soname: [libdw.so.1]
0x0000000f (RPATH) Library rpath: [/usr/lib/elfutils]
0x0000001d (RUNPATH) Library runpath: [/usr/lib/elfutils]
0x0000000c (INIT) 0x542c
0x0000000d (FINI) 0x39f58
0x00000004 (HASH) 0xf4
0x00000005 (STRTAB) 0x1df0
0x00000006 (SYMTAB) 0xa10
0x0000000a (STRSZ) 4725 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000003 (PLTGOT) 0x4abb0
0x00000002 (PLTRELSZ) 992 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0x504c
0x00000011 (REL) 0x35bc
0x00000012 (RELSZ) 6800 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x00000016 (TEXTREL) 0x0
0x6ffffffc (VERDEF) 0x32e4
0x6ffffffd (VERDEFNUM) 14
0x0000001e (FLAGS) TEXTREL
0x6ffffffe (VERNEED) 0x34cc
0x6fffffff (VERNEEDNUM) 4
0x6ffffff0 (VERSYM) 0x3066
0x6ffffffa (RELCOUNT) 764
0x00000000 (NULL) 0x0
Here's the following versions of packages installed:
gcc 4.6.3
binutils 2.22
glibc 2.15
Linux 3.3.1
Any ideas? I'm stumped.
--
Zachary McGrew
11 years, 11 months
[Patch] gelf_offscn vs SHT_NOBITS
by Mark Wielaard
Hi,
While coming up with a test case for rhbz#807823 "elflint doesn't
recognize SHF_INFO_LINK on relocation sections", I came across another
issue. Not just with elflint, but also with readelf -d. If there is a
SHT_NOBITS section before the .dynamic section then gelf_offscn will
miss it. The solution is similar to commit e9c4e8 (Do not match empty
sections at OFFSET), skip SHT_NOBITS sections too if there is a "real"
section at the same offset that does have content. Does the solution
look sane?
The test binary is a testcase for both this issue and the original
rhbz#807823. Both tests fail before and succeed after the fixes.
Patch attached and in git on the mjw/offscn_nobits branch for those that
want to check out the test binary.
Cheers,
Mark
commit 191d1f0b9163593eee8c4f5cbe3e95cabf6ae9a9
Author: Mark Wielaard <mjw(a)redhat.com>
Date: Mon Apr 2 17:11:25 2012 +0200
elf32_offscn.c: Do not match SHT_NOBITS sections at OFFSET.
readelf -d doesn't work if a SHT_NOBITS section is right before the actual
.dynamic section at the same offset. elflint also fails on such binaries.
So skip SHT_NOBITS sections at the same offset in [g]elf[32|64]_offscn().
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 19b76e8..89dd35f 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,8 @@
+2012-04-02 Mark Wielaard <mjw(a)redhat.com>
+
+ * elf32_offscn.c: Do not match SHT_NOBITS sections at OFFSET unless
+ there are no nonempty sections at that offset.
+
2012-03-21 Roland McGrath <roland(a)hack.frob.com>
* elf-knowledge.h (SECTION_STRIP_P): Remove < SHT_NUM check.
diff --git a/libelf/elf32_offscn.c b/libelf/elf32_offscn.c
index 86eff8b..5dcfc4a 100644
--- a/libelf/elf32_offscn.c
+++ b/libelf/elf32_offscn.c
@@ -101,7 +101,8 @@ elfw2(LIBELFBITS,offscn) (elf, offset)
/* If this section is empty, the following one has the same
sh_offset. We presume the caller is looking for a nonempty
section, so keep looking if this one is empty. */
- if (runp->data[i].shdr.ELFW(e,LIBELFBITS)->sh_size != 0)
+ if (runp->data[i].shdr.ELFW(e,LIBELFBITS)->sh_size != 0
+ && runp->data[i].shdr.ELFW(e,LIBELFBITS)->sh_type != SHT_NOBITS)
goto out;
}
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 8d2b83f..6f6c592 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,10 @@
+2012-04-02 Mark Wielaard <mjw(a)redhat.com>
+
+ * Makefile.am (TESTS): Add run-readelf-d.sh.
+ (EXTRA_DIST): Add testlib_dynseg.so.bz2 and run-readelf-d.sh.
+ * run-readelf-d.sh: New test.
+ * run-elflint-test.sh: Check new testfile.
+
2012-03-21 Tom Tromey <tromey(a)redhat.com>
* typeiter.c: New file.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f2c211b..980aa12 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -86,7 +86,8 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
run-disasm-x86.sh run-disasm-x86-64.sh \
run-early-offscn.sh run-dwarf-getmacros.sh \
run-test-flag-nobits.sh run-prelink-addr-test.sh \
- run-dwarf-getstring.sh run-rerequest_tag.sh run-typeiter.sh
+ run-dwarf-getstring.sh run-rerequest_tag.sh run-typeiter.sh \
+ run-readelf-d.sh
# run-show-ciefde.sh
if !STANDALONE
@@ -162,7 +163,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
testfile55-32.prelink.bz2 testfile55-64.bz2 \
testfile55-64.debug.bz2 testfile55-64.prelink.bz2 \
testfile56.bz2 testfile57.bz2 testfile58.bz2 \
- run-typeiter.sh testfile59.bz2
+ run-typeiter.sh testfile59.bz2 \
+ run-readelf-d.sh testlib_dynseg.so.bz2
installed_TESTS_ENVIRONMENT = libdir=$(DESTDIR)$(libdir) \
bindir=$(DESTDIR)$(bindir) \
diff --git a/tests/run-elflint-test.sh b/tests/run-elflint-test.sh
index e0e1c54..0c872fe 100755
--- a/tests/run-elflint-test.sh
+++ b/tests/run-elflint-test.sh
@@ -44,4 +44,8 @@ testrun ../src/elflint -q --gnu-ld testfile42
testfiles testfile46
testrun ../src/elflint -q testfile46
+# see also run-readelf-d.sh
+testfiles testlib_dynseg.so
+testrun ../src/elflint -q --gnu-ld testlib_dynseg.so
+
exit 0
diff --git a/tests/run-readelf-d.sh b/tests/run-readelf-d.sh
new file mode 100755
index 0000000..9022e70
--- /dev/null
+++ b/tests/run-readelf-d.sh
@@ -0,0 +1,78 @@
+#! /bin/sh
+# Copyright (C) 2012 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
+
+# #include <stdio.h>
+#
+# __thread int i;
+#
+# void print_i ()
+# {
+# printf("%d\n", i);
+# }
+#
+# gcc -fPIC -shared -o testlib_dynseg.so testlib_dynseg.c
+# With ld --version
+# GNU gold (GNU Binutils 2.22.52.20120402) 1.11
+
+testfiles testlib_dynseg.so
+
+testrun_compare ../src/readelf -d testlib_dynseg.so <<\EOF
+
+Dynamic segment contains 28 entries:
+ Addr: 0x00000000000017e0 Offset: 0x0007e0 Link to section: [ 3] '.dynstr'
+ Type Value
+ PLTGOT 0x00000000000019c8
+ PLTRELSZ 72 (bytes)
+ JMPREL 0x0000000000000568
+ PLTREL RELA
+ RELA 0x00000000000004d8
+ RELASZ 144 (bytes)
+ RELAENT 24 (bytes)
+ RELACOUNT 1
+ SYMTAB 0x0000000000000228
+ SYMENT 24 (bytes)
+ STRTAB 0x0000000000000360
+ STRSZ 190 (bytes)
+ GNU_HASH 0x0000000000000420
+ NEEDED Shared library: [libc.so.6]
+ NEEDED Shared library: [ld-linux-x86-64.so.2]
+ INIT 0x00000000000005b0
+ FINI 0x0000000000000748
+ VERSYM 0x0000000000000460
+ VERDEF 0x000000000000047c
+ VERDEFNUM 1
+ VERNEED 0x0000000000000498
+ VERNEEDNUM 2
+ NULL
+ NULL
+ NULL
+ NULL
+ NULL
+ NULL
+EOF
+
+exit 0
diff --git a/tests/testlib_dynseg.so.bz2 b/tests/testlib_dynseg.so.bz2
new file mode 100755
index 0000000..94296a4
Binary files /dev/null and b/tests/testlib_dynseg.so.bz2 differ
11 years, 11 months