memcpy overlap: quickly detect, diagnose, work around

John Reiser jreiser at bitwagon.com
Mon Nov 29 23:35:52 UTC 2010


On 11/29/2010 01:46 PM, Kevin Kofler wrote:
> John Reiser wrote:
>> This patch (with .rpms for x86_64 and i686) enables glibc optionally
>> to detect, diagnose, and work around overlap in memcpy/mempcpy:
>>     http://bitwagon.com/glibc-memlap/glibc-memlap.html
>> The option to check is controlled by an environment variable
>> MEMCPY_CHECK_ which influences choices made by __init_cpu_features
>> and the STT_GNU_IFUNC mechanism for choosing alternate implementations
>> at runtime.
> 
> This does not work where the memcpy is inlined (which glibc can do in 
> several cases).

Right.  However, specifying the flag -fno-builtin-memcpy at compilation
disables gcc inlining of memcpy, thus exposing calls to memcpy that
can be checked.  Also, a survey of recent versions of gcc indicates
that the inlining always copies in ascending address order (of both
source and destination.)  While the details of inlining are subject
to change, copying in ascending address order is the order that is
assumed by all violators of the no-overlap requirement.

-- 


More information about the devel mailing list