From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11554 invoked by alias); 26 Jun 2018 02:37:08 -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 11539 invoked by uid 89); 26 Jun 2018 02:37:07 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 26 Jun 2018 02:37:06 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id w5Q2axgp004956 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 25 Jun 2018 22:37:04 -0400 Received: by simark.ca (Postfix, from userid 112) id E6F8B1EF2A; Mon, 25 Jun 2018 22:36:59 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id 86AA01E003; Mon, 25 Jun 2018 22:36:58 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 26 Jun 2018 02:37:00 -0000 From: Simon Marchi To: Petr Tesarik Cc: gdb-patches@sourceware.org, Jeff Mahoney Subject: Re: [PATCH v2 3/4] Make sure that sorting does not change section order In-Reply-To: <20180611120835.27343-4-ptesarik@suse.cz> References: <20180611120835.27343-1-ptesarik@suse.cz> <20180611120835.27343-4-ptesarik@suse.cz> Message-ID: <2a43d96e7d7c435bb9344dc1825e5be8@polymtl.ca> X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.6 X-IsSubscribed: yes X-SW-Source: 2018-06/txt/msg00594.txt.bz2 On 2018-06-11 08:08, Petr Tesarik wrote: > 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-11 Petr Tesarik > > * symfile.c (add_symbol_file_command): Make sure that sections > with the same name are sorted in the same order. > --- > gdb/ChangeLog | 5 +++++ > gdb/symfile.c | 2 +- > 2 files changed, 6 insertions(+), 1 deletion(-) > > diff --git a/gdb/ChangeLog b/gdb/ChangeLog > index 1c5a1f6bfb..0f75992d4c 100644 > --- a/gdb/ChangeLog > +++ b/gdb/ChangeLog > @@ -1,5 +1,10 @@ > 2018-06-11 Petr Tesarik > > + * symfile.c (add_symbol_file_command): Make sure that sections > + with the same name are sorted in the same order. > + > +2018-06-11 Petr Tesarik > + > * 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 3e3ab20412..8b8b194334 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)); It took me a while to acknowledge that this was correct, because other_sections::sectindex usually refers to the section index in the BFD. After digging I understood that this field was actually unused until filled by addr_info_make_relative, and that you kind of re-purposed it. It sounds like there should be some comment at other_sections::sectindex and probably in add_symbol_file_command to explain how it's used. Another option would be to use std::stable_sort instead of std::sort. But it's more resource-hungry and not needed for all paths that lead to addrs_section_sort, so it would be a bit wasteful. Simon