Created attachment 5926 [details] Test program to show unnecessary IFUNC relocation When compiling the attached code using gcc -shared -o u.so -fpic u.so on an x86-64 system you will see the following relocations: Relocation section [ 7] '.rela.dyn' for section [ 0] '' at offset 0x3e8 contains 5 entries: Offset Type Value Addend Name 0x0000000000200760 X86_64_RELATIVE 000000000000000000 +2099040 0x00000000002008e8 X86_64_GLOB_DAT 000000000000000000 +0 __gmon_start__ 0x00000000002008f0 X86_64_GLOB_DAT 000000000000000000 +0 _Jv_RegisterClasses 0x00000000002008f8 X86_64_GLOB_DAT 000000000000000000 +0 __cxa_finalize 0x0000000000200900 X86_64_GLOB_DAT 0x00000000000005d8 +0 f Relocation section [ 8] '.rela.plt' for section [10] '.plt' at offset 0x460 contains 3 entries: Offset Type Value Addend Name 0x0000000000200920 X86_64_JUMP_SLOT 000000000000000000 +0 __cxa_finalize 0x0000000000200928 X86_64_JUMP_SLOT 0x00000000000005d8 +0 f 0x0000000000200930 X86_64_JUMP_SLOT 0x00000000000005e5 +0 g There are two relocations against f. Since there is no reference to f other than through a call there is no need for a GOT relocation. The PLT relocation is all that's needed. It works fine for normal symbols (there is only one relocation for g) and IFUNCs should be handled just like that.
X86_64_GLOB_DAT was used to preempt f. Will preempt work without X86_64_GLOB_DAT?
(In reply to comment #1) > X86_64_GLOB_DAT was used to preempt f. Will preempt work without > X86_64_GLOB_DAT? You mean preloading such an object? Why should this matter? Any relocation will only look at the symbol record in the DSO with the definition. This will prevoke the indirect function be called, even in the case of dlsym(). What do I miss? Please describe the situation I think needs this relocation.
(In reply to comment #2) > (In reply to comment #1) > > X86_64_GLOB_DAT was used to preempt f. Will preempt work without > > X86_64_GLOB_DAT? > > You mean preloading such an object? Why should this matter? Any relocation > will only look at the symbol record in the DSO with the definition. This will > prevoke the indirect function be called, even in the case of dlsym(). > > What do I miss? Please describe the situation I think needs this relocation. There may be another 'f' definition in executable or a DSO before u.so. We need to make sure that f in u.so isn't used in this case by updating its GOT entry.
HJ, where is the .got entry used in the .so? I can't see any use, but maybe I'm missing something. If it isn't used, then your last comment makes no sense.
CVSROOT: /cvs/src Module name: src Changes by: hjl@sourceware.org 2011-09-12 18:17:36 Modified files: bfd : ChangeLog elf-ifunc.c ld/testsuite : ChangeLog ld/testsuite/ld-ifunc: ifunc-13-i386.d ifunc-13-x86-64.d ifunc-3a-x86.d ld/testsuite/ld-x86-64: pr13082-5a.d Added files: ld/testsuite/ld-ifunc: ifunc-15-i386.d ifunc-15-i386.s ifunc-15-x86-64.d ifunc-15-x86-64.s Log message: Use .got.plt for IFUNC symbols if there are no GOT relocations. bfd/ 2011-09-12 H.J. Lu <hongjiu.lu@intel.com> PR ld/13178 * elf-ifunc.c (_bfd_elf_allocate_ifunc_dyn_relocs): Use .got.plt if there are no GOT relocations. ld/testsuite/ 2011-09-12 H.J. Lu <hongjiu.lu@intel.com> PR ld/13178 * ld-ifunc/ifunc-13-i386.d: Updated. * ld-ifunc/ifunc-13-x86-64.d: Likewise. * ld-ifunc/ifunc-3a-x86.d: Likewise. * ld-x86-64/pr13082-5a.d: Likewise. * ld-ifunc/ifunc-15-i386.d: New. * ld-ifunc/ifunc-15-i386.s: Likewise. * ld-ifunc/ifunc-15-x86-64.d: Likewise. * ld-ifunc/ifunc-15-x86-64.s: Likewise. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.5468&r2=1.5469 http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf-ifunc.c.diff?cvsroot=src&r1=1.6&r2=1.7 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1456&r2=1.1457 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-ifunc/ifunc-15-i386.d.diff?cvsroot=src&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-ifunc/ifunc-15-i386.s.diff?cvsroot=src&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-ifunc/ifunc-15-x86-64.d.diff?cvsroot=src&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-ifunc/ifunc-15-x86-64.s.diff?cvsroot=src&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-ifunc/ifunc-13-i386.d.diff?cvsroot=src&r1=1.1&r2=1.2 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-ifunc/ifunc-13-x86-64.d.diff?cvsroot=src&r1=1.1&r2=1.2 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-ifunc/ifunc-3a-x86.d.diff?cvsroot=src&r1=1.5&r2=1.6 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-x86-64/pr13082-5a.d.diff?cvsroot=src&r1=1.1&r2=1.2
Fixed.