public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] readelf: Don't print average number of tests when no tests are done
@ 2023-11-15 16:41 Mark Wielaard
  2023-11-20 17:30 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2023-11-15 16:41 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

If the symbol hash table only contains lenght zero chains, no lookup
tests need to be done and eu-readelf -I would print out bogus numbers
for the number of tests that were successful/unsuccessful.

e.g. for an "empty" program like
  int main() {}
eu-readelf -I would print:

Histogram for bucket list length in section [ 5] '.gnu.hash' (total of 1 bucket):
 Addr: 0x00000000004003c0  Offset: 0x0003c0  Link to section: [ 6] '.dynsym'
 Symbol Bias: 1
 Bitmask Size: 8 bytes  0% bits set  2nd hash shift: 0
 Length  Number  % of total  Coverage
      0       1      100.0%
 Average number of tests:   successful lookup: -nan
			  unsuccessful lookup: 0.000000

Only print out the Average number of tests when there were actual
tests to do.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/readelf.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/readelf.c b/src/readelf.c
index decfaf15..802f8ede 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -3644,11 +3644,12 @@ print_hash_info (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, size_t shstrndx,
 	  success += counts[cnt] * acc;
 	}
 
-      printf (_("\
+      if (nzero_counts > 0)
+	printf (_("\
  Average number of tests:   successful lookup: %f\n\
 			  unsuccessful lookup: %f\n"),
-	      (double) success / (double) nzero_counts,
-	      (double) nzero_counts / (double) nbucket);
+		(double) success / (double) nzero_counts,
+		(double) nzero_counts / (double) nbucket);
     }
 
   free (counts);
-- 
2.41.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] readelf: Don't print average number of tests when no tests are done
  2023-11-15 16:41 [PATCH] readelf: Don't print average number of tests when no tests are done Mark Wielaard
@ 2023-11-20 17:30 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2023-11-20 17:30 UTC (permalink / raw)
  To: elfutils-devel

Hi,

On Wed, 2023-11-15 at 17:41 +0100, Mark Wielaard wrote:
> If the symbol hash table only contains lenght zero chains, no lookup
> tests need to be done and eu-readelf -I would print out bogus numbers
> for the number of tests that were successful/unsuccessful.
> 
> e.g. for an "empty" program like
>   int main() {}
> eu-readelf -I would print:
> 
> Histogram for bucket list length in section [ 5] '.gnu.hash' (total of 1 bucket):
>  Addr: 0x00000000004003c0  Offset: 0x0003c0  Link to section: [ 6] '.dynsym'
>  Symbol Bias: 1
>  Bitmask Size: 8 bytes  0% bits set  2nd hash shift: 0
>  Length  Number  % of total  Coverage
>       0       1      100.0%
>  Average number of tests:   successful lookup: -nan
> 			  unsuccessful lookup: 0.000000
> 
> Only print out the Average number of tests when there were actual
> tests to do.

Pushed,

Mark

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-11-20 17:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-15 16:41 [PATCH] readelf: Don't print average number of tests when no tests are done Mark Wielaard
2023-11-20 17:30 ` Mark Wielaard

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).