From patchwork Fri Jun 8 12:39:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Tesarik X-Patchwork-Id: 27712 Received: (qmail 30481 invoked by alias); 8 Jun 2018 12:40:35 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 30341 invoked by uid 89); 8 Jun 2018 12:40:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No 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=randomly, H*Ad:D*ca 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; Fri, 08 Jun 2018 12:40:33 +0000 Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 15122AEB9; Fri, 8 Jun 2018 12:40:30 +0000 (UTC) From: Petr Tesarik To: gdb-patches@sourceware.org Cc: Simon Marchi , John Baldwin , Petr Tesarik , Jeff Mahoney Subject: [PATCH 3/4] Make sure that sorting does not change section order Date: Fri, 8 Jun 2018 14:39:59 +0200 Message-Id: <20180608124000.10668-4-ptesarik@suse.cz> In-Reply-To: <20180608124000.10668-1-ptesarik@suse.cz> References: <20180608124000.10668-1-ptesarik@suse.cz> X-IsSubscribed: yes From: Petr Tesarik 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 * 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 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));