COMMITTED: Add support for STT_IFUNC
Nick Clifton
nickc@redhat.com
Wed Dec 3 14:48:00 GMT 2008
Hi Guys,
I am applying the patch below to add support for a new ELF symbol
type. It is currently under review by the ELF committee and I am
reliably informed that it will be added to the official
specification fairly soon now. This is what the specification looks
like:
STT_IFUNC
This symbol type is the same as STT_IFUNC except that it always
points to a function or piece of executable code which takes no
arguments and which returns a function pointer. If an STT_IFUNC
symbol is referred to by a relocation then evaluation of that
relocation is delayed until load-time. The value used in the
relocation is the function pointer returned by an invocation
of the STT_IFUNC symbol.
The purpose of this symbol type is it to allow the run-time to
select between multiple versions of the implementation of a
specific function. The selection made in general will take the
currently available hardware into account and select the most
appropriate version.
So this patch adds support for this symbol type to the assembler
(via ".type <foo>, %STT_IFUNC"), the linker and the binutils.
Currently linker support has only been added for the x86 and x86_64
targets, but it can easily be extended to other targets that might
wish to use it.
Run-time relocations against this symbol type are placed into a new
section called .rel[a].ifunc.dyn which immediately follows the
.rel[a].dyn section. The idea here is to allow the dynamic linker
to execute all of the normal dynamic relocations first, before it
tries to execute any of the STT_IFUNC using dynamic relocs. This is
just in case the invoked STT_IFUNC function has any dependencies
upon other symbols.
Readelf, nm and objdump have been extended to display the new symbol
type. Objdump and nm use the letter 'i' to indicate the new
symbol type, eg:
080484c0 g i .text 00000024 ifunction
whereas readelf uses IFUNC:
7: 080484c0 36 IFUNC GLOBAL DEFAULT 14 ifunction
Plus objdump and readelf will append "()" to relocs which are made
against STT_IFUNC symbols, as a hint that the relocation invokes a
function:
RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
00000009 R_386_32 .rodata
0000009f R_386_PC32 ifunction()
Tested against all sorts of toolchains without any regressions.
Cheers
Nick
include/elf/ChangeLog
2008-12-03 Nick Clifton <nickc@redhat.com>
* common.h (STT_IFUNC): Define.
elfcpp/ChangeLog
2008-12-03 Nick Clifton <nickc@redhat.com>
* elfcpp.h (enum STT): Add STT_IFUNC.
bfd/ChangeLog
2008-12-03 Nick Clifton <nickc@redhat.com>
* syms.c (struct bfd_symbol): Add new flag BSF_INDIRECT_FUNCTION.
Remove redundant flag BFD_FORT_COMM_DEFAULT_VALUE. Renumber flags
to remove gaps.
(bfd_print_symbol_vandf): Return 'i' for BSF_INDIRECT_FUNCTION.
(bfd_decode_symclass): Likewise.
* elf.c (swap_out_syms): Translate BSF_INDIRECT_FUNCTION into
STT_IFUNC.
(elf_find_function): Treat STT_IFUNC in the same way as STT_FUNC.
(_bfd_elf_is_function_type): Likewise.
* elf32-arm.c (arm_elf_find_function): Likewise.
(elf32_arm_adjust_dynamic_symbol): Likewise.
(elf32_arm_swap_symbol_in): Likewise.
(elf32_arm_additional_program_headers): Likewise.
* elf32-i386.c (is_indirect_symbol): New function.
(elf_i386_check_relocs): Also generate dynamic relocs for
relocations against STT_IFUNC symbols.
(allocate_dynrelocs): Likewise.
(elf_i386_relocate_section): Likewise.
* elf64-x86-64.c (is_indirect_symbol): New function.
(elf64_x86_64_check_relocs): Also generate dynamic relocs for
relocations against STT_IFUNC symbols.
(allocate_dynrelocs): Likewise.
(elf64_x86_64_relocate_section): Likewise.
* elfcode.h (elf_slurp_symbol_table): Translate STT_IFUNC into
BSF_INDIRECT_FUNCTION.
* elflink.c (_bfd_elf_adjust_dynamic_reloc_section): Add support
for STT_IFUNC symbols.
(get_ifunc_reloc_section_name): New function.
(_bfd_elf_make_ifunc_reloc_section): New function.
* elf-bfd.h (struct bfd_elf_section_data): Add indirect_relocs field.
* bfd-in2.h: Regenerate.
gas/ChangeLog
2008-12-03 Nick Clifton <nickc@redhat.com>
* config/obj-elf.c (obj_elf_type): Add support for STT_IFUNC type.
* doc/as.texinfo: Document new feature.
* NEWS: Mention new feature.
gas/testsuite/ChangeLog
2008-12-03 Nick Clifton <nickc@redhat.com>
* gas/elf/type.s: Add test of STT_IFUNC symbol type.
* gas/elf/type.e: Update expected disassembly.
* gas/elf/elf.exp: Update grep of symbol types.
ld/ChangeLog
2008-12-03 Nick Clifton <nickc@redhat.com>
* NEWS: Mention new feature.
* NEWS: Mention new feature.
* pe-dll.c (process_def_file): Replace use of redundant
BFD_FORT_COMM_DEFAULT_VALUE with 0.
* scripttempl/elf.sc: Add .rel.ifunc.dyn and .rela.ifunc.dyn
sections.
ld/testsuite/ChangeLog
2008-12-03 Nick Clifton <nickc@redhat.com>
* ld-mips-elf/reloc-1-n32.d: Updated expected output for reloc
descriptions.
* ld-mips-elf/reloc-1-n64.d: Likewise.
* ld-i386/ifunc.d: New test.
* ld-i386/ifunc.s: Source file for the new test.
* ld-i386/i386.exp: Run the new test.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ifunc.patch
Type: text/x-patch
Size: 62682 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20081203/d7353052/attachment.bin>
More information about the Binutils
mailing list