Make sure that sorting does not change section order
authorPetr Tesarik <ptesarik@suse.cz>
Thu, 28 Jun 2018 06:32:27 +0000 (08:32 +0200)
committerPetr Tesarik <ptesarik@suse.cz>
Thu, 28 Jun 2018 06:35:34 +0000 (08:35 +0200)
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

gdb/ChangeLog
gdb/symfile.c
gdb/symfile.h

index f17c1a105aee3da7357161bc34c42e5db1958cdc..bd19de96e89d06356aea4ba8ca5138c57c34c627 100644 (file)
@@ -1,3 +1,8 @@
+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
index 2a41fce64fdfb380cdba9f389f88a14fb7f8ef1e..b592be74cfc1cdbbbd6a124c61dc1c21710796d2 100644 (file)
@@ -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));
 
index d9185092eec6f68649133a2efef9c32fb5afc719..1b47669048822a2b7fe1efcfbd2c62537684d7c7 100644 (file)
@@ -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;
 };
 
This page took 0.034601 seconds and 4 git commands to generate.