public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* bfd_log2 fix
@ 2011-04-20  7:18 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2011-04-20  7:18 UTC (permalink / raw)
  To: binutils

bfd_log2 is supposed to round up, but this was changed (accidentally I
believe) in 1999 when another bug was fixed.  Since bfd_log2 is mostly
used to calculate power-of-2 alignment values, round up is appropriate.
The only place that looked like it should stay as round down was one
of the gnu hash calculations.

	* libbfd.c (bfd_log2): Do return rounded up value.
	* elflink.c (bfd_elf_size_dynsym_hash_dynstr): Replace bfd_log2
	call with expanded old round down version of the function.

Index: bfd/libbfd.c
===================================================================
RCS file: /cvs/src/src/bfd/libbfd.c,v
retrieving revision 1.55
diff -u -p -r1.55 libbfd.c
--- bfd/libbfd.c	11 Apr 2011 04:08:12 -0000	1.55
+++ bfd/libbfd.c	20 Apr 2011 00:50:28 -0000
@@ -979,8 +979,12 @@ bfd_log2 (bfd_vma x)
 {
   unsigned int result = 0;
 
-  while ((x = (x >> 1)) != 0)
+  if (x <= 1)
+    return result;
+  --x;
+  do
     ++result;
+  while ((x >>= 1) != 0);
   return result;
 }
 
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.399
diff -u -p -r1.399 elflink.c
--- bfd/elflink.c	20 Apr 2011 00:22:08 -0000	1.399
+++ bfd/elflink.c	20 Apr 2011 00:50:22 -0000
@@ -6540,10 +6537,13 @@ bfd_elf_size_dynsym_hash_dynstr (bfd *ou
 	    }
 	  else
 	    {
-	      unsigned long int maskwords, maskbitslog2;
+	      unsigned long int maskwords, maskbitslog2, x;
 	      BFD_ASSERT (cinfo.min_dynindx != -1);
 
-	      maskbitslog2 = bfd_log2 (cinfo.nsyms) + 1;
+	      x = cinfo.nsyms;
+	      maskbitslog2 = 1;
+	      while ((x >>= 1) != 0)
+		++maskbitslog2;
 	      if (maskbitslog2 < 3)
 		maskbitslog2 = 5;
 	      else if ((1 << (maskbitslog2 - 2)) & cinfo.nsyms)

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-04-20  7:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-20  7:18 bfd_log2 fix Alan Modra

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