Bug 465302 - FEAT: STT_IFUNC indirect relocations support
Summary: FEAT: STT_IFUNC indirect relocations support
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: binutils
Version: rawhide
Hardware: All
OS: Linux
high
low
Target Milestone: ---
Assignee: Nick Clifton
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2008-10-02 16:57 UTC by Jan Kratochvil
Modified: 2009-07-14 10:03 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: Enhancement
Doc Text:
Clone Of:
Environment:
Last Closed: 2009-07-14 10:03:03 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
glibc patch. (22.77 KB, patch)
2008-10-02 16:59 UTC, Jan Kratochvil
no flags Details | Diff
binutils patch. (5.68 KB, patch)
2008-10-02 17:00 UTC, Jan Kratochvil
no flags Details | Diff
Second version of binutils patch with code to emit the relocs into the executable (28.80 KB, patch)
2008-10-30 14:12 UTC, Nick Clifton
no flags Details | Diff
Third version of patch - now with ifunc relocs placed in their own section (88.07 KB, patch)
2008-10-31 17:38 UTC, Nick Clifton
no flags Details | Diff
Revision of the v3 patch suitable for application to the current rawhide sources (27.90 KB, patch)
2009-02-09 19:09 UTC, Nick Clifton
no flags Details | Diff
Fix problem when the ifunc symbols are in a library, not an object file. Plus switch back to STT_GNU_IFUNC. (28.32 KB, patch)
2009-02-10 12:49 UTC, Nick Clifton
no flags Details | Diff

Description Jan Kratochvil 2008-10-02 16:57:55 UTC
Provide feature to build STT_IFUNC symbol type.  It contains an address of a function to be called returning address which should be used by the symbol references later.

There is now new gELF number:
  #define STT_IFUNC   7

Provided patch from Ulrich Drepper for glibc and mine for binutils.
TODO:
binutils - sort the relocations so that STT_IFUNC ones are the last ones.
binutils - make the relocations working also for executables (not just shared
           libraries)
prelink - (not a part of this Bug)

Comment 1 Jan Kratochvil 2008-10-02 16:59:33 UTC
Created attachment 319264 [details]
glibc patch.

Comment 2 Jan Kratochvil 2008-10-02 17:00:02 UTC
Created attachment 319265 [details]
binutils patch.

Comment 3 Nick Clifton 2008-10-30 14:12:32 UTC
Created attachment 321935 [details]
Second version of binutils patch with code to emit the relocs into the executable

Comment 4 Nick Clifton 2008-10-30 14:17:17 UTC
Hi Guys,

  I have uploaded a revised version of the binutils patch which emits relocs against IFUNC symbols into the executables.  

I have not been able to arrange for the relocs to be sorted so that the IFUNC using ones are last, and I do not think that it is going to be possible to do this.  This is because the relocs are created and stored on a per section basis (eg .rel[a].text for relocs against the .text section) but then the x86 linker script merges all of these reloc sections into one large .rel[a].plt section in the final executable.  The only way to achieve the desired sorting would be to have a post-processing tool which reads in the .rel[a].plt section and then sorts it before re-emitting it.

I think that the need for a sorted .rel[a].plt section can be avoided however - all that is needed is for the loader to perform two passes over the section, the first time ignoring relocas against IFUNC symbols and the second time ignoring relocs against non-IFUNC symbols.

Cheers
 Nick

Comment 5 Ulrich Drepper 2008-10-30 15:00:19 UTC
(In reply to comment #4)
> I think that the need for a sorted .rel[a].plt section can be avoided however -
> all that is needed is for the loader to perform two passes over the section,

This means performing work at runtime thousands and millions of times instead of once at link-time.  That's not a long-term solution.

We can play around with the code as you have it now.  So far, there is no need for the sorting anyway.  The code used so far (and for x86/x86-64 in future) doesn't have dependencies.  When we come across a situation where the sorting is really needed we can look at the problem again.

Thanks for the patch.

Comment 6 Jan Kratochvil 2008-10-31 08:45:32 UTC
Thanks, Nick, at least the elf32-i386.c/elf64-x86-64.c looks really tricky to me.

[ The patch has some unrelated changes leftover(s) - like `.gnu.linkonce.r'. ]

Comment 7 Nick Clifton 2008-10-31 17:38:22 UTC
Created attachment 322112 [details]
Third version of patch - now with ifunc relocs placed in their own section

Comment 8 Nick Clifton 2008-10-31 17:43:17 UTC
Hi Guys,

  I have uploaded a third version of the binutils patch.  This version implements a possible solution to the reloc ordering problem by placing all of the STT_GNU_IFUNC referring relocs into their own section in the executable.  Called .rel[a].ifunc.plt this section will be placed immediately after the .rel[a].plt section and is basically the same, except that it contains all of the relocs that refer to ifunc symbols.

Cheers
  Nick

PS.  Jan - thanks for catching that .gnu.linkonce.r leakage - I have fixed it in this version of the patch.

Comment 9 Jan Kratochvil 2008-11-03 10:36:40 UTC
A typo?  It is called .rel[a].ifunc.dyn (not .rel[a].ifunc.plt).
I would guess it should be after .rel[a].plt to have better functions availability in the ifunc resolving functions.
Sure a nice functionality so quickly done.

Relocation section '.rela.dyn' at offset 0x390 contains 1 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
0000006009b0  000100000006 R_X86_64_GLOB_DAT 0000000000000000 __gmon_start__ + 0

Relocation section '.rela.ifunc.dyn' at offset 0x3a8 contains 1 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
00000040059a  000500000002 R_X86_64_PC32     func()           func - 4

Relocation section '.rela.plt' at offset 0x3c0 contains 3 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
0000006009d0  000200000007 R_X86_64_JUMP_SLO 0000000000000000 puts + 0
0000006009d8  000300000007 R_X86_64_JUMP_SLO 0000000000000000 __libc_start_main + 0
0000006009e0  000400000007 R_X86_64_JUMP_SLO 0000000000000000 rand + 0

Comment 10 Nick Clifton 2008-11-06 15:34:11 UTC
Hi Jan,

> A typo?  It is called .rel[a].ifunc.dyn (not .rel[a].ifunc.plt).

Nope - it is deliberate.  The normal relocations against code sections go into the .rel[a].dyn section so I chose to put the ifunc using versions into .rel[a].ifunc.dyn.

That said if you want to change the name or placement of the section it is trivial to do - just edit the ld/scripttempl/elf.sc file.

Cheers
  Nick

Comment 11 Nick Clifton 2009-02-09 19:09:51 UTC
Created attachment 331348 [details]
Revision of the v3 patch suitable for application to the current rawhide sources

Comment 12 Nick Clifton 2009-02-10 12:49:16 UTC
Created attachment 331420 [details]
Fix problem when the ifunc symbols are in a library, not an object file.  Plus switch back to STT_GNU_IFUNC.

Comment 13 Nick Clifton 2009-07-14 10:03:03 UTC
Hi Jan,

  I am closing this bug report for now.  The latest rawhide binutils now has IFUNC support in it.

Cheers
  Nick


Note You need to log in before you can comment on or make changes to this bug.