[PATCH 2/2] nonstring: _FORTIFY_SOURCE=3 using __builtin_dynamic_object_size

Siddhesh Poyarekar siddhesh@sourceware.org
Tue Dec 29 14:04:09 GMT 2020


On 12/28/20 11:06 PM, Adhemerval Zanella via Libc-alpha wrote:
> 
> 
> On 19/12/2020 03:33, Siddhesh Poyarekar via Libc-alpha wrote:
>> These fortified functions use, roughly, the following idiom to
>> implement fortifications:
>>
>>    if (__builtin_dynamic_object_size (obj) != -1)
>>      {
>>        __fortified_chk ();
>>        return;
>>      }
>>    __unfortified ();
> 
> Reading the D93015, it should be:
> 
>    if (__builtin_dynamic_object_size (obj, 0 or 1) != -1ULL)
> 
> right?

Technically, 0, 1, 2 or 3 but we only use 0 and 1 for _FORTIFY_SOURCE at 
the moment.

> 
> The __builtin_dynamic_object_size seems to be a 64-bit integer.
> How does it play in 32-bit targets? Would clang optimize the check
> when dynamic one need to be emitted?
> 

It should work, but I'll confirm just the same.

>> LLVM is currently unable to fold the conditional; a patch has been
>> proposed[1] to fix this.
>>
>> Due to this limitation in llvm, these fortifications have a higher
>> performance cost than those in the first patch.
>>
>> [1] https://reviews.llvm.org/D93015
> 
> I think you can state that this has been implemented on LLVM.

Given that it's no longer an issue, I suppose it's OK to simply omit this?

Siddhesh


More information about the Libc-alpha mailing list