public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: Ulf Hermann <ulf.hermann@qt.io>
Cc: elfutils-devel@sourceware.org
Subject: Re: [PATCH] Make elf section sorting more deterministic
Date: Fri, 28 Apr 2017 00:35:00 -0000	[thread overview]
Message-ID: <20170427194124.GE2061@stream> (raw)
In-Reply-To: <a45db26a-b31f-c395-b633-deefd2f51c8c@qt.io>

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

  reply	other threads:[~2017-04-27 19:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-20 14:54 Ulf Hermann
2017-04-28  0:35 ` Mark Wielaard [this message]
2017-04-28 11:21   ` Ulf Hermann
2017-05-03 11:04     ` Mark Wielaard
2017-05-03 11:08       ` Ulf Hermann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170427194124.GE2061@stream \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.org \
    --cc=ulf.hermann@qt.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).