summaryrefslogtreecommitdiffstats
path: root/libdwfl
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2017-04-07 15:57:45 +0200
committerUlf Hermann <ulf.hermann@qt.io>2017-04-26 14:32:18 +0000
commitb9e2d78403173c35c1d8e31ef2e249f311b5e9dd (patch)
tree34eff6920338d2226bff066f5b0f77b6666b7dba /libdwfl
parentbb8bd71deb85ce7818fa747c3297d4b0ed7cf367 (diff)
Make elf section sorting more deterministic
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. Change-Id: I0e85e7b86a0489b6bc85f45f9a359c68a04f635a Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'libdwfl')
-rw-r--r--libdwfl/ChangeLog5
-rw-r--r--libdwfl/derelocate.c17
2 files changed, 16 insertions, 6 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index f605f466..a1ed675d 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,5 +1,10 @@
2017-04-20 Ulf Hermann <ulf.hermann@qt.io>
+ * derelocate.c (compare_secrefs): Compare by end address and then by
+ name if start addresses are equal.
+
+2017-04-20 Ulf Hermann <ulf.hermann@qt.io>
+
* elf-from-memory.c: Explicitly cast phnum to size_t.
2017-04-20 Ulf Hermann <ulf.hermann@qt.io>
diff --git a/libdwfl/derelocate.c b/libdwfl/derelocate.c
index e5c3e12e..8d965af9 100644
--- a/libdwfl/derelocate.c
+++ b/libdwfl/derelocate.c
@@ -57,17 +57,22 @@ struct secref
static int
compare_secrefs (const void *a, const void *b)
{
- struct secref *const *p1 = a;
- struct secref *const *p2 = b;
+ struct secref const *p1 = *(struct secref *const *)a;
+ struct secref const *p2 = *(struct secref *const *)b;
/* No signed difference calculation is correct here, since the
terms are unsigned and could be more than INT64_MAX apart. */
- if ((*p1)->start < (*p2)->start)
+ if (p1->start < p2->start)
return -1;
- if ((*p1)->start > (*p2)->start)
+ if (p1->start > p2->start)
return 1;
-
- return 0;
+ if (p1->end < p2->end)
+ return -1;
+ if (p1->end > p2->end)
+ return 1;
+ if (p1->name == NULL)
+ return p2->name == NULL ? 0 : -1;
+ return p2->name == NULL ? 1 : strcmp(p1->name, p2->name);
}
static int