memcpy overlap: quickly detect, diagnose, work around

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


On 11/28/2010 03:36 PM, Nicholas Miell wrote:
> On 11/28/2010 03:13 PM, John Reiser wrote:
>> 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.
> 
> If you're going to control it via an environment variable, why not just
> make a LD_PRELOADed shared library which intercepts memcpy() in the
> usual manner?
> 
> Doing it that way has the added benefit that anybody could use it
> immediately, without needing to replace their glibc with a patched
> version that will never get merged upstream.

Using LD_PRELOAD is a good option in many cases.  Having a built-in tool
can be more convenient, easier to use, and more likely to be used.
Using LD_PRELOAD often involves a trip through two PLTs (Program
Linkage Tables), each with an indirect JUMP.  Often such a JUMP
takes many cycles.  A builtin solution that enables using only one
indirect JUMP can be faster, enough to make a difference.

-- 


More information about the devel mailing list