This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Remove unnecessary IFUNC dispatch for __memset_chk.


On Mon, Aug 17, 2015 at 1:04 PM, Alexander Monakov <amonakov@ispras.ru> wrote:
>
>
> On Mon, 17 Aug 2015, H.J. Lu wrote:
>
>> On Mon, Aug 17, 2015 at 12:35 PM, Alexander Monakov <amonakov@ispras.ru> wrote:
>> > On Mon, 17 Aug 2015, H.J. Lu wrote:
>> >
>> >> On Mon, Aug 17, 2015 at 11:05 AM, Alexander Monakov <amonakov@ispras.ru> wrote:
>> >> > On Mon, 17 Aug 2015, H.J. Lu wrote:
>> >> >
>> >> >> On Mon, Aug 17, 2015 at 10:53 AM, Alexander Monakov <amonakov@ispras.ru> wrote:
>> >> >> >> > Earlier you rejected the idea that a resolver can use an externally visible
>> >> >> >> > symbol.  I just don't see why you say it might be non-deterministic.  One
>> >> >> >> > can inspect the executable, LD_PRELOAD'ed modules, etc. to see whether they
>> >> >> >> > are going to provide an interposing definition of a symbol or not.  What is
>> >> >> >> > non-deterministic in there?
>> >> >> >>
>> >> >> >> Due to the way how IFUNC is implemented, dependency on
>> >> >> >> external relocation may lead to undefined behavior.  We tried
>> >> >> >> to support external relocations in IFUNC selector:
>> >> >> >>
>> >> >> >> https://sourceware.org/bugzilla/show_bug.cgi?id=13302
>> >> >> >>
>> >> >> >> But external relocation on  function address returned by IFUNC
>> >> >> >> selector isn't supported.
>> >> >> >
>> >> >> > Isn't this an implementation deficiency that can be solved, for example, by
>> >> >> > sorting GLOB_DAT relocation appropriately, rather than a fundamental
>> >> >> > restriction that any reasonable implementation of IFUNC would exhibit?
>> >> >>
>> >> >> We have no control over GLOB_DAT, which can be a relocation
>> >> >> against IFUNC symbol and we only know for sure at run-time.
>> >> >
>> >> > Surely such a counter-argument applies equally to JUMP_SLOT relocations?
>> >> > Imagine that 'extern int f(void)' in bug 13302 that you've linked turns
>> >> > out to be an IFUNC symbol at runtime.
>> >> >
>> >> > extern int f(void);
>> >> >
>> >> > void alt1(void) { }
>> >> > void alt2(void) { }
>> >> >
>> >> > static void (*resolve (void)) (void)
>> >> > {
>> >> >   return f() ? alt1 : alt2;
>> >> > }
>> >> >
>> >> > void fct(void) __attribute__ ((ifunc ("resolve")));
>> >> >
>> >>
>> >> The difference here is symbol definition for GLOB_DAT is known
>> >> only at run-time while relocations are known at link-time.
>> >
>> > Sorry, I just don't see what point you're trying to make here.
>> >
>> > Anyway.  Suppose 'resolve()' is compiled with -fno-plt.  Then instead of
>> > JUMP_SLOT relocation to 'f' it'll have a GLOB_DAT relocation to 'f', correct?
>> > What's going to happen then?
>> >
>>
>> I believe it is OK since GLOB_DAT relocations are performed before
>> IRELATIVE relocations in .rela.plt / .rel.plt section.
>
> OK.  Now further suppose that we are
>
> a) calling 'fct' with -fno-plt, or
> b) taking the address of 'fct' (as in Ondrey's original example)
>
> In both cases we're going to have a GLOB_DAT relocation to 'fct'.
>
> So we have a GLOB_DAT relocation to 'fct', which is an IFUNC symbol with
> 'resolve' as its resolver, and the resolver invokes 'f', using a GLOB_DAT
> relocation.
>
> Are you saying it's not supposed to work?

They won't work because

 void alt1(void) { }
 void alt2(void) { }

which has nothing to do with fct.  They work if alt1 and alt2 are internal
to DSO.

-- 
H.J.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]