RFC: Add DT_FLAGS_2 and DF_2_GNU_IFUNC

H.J. Lu hjl.tools@gmail.com
Fri May 25 21:18:00 GMT 2018


On Fri, May 25, 2018 at 2:09 PM, Florian Weimer <fweimer@redhat.com> wrote:
> On 05/25/2018 10:58 PM, H.J. Lu wrote:
>>
>> On Fri, May 25, 2018 at 1:35 PM, Florian Weimer <fweimer@redhat.com>
>> wrote:
>>>
>>> On 05/25/2018 07:47 PM, H.J. Lu wrote:
>>>>
>>>>
>>>> This patch extends gABI with DT_FLAGS_2 and DF_2_GNU_IFUNC to indicate
>>>> that a shared object or executable has IFUNC symbols so that dynamic
>>>> linker can relocate it early.
>>>
>>>
>>>
>>> I don't think this will solve any of the thorny cases.  It may help with
>>> missing DT_NEEDED entries, but that's only a small subset of the issues,
>>> and
>>> as far as linking against glibc is concerned, such binaries are invalid
>>> anyway.
>>
>>
>> In my case, LD_PRELOADed shared library is linked against libc.so.  But
>> there
>> is no dependency on it by definition.
>
>
> Still I don't see what this buys you if the LD_PRELOAD object has IFUNCs,
> too.

[hjl@gnu-cfl-1 ifunc-2]$ cat bar.c
void
bar (char *dst, const char *src, unsigned int size)
{
  __builtin_memmove (dst, src, size);
}
[hjl@gnu-cfl-1 ifunc-2]$ cat main.c
extern void bar (char *, const char *, unsigned int);

int
main ()
{
  char dst[50];
  const char src[] =
    {
      "This is a test"
    };
  bar (dst, src, sizeof (src));
  if (__builtin_memcmp (dst, src, sizeof (src)) != 0)
    __builtin_abort ();
  return 0;
}
[hjl@gnu-cfl-1 ifunc-2]$ make
gcc -O2 -g   -c -o main.o main.c
gcc -O2 -g -fPIC   -c -o bar.o bar.c
gcc -shared -z now -o libbar.so bar.o
gcc -z now -o x main.o libbar.so -Wl,-R,.
./x
[hjl@gnu-cfl-1 ifunc-2]$ LD_PRELOAD=./libmemmove.so ./x
./x: Relink `./libbar.so' with `./libmemmove.so' for IFUNC symbol `memmove'
[hjl@gnu-cfl-1 ifunc-2]$

-- 
H.J.



More information about the Binutils mailing list