This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 3/4] Make sure that sorting does not change section order
- From: Petr Tesarik <ptesarik at suse dot cz>
- To: gdb-patches at sourceware dot org
- Cc: Simon Marchi <simon dot marchi at polymtl dot ca>, John Baldwin <jhb at freebsd dot org>, Petr Tesarik <petr at tesarici dot cz>, Jeff Mahoney <jeffm at suse dot com>
- Date: Fri, 8 Jun 2018 14:39:59 +0200
- Subject: [PATCH 3/4] Make sure that sorting does not change section order
- References: <20180608124000.10668-1-ptesarik@suse.cz>
From: Petr Tesarik <petr@tesarici.cz>
Symbol files may contain multiple sections with the same name.
Section addresses specified add-symbol-file are assigned to the
corresponding BFD sections in addr_info_make_relative using sorted
indexes of both vectors. Since the sort algorithm is not inherently
stable, the comparison function uses sectindex to maintain the
original order. However, add_symbol_file_command uses zero for all
sections, so if the user specifies multiple sections with the same
name, they will be assigned randomly to symbol file sections with
the same name.
gdb/ChangeLog:
2018-06-08 Petr Tesarik <ptesarik@suse.com>
* symfile.c (add_symbol_file_command): Make sure that sections
with the same name are sorted in the same order.
---
gdb/ChangeLog | 2 ++
gdb/symfile.c | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e6e763b506..91a5d7b4b9 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -5,6 +5,8 @@
offset to each section of the symbol file.
(add_symbol_file_command): Do not require the second argument. If
omitted, load sections at the addresses specified in the file.
+ (add_symbol_file_command): Make sure that sections with the same
+ name are sorted in the same order.
2018-06-07 Pedro Alves <palves@redhat.com>
diff --git a/gdb/symfile.c b/gdb/symfile.c
index d319bb0564..890e2478bf 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2185,7 +2185,7 @@ add_symbol_file_command (const char *args, int from_tty)
/* Here we store the section offsets in the order they were
entered on the command line. */
- section_addrs.emplace_back (addr, sec, 0);
+ section_addrs.emplace_back (addr, sec, section_addrs.size ());
printf_unfiltered ("\t%s_addr = %s\n", sec,
paddress (gdbarch, addr));
--
2.13.6