diff options
author | Petr Tesarik <ptesarik@suse.cz> | 2018-06-28 08:32:27 +0200 |
---|---|---|
committer | Petr Tesarik <ptesarik@suse.cz> | 2018-06-28 08:35:34 +0200 |
commit | d81a3eaff36b41ed67758a119a6864b50f60a60d (patch) | |
tree | e76d370a089eea74975ac1d92fdc91cc3dcdee50 | |
parent | ed6dfe517ee323ed631aa8b9816289ea35219409 (diff) | |
download | gdb-d81a3eaff36b41ed67758a119a6864b50f60a60d.zip gdb-d81a3eaff36b41ed67758a119a6864b50f60a60d.tar.gz gdb-d81a3eaff36b41ed67758a119a6864b50f60a60d.tar.bz2 |
Make sure that sorting does not change section order
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-28 Petr Tesarik <ptesarik@suse.cz>
* symfile.c (add_symbol_file_command): Make sure that sections
-rw-r--r-- | gdb/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/symfile.c | 11 | ||||
-rw-r--r-- | gdb/symfile.h | 4 |
3 files changed, 17 insertions, 3 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f17c1a1..bd19de9 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2018-06-28 Petr Tesarik <ptesarik@suse.cz> + * symfile.c (add_symbol_file_command): Make sure that sections + with the same name are sorted in the same order. + +2018-06-28 Petr Tesarik <ptesarik@suse.cz> + * symfile.c (add_symbol_file_command, _initialize_symfile): Do not require the second argument. If omitted, load sections at the addresses specified in the file. diff --git a/gdb/symfile.c b/gdb/symfile.c index 2a41fce..b592be7 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 d918509..1b47669 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; }; |