This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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]

Re: master: Build failure in malloc with GCC 7


On Wed, Jul 12, 2017 at 8:58 AM, Florian Weimer <fweimer@redhat.com> wrote:
> On 07/12/2017 02:29 PM, Andreas Schwab wrote:
>> On Jul 12 2017, Florian Weimer <fweimer@redhat.com> wrote:
>>
>>> The attached patch adds an assert which reveals to the GCC optimizers
>>> that the global_max_fast can never MAX_FAST_SIZE, so this particular
>>> issue goes away.  However, there is a cost in terms of code size because
>>> it affects many places in malloc.
>>
>> Can __builtin_unreachable avoid the runtime overhead?
>
> Interesting idea.  I have never used __builtin_unreachable before, I think.

I think this code should be defensive against the possibility of
global_max_fast somehow getting corrupted.  What about

+static inline INTERNAL_SIZE_T
+get_max_fast (void)
+{
+  /* If this function ever returns a value larger than MAX_FAST_SIZE,
+     _int_malloc will make out-of-bounds array accesses.  It should be
+     impossible for global_max_fast to become larger than than
+     MAX_FAST_SIZE, but as an extra precaution, limit the value here
+     as well.  */
+  if (global_max_fast > MAX_FAST_SIZE)
+    return MAX_FAST_SIZE;
+  return global_max_fast;
+}


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