This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [google][4.7]Using CPU mocks to test code coverage of multiversioned functions
- From: Alan Modra <amodra at gmail dot com>
- To: Sriraman Tallam <tmsriram at google dot com>
- Cc: Richard Biener <richard dot guenther at gmail dot com>, "H.J. Lu" <hjl dot tools at gmail dot com>, Paul Pluzhnikov <ppluzhnikov at google dot com>, Xinliang David Li <davidxl at google dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, GLIBC Devel <libc-alpha at sourceware dot org>
- Date: Tue, 26 Mar 2013 10:16:56 +1030
- Subject: Re: [google][4.7]Using CPU mocks to test code coverage of multiversioned functions
- References: <CAAs8HmyUjEf5ecGBerysqSFgOq3SC0esvN3AnEJm5O_kxzrGyQ at mail dot gmail dot com> <CAFiYyc0FSA-hZ0YQr0b9DXUO0S-Nf4OfLzgA5uYi3DDTai75Rg at mail dot gmail dot com> <CAAkRFZLLx9b=ECQ0P0rbX0YqCasY7YhjV+cvdKZC_0nOz9UM5g at mail dot gmail dot com> <CALoOobPj=1E8gR=_kXwYHJ1FRSBaozuzFj_J3zZ6xJAuzWacKQ at mail dot gmail dot com> <CAMe9rOrn6iuSgCzKctaZGX02rACXE3YGc+=iN287c3e+eHzRNg at mail dot gmail dot com> <22407982-cd6c-4d91-a2a4-472365c1ecd2 at email dot android dot com> <20130319054405 dot GI18331 at bubble dot grove dot modra dot org> <CAAs8Hmz=7cv8nTbDk+Ss5y3rGxtyW5axZsajKBc-KZNDeB44tA at mail dot gmail dot com>
On Mon, Mar 25, 2013 at 02:24:21PM -0700, Sriraman Tallam wrote:
> Does this also mean that Paul's idea of doing:
>
> LD_CPU_FEATURES=sse,sse2 ./a.out # run as if only sse and sse2 are available
>
> is fraught with risk when used with IFUNC, particularly on x86_64?
>
> Shouldn't the IFUNC resolver go through the GOT even in this case.
> This could work well for the MV testing problem I explained earlier,
> but if this is not feasible with IFUNC in play I would like my
> original proposal reconsidered.
I haven't been following the thread so can't comment, sorry. I jumped
in on seeing Richard's suggestion re LD_PRELOAD, which is a bad idea
given glibc's current support for STT_GNU_IFUNC. IFUNC as it stands
is not a general purpose feature and interacts badly with other
features of ELF shared libraries. Trivial testcases can easily be
created that
1) won't work on any architecture.
eg. shared library takes address of ifunc, ifunc resolver in main
app, resolver uses variable in shared library.
2) only work on x86_64 and powerpc64.
eg. shared library takes address of ifunc, ifunc resolver in main
app which is PIC, resolver uses variable in main app.
3) won't work with LD_BIND_NOW=1
either of the above examples but shared library doesn't take
address, just calls ifunc.
The reason for these problems is that ld.so makes a single pass over
dynamic relocations. In the simple case of LD_BIND_NOW=1 and an
application that uses a single shared library, relocations for the
library will be applied first, then relocations for the main app. So
if the shared library has relocations against symbols that turn out to
be ifunc, and the ifunc resolver lives in the main app, then the
resolver will run *before* the main app has been relocated. The
resolver had better not have code that requires relocation!
Of course, the obvious fix of making ld.so do two passes over
relocations, applying ifunc relocations on the second pass, is
somewhat counterproductive. Mostly ifunc is used to gain a speedup
when running on particular hardware. Two passes would have to slow
down application startup.. Nonetheless, I believe that is the correct
solution if we want to make ifunc generally useful.
What we have at the moment requires quite a lot of care when using
ifunc. Accidentally writing code that only works on x86_64 or
powerpc64 is very easy, and might lead people to think you own shares
in Intel or IBM.
--
Alan Modra
Australia Development Lab, IBM