summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOmar Sandoval <osandov@fb.com>2019-12-11 17:29:44 -0800
committerMark Wielaard <mark@klomp.org>2019-12-18 21:18:59 +0100
commit2e75c987d591d3af313ee38a31ab677f6f4eb1ff (patch)
tree7f2bfca702f5dca0ce5e82a34d222273fa1cfb3f /tests
parent277c2c54f5579523649a29d26966bfed35a159bf (diff)
libdwfl: remove broken coalescing logic in dwfl_report_segment
dwfl_report_segment has some logic that detects when a segment is contiguous with the previously reported segment, in which case it's supposed to coalesce them. However, in this case, it actually returns without updating the segment array at all. As far as I can tell, this has always been broken. It appears that no one uses the coalescing logic anyways, as they pass IDENT as NULL. Let's just get rid of the logic and add a test case. Signed-off-by: Omar Sandoval <osandov@fb.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog5
-rw-r--r--tests/Makefile.am6
-rw-r--r--tests/dwfl-report-segment-contiguous.c82
3 files changed, 91 insertions, 2 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index ce67ce55..30bd8256 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,8 @@
+2019-12-11 Omar Sandoval <osandov@fb.com>
+
+ * dwfl-report-segment-coalesce.c: New test.
+ * Makefile.am: Add dwfl-report-segment-coalesce
+
2019-12-06 Mark Wielaard <mark@klomp.org>
* run-debuginfod-find.sh: Force -Wl,--build-id.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index eab4ae6f..2c3ac299 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -50,7 +50,8 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \
test-flag-nobits dwarf-getstring rerequest_tag \
alldts typeiter typeiter2 low_high_pc \
test-elf_cntl_gelf_getshdr dwflsyms dwfllines \
- dwfl-report-elf-align varlocs backtrace backtrace-child \
+ dwfl-report-elf-align dwfl-report-segment-contiguous \
+ varlocs backtrace backtrace-child \
backtrace-data backtrace-dwarf debuglink debugaltlink \
buildid deleted deleted-lib.so aggregate_size peel_type \
vdsosyms \
@@ -113,7 +114,7 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \
run-native-test.sh run-bug1-test.sh \
run-debuglink.sh run-debugaltlink.sh run-buildid.sh \
dwfl-bug-addr-overflow run-addrname-test.sh \
- dwfl-bug-fd-leak dwfl-bug-report \
+ dwfl-bug-fd-leak dwfl-bug-report dwfl-report-segment-contiguous \
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-dwarf-ranges.sh \
@@ -589,6 +590,7 @@ test_elf_cntl_gelf_getshdr_LDADD = $(libelf)
dwflsyms_LDADD = $(libdw) $(libelf) $(argp_LDADD)
dwfllines_LDADD = $(libdw) $(libelf) $(argp_LDADD)
dwfl_report_elf_align_LDADD = $(libdw)
+dwfl_report_segment_contiguous_LDADD = $(libdw) $(libebl) $(libelf)
varlocs_LDADD = $(libdw) $(libelf) $(argp_LDADD)
backtrace_LDADD = $(libdw) $(libelf) $(argp_LDADD)
# backtrace-child-biarch also uses those *_CFLAGS and *_LDLAGS variables:
diff --git a/tests/dwfl-report-segment-contiguous.c b/tests/dwfl-report-segment-contiguous.c
new file mode 100644
index 00000000..61e6bfee
--- /dev/null
+++ b/tests/dwfl-report-segment-contiguous.c
@@ -0,0 +1,82 @@
+/* Test bug in dwfl_report_segment() coalescing.
+ Copyright (C) 2019 Facebook
+ 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 <assert.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdio_ext.h>
+#include <locale.h>
+#include ELFUTILS_HEADER(dwfl)
+
+
+static const Dwfl_Callbacks offline_callbacks =
+ {
+ .find_debuginfo = INTUSE(dwfl_standard_find_debuginfo),
+ .section_address = INTUSE(dwfl_offline_section_address),
+ };
+
+
+int
+main (void)
+{
+ /* We use no threads here which can interfere with handling a stream. */
+ (void) __fsetlocking (stdout, FSETLOCKING_BYCALLER);
+
+ /* Set locale. */
+ (void) setlocale (LC_ALL, "");
+
+ Dwfl *dwfl = dwfl_begin (&offline_callbacks);
+ assert (dwfl != NULL);
+
+ GElf_Phdr phdr1 =
+ {
+ .p_type = PT_LOAD,
+ .p_flags = PF_R,
+ .p_offset = 0xf00,
+ .p_vaddr = 0xf00,
+ .p_filesz = 0x100,
+ .p_memsz = 0x100,
+ .p_align = 4,
+ };
+
+ int ndx = dwfl_report_segment (dwfl, 1, &phdr1, 0, dwfl);
+ assert(ndx == 1);
+
+ ndx = dwfl_addrsegment (dwfl, 0xf00, NULL);
+ assert(ndx == 1);
+
+ GElf_Phdr phdr2 =
+ {
+ .p_type = PT_LOAD,
+ .p_flags = PF_R | PF_W,
+ .p_offset = 0x1000,
+ .p_vaddr = 0x1000,
+ .p_filesz = 0x100,
+ .p_memsz = 0x100,
+ .p_align = 4,
+ };
+ ndx = dwfl_report_segment (dwfl, 2, &phdr2, 0, dwfl);
+ assert(ndx == 2);
+
+ ndx = dwfl_addrsegment (dwfl, 0x1000, NULL);
+ assert(ndx == 1 || ndx == 2);
+
+ dwfl_end (dwfl);
+
+ return 0;
+}