This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: Properly use __builtin_clzll/__builtin_clzl.
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: "Simonov, Vladimir" <Vladimir dot Simonov at acronis dot com>
- Cc: "binutils at sourceware dot org" <binutils at sourceware dot org>
- Date: Fri, 26 Oct 2012 14:10:39 -0700
- Subject: PATCH: Properly use __builtin_clzll/__builtin_clzl.
On Fri, Oct 26, 2012 at 11:13 AM, Simonov, Vladimir
<Vladimir.Simonov@acronis.com> wrote:
> Hi all,
>
> I'm using host == build == mingw64, target x86_64-unknown-linux-gnu.
> e:/cygwin/opt/crosstool64/x86_64-unknown-linux-gnu/gcc-4.7.2-glibc-2.16.0/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../x86_64-unknown-linux-gnu/bin/as.exe --gdwarf2 --64 -v -o msgstub.obj msgstub.s
> GNU assembler version 2.23 (x86_64-unknown-linux-gnu) using BFD version (GNU Binutils) 2.23
>
> e:\cygwin\opt\crosstool64\x86_64-unknown-linux-gnu\gcc-4.7.2-glibc-2.16.0\x86_64-unknown-linux-gnu\bin\as.exe: out of memory allocating 4294967280 bytes
>
> IMO the problem is in gas\sb.c
> static void
> sb_check (sb *ptr, size_t len)
> ...
> #if GCC_VERSION >= 3004
> max = (size_t) 1 << (CHAR_BIT * sizeof (want) - __builtin_clzl (want));
> #else
> ...
> "want" size_t type which is 64-bit. Replace __builtin_clzl with __builtin_clzll fixes the problem.
>
> CVS head has the same code. I'm not sure either it my cross tools mis-configuration or real bug in as.
> If the second, it is strange - the code was committed 4 months ago...
>
> Thank you
> Vladimir Simonov
Please try this. It generates the same assembly code on x32, ia32 and
x86-64.
--
H.J.
--
2012-10-26 H.J. Lu <hongjiu.lu@intel.com>
* sb.c (sb_check): Properly use __builtin_clzll/__builtin_clzl.
diff --git a/gas/sb.c b/gas/sb.c
index f68402f..5458f52 100644
--- a/gas/sb.c
+++ b/gas/sb.c
@@ -137,12 +137,19 @@ sb_check (sb *ptr, size_t len)
if ((ssize_t) want < 0)
as_fatal ("string buffer overflow");
#if GCC_VERSION >= 3004
- max = (size_t) 1 << (CHAR_BIT * sizeof (want) - __builtin_clzl (want));
-#else
- max = 128;
- while (want > max)
- max <<= 1;
+ if (sizeof (want) == sizeof (long long))
+ max = (size_t) 1 << (CHAR_BIT * sizeof (want)
+ - __builtin_clzll (want));
+ else if (sizeof (want) == sizeof (long))
+ max = (size_t) 1 << (CHAR_BIT * sizeof (want)
+ - __builtin_clzl (want));
+ else
#endif
+ {
+ max = 128;
+ while (want > max)
+ max <<= 1;
+ }
max -= MALLOC_OVERHEAD + 1;
ptr->max = max;
ptr->ptr = xrealloc (ptr->ptr, max + 1);