This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

bfd_log2 fix


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]