Re: [PATCH] Pass HWCAP to ifunc resolver

Andreas Arnez
2016-09-01T09:19:37Z

On Thu, Sep 01 2016, Andrew Pinski wrote:

> On Wed, Aug 31, 2016 at 4:49 AM, Andreas Arnez <arnez@linux.vnet.ibm.com> wrote:
>> On various GNU Elf architectures, including AArch64, ARM, s390/s390x,
>> ppc32/64, and sparc32/64, the dynamic loader passes HWCAP as a parameter
>> to each ifunc resolver. Currently there is an open glibc Bugzilla that
>> requests this to be generalized to all architectures:
>>
>> https://sourceware.org/bugzilla/show_bug.cgi?id=19766
>>
>> And various ifunc resolvers already rely on receiving HWCAP. Currently
>> GDB always calls an ifunc resolver without any arguments; thus the
>> resolver may receive garbage, and based on that, the resolver may decide
>> to return a function that is not suited for the given platform.
>>
>> This patch always passes HWCAP to ifunc resolvers, even on systems where
>> the dynamic loader currently behaves otherwise. The rationale is
>> that (1) the dynamic loader may get adjusted on those systems as well in
>> the future; (2) passing an unused argument should not cause a problem
>> with existing resolvers; and (3) the logic is much simpler without such
>> a distinction.
>
> Doesn't some targets pass HWCAP2 too?

If I understand the glibc code correctly, no. The loader maintains the
variables dl_hwcap and dl_hwcap2 and fills them from AT_HWCAP and
AT_HWCAP2, respectively, but the ifunc resolvers only receive dl_hwcap:

./sysdeps/aarch64/dl-irel.h:33: return ((ElfW(Addr) (*) (unsigned long int)) (addr)) (GLRO(dl_hwcap));
./sysdeps/arm/dl-irel.h:33: return ((Elf32_Addr (*) (unsigned long int)) (addr)) (GLRO(dl_hwcap));
./sysdeps/generic/dl-irel.h:26: return ((DL_FIXUP_VALUE_TYPE (*) (void)) (addr)) ();
./sysdeps/hppa/dl-irel.h:36: return ((struct fdesc) {0, 0});
./sysdeps/i386/dl-irel.h:32: return ((Elf32_Addr (*) (void)) (addr)) ();
./sysdeps/powerpc/powerpc32/dl-irel.h:33: return ((Elf32_Addr (*) (unsigned long int)) (addr)) (GLRO(dl_hwcap));
./sysdeps/powerpc/powerpc64/dl-irel.h:34: return ((Elf64_Addr (*) (unsigned long int)) (addr)) (GLRO(dl_hwcap));
./sysdeps/s390/dl-irel.h:33: return ((ElfW(Addr) (*) (unsigned long int)) (addr)) (GLRO(dl_hwcap));
./sysdeps/sparc/sparc32/dl-irel.h:34: return ((Elf32_Addr (*) (int)) (addr)) (GLRO(dl_hwcap));
./sysdeps/sparc/sparc64/dl-irel.h:34: return ((Elf64_Addr (*) (int)) (addr)) (GLRO(dl_hwcap));
./sysdeps/x86_64/dl-irel.h:32: return ((ElfW(Addr) (*) (void)) (addr)) ();

--
Andreas