[PATCH] free: preserve errno [BZ#17924]

Siddhesh Poyarekar siddhesh@gotplt.org
Mon Dec 21 10:03:23 GMT 2020


On 12/21/20 3:03 PM, Florian Weimer via Libc-alpha wrote:
> * Paul Eggert:
> 
>> +/* The indirection through a volatile function pointer is necessary to prevent
>> +   a GCC optimization.  Without it, when optimizing, GCC would "know" that errno
>> +   is unchanged by calling free(ptr), when ptr was the result of a malloc(...)
>> +   call in the same function.  */
>> +static int
>> +get_errno (void)
> 
> Long line (80 characters).
> 
> I think you need to use this:
> 
> int __attribute__ ((weak))
> get_errno (void)
> {
>    return errno;
> }
> 
> With that volatile construct, the read of errno is not actually behind a
> compiler barrier.

Wouldn't it be a bug in the compiler if it delays load of the TLS var 
beyond a function call boundary?

Siddhesh


More information about the Libc-alpha mailing list