[PATCH] libelf: Make sure version xlate dest buffer is fully defined.
by Mark Wielaard
https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c16
contains an example of usage of undefined memory when version section
data needs to be translated, but the version xlate functions detect they
cannot fully transform the section data. To make sure the dest buffer
data is completely defined this patch makes sure all data is moved
from src to dest first. This is somewhat inefficient since normally
all data will be fully converted. But the translation functions have
no way to indicate only partial data was converted.
Reported-by: Alexander Cherepanov <cherepan(a)mccme.ru>
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
libelf/ChangeLog | 5 +++++
libelf/version_xlate.h | 12 +++++++++++-
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 2ca9509..adfccf1 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,8 @@
+2015-01-03 Mark Wielaard <mjw(a)redhat.com>
+
+ * version_xlate.h (elf_cvt_Verdef): Use memmove to copy src to dest.
+ (elf_cvt_Verneed): Likewise.
+
2014-12-30 Mark Wielaard <mjw(a)redhat.com>
* elf_getphdrnum.c (__elf_getphdrnum_chk_rdlock): New function.
diff --git a/libelf/version_xlate.h b/libelf/version_xlate.h
index 16eaa19..9fe01c6 100644
--- a/libelf/version_xlate.h
+++ b/libelf/version_xlate.h
@@ -1,5 +1,5 @@
/* Conversion functions for versioning information.
- Copyright (C) 1998, 1999, 2000, 2002, 2003 Red Hat, Inc.
+ Copyright (C) 1998, 1999, 2000, 2002, 2003, 2015 Red Hat, Inc.
This file is part of elfutils.
Written by Ulrich Drepper <drepper(a)redhat.com>, 1998.
@@ -55,6 +55,11 @@ elf_cvt_Verdef (void *dest, const void *src, size_t len, int encode)
if (len == 0)
return;
+ /* Below we rely on the next field offsets to be correct, start by
+ copying over all data as is in case some data isn't translated.
+ We don't want to leave (undefined) garbage in the dest buffer. */
+ memmove (dest, src, len);
+
do
{
size_t aux_offset;
@@ -149,6 +154,11 @@ elf_cvt_Verneed (void *dest, const void *src, size_t len, int encode)
if (len == 0)
return;
+ /* Below we rely on the next field offsets to be correct, start by
+ copying over all data as is in case some data isn't translated.
+ We don't want to leave (undefined) garbage in the dest buffer. */
+ memmove (dest, src, len);
+
do
{
size_t aux_offset;
--
2.1.0
8 years, 4 months
[PATCH] Fix section corruption bug
by Thilo Schulz
Hi,
When adding data to existing sections in ELF files, libelf may corrupt
those sections, i.e. overwrite the existing data if certain conditions are
met.
If an Elf_Scn structure has seen a call to elf_rawdata(scn) before but no
call to elf_getdata(scn), scn->read_data flag is set, but not
scn->data_list_rear.
Thus, elf_newdata(scn) incorrectly detects a "new user added section" when
really it is a section with live, valid data that will be overwritten by
elf_update(), corrupting the section.
This patch fixes this incorrect behaviour.
Signed-off-by: Thilo Schulz <thilo(a)tjps.eu>
---
libelf/elf_newdata.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libelf/elf_newdata.c b/libelf/elf_newdata.c
index 90d1813..f90eb0a 100644
--- a/libelf/elf_newdata.c
+++ b/libelf/elf_newdata.c
@@ -64,7 +64,7 @@ elf_newdata (Elf_Scn *scn)
rwlock_wrlock (scn->elf->lock);
- if (scn->data_read && scn->data_list_rear == NULL)
+ if (scn->data_read && scn->data_list_rear == NULL && !scn->rawdata.s)
{
/* This means the section was created by the user and this is the
first data. */
--
1.7.10.4
8 years, 6 months
[PATCH] Drop two useless variables from known-dwarf.awk
by Petr Machata
Signed-off-by: Petr Machata <pmachata(a)redhat.com>
---
config/ChangeLog | 5 +++++
config/known-dwarf.awk | 11 ++---------
2 files changed, 7 insertions(+), 9 deletions(-)
mode change 100644 => 100755 config/known-dwarf.awk
diff --git a/config/ChangeLog b/config/ChangeLog
index 1b4e896..409e2b1 100644
--- a/config/ChangeLog
+++ b/config/ChangeLog
@@ -1,3 +1,8 @@
+2015-02-20 Petr Machata <pmachata(a)redhat.com>
+
+ * known-dwarf.awk (END): Drop useless variables lo, hi. Merge two
+ continue-checks in one.
+
2014-12-18 Mark Wielaard <mjw(a)redhat.com>
* elfutils.spec.in: Update for 0.161.
diff --git a/config/known-dwarf.awk b/config/known-dwarf.awk
old mode 100644
new mode 100755
index 52ec5b6..4d89f0f
--- a/config/known-dwarf.awk
+++ b/config/known-dwarf.awk
@@ -1,6 +1,6 @@
#!/bin/gawk -f
-## Copyright (C) 2012 Red Hat, Inc.
+## Copyright (C) 2012, 2015 Red Hat, Inc.
##
## This file is part of elfutils.
##
@@ -48,19 +48,12 @@ END {
if (what && what != set) continue;
split(DW[set], elts, ",");
m = asort(elts);
- lo = hi = "";
if (m == 0) continue;
print "\n#define ALL_KNOWN_DW_" set " \\";
for (j = 1; j <= m; ++j) {
elt = elts[j];
- if (elt ~ /(lo|low)_user$/) {
- lo = elt;
+ if (elt ~ /(low?|hi|high)_user$/)
continue;
- }
- if (elt ~ /(hi|high)_user$/) {
- hi = elt;
- continue;
- }
if (comment[set, elt])
print " ONE_KNOWN_DW_" set "_DESC (" elt ", DW_" set "_" elt \
", \"" comment[set, elt] "\") \\";
--
2.1.0
8 years, 6 months
[PATCH] Support STT_ARM_FUNC symbol type in ebl_symbol_type_name hook
by Petr Machata
Signed-off-by: Petr Machata <pmachata(a)redhat.com>
---
backends/ChangeLog | 5 +++++
backends/arm_init.c | 3 ++-
backends/arm_symbol.c | 15 ++++++++++++++-
3 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/backends/ChangeLog b/backends/ChangeLog
index 57e1b8e..9f5975a 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,3 +1,8 @@
+2015-02-23 Petr Machata <pmachata(a)redhat.com>
+
+ * arm_symbol.c (arm_symbol_type_name): New function.
+ * arm_init.c (arm_init): Initialize the hook.
+
2014-12-30 Mark Wielaard <mjw(a)redhat.com>
* ppc_symbol.c (find_dyn_got): Check sh_entsize is not zero.
diff --git a/backends/arm_init.c b/backends/arm_init.c
index 3283c97..f3e5f0a 100644
--- a/backends/arm_init.c
+++ b/backends/arm_init.c
@@ -1,5 +1,5 @@
/* Initialization of Arm specific backend library.
- Copyright (C) 2002, 2005, 2009, 2013, 2014 Red Hat, Inc.
+ Copyright (C) 2002, 2005, 2009, 2013, 2014, 2015 Red Hat, Inc.
This file is part of elfutils.
Written by Ulrich Drepper <drepper(a)redhat.com>, 2002.
@@ -64,6 +64,7 @@ arm_init (elf, machine, eh, ehlen)
HOOK (eh, return_value_location);
HOOK (eh, abi_cfi);
HOOK (eh, check_reloc_target_type);
+ HOOK (eh, symbol_type_name);
/* We only unwind the core integer registers. */
eh->frame_nregs = 16;
diff --git a/backends/arm_symbol.c b/backends/arm_symbol.c
index cd467ff..da4a50a 100644
--- a/backends/arm_symbol.c
+++ b/backends/arm_symbol.c
@@ -1,5 +1,5 @@
/* Arm specific symbolic name handling.
- Copyright (C) 2002-2009, 2014 Red Hat, Inc.
+ Copyright (C) 2002-2009, 2014, 2015 Red Hat, Inc.
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
@@ -129,3 +129,16 @@ arm_check_reloc_target_type (Ebl *ebl __attribute__ ((unused)), Elf64_Word sh_ty
{
return sh_type == SHT_ARM_EXIDX;
}
+
+const char *
+arm_symbol_type_name (int type,
+ char *buf __attribute__ ((unused)),
+ size_t len __attribute__ ((unused)))
+{
+ switch (type)
+ {
+ case STT_ARM_TFUNC:
+ return "ARM_TFUNC";
+ }
+ return NULL;
+}
--
2.1.0
8 years, 7 months
[COMMITTED] tests: Use PRId64 for printing loff_t.
by Mark Wielaard
loff_t is always 64bits.
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
tests/ChangeLog | 4 ++++
tests/newdata.c | 7 ++++---
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 9d3290f..6ae5e53 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,7 @@
+2015-02-18 Mark Wielaard <mjw(a)redhat.com>
+
+ * newdata.c (check_section_data): Use PRId64 for printing loff_t.
+
2015-02-11 Josh Stone <jistone(a)redhat.com>
* backtrace.c (exec_dump): Initialize jmp.
diff --git a/tests/newdata.c b/tests/newdata.c
index 3cd872e..9af9956 100644
--- a/tests/newdata.c
+++ b/tests/newdata.c
@@ -217,11 +217,12 @@ check_section_data (Elf *elf, char *data, size_t len, size_t times)
exit (1);
}
else
- printf ("OK, section data item %zd (d_off: %zd, d_size: %zd)\n",
- i, d->d_off, d->d_size);
+ printf ("OK, section data item %zd (d_off: %" PRId64
+ ", d_size: %zd)\n", i, d->d_off, d->d_size);
}
char *d_data = (char *) d->d_buf + (len * i) - d->d_off;
- printf ("%zd data (d_off: %zd, len * i: %zd): (%p + %zd) %s\n",
+ printf ("%zd data (d_off: %" PRId64
+ ", len * i: %zd): (%p + %" PRId64 ") %s\n",
i, d->d_off, len * i, d->d_buf, (len * i) - d->d_off, d_data);
if (memcmp (data, d_data, len) != 0)
{
--
2.1.0
8 years, 7 months
[PATCH] libdw: Add DWARF5/GCC5 DW_LANG_Fortran03 and DW_LANG_Fortran08 support.
by Mark Wielaard
GCC5 adds support for the new Fortran 2003 and 2008 standard DWARF5
language codes. Add them to dwarf.h and handle them in dwarf_aggregate_size.
http://dwarfstd.org/ShowIssue.php?issue=141121.1
Also documented at https://fedorahosted.org/elfutils/wiki/DwarfExtensions
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
libdw/ChangeLog | 6 ++++++
libdw/dwarf.h | 2 ++
libdw/dwarf_aggregate_size.c | 2 ++
3 files changed, 10 insertions(+)
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 3432557..813eab4 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,5 +1,11 @@
2015-02-09 Mark Wielaard <mjw(a)redhat.com>
+ * dwarf.h: Add DW_LANG_Fortran03 and DW_LANG_Fortran08.
+ * dwarf_aggregate_size.c (array_size): Recognize array lower bound
+ for new Fortran language codes is 1.
+
+2015-02-09 Mark Wielaard <mjw(a)redhat.com>
+
* dwarf.h: Add DW_TAG_atomic_type.
* libdw.h (dwarf_peel_type): Document DW_TAG_atomic_type.
* dwarf_peel_type.c (dwarf_peel_type): Handle DW_TAG_atomic_type.
diff --git a/libdw/dwarf.h b/libdw/dwarf.h
index a97a2c3..5b88c8f 100644
--- a/libdw/dwarf.h
+++ b/libdw/dwarf.h
@@ -592,6 +592,8 @@ enum
DW_LANG_C_plus_plus_11 = 0x001a, /* ISO C++:2011 */
DW_LANG_C11 = 0x001d, /* ISO C:2011 */
DW_LANG_C_plus_plus_14 = 0x0021, /* ISO C++:2014 */
+ DW_LANG_Fortran03 = 0x0022, /* ISO/IEC 1539-1:2004 */
+ DW_LANG_Fortran08 = 0x0023, /* ISO/IEC 1539-1:2010 */
DW_LANG_lo_user = 0x8000,
diff --git a/libdw/dwarf_aggregate_size.c b/libdw/dwarf_aggregate_size.c
index 667c274..0247847 100644
--- a/libdw/dwarf_aggregate_size.c
+++ b/libdw/dwarf_aggregate_size.c
@@ -123,6 +123,8 @@ array_size (Dwarf_Die *die, Dwarf_Word *size,
case DW_LANG_Fortran77:
case DW_LANG_Fortran90:
case DW_LANG_Fortran95:
+ case DW_LANG_Fortran03:
+ case DW_LANG_Fortran08:
case DW_LANG_Pascal83:
case DW_LANG_Modula2:
case DW_LANG_PL1:
--
1.8.3.1
8 years, 7 months
[PATCH] libdw: Add support for DWARF5/GCC5 DW_TAG_atomic_type.
by Mark Wielaard
GCC5 adds support for the new C11 _Atomic DWARF5 DW_TAG_atomic_type
qualifier. Add it to dwarf.h and handle it in dwarf_peel_type.
http://dwarfstd.org/ShowIssue.php?issue=131112.1
Also documented at https://fedorahosted.org/elfutils/wiki/DwarfExtensions
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
libdw/ChangeLog | 6 ++++++
libdw/dwarf.h | 3 +++
libdw/dwarf_peel_type.c | 3 ++-
libdw/libdw.h | 3 ++-
4 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index d377937..3432557 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,9 @@
+2015-02-09 Mark Wielaard <mjw(a)redhat.com>
+
+ * dwarf.h: Add DW_TAG_atomic_type.
+ * libdw.h (dwarf_peel_type): Document DW_TAG_atomic_type.
+ * dwarf_peel_type.c (dwarf_peel_type): Handle DW_TAG_atomic_type.
+
2014-12-24 Mark Wielaard <mjw(a)redhat.com>
* dwarf_getsrc_die.c (dwarf_getsrc_die): Return the last line record
diff --git a/libdw/dwarf.h b/libdw/dwarf.h
index da8cf3a..a97a2c3 100644
--- a/libdw/dwarf.h
+++ b/libdw/dwarf.h
@@ -94,6 +94,9 @@ enum
DW_TAG_rvalue_reference_type = 0x42,
DW_TAG_template_alias = 0x43,
+ /* DWARF 5. */
+ DW_TAG_atomic_type = 0x47,
+
DW_TAG_lo_user = 0x4080,
DW_TAG_MIPS_loop = 0x4081,
diff --git a/libdw/dwarf_peel_type.c b/libdw/dwarf_peel_type.c
index a110bc5..9be838d 100644
--- a/libdw/dwarf_peel_type.c
+++ b/libdw/dwarf_peel_type.c
@@ -51,7 +51,8 @@ dwarf_peel_type (die, result)
while (tag == DW_TAG_typedef
|| tag == DW_TAG_const_type
|| tag == DW_TAG_volatile_type
- || tag == DW_TAG_restrict_type)
+ || tag == DW_TAG_restrict_type
+ || tag == DW_TAG_atomic_type)
{
Dwarf_Attribute attr_mem;
Dwarf_Attribute *attr = INTUSE (dwarf_attr_integrate) (die, DW_AT_type,
diff --git a/libdw/libdw.h b/libdw/libdw.h
index b2b2282..473e1a2 100644
--- a/libdw/libdw.h
+++ b/libdw/libdw.h
@@ -409,7 +409,8 @@ extern int dwarf_siblingof (Dwarf_Die *die, Dwarf_Die *result)
The current DWARF specification defines one type alias tag
(DW_TAG_typedef) and three qualifier type tags (DW_TAG_const_type,
- DW_TAG_volatile_type, DW_TAG_restrict_type). A future version of
+ DW_TAG_volatile_type, DW_TAG_restrict_type). DWARF5 defines one
+ other qualifier type tag (DW_TAG_atomic_type). A future version of
this function might peel other alias or qualifier type tags if a
future DWARF version or GNU extension defines other type aliases or
qualifier type tags that don't modify or change the structural
--
1.8.3.1
8 years, 7 months
[PATCH 1/2] libdw: ensure read_encoded_value's value is set
by Josh Stone
With CFLAGS='-Og -g', F21 gcc hits -Werror=maybe-uninitialized in
read_encoded_value at "*result += value". It's fine with -O2/-O0.
In particular it seems to care about the __libdw_cfi_read_address_inc
calls. By my inspection, the only way those don't set value are for
error cases, which will then return immediately. This patch just sets
value = 0 to begin with, so gcc is always convinced it's fine.
Signed-off-by: Josh Stone <jistone(a)redhat.com>
---
libdw/ChangeLog | 4 ++++
libdw/encoded-value.h | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index d377937ff57c..b6ad425d8640 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,7 @@
+2015-02-11 Josh Stone <jistone(a)redhat.com>
+
+ * encoded-value.h (read_encoded_value): Initialize value.
+
2014-12-24 Mark Wielaard <mjw(a)redhat.com>
* dwarf_getsrc_die.c (dwarf_getsrc_die): Return the last line record
diff --git a/libdw/encoded-value.h b/libdw/encoded-value.h
index f953f5ef2a5f..0fa201835c5e 100644
--- a/libdw/encoded-value.h
+++ b/libdw/encoded-value.h
@@ -152,7 +152,7 @@ read_encoded_value (const Dwarf_CFI *cache, uint8_t encoding,
return true;
}
- Dwarf_Addr value;
+ Dwarf_Addr value = 0;
const unsigned char *endp = cache->data->d.d_buf + cache->data->d.d_size;
switch (encoding & 0x0f)
{
--
2.1.0
8 years, 7 months
[PATCH] dwarf_ranges: do not request base address attributes if not necessary
by Petr Machata
- Instead of bailing out at iteration start, we remember the
base-address-selecting attributes were not seen, and then bail out
later if no base address selection entry has been seen.
Signed-off-by: Petr Machata <pmachata(a)redhat.com>
---
libdw/ChangeLog | 7 +++++
libdw/dwarf_ranges.c | 22 +++++++++------
tests/ChangeLog | 6 ++++
tests/Makefile.am | 5 ++--
tests/debug-ranges-no-lowpc.o.bz2 | Bin 0 -> 376 bytes
tests/debug-ranges-no-lowpc.s | 49 ++++++++++++++++++++++++++++++++
tests/dwarf-ranges.c | 57 ++++++++++++++++++++++++++++++++++++++
tests/run-dwarf-ranges.sh | 27 ++++++++++++++++++
8 files changed, 162 insertions(+), 11 deletions(-)
create mode 100644 tests/debug-ranges-no-lowpc.o.bz2
create mode 100644 tests/debug-ranges-no-lowpc.s
create mode 100644 tests/dwarf-ranges.c
create mode 100755 tests/run-dwarf-ranges.sh
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index d377937..212b87b 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,10 @@
+2015-02-11 Petr Machata <pmachata(a)redhat.com>
+
+ * dwarf_ranges.c (dwarf_ranges): Do not bail out when neither
+ DW_AT_entry_pc nor DW_AT_low_pc are available. Instead remember
+ the fact in *BASEP and bail out later if it hasn't been updated by
+ __libdw_read_begin_end_pair_inc.
+
2014-12-24 Mark Wielaard <mjw(a)redhat.com>
* dwarf_getsrc_die.c (dwarf_getsrc_die): Return the last line record
diff --git a/libdw/dwarf_ranges.c b/libdw/dwarf_ranges.c
index d9b7293..e8706f7 100644
--- a/libdw/dwarf_ranges.c
+++ b/libdw/dwarf_ranges.c
@@ -33,6 +33,7 @@
#include "libdwP.h"
#include <dwarf.h>
#include <assert.h>
+#include <stdio.h>
/* Read up begin/end pair and increment read pointer.
- If it's normal range record, set up `*beginp' and `*endp' and return 0.
@@ -142,14 +143,7 @@ dwarf_ranges (Dwarf_Die *die, ptrdiff_t offset, Dwarf_Addr *basep,
DW_AT_entry_pc,
&attr_mem),
basep) != 0)
- {
- if (INTUSE(dwarf_errno) () == 0)
- {
- invalid:
- __libdw_seterrno (DWARF_E_INVALID_DWARF);
- }
- return -1;
- }
+ *basep = (Dwarf_Addr) -1;
}
else
{
@@ -182,7 +176,17 @@ dwarf_ranges (Dwarf_Die *die, ptrdiff_t offset, Dwarf_Addr *basep,
return -1l;
}
- /* We have an address range entry. */
+ /* We have an address range entry. Check that we have a base. */
+ if (*basep == (Dwarf_Addr) -1)
+ {
+ if (INTUSE(dwarf_errno) () == 0)
+ {
+ invalid:
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ }
+ return -1;
+ }
+
*startp = *basep + begin;
*endp = *basep + end;
return readp - (unsigned char *) d->d_buf;
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 97c7ab8..5091a9b 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,9 @@
+2015-02-11 Petr Machata <pmachata(a)redhat.com>
+
+ * run-dwarf-ranges.sh: New test.
+ * dwarf-ranges.c: New file.
+ * debug-ranges-no-lowpc.s, debug-ranges-no-lowpc.o.bz2: New test case.
+
2015-01-21 Mark Wielaard <mjw(a)redhat.com>
* Makefile.am (check_PROGRAMS): Add elfstrtab.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5ba8cdd..b03f62e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -44,7 +44,7 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \
find-prologues funcretval allregs rdwrmmap \
dwfl-bug-addr-overflow arls dwfl-bug-fd-leak \
dwfl-addr-sect dwfl-bug-report early-offscn \
- dwfl-bug-getmodules dwarf-getmacros addrcfi \
+ dwfl-bug-getmodules dwarf-getmacros dwarf-ranges addrcfi \
test-flag-nobits dwarf-getstring rerequest_tag \
alldts md5-sha1-test typeiter typeiter2 low_high_pc \
test-elf_cntl_gelf_getshdr dwflsyms dwfllines \
@@ -94,7 +94,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
dwfl-bug-fd-leak dwfl-bug-report \
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 \
+ run-early-offscn.sh run-dwarf-getmacros.sh run-dwarf-ranges.sh \
run-test-flag-nobits.sh run-prelink-addr-test.sh \
run-dwarf-getstring.sh run-rerequest_tag.sh run-typeiter.sh \
run-readelf-d.sh run-readelf-gdb_index.sh run-unstrip-n.sh \
@@ -394,6 +394,7 @@ dwfl_bug_report_LDADD = $(libdw) $(libebl) $(libelf) -ldl
dwfl_bug_getmodules_LDADD = $(libdw) $(libebl) $(libelf) -ldl
dwfl_addr_sect_LDADD = $(libdw) $(libebl) $(libelf) -ldl
dwarf_getmacros_LDADD = $(libdw)
+dwarf_ranges_LDADD = $(libdw)
dwarf_getstring_LDADD = $(libdw)
addrcfi_LDADD = $(libdw) $(libebl) $(libelf) -ldl
test_flag_nobits_LDADD = $(libelf)
diff --git a/tests/debug-ranges-no-lowpc.o.bz2 b/tests/debug-ranges-no-lowpc.o.bz2
new file mode 100644
index 0000000000000000000000000000000000000000..871a3fb4b059fa600e49137b56f6d4a6ee5bdcf3
GIT binary patch
literal 376
zcmV-;0f+uVT4*^jL0KkKSs6X{L;wM0|IYva>S`c|AOpk2LIL;ZzhHnsAOHXX06+i;
zumL6rG(ZTRfS?0UQ)+rcK+`|~dY+m?nqp+hqX~jyX@E=u7$X8O4AnIS439`?XvhEn
z8Z>A!dYUx#5X7p+hN+9yw&T|MM@|d(*EC`zzb^ahi%6S5r6dq=G@4BaN~@uyr#s3w
zRj1n9S;}HCwI!7^$1)ZG7g&O^sOU5<^OmMfH9>f8LT$CwI1=SBi9pf>(geT~1P~<E
zt;r;o0X$XXuQhV`RFz3yC9Hbe+E@?{gv2G?MC3GIyA66xG&zL!?YAdL)6Zm;12SQY
zm+?cWePVTTX+Qup(dR1$lwG+EIFPnIr8=C!EaKl6c%1Y}YGa9=R%ND)nQ32B%Q6hl
zsLS^nsRKRrfOtIwF@u17rj>30Y{)cVxJ^7_orn}kHZhBrOyWt@qqy&ut%s#<86H9$
WX0B<AHztDN{}*yaI8cxoJ@!P@45BIk
literal 0
HcmV?d00001
diff --git a/tests/debug-ranges-no-lowpc.s b/tests/debug-ranges-no-lowpc.s
new file mode 100644
index 0000000..879bce2
--- /dev/null
+++ b/tests/debug-ranges-no-lowpc.s
@@ -0,0 +1,49 @@
+ .section .debug_info
+.Lcu1_begin:
+ .4byte .Lcu1_end - .Lcu1_start
+.Lcu1_start:
+ .2byte 3 /* Version */
+ .4byte .Labbrev1_begin /* Abbrevs */
+ .byte 8 /* Pointer size */
+ .uleb128 2 /* Abbrev (DW_TAG_compile_unit) */
+ .4byte 0
+.Lcu1_end:
+ .section .note.gnu.build-id, "a", %note
+ .4byte 4
+ .4byte 8
+ .4byte 3
+ .ascii "GNU\0"
+ .byte 0x01
+ .byte 0x02
+ .byte 0x03
+ .byte 0x04
+ .byte 0x05
+ .byte 0x06
+ .byte 0x07
+ .byte 0x08
+ .section .debug_abbrev
+.Labbrev1_begin:
+ .uleb128 2 /* Abbrev start */
+ .uleb128 0x11 /* DW_TAG_compile_unit */
+ .byte 0 /* has_children */
+ .uleb128 0x55 /* DW_AT_ranges */
+ .uleb128 0x06 /* DW_FORM_data4 */
+ .byte 0x0 /* Terminator */
+ .byte 0x0 /* Terminator */
+ .byte 0x0 /* Terminator */
+ .byte 0x0 /* Terminator */
+
+ .section .debug_ranges
+
+ .8byte 0xffffffffffffffff
+ .8byte 0
+
+ .8byte 1
+ .8byte 2
+
+ .8byte 3
+ .8byte 4
+
+ .8byte 0
+ .8byte 0
+
diff --git a/tests/dwarf-ranges.c b/tests/dwarf-ranges.c
new file mode 100644
index 0000000..4bcf96c
--- /dev/null
+++ b/tests/dwarf-ranges.c
@@ -0,0 +1,57 @@
+/* Test program for dwarf_ranges
+ Copyright (C) 2015 Red Hat, Inc.
+ This file is part of elfutils.
+
+ This file 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; either version 3 of the License, or
+ (at your option) any later version.
+
+ 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 this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include ELFUTILS_HEADER(dw)
+#include <dwarf.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <inttypes.h>
+
+int
+main (int argc, char *argv[])
+{
+ assert (argc >= 3);
+ const char *name = argv[1];
+ ptrdiff_t cuoff = strtol (argv[2], NULL, 0);
+
+ int fd = open (name, O_RDONLY);
+ Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
+
+ Dwarf_Die cudie_mem, *cudie = dwarf_offdie (dbg, cuoff, &cudie_mem);
+
+ Dwarf_Addr base, start, end;
+ for (ptrdiff_t off = 0;
+ (off = dwarf_ranges (cudie, off, &base, &start, &end)); )
+ if (off == -1)
+ {
+ puts (dwarf_errmsg (dwarf_errno ()));
+ break;
+ }
+ else
+ fprintf (stderr, "%"PRIx64"..%"PRIx64" (base %"PRIx64")\n",
+ start, end, base);
+
+ dwarf_end (dbg);
+
+ return 0;
+}
diff --git a/tests/run-dwarf-ranges.sh b/tests/run-dwarf-ranges.sh
new file mode 100755
index 0000000..d202ed3
--- /dev/null
+++ b/tests/run-dwarf-ranges.sh
@@ -0,0 +1,27 @@
+#! /bin/sh
+# Copyright (C) 2015 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file 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; either version 3 of the License, or
+# (at your option) any later version.
+#
+# 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 this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/test-subr.sh
+
+testfiles debug-ranges-no-lowpc.o
+
+testrun_compare ${abs_builddir}/dwarf-ranges debug-ranges-no-lowpc.o 0xb <<\EOF
+1..2 (base 0)
+3..4 (base 0)
+EOF
+
+exit 0
--
2.1.0
8 years, 7 months