This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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: PR ld/14968: Missing R_*_IRELATIVE relocation


On Sun, Dec 16, 2012 at 12:35 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
> On Thu, Dec 13, 2012 at 01:08:52PM -0800, H.J. Lu wrote:
>> Hi,
>>
>> I checked in this patch to check local IFUNC calls so that we can
>> avoid unnecessary R_*_NONE relocations.
>>
>>
>> H.J.
>> ----
>> diff --git a/bfd/ChangeLog b/bfd/ChangeLog
>> index 5c4ace1..1ff8574 100644
>> --- a/bfd/ChangeLog
>> +++ b/bfd/ChangeLog
>> @@ -1,3 +1,10 @@
>> +2012-12-13  H.J. Lu  <hongjiu.lu@intel.com>
>> +
>> +     PR ld/14956
>> +     * elf32-i386.c (elf_i386_adjust_dynamic_symbol): Check local
>> +     IFUNC calls.
>> +     * elf64-x86-64.c (elf_x86_64_adjust_dynamic_symbol): Likewise.
>> +
>>  2012-12-10  Edgar E. Iglesias <edgar.iglesias@gmail.com>
>>
>>       * reloc.c (MICROBLAZE): Document new relocations
>> diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
>> index 1b04a6e..bb41302 100644
>> --- a/bfd/elf32-i386.c
>> +++ b/bfd/elf32-i386.c
>> @@ -2066,10 +2066,39 @@ elf_i386_adjust_dynamic_symbol (struct bfd_link_info *info,
>>  {
>>    struct elf_i386_link_hash_table *htab;
>>    asection *s;
>> +  struct elf_i386_link_hash_entry *eh;
>> +  struct elf_dyn_relocs *p;
>>
>>    /* STT_GNU_IFUNC symbol must go through PLT. */
>>    if (h->type == STT_GNU_IFUNC)
>>      {
>> +      /* Check local STT_GNU_IFUNC calls.  */
>> +      if (h->ref_regular
>> +       && SYMBOL_CALLS_LOCAL (info, h))
>> +     {
>> +       bfd_size_type pc_count = 0;
>> +       struct elf_dyn_relocs **pp;
>> +
>> +       eh = (struct elf_i386_link_hash_entry *) h;
>> +       for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
>> +         {
>> +           pc_count += p->pc_count;
>> +           p->count -= p->pc_count;
>> +           p->pc_count = 0;
>> +           if (p->count == 0)
>> +             *pp = p->next;
>> +           else
>> +             pp = &p->next;
>> +         }
>> +
>> +       if (pc_count)
>> +         {
>> +           h->needs_plt = 1;
>> +           h->plt.refcount += 1;
>> +           h->non_got_ref = 1;
>> +         }
>> +     }
>> +
>>        if (h->plt.refcount <= 0)
>>       {
>>         h->plt.offset = (bfd_vma) -1;
>
> The above patch has a hole. All local IFUNC references, including
> non-call references, must go though local PLT.  I checked in this
> patch to fix it.
>
>
> H.J.
> ----
> diff --git a/bfd/ChangeLog b/bfd/ChangeLog
> index 87cc9d7..070acb4 100644
> --- a/bfd/ChangeLog
> +++ b/bfd/ChangeLog
> @@ -1,6 +1,13 @@
> +2012-12-16  H.J. Lu  <hongjiu.lu@intel.com>
> +
> +       PR ld/14968
> +       * elf32-i386.c (elf_i386_adjust_dynamic_symbol): Also check
> +       local IFUNC references.
> +       * elf64-x86-64.c (elf_x86_64_adjust_dynamic_symbol): Likewise.
> +
>  2012-12-14  Tom Tromey  <tromey@redhat.com>
>
> -        * elf.c (elfcore_grok_note) <NT_FILE>: New case.
> +       * elf.c (elfcore_grok_note) <NT_FILE>: New case.
>
>  2012-12-13  H.J. Lu  <hongjiu.lu@intel.com>
>
> diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
> index bb41302..a188cec 100644
> --- a/bfd/elf32-i386.c
> +++ b/bfd/elf32-i386.c
> @@ -2072,11 +2072,12 @@ elf_i386_adjust_dynamic_symbol (struct bfd_link_info *info,
>    /* STT_GNU_IFUNC symbol must go through PLT. */
>    if (h->type == STT_GNU_IFUNC)
>      {
> -      /* Check local STT_GNU_IFUNC calls.  */
> +      /* All local STT_GNU_IFUNC references must be treate as local
> +        calls via local PLT.  */
>        if (h->ref_regular
>           && SYMBOL_CALLS_LOCAL (info, h))
>         {
> -         bfd_size_type pc_count = 0;
> +         bfd_size_type pc_count = 0, count = 0;
>           struct elf_dyn_relocs **pp;
>
>           eh = (struct elf_i386_link_hash_entry *) h;
> @@ -2085,13 +2086,14 @@ elf_i386_adjust_dynamic_symbol (struct bfd_link_info *info,
>               pc_count += p->pc_count;
>               p->count -= p->pc_count;
>               p->pc_count = 0;
> +             count += p->count;
>               if (p->count == 0)
>                 *pp = p->next;
>               else
>                 pp = &p->next;
>             }
>
> -         if (pc_count)
> +         if (pc_count || count)
>             {
>               h->needs_plt = 1;
>               h->plt.refcount += 1;
> diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
> index ec38ddc..283681c 100644
> --- a/bfd/elf64-x86-64.c
> +++ b/bfd/elf64-x86-64.c
> @@ -2140,11 +2140,12 @@ elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info,
>    /* STT_GNU_IFUNC symbol must go through PLT. */
>    if (h->type == STT_GNU_IFUNC)
>      {
> -      /* Check local STT_GNU_IFUNC calls.  */
> +      /* All local STT_GNU_IFUNC references must be treate as local
> +        calls via local PLT.  */
>        if (h->ref_regular
>           && SYMBOL_CALLS_LOCAL (info, h))
>         {
> -         bfd_size_type pc_count = 0;
> +         bfd_size_type pc_count = 0, count = 0;
>           struct elf_dyn_relocs **pp;
>
>           eh = (struct elf_x86_64_link_hash_entry *) h;
> @@ -2153,13 +2154,14 @@ elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info,
>               pc_count += p->pc_count;
>               p->count -= p->pc_count;
>               p->pc_count = 0;
> +             count += p->count;
>               if (p->count == 0)
>                 *pp = p->next;
>               else
>                 pp = &p->next;
>             }
>
> -         if (pc_count)
> +         if (pc_count || count)
>             {
>               h->needs_plt = 1;
>               h->plt.refcount += 1;
> diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
> index 7ae4014..7a2cb17 100644
> --- a/ld/testsuite/ChangeLog
> +++ b/ld/testsuite/ChangeLog
> @@ -1,3 +1,19 @@
> +2012-12-16  H.J. Lu  <hongjiu.lu@intel.com>
> +
> +       PR ld/14968
> +       * ld-ifunc/ifunc-18a-i386.d: New file.
> +       * ld-ifunc/ifunc-18a-x86-64.d: Likewise.
> +       * ld-ifunc/ifunc-18a.s: Likewise.
> +       * ld-ifunc/ifunc-18b-i386.d: Likewise.
> +       * ld-ifunc/ifunc-18b-x86-64.d: Likewise.
> +       * ld-ifunc/ifunc-18b.s: Likewise.
> +       * ld-ifunc/ifunc-19a-i386.d: Likewise.
> +       * ld-ifunc/ifunc-19a-x86-64.d: Likewise.
> +       * ld-ifunc/ifunc-19a.s: Likewise.
> +       * ld-ifunc/ifunc-19b-i386.d: Likewise.
> +       * ld-ifunc/ifunc-19b-x86-64.d: Likewise.
> +       * ld-ifunc/ifunc-19b.s: Likewise.
> +
>  2012-12-15  Thomas Schwinge  <thomas@codesourcery.com>
>
>         * ld-elf/elf.exp (stack exec, stack size): Run for any GNU target.
> diff --git a/ld/testsuite/ld-ifunc/ifunc-18a-i386.d b/ld/testsuite/ld-ifunc/ifunc-18a-i386.d
> new file mode 100644
> index 0000000..10490b1
> --- /dev/null
> +++ b/ld/testsuite/ld-ifunc/ifunc-18a-i386.d
> @@ -0,0 +1,15 @@
> +#source: ifunc-18a.s
> +#source: ifunc-18b.s
> +#ld: -shared -m elf_i386 -z nocombreloc
> +#as: --32
> +#readelf: -r --wide
> +#target: x86_64-*-* i?86-*-*
> +
> +Relocation section '.rel.ifunc' at .*
> +[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
> +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_IRELATIVE[ ]*
> +
> +Relocation section '.rel.plt' at .*
> +[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
> +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_IRELATIVE[ ]*
> +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_IRELATIVE[ ]*
> diff --git a/ld/testsuite/ld-ifunc/ifunc-18a-x86-64.d b/ld/testsuite/ld-ifunc/ifunc-18a-x86-64.d
> new file mode 100644
> index 0000000..0d600eb
> --- /dev/null
> +++ b/ld/testsuite/ld-ifunc/ifunc-18a-x86-64.d
> @@ -0,0 +1,15 @@
> +#source: ifunc-18a.s
> +#source: ifunc-18b.s
> +#as: --64
> +#ld: -shared -melf_x86_64 -z nocombreloc
> +#readelf: -r --wide
> +#target: x86_64-*-*
> +
> +Relocation section '.rela.ifunc' at .*
> +[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
> +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_IRELATIVE[ ]+[0-9a-f]*
> +
> +Relocation section '.rela.plt' at .*
> +[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
> +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_IRELATIVE[ ]+[0-9a-f]*
> +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_IRELATIVE[ ]+[0-9a-f]*
> diff --git a/ld/testsuite/ld-ifunc/ifunc-18a.s b/ld/testsuite/ld-ifunc/ifunc-18a.s
> new file mode 100644
> index 0000000..c29c121
> --- /dev/null
> +++ b/ld/testsuite/ld-ifunc/ifunc-18a.s
> @@ -0,0 +1,5 @@
> +       .section .data.rel,"aw",@progbits
> +       .globl foo_ptrt
> +       .type   foo_ptr, @object
> +foo_ptr:
> +       .dc.a foo
> diff --git a/ld/testsuite/ld-ifunc/ifunc-18b-i386.d b/ld/testsuite/ld-ifunc/ifunc-18b-i386.d
> new file mode 100644
> index 0000000..a5eda94
> --- /dev/null
> +++ b/ld/testsuite/ld-ifunc/ifunc-18b-i386.d
> @@ -0,0 +1,15 @@
> +#source: ifunc-18b.s
> +#source: ifunc-18a.s
> +#ld: -shared -m elf_i386 -z nocombreloc
> +#as: --32
> +#readelf: -r --wide
> +#target: x86_64-*-* i?86-*-*
> +
> +Relocation section '.rel.ifunc' at .*
> +[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
> +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_IRELATIVE[ ]*
> +
> +Relocation section '.rel.plt' at .*
> +[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
> +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_IRELATIVE[ ]*
> +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_IRELATIVE[ ]*
> diff --git a/ld/testsuite/ld-ifunc/ifunc-18b-x86-64.d b/ld/testsuite/ld-ifunc/ifunc-18b-x86-64.d
> new file mode 100644
> index 0000000..8dfebfb
> --- /dev/null
> +++ b/ld/testsuite/ld-ifunc/ifunc-18b-x86-64.d
> @@ -0,0 +1,15 @@
> +#source: ifunc-18b.s
> +#source: ifunc-18a.s
> +#as: --64
> +#ld: -shared -melf_x86_64 -z nocombreloc
> +#readelf: -r --wide
> +#target: x86_64-*-*
> +
> +Relocation section '.rela.ifunc' at .*
> +[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
> +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_IRELATIVE[ ]+[0-9a-f]*
> +
> +Relocation section '.rela.plt' at .*
> +[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
> +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_IRELATIVE[ ]+[0-9a-f]*
> +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_IRELATIVE[ ]+[0-9a-f]*
> diff --git a/ld/testsuite/ld-ifunc/ifunc-18b.s b/ld/testsuite/ld-ifunc/ifunc-18b.s
> new file mode 100644
> index 0000000..fece413
> --- /dev/null
> +++ b/ld/testsuite/ld-ifunc/ifunc-18b.s
> @@ -0,0 +1,15 @@
> +       .text
> +       .type foo, %gnu_indirect_function
> +       .hidden foo
> +       .globl foo
> +foo:
> +       ret
> +       .size   foo, .-foo
> +       .globl bar
> +bar:
> +       jmp     foo1@PLT
> +       ret
> +       .size   bar, .-bar
> +       .hidden foo1
> +       .globl foo1
> +       foo1 = foo
> diff --git a/ld/testsuite/ld-ifunc/ifunc-19a-i386.d b/ld/testsuite/ld-ifunc/ifunc-19a-i386.d
> new file mode 100644
> index 0000000..8319bfc
> --- /dev/null
> +++ b/ld/testsuite/ld-ifunc/ifunc-19a-i386.d
> @@ -0,0 +1,14 @@
> +#source: ifunc-19a.s
> +#source: ifunc-19b.s
> +#ld: -shared -m elf_i386 -z nocombreloc
> +#as: --32
> +#readelf: -r --wide
> +#target: x86_64-*-* i?86-*-*
> +
> +Relocation section '.rel.ifunc' at .*
> +[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
> +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_IRELATIVE[ ]*
> +
> +Relocation section '.rel.plt' at .*
> +[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
> +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_IRELATIVE[ ]*
> diff --git a/ld/testsuite/ld-ifunc/ifunc-19a-x86-64.d b/ld/testsuite/ld-ifunc/ifunc-19a-x86-64.d
> new file mode 100644
> index 0000000..fe576d2
> --- /dev/null
> +++ b/ld/testsuite/ld-ifunc/ifunc-19a-x86-64.d
> @@ -0,0 +1,14 @@
> +#source: ifunc-19a.s
> +#source: ifunc-19b.s
> +#as: --64
> +#ld: -shared -melf_x86_64 -z nocombreloc
> +#readelf: -r --wide
> +#target: x86_64-*-*
> +
> +Relocation section '.rela.ifunc' at .*
> +[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
> +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_IRELATIVE[ ]+[0-9a-f]*
> +
> +Relocation section '.rela.plt' at .*
> +[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
> +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_IRELATIVE[ ]+[0-9a-f]*
> diff --git a/ld/testsuite/ld-ifunc/ifunc-19a.s b/ld/testsuite/ld-ifunc/ifunc-19a.s
> new file mode 100644
> index 0000000..3a3d0cd
> --- /dev/null
> +++ b/ld/testsuite/ld-ifunc/ifunc-19a.s
> @@ -0,0 +1,5 @@
> +       .section .data.rel,"aw",@progbits
> +       .globl foo_ptrt
> +       .type   foo_ptr, @object
> +foo_ptr:
> +       .dc.a foo1
> diff --git a/ld/testsuite/ld-ifunc/ifunc-19b-i386.d b/ld/testsuite/ld-ifunc/ifunc-19b-i386.d
> new file mode 100644
> index 0000000..5bb8170
> --- /dev/null
> +++ b/ld/testsuite/ld-ifunc/ifunc-19b-i386.d
> @@ -0,0 +1,14 @@
> +#source: ifunc-19b.s
> +#source: ifunc-19a.s
> +#ld: -shared -m elf_i386 -z nocombreloc
> +#as: --32
> +#readelf: -r --wide
> +#target: x86_64-*-* i?86-*-*
> +
> +Relocation section '.rel.ifunc' at .*
> +[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
> +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_IRELATIVE[ ]*
> +
> +Relocation section '.rel.plt' at .*
> +[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
> +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_IRELATIVE[ ]*
> diff --git a/ld/testsuite/ld-ifunc/ifunc-19b-x86-64.d b/ld/testsuite/ld-ifunc/ifunc-19b-x86-64.d
> new file mode 100644
> index 0000000..35fa328
> --- /dev/null
> +++ b/ld/testsuite/ld-ifunc/ifunc-19b-x86-64.d
> @@ -0,0 +1,14 @@
> +#source: ifunc-19b.s
> +#source: ifunc-19a.s
> +#as: --64
> +#ld: -shared -melf_x86_64 -z nocombreloc
> +#readelf: -r --wide
> +#target: x86_64-*-*
> +
> +Relocation section '.rela.ifunc' at .*
> +[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
> +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_IRELATIVE[ ]+[0-9a-f]*
> +
> +Relocation section '.rela.plt' at .*
> +[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
> +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_IRELATIVE[ ]+[0-9a-f]*
> diff --git a/ld/testsuite/ld-ifunc/ifunc-19b.s b/ld/testsuite/ld-ifunc/ifunc-19b.s
> new file mode 100644
> index 0000000..fece413
> --- /dev/null
> +++ b/ld/testsuite/ld-ifunc/ifunc-19b.s
> @@ -0,0 +1,15 @@
> +       .text
> +       .type foo, %gnu_indirect_function
> +       .hidden foo
> +       .globl foo
> +foo:
> +       ret
> +       .size   foo, .-foo
> +       .globl bar
> +bar:
> +       jmp     foo1@PLT
> +       ret
> +       .size   bar, .-bar
> +       .hidden foo1
> +       .globl foo1
> +       foo1 = foo

I also checked this into 2.23 branch.

-- 
H.J.


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