This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
[PATCH] Make elf section sorting more deterministic
- From: Ulf Hermann <ulf dot hermann at qt dot io>
- To: <elfutils-devel at sourceware dot org>
- Date: Thu, 20 Apr 2017 16:54:26 +0200
- Subject: [PATCH] Make elf section sorting more deterministic
- Authentication-results: sourceware.org; auth=none
- Authentication-results: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=qt.io;
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qtcompany.onmicrosoft.com; s=selector1-qt-io; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=lFous9d61fykUXMGOfMeTFNQwbcMgnzsELE9cpZkbIw=; b=sAfYswqNC7ndrWWrH0/NhsmShXvObq4D1WqLsHUHnCB4Q8Hgik/0gXNi3Q6vYPrLcKx2C1DlQH8ZYKUQMh8o5CXMcaprjG2LJMGYtzicwZkLPmQUc7fDU73voJjcVRQCkTczDTBTo4trZWu/y2fEtKCYVFR2NTmVeDQUuzaiB0w=
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
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.
Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
---
libdwfl/ChangeLog | 5 +++++
libdwfl/derelocate.c | 17 +++++++++++------
tests/ChangeLog | 6 ++++++
tests/run-dwfl-addr-sect.sh | 2 +-
4 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index f605f46..a1ed675 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 e5c3e12..8d965af 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
diff --git a/tests/ChangeLog b/tests/ChangeLog
index c4e76d1..4da049b 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,11 @@
2017-04-20 Ulf Hermann <ulf.hermann@qt.io>
+ * run-dwfl-addr-sect.sh: Expect section with alphabetically smaller
+ name when requesting the start address of two otherwise equal
+ zero-sized sections.
+
+2017-04-20 Ulf Hermann <ulf.hermann@qt.io>
+
* run-readelf-dwz-multi.sh: Expect readelf to output "yes" for flags
that are set.
* run-readelf-zdebug-rel.sh: Likewise.
diff --git a/tests/run-dwfl-addr-sect.sh b/tests/run-dwfl-addr-sect.sh
index 80da008..e257bfc 100755
--- a/tests/run-dwfl-addr-sect.sh
+++ b/tests/run-dwfl-addr-sect.sh
@@ -20,7 +20,7 @@
testfiles testfile43 testfile50
testrun_compare ${abs_builddir}/dwfl-addr-sect -e testfile43 0x64 0x8 0x98 <<\EOF
-address 0x64 => module "" section 4 + 0
+address 0x64 => module "" section 3 + 0
address 0x8 => module "" section 1 + 0x8
address 0x98 => module "" section 7 + 0
EOF
--
2.1.4