From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 55607 invoked by alias); 27 Apr 2017 19:41:18 -0000 Mailing-List: contact elfutils-devel-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: elfutils-devel-owner@sourceware.org Received: (qmail 55593 invoked by uid 89); 27 Apr 2017 19:41:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99.2 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.3 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=H*M:stream, breaker, guaranteed X-Spam-Status: No, score=-24.3 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: gnu.wildebeest.org Date: Fri, 28 Apr 2017 00:35:00 -0000 From: Mark Wielaard To: Ulf Hermann Cc: elfutils-devel@sourceware.org Subject: Re: [PATCH] Make elf section sorting more deterministic Message-ID: <20170427194124.GE2061@stream> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.8.0 (2017-02-23) X-SW-Source: 2017-q2/txt/msg00116.txt.bz2 On Thu, Apr 20, 2017 at 04:54:26PM +0200, Ulf Hermann wrote: > At least one test (dwfl-addr-sect) depends on the order of elf sections > with equal addresses. This is not guaranteed by the code. Compare also > by end address and name to tell entries apart. O, interesting find. If the start addresses match the order depends on the specific qsort algorithm. So you need a real tie breaker. I think it is simpler and more predictable if we just take the section number into account. It seem to have the added benefit that it provide the same ordering as before with the glibc qsort, so no testcases need to be adjusted. Does the following work for you? diff --git a/libdwfl/derelocate.c b/libdwfl/derelocate.c index 439a24e..0d10672 100644 --- a/libdwfl/derelocate.c +++ b/libdwfl/derelocate.c @@ -63,7 +63,10 @@ compare_secrefs (const void *a, const void *b) if ((*p1)->start > (*p2)->start) return 1; - return 0; + /* Same start address, then just compare which section came first. */ + size_t n1 = elf_ndxscn ((*p1)->scn); + size_t n2 = elf_ndxscn ((*p2)->scn); + return n1 - n2; } static int