]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Make elf section sorting more deterministic
authorUlf Hermann <ulf.hermann@qt.io>
Thu, 20 Apr 2017 14:54:26 +0000 (16:54 +0200)
committerMark Wielaard <mark@klomp.org>
Tue, 2 May 2017 22:28:08 +0000 (00:28 +0200)
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 section index to tell entries apart.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
Signed-off-by: Mark Wielaard <mark@klomp.org>
libdwfl/ChangeLog
libdwfl/derelocate.c

index 859b2ff56a83e7784f928d20c7055fd15b9736cb..9bce6b1eee20ba34bf668ab2bcd2fff06fa313a2 100644 (file)
@@ -1,3 +1,9 @@
+2017-04-20  Ulf Hermann  <ulf.hermann@qt.io>
+           Mark Wielaard  <mark@klomp.org>
+
+       * derelocate.c (compare_secrefs): Compare by end address and then by
+       section number if addresses are equal.
+
 2017-04-20  Ulf Hermann  <ulf.hermann@qt.io>
            Mark Wielaard  <mark@klomp.org>
 
index e5c3e12e1f65fda00b9186b2496174ca3b0c170a..2f80b20fc6dd38d286c391f13f91bf503463dc46 100644 (file)
@@ -67,7 +67,13 @@ compare_secrefs (const void *a, const void *b)
   if ((*p1)->start > (*p2)->start)
     return 1;
 
-  return 0;
+  if ((*p1)->end < (*p2)->end)
+    return -1;
+  if ((*p1)->end > (*p2)->end)
+    return 1;
+
+  /* Same start/end, then just compare which section came first.  */
+  return elf_ndxscn ((*p1)->scn) - elf_ndxscn ((*p2)->scn);
 }
 
 static int