|
From: John R. <jr...@bi...> - 2009-08-25 12:57:24
|
On 08/25/2009 12:51 AM, Tom Hughes wrote: > Are you saying that the dynamic linker takes care of all this magic > itself without the client of the library having to know about it? ie > that the first time you call the function the dynamic linker looks up > the selection function and calls it and puts the returned address in the > PLT instead of just looking up the symbol and putting that address in > the PLT? Yes, the dynamic linker ld*.so does that all by itself. > What exactly are you suggesting that memcheck should do differently? > > Are you saying that we need to consider STT_IFUNC when scanning the > symbol table and override the STT_IFUNC for strlen with our own version > that returns a pointer to a naïve strlen that won't confuse memcheck? Yes. glibc no longer defines a symbol 'strlen' with type STT_FUNC. Instead the symbol is 'strlen' with type STT_IFUNC. So the name has the wrong "flavour" as far as get_elf_symbol_info (coregrind/m_debuginfo/readelf.c; etc.) is concerned. So memcheck's redirection is blind to this new strlen, so &__GI_strlen gets installed into the PLT, and never redirected as far as memcheck is concerned. There is a symbol 'strlen@@GLIBC_2.0' which the runtime dynamic linker ld*.so will find *if* the request is for 'strlen' with the _explicit_ symbol version GLIBC_2.0 (or for "strlen with the latest version" because the double at sign '@@' means "default version".) However, nearly all executables ask for only 'strlen' with no explicit version. This means _implicitly_ "the most recent version", and when requested via PLT lookup then ld*.so chooses to bend the semantics slightly by satisfying this request with the symbol 'strlen' with type STT_IFUNC, calling it, and putting the value returned into the PLT. Thus the new type STT_IFUNC, if present, takes precedence over the '@@' default version. So with STT_IFUNC then the runtime dynamic linker has implemented another redirection mechanism of its own. [The PLT itself is a redirection mechanism.] memcheck must learn (and benefit from) the new symbol type STT_IFUNC. -- |