From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 122385 invoked by alias); 27 Jun 2018 12:14:51 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 122349 invoked by uid 89); 27 Jun 2018 12:14:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.2 spammy=Upon, symfile.c, D*suse.com, sk:ptesari X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 27 Jun 2018 12:14:48 +0000 Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 47B68AF5D; Wed, 27 Jun 2018 12:14:46 +0000 (UTC) From: Petr Tesarik To: gdb-patches@sourceware.org Cc: Simon Marchi , Eli Zaretskii , Petr Tesarik Subject: [PATCH v3 3/4] Make sure that sorting does not change section order Date: Wed, 27 Jun 2018 12:14:00 -0000 Message-Id: <20180627121429.16414-4-ptesarik@suse.cz> In-Reply-To: <20180627121429.16414-1-ptesarik@suse.cz> References: <20180611120835.27343-1-ptesarik@suse.cz> <20180627121429.16414-1-ptesarik@suse.cz> X-IsSubscribed: yes X-SW-Source: 2018-06/txt/msg00638.txt.bz2 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 * 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 + + * 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 * 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