From: Petr Tesarik <ptesarik@suse.cz>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>,
Eli Zaretskii <eliz@gnu.org>, Petr Tesarik <ptesarik@suse.cz>
Subject: [PATCH v3 3/4] Make sure that sorting does not change section order
Date: Wed, 27 Jun 2018 12:14:00 -0000 [thread overview]
Message-ID: <20180627121429.16414-4-ptesarik@suse.cz> (raw)
In-Reply-To: <20180627121429.16414-1-ptesarik@suse.cz>
Symbol files may contain multiple sections with the same name.
Section addresses specified by 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-27 Petr Tesarik <ptesarik@suse.com>
* symfile.c (add_symbol_file_command): Make sure that sections
---
gdb/ChangeLog | 5 +++++
gdb/symfile.c | 11 +++++++++--
gdb/symfile.h | 4 +++-
3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e5303a9e9e..96ae6cc1a8 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2018-06-27 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.
+
2018-06-27 Petr Tesarik <ptesarik@suse.com>
* symfile.c (add_symbol_file_command, _initialize_symfile): Do not
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 2a41fce64f..b592be74cf 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -908,6 +908,9 @@ init_entry_point_info (struct objfile *objfile)
into an offset from the section VMA's as it appears in the object
file, and then call the file's sym_offsets function to convert this
into a format-specific offset table --- a `struct section_offsets'.
+ The sectindex field is used to control the ordering of sections
+ with the same name. Upon return, it is updated to contain the
+ correspondig BFD section index, or -1 if the section was not found.
ADD_FLAGS encodes verbosity level, whether this is main symbol or
an extra symbol file such as dynamically loaded code, and wether
@@ -2184,8 +2187,12 @@ add_symbol_file_command (const char *args, int from_tty)
addr = parse_and_eval_address (val);
/* Here we store the section offsets in the order they were
- entered on the command line. */
- section_addrs.emplace_back (addr, sec, 0);
+ entered on the command line. Every array element is
+ assigned an ascending section index to preserve the above
+ order over an unstable sorting algorithm. This dummy
+ index is not used for any other purpose.
+ */
+ section_addrs.emplace_back (addr, sec, section_addrs.size ());
printf_unfiltered ("\t%s_addr = %s\n", sec,
paddress (gdbarch, addr));
diff --git a/gdb/symfile.h b/gdb/symfile.h
index d9185092ee..1b47669048 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -61,7 +61,9 @@ struct other_sections
CORE_ADDR addr;
std::string name;
- /* SECTINDEX must be valid for associated BFD or set to -1. */
+ /* SECTINDEX must be valid for associated BFD or set to -1.
+ See syms_from_objfile_1 for an exception to this rule.
+ */
int sectindex;
};
--
2.16.4
next prev parent reply other threads:[~2018-06-27 12:14 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-11 12:08 [PATCH v2 0/4] Allow loading symbol files with an offset Petr Tesarik
2018-06-11 12:08 ` [PATCH v2 2/4] Make add-symbol-file's address argument optional Petr Tesarik
2018-06-11 15:25 ` Eli Zaretskii
2018-06-11 16:50 ` Petr Tesarik
2018-06-11 17:25 ` Eli Zaretskii
2018-06-26 2:14 ` Simon Marchi
2018-06-11 12:08 ` [PATCH v2 1/4] Add an optional offset option to the "symbol-file" command Petr Tesarik
2018-06-11 15:23 ` Eli Zaretskii
2018-06-26 2:02 ` Simon Marchi
2018-06-11 12:08 ` [PATCH v2 3/4] Make sure that sorting does not change section order Petr Tesarik
2018-06-26 2:37 ` Simon Marchi
2018-06-26 5:10 ` Petr Tesarik
2018-06-26 13:26 ` Simon Marchi
2018-06-11 12:23 ` [PATCH v2 4/4] Add an optional offset option to the "add-symbol-file" command Petr Tesarik
2018-06-26 2:52 ` Simon Marchi
2018-06-22 7:52 ` [PATCH v2 0/4] Allow loading symbol files with an offset Petr Tesarik
2018-06-26 2:58 ` Simon Marchi
2018-06-26 5:01 ` Petr Tesarik
2018-06-26 15:15 ` Simon Marchi
2018-06-26 15:23 ` Petr Tesarik
2018-06-27 12:14 ` [PATCH v3 " Petr Tesarik
2018-06-27 12:14 ` Petr Tesarik [this message]
2018-06-27 12:14 ` [PATCH v3 2/4] Make add-symbol-file's address argument optional Petr Tesarik
2018-06-27 12:14 ` [PATCH v3 1/4] Add an optional offset option to the "symbol-file" command Petr Tesarik
2018-06-27 12:33 ` [PATCH v3 4/4] Add an optional offset option to the "add-symbol-file" command Petr Tesarik
2018-06-27 12:57 ` [PATCH v3 0/4] Allow loading symbol files with an offset Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180627121429.16414-4-ptesarik@suse.cz \
--to=ptesarik@suse.cz \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox