From e7c3341679431c5ecfc170a984d7196cdc175777 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Wed, 3 Dec 2008 14:51:00 +0000 Subject: [PATCH] include/elf/ * common.h (STT_IFUNC): Define. elfcpp/ * elfcpp.h (enum STT): Add STT_IFUNC. bfd/ * 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/ * 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/ * 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/ * 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/ * 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. --- bfd/ChangeLog | 34 +++++++ bfd/bfd-in2.h | 58 +++++------ bfd/elf-bfd.h | 5 + bfd/elf.c | 7 +- bfd/elf32-arm.c | 8 +- bfd/elf32-i386.c | 65 +++++++++++-- bfd/elf64-x86-64.c | 69 ++++++++++--- bfd/elfcode.h | 3 + bfd/elflink.c | 75 +++++++++++++++ bfd/syms.c | 62 ++++++------ elfcpp/ChangeLog | 4 + elfcpp/elfcpp.h | 3 +- gas/ChangeLog | 6 ++ gas/NEWS | 5 + gas/config/obj-elf.c | 14 +++ gas/doc/as.texinfo | 11 ++- gas/testsuite/ChangeLog | 6 ++ gas/testsuite/gas/elf/elf.exp | 2 +- gas/testsuite/gas/elf/type.e | 1 + gas/testsuite/gas/elf/type.s | 4 + include/elf/ChangeLog | 4 + include/elf/common.h | 1 + ld/ChangeLog | 8 ++ ld/NEWS | 3 + ld/pe-dll.c | 2 +- ld/scripttempl/elf.sc | 8 ++ ld/testsuite/ChangeLog | 9 ++ ld/testsuite/ld-i386/i386.exp | 1 + ld/testsuite/ld-i386/ifunc.d | 14 +++ ld/testsuite/ld-i386/ifunc.s | 128 +++++++++++++++++++++++++ ld/testsuite/ld-mips-elf/reloc-1-n32.d | 70 +++++++------- ld/testsuite/ld-mips-elf/reloc-1-n64.d | 70 +++++++------- 32 files changed, 604 insertions(+), 156 deletions(-) create mode 100644 ld/testsuite/ld-i386/ifunc.d create mode 100644 ld/testsuite/ld-i386/ifunc.s diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 27327e7b676..73615b7a31d 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,37 @@ +2008-12-03 Nick Clifton + + * 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. + 2008-12-02 Tristan Gingold * config.bfd: Add x86_64-*-darwin* diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 917b8bc205c..b1451c9e56a 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -4445,100 +4445,104 @@ typedef struct bfd_symbol symvalue value; /* Attributes of a symbol. */ -#define BSF_NO_FLAGS 0x00 +#define BSF_NO_FLAGS 0x00 /* The symbol has local scope; <> in <>. The value is the offset into the section of the data. */ -#define BSF_LOCAL 0x01 +#define BSF_LOCAL (1 << 0) /* The symbol has global scope; initialized data in <>. The value is the offset into the section of the data. */ -#define BSF_GLOBAL 0x02 +#define BSF_GLOBAL (1 << 1) /* The symbol has global scope and is exported. The value is the offset into the section of the data. */ #define BSF_EXPORT BSF_GLOBAL /* No real difference. */ /* A normal C symbol would be one of: - <>, <>, <> or + <>, <>, <> or <>. */ /* The symbol is a debugging record. The value has an arbitrary meaning, unless BSF_DEBUGGING_RELOC is also set. */ -#define BSF_DEBUGGING 0x08 +#define BSF_DEBUGGING (1 << 2) /* The symbol denotes a function entry point. Used in ELF, perhaps others someday. */ -#define BSF_FUNCTION 0x10 - +#define BSF_FUNCTION (1 << 3) + + /* The symbol is an indirect code object. Unrelated to BSF_INDIRECT. + Relocations against a symbol with this flag have to evaluated at + run-time, where the function pointed to by this symbol is invoked + in order to determine the value to be used in the relocation. + BSF_FUNCTION must also be set for symbols with this flag. */ +#define BSF_INDIRECT_FUNCTION (1 << 4) + /* Used by the linker. */ -#define BSF_KEEP 0x20 -#define BSF_KEEP_G 0x40 +#define BSF_KEEP (1 << 5) +#define BSF_KEEP_G (1 << 6) /* A weak global symbol, overridable without warnings by a regular global symbol of the same name. */ -#define BSF_WEAK 0x80 +#define BSF_WEAK (1 << 7) /* This symbol was created to point to a section, e.g. ELF's STT_SECTION symbols. */ -#define BSF_SECTION_SYM 0x100 +#define BSF_SECTION_SYM (1 << 8) /* The symbol used to be a common symbol, but now it is allocated. */ -#define BSF_OLD_COMMON 0x200 - - /* The default value for common data. */ -#define BFD_FORT_COMM_DEFAULT_VALUE 0 +#define BSF_OLD_COMMON (1 << 9) /* In some files the type of a symbol sometimes alters its location in an output file - ie in coff a <> symbol which is also <> symbol appears where it was declared and not at the end of a section. This bit is set by the target BFD part to convey this information. */ -#define BSF_NOT_AT_END 0x400 +#define BSF_NOT_AT_END (1 << 10) /* Signal that the symbol is the label of constructor section. */ -#define BSF_CONSTRUCTOR 0x800 +#define BSF_CONSTRUCTOR (1 << 11) /* Signal that the symbol is a warning symbol. The name is a warning. The name of the next symbol is the one to warn about; if a reference is made to a symbol with the same name as the next symbol, a warning is issued by the linker. */ -#define BSF_WARNING 0x1000 +#define BSF_WARNING (1 << 12) /* Signal that the symbol is indirect. This symbol is an indirect pointer to the symbol with the same name as the next symbol. */ -#define BSF_INDIRECT 0x2000 +#define BSF_INDIRECT (1 << 13) /* BSF_FILE marks symbols that contain a file name. This is used for ELF STT_FILE symbols. */ -#define BSF_FILE 0x4000 +#define BSF_FILE (1 << 14) /* Symbol is from dynamic linking information. */ -#define BSF_DYNAMIC 0x8000 +#define BSF_DYNAMIC (1 << 15) /* The symbol denotes a data object. Used in ELF, and perhaps others someday. */ -#define BSF_OBJECT 0x10000 +#define BSF_OBJECT (1 << 16) /* This symbol is a debugging symbol. The value is the offset into the section of the data. BSF_DEBUGGING should be set as well. */ -#define BSF_DEBUGGING_RELOC 0x20000 +#define BSF_DEBUGGING_RELOC (1 << 17) /* This symbol is thread local. Used in ELF. */ -#define BSF_THREAD_LOCAL 0x40000 +#define BSF_THREAD_LOCAL (1 << 18) /* This symbol represents a complex relocation expression, with the expression tree serialized in the symbol name. */ -#define BSF_RELC 0x80000 +#define BSF_RELC (1 << 19) /* This symbol represents a signed complex relocation expression, with the expression tree serialized in the symbol name. */ -#define BSF_SRELC 0x100000 +#define BSF_SRELC (1 << 20) /* This symbol was created by bfd_get_synthetic_symtab. */ -#define BSF_SYNTHETIC 0x200000 +#define BSF_SYNTHETIC (1 << 21) flagword flags; diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 5418e7f82ef..effa34478b3 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -1287,6 +1287,9 @@ struct bfd_elf_section_data /* A pointer to the bfd section used for dynamic relocs. */ asection *sreloc; + /* A pointer to the bfd section used for dynamic relocs against ifunc symbols. */ + asection *indirect_relocs; + union { /* Group name, if this section is a member of a group. */ const char *name; @@ -1768,6 +1771,8 @@ extern asection * _bfd_elf_get_dynamic_reloc_section (bfd *, asection *, bfd_boolean); extern asection * _bfd_elf_make_dynamic_reloc_section (asection *, bfd *, unsigned int, bfd *, bfd_boolean); +extern asection * _bfd_elf_make_ifunc_reloc_section + (bfd *, asection *, bfd *, unsigned int); extern long _bfd_elf_get_dynamic_reloc_upper_bound (bfd *); extern long _bfd_elf_canonicalize_dynamic_reloc diff --git a/bfd/elf.c b/bfd/elf.c index 70ed7656d0b..7597d010ca9 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -6427,6 +6427,8 @@ Unable to find equivalent output section for symbol '%s' from section '%s'"), if ((flags & BSF_THREAD_LOCAL) != 0) type = STT_TLS; + else if ((flags & BSF_INDIRECT_FUNCTION) != 0) + type = STT_IFUNC; else if ((flags & BSF_FUNCTION) != 0) type = STT_FUNC; else if ((flags & BSF_OBJECT) != 0) @@ -7120,6 +7122,7 @@ elf_find_function (bfd *abfd ATTRIBUTE_UNUSED, continue; case STT_NOTYPE: case STT_FUNC: + case STT_IFUNC: if (bfd_get_section (&q->symbol) == section && q->symbol.value >= low_func && q->symbol.value <= offset) @@ -8938,10 +8941,10 @@ _bfd_elf_set_osabi (bfd * abfd, /* Return TRUE for ELF symbol types that represent functions. This is the default version of this function, which is sufficient for - most targets. It returns true if TYPE is STT_FUNC. */ + most targets. It returns true if TYPE is STT_FUNC or STT_IFUNC. */ bfd_boolean _bfd_elf_is_function_type (unsigned int type) { - return (type == STT_FUNC); + return (type == STT_FUNC || type == STT_IFUNC); } diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c index cd5a9bfc071..dacbc16c60e 100644 --- a/bfd/elf32-arm.c +++ b/bfd/elf32-arm.c @@ -9430,6 +9430,7 @@ arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED, filename = bfd_asymbol_name (&q->symbol); break; case STT_FUNC: + case STT_IFUNC: case STT_ARM_TFUNC: case STT_NOTYPE: /* Skip mapping symbols. */ @@ -9555,7 +9556,7 @@ elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info, /* If this is a function, put it in the procedure linkage table. We will fill in the contents of the procedure linkage table later, when we know the address of the .got section. */ - if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC + if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC || h->type == STT_IFUNC || h->needs_plt) { if (h->plt.refcount <= 0 @@ -11729,7 +11730,8 @@ elf32_arm_swap_symbol_in (bfd * abfd, /* New EABI objects mark thumb function symbols by setting the low bit of the address. Turn these into STT_ARM_TFUNC. */ - if (ELF_ST_TYPE (dst->st_info) == STT_FUNC + if ((ELF_ST_TYPE (dst->st_info) == STT_FUNC + || ELF_ST_TYPE (dst->st_info) == STT_IFUNC) && (dst->st_value & 1)) { dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC); @@ -11830,7 +11832,7 @@ elf32_arm_additional_program_headers (bfd *abfd, static bfd_boolean elf32_arm_is_function_type (unsigned int type) { - return (type == STT_FUNC) || (type == STT_ARM_TFUNC); + return (type == STT_FUNC) || (type == STT_ARM_TFUNC) || (type == STT_IFUNC); } /* We use this to override swap_symbol_in and swap_symbol_out. */ diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 7d14fef561d..ec0c16fd83e 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -1193,6 +1193,26 @@ elf_i386_tls_transition (struct bfd_link_info *info, bfd *abfd, return TRUE; } +/* Returns true if the hash entry refers to a symbol + marked for indirect handling during reloc processing. */ + +static bfd_boolean +is_indirect_symbol (bfd * abfd, struct elf_link_hash_entry * h) +{ + const struct elf_backend_data * bed; + + if (abfd == NULL || h == NULL) + return FALSE; + + bed = get_elf_backend_data (abfd); + + return h->type == STT_IFUNC + && bed != NULL + && (bed->elf_osabi == ELFOSABI_LINUX + /* GNU/Linux is still using the default value 0. */ + || bed->elf_osabi == ELFOSABI_NONE); +} + /* Look through the relocs for a section during the first phase, and calculate needed space in the global offset table, procedure linkage table, and dynamic reloc sections. */ @@ -1452,7 +1472,8 @@ elf_i386_check_relocs (bfd *abfd, && (sec->flags & SEC_ALLOC) != 0 && h != NULL && (h->root.type == bfd_link_hash_defweak - || !h->def_regular))) + || !h->def_regular)) + || is_indirect_symbol (abfd, h)) { struct elf_i386_dyn_relocs *p; struct elf_i386_dyn_relocs **head; @@ -1472,6 +1493,9 @@ elf_i386_check_relocs (bfd *abfd, return FALSE; } + if (is_indirect_symbol (abfd, h)) + (void) _bfd_elf_make_ifunc_reloc_section (abfd, sec, htab->elf.dynobj, 2); + /* If this is a global symbol, we count the number of relocations we need for this symbol. */ if (h != NULL) @@ -2033,6 +2057,15 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) } } } + else if (is_indirect_symbol (info->output_bfd, h)) + { + if (h->dynindx == -1 + && !h->forced_local) + { + if (! bfd_elf_link_record_dynamic_symbol (info, h)) + return FALSE; + } + } else if (ELIMINATE_COPY_RELOCS) { /* For the non-shared case, discard space for relocs against @@ -2069,7 +2102,15 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) /* Finally, allocate space. */ for (p = eh->dyn_relocs; p != NULL; p = p->next) { - asection *sreloc = elf_section_data (p->sec)->sreloc; + asection *sreloc; + + if (! info->shared + && is_indirect_symbol (info->output_bfd, h)) + sreloc = elf_section_data (p->sec)->indirect_relocs; + else + sreloc = elf_section_data (p->sec)->sreloc; + + BFD_ASSERT (sreloc != NULL); sreloc->size += p->count * sizeof (Elf32_External_Rel); } @@ -2248,7 +2289,7 @@ elf_i386_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, /* Allocate global sym .plt and .got entries, and space for global sym dynamic relocs. */ - elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info); + elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info); /* For every jump slot reserved in the sgotplt, reloc_count is incremented. However, when we reserve space for TLS descriptors, @@ -2361,8 +2402,7 @@ elf_i386_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, /* If any dynamic relocs apply to a read-only section, then we need a DT_TEXTREL entry. */ if ((info->flags & DF_TEXTREL) == 0) - elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, - (PTR) info); + elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, info); if ((info->flags & DF_TEXTREL) != 0) { @@ -2879,7 +2919,8 @@ elf_i386_relocate_section (bfd *output_bfd, && ((h->def_dynamic && !h->def_regular) || h->root.type == bfd_link_hash_undefweak - || h->root.type == bfd_link_hash_undefined))) + || h->root.type == bfd_link_hash_undefined)) + || is_indirect_symbol (output_bfd, h)) { Elf_Internal_Rela outrel; bfd_byte *loc; @@ -2919,19 +2960,23 @@ elf_i386_relocate_section (bfd *output_bfd, outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE); } - sreloc = elf_section_data (input_section)->sreloc; - if (sreloc == NULL) - abort (); + if ((! info->shared) && is_indirect_symbol (output_bfd, h)) + sreloc = elf_section_data (input_section)->indirect_relocs; + else + sreloc = elf_section_data (input_section)->sreloc; + + BFD_ASSERT (sreloc != NULL && sreloc->contents != NULL); loc = sreloc->contents; loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rel); + bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc); /* If this reloc is against an external symbol, we do not want to fiddle with the addend. Otherwise, we need to include the symbol value so that it becomes an addend for the dynamic reloc. */ - if (! relocate) + if (! relocate || is_indirect_symbol (output_bfd, h)) continue; } break; diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 7eecb22ea3a..1ea033bda04 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -974,6 +974,26 @@ elf64_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd, return TRUE; } +/* Returns true if the hash entry refers to a symbol + marked for indirect handling during reloc processing. */ + +static bfd_boolean +is_indirect_symbol (bfd * abfd, struct elf_link_hash_entry * h) +{ + const struct elf_backend_data * bed; + + if (abfd == NULL || h == NULL) + return FALSE; + + bed = get_elf_backend_data (abfd); + + return h->type == STT_IFUNC + && bed != NULL + && (bed->elf_osabi == ELFOSABI_LINUX + /* GNU/Linux is still using the default value 0. */ + || bed->elf_osabi == ELFOSABI_NONE); +} + /* Look through the relocs for a section during the first phase, and calculate needed space in the global offset table, procedure linkage table, and dynamic reloc sections. */ @@ -1255,7 +1275,10 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info, If on the other hand, we are creating an executable, we may need to keep relocations for symbols satisfied by a dynamic library if we manage to avoid copy relocs for the - symbol. */ + symbol. + + Also we must keep any relocations against IFUNC symbols as + they will be evaluated at load time. */ if ((info->shared && (sec->flags & SEC_ALLOC) != 0 && (((r_type != R_X86_64_PC8) @@ -1271,7 +1294,8 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info, && (sec->flags & SEC_ALLOC) != 0 && h != NULL && (h->root.type == bfd_link_hash_defweak - || !h->def_regular))) + || !h->def_regular)) + || is_indirect_symbol (abfd, h)) { struct elf64_x86_64_dyn_relocs *p; struct elf64_x86_64_dyn_relocs **head; @@ -1291,6 +1315,9 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info, return FALSE; } + if (is_indirect_symbol (abfd, h)) + (void) _bfd_elf_make_ifunc_reloc_section (abfd, sec, htab->elf.dynobj, 2); + /* If this is a global symbol, we count the number of relocations we need for this symbol. */ if (h != NULL) @@ -1830,6 +1857,13 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) } } } + else if (is_indirect_symbol (info->output_bfd, h)) + { + if (h->dynindx == -1 + && ! h->forced_local + && ! bfd_elf_link_record_dynamic_symbol (info, h)) + return FALSE; + } else if (ELIMINATE_COPY_RELOCS) { /* For the non-shared case, discard space for relocs against @@ -1866,7 +1900,16 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) /* Finally, allocate space. */ for (p = eh->dyn_relocs; p != NULL; p = p->next) { - asection *sreloc = elf_section_data (p->sec)->sreloc; + asection * sreloc; + + if (! info->shared + && is_indirect_symbol (info->output_bfd, h)) + sreloc = elf_section_data (p->sec)->indirect_relocs; + else + sreloc = elf_section_data (p->sec)->sreloc; + + BFD_ASSERT (sreloc != NULL); + sreloc->size += p->count * sizeof (Elf64_External_Rela); } @@ -1970,7 +2013,6 @@ elf64_x86_64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, srel->size += p->count * sizeof (Elf64_External_Rela); if ((p->sec->output_section->flags & SEC_READONLY) != 0) info->flags |= DF_TEXTREL; - } } } @@ -2039,7 +2081,7 @@ elf64_x86_64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, /* Allocate global sym .plt and .got entries, and space for global sym dynamic relocs. */ - elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info); + elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info); /* For every jump slot reserved in the sgotplt, reloc_count is incremented. However, when we reserve space for TLS descriptors, @@ -2170,8 +2212,7 @@ elf64_x86_64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, /* If any dynamic relocs apply to a read-only section, then we need a DT_TEXTREL entry. */ if ((info->flags & DF_TEXTREL) == 0) - elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, - (PTR) info); + elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, info); if ((info->flags & DF_TEXTREL) != 0) { @@ -2680,7 +2721,8 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info, && ((h->def_dynamic && !h->def_regular) || h->root.type == bfd_link_hash_undefweak - || h->root.type == bfd_link_hash_undefined))) + || h->root.type == bfd_link_hash_undefined)) + || is_indirect_symbol (output_bfd, h)) { Elf_Internal_Rela outrel; bfd_byte *loc; @@ -2766,9 +2808,12 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info, } } - sreloc = elf_section_data (input_section)->sreloc; - if (sreloc == NULL) - abort (); + if ((! info->shared) && is_indirect_symbol (output_bfd, h)) + sreloc = elf_section_data (input_section)->indirect_relocs; + else + sreloc = elf_section_data (input_section)->sreloc; + + BFD_ASSERT (sreloc != NULL && sreloc->contents != NULL); loc = sreloc->contents; loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela); @@ -2778,7 +2823,7 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info, not want to fiddle with the addend. Otherwise, we need to include the symbol value so that it becomes an addend for the dynamic reloc. */ - if (! relocate) + if (! relocate || is_indirect_symbol (output_bfd, h)) continue; } diff --git a/bfd/elfcode.h b/bfd/elfcode.h index b42229f007b..cd8ffe4d805 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -1311,6 +1311,9 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bfd_boolean dynamic) case STT_SRELC: sym->symbol.flags |= BSF_SRELC; break; + case STT_IFUNC: + sym->symbol.flags |= BSF_INDIRECT_FUNCTION; + break; } if (dynamic) diff --git a/bfd/elflink.c b/bfd/elflink.c index 43379c71a6e..952b4e0bb97 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -2652,6 +2652,13 @@ _bfd_elf_adjust_dynamic_symbol (struct elf_link_hash_entry *h, void *data) dynobj = elf_hash_table (eif->info)->dynobj; bed = get_elf_backend_data (dynobj); + + if (h->type == STT_IFUNC + && (bed->elf_osabi == ELFOSABI_LINUX + /* GNU/Linux is still using the default value 0. */ + || bed->elf_osabi == ELFOSABI_NONE)) + h->needs_plt = 1; + if (! (*bed->elf_backend_adjust_dynamic_symbol) (eif->info, h)) { eif->failed = TRUE; @@ -12400,3 +12407,71 @@ _bfd_elf_make_dynamic_reloc_section (asection * sec, return reloc_sec; } + +#define IFUNC_INFIX ".ifunc" + +/* Returns the name of the ifunc-using-dynamic-reloc section associated with SEC. */ + +static const char * +get_ifunc_reloc_section_name (bfd * abfd, + asection * sec) +{ + const char * dot; + char * name; + const char * base_name; + unsigned int strndx = elf_elfheader (abfd)->e_shstrndx; + unsigned int shnam = elf_section_data (sec)->rel_hdr.sh_name; + + base_name = bfd_elf_string_from_elf_section (abfd, strndx, shnam); + if (base_name == NULL) + return NULL; + + dot = strchr (base_name + 1, '.'); + name = bfd_alloc (abfd, strlen (base_name) + strlen (IFUNC_INFIX) + 1); + sprintf (name, "%.*s%s%s", (int)(dot - base_name), base_name, IFUNC_INFIX, dot); + + return name; +} + +/* Like _bfd_elf_make_dynamic_reloc_section but it creates a + section for holding relocs against symbols with the STT_IFUNC + type. The section is attached to the OWNER bfd but it is created + with a name based on SEC from ABFD. */ + +asection * +_bfd_elf_make_ifunc_reloc_section (bfd * abfd, + asection * sec, + bfd * owner, + unsigned int align) +{ + asection * reloc_sec = elf_section_data (sec)->indirect_relocs; + + if (reloc_sec == NULL) + { + const char * name = get_ifunc_reloc_section_name (abfd, sec); + + if (name == NULL) + return NULL; + + reloc_sec = bfd_get_section_by_name (owner, name); + + if (reloc_sec == NULL) + { + flagword flags; + + flags = (SEC_HAS_CONTENTS | SEC_READONLY | SEC_IN_MEMORY | SEC_LINKER_CREATED); + if ((sec->flags & SEC_ALLOC) != 0) + flags |= SEC_ALLOC | SEC_LOAD; + + reloc_sec = bfd_make_section_with_flags (owner, name, flags); + + if (reloc_sec != NULL + && ! bfd_set_section_alignment (owner, reloc_sec, align)) + reloc_sec = NULL; + } + + elf_section_data (sec)->indirect_relocs = reloc_sec; + } + + return reloc_sec; +} diff --git a/bfd/syms.c b/bfd/syms.c index 371916b9404..9b4c6524497 100644 --- a/bfd/syms.c +++ b/bfd/syms.c @@ -1,6 +1,6 @@ /* Generic symbol-table support for the BFD library. Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, - 2000, 2001, 2002, 2003, 2004, 2007 + 2000, 2001, 2002, 2003, 2004, 2007, 2008 Free Software Foundation, Inc. Written by Cygnus Support. @@ -205,100 +205,104 @@ CODE_FRAGMENT . symvalue value; . . {* Attributes of a symbol. *} -.#define BSF_NO_FLAGS 0x00 +.#define BSF_NO_FLAGS 0x00 . . {* The symbol has local scope; <> in <>. The value . is the offset into the section of the data. *} -.#define BSF_LOCAL 0x01 +.#define BSF_LOCAL (1 << 0) . . {* The symbol has global scope; initialized data in <>. The . value is the offset into the section of the data. *} -.#define BSF_GLOBAL 0x02 +.#define BSF_GLOBAL (1 << 1) . . {* The symbol has global scope and is exported. The value is . the offset into the section of the data. *} .#define BSF_EXPORT BSF_GLOBAL {* No real difference. *} . . {* A normal C symbol would be one of: -. <>, <>, <> or +. <>, <>, <> or . <>. *} . . {* The symbol is a debugging record. The value has an arbitrary . meaning, unless BSF_DEBUGGING_RELOC is also set. *} -.#define BSF_DEBUGGING 0x08 +.#define BSF_DEBUGGING (1 << 2) . . {* The symbol denotes a function entry point. Used in ELF, . perhaps others someday. *} -.#define BSF_FUNCTION 0x10 +.#define BSF_FUNCTION (1 << 3) . +. {* The symbol is an indirect code object. Unrelated to BSF_INDIRECT. +. Relocations against a symbol with this flag have to evaluated at +. run-time, where the function pointed to by this symbol is invoked +. in order to determine the value to be used in the relocation. +. BSF_FUNCTION must also be set for symbols with this flag. *} +.#define BSF_INDIRECT_FUNCTION (1 << 4) +. . {* Used by the linker. *} -.#define BSF_KEEP 0x20 -.#define BSF_KEEP_G 0x40 +.#define BSF_KEEP (1 << 5) +.#define BSF_KEEP_G (1 << 6) . . {* A weak global symbol, overridable without warnings by . a regular global symbol of the same name. *} -.#define BSF_WEAK 0x80 +.#define BSF_WEAK (1 << 7) . . {* This symbol was created to point to a section, e.g. ELF's . STT_SECTION symbols. *} -.#define BSF_SECTION_SYM 0x100 +.#define BSF_SECTION_SYM (1 << 8) . . {* The symbol used to be a common symbol, but now it is . allocated. *} -.#define BSF_OLD_COMMON 0x200 -. -. {* The default value for common data. *} -.#define BFD_FORT_COMM_DEFAULT_VALUE 0 +.#define BSF_OLD_COMMON (1 << 9) . . {* In some files the type of a symbol sometimes alters its . location in an output file - ie in coff a <> symbol . which is also <> symbol appears where it was . declared and not at the end of a section. This bit is set . by the target BFD part to convey this information. *} -.#define BSF_NOT_AT_END 0x400 +.#define BSF_NOT_AT_END (1 << 10) . . {* Signal that the symbol is the label of constructor section. *} -.#define BSF_CONSTRUCTOR 0x800 +.#define BSF_CONSTRUCTOR (1 << 11) . . {* Signal that the symbol is a warning symbol. The name is a . warning. The name of the next symbol is the one to warn about; . if a reference is made to a symbol with the same name as the next . symbol, a warning is issued by the linker. *} -.#define BSF_WARNING 0x1000 +.#define BSF_WARNING (1 << 12) . . {* Signal that the symbol is indirect. This symbol is an indirect . pointer to the symbol with the same name as the next symbol. *} -.#define BSF_INDIRECT 0x2000 +.#define BSF_INDIRECT (1 << 13) . . {* BSF_FILE marks symbols that contain a file name. This is used . for ELF STT_FILE symbols. *} -.#define BSF_FILE 0x4000 +.#define BSF_FILE (1 << 14) . . {* Symbol is from dynamic linking information. *} -.#define BSF_DYNAMIC 0x8000 +.#define BSF_DYNAMIC (1 << 15) . . {* The symbol denotes a data object. Used in ELF, and perhaps . others someday. *} -.#define BSF_OBJECT 0x10000 +.#define BSF_OBJECT (1 << 16) . . {* This symbol is a debugging symbol. The value is the offset . into the section of the data. BSF_DEBUGGING should be set . as well. *} -.#define BSF_DEBUGGING_RELOC 0x20000 +.#define BSF_DEBUGGING_RELOC (1 << 17) . . {* This symbol is thread local. Used in ELF. *} -.#define BSF_THREAD_LOCAL 0x40000 +.#define BSF_THREAD_LOCAL (1 << 18) . . {* This symbol represents a complex relocation expression, . with the expression tree serialized in the symbol name. *} -.#define BSF_RELC 0x80000 +.#define BSF_RELC (1 << 19) . . {* This symbol represents a signed complex relocation expression, . with the expression tree serialized in the symbol name. *} -.#define BSF_SRELC 0x100000 +.#define BSF_SRELC (1 << 20) . . {* This symbol was created by bfd_get_synthetic_symtab. *} -.#define BSF_SYNTHETIC 0x200000 +.#define BSF_SYNTHETIC (1 << 21) . . flagword flags; . @@ -486,7 +490,7 @@ bfd_print_symbol_vandf (bfd *abfd, void *arg, asymbol *symbol) (type & BSF_WEAK) ? 'w' : ' ', (type & BSF_CONSTRUCTOR) ? 'C' : ' ', (type & BSF_WARNING) ? 'W' : ' ', - (type & BSF_INDIRECT) ? 'I' : ' ', + (type & BSF_INDIRECT) ? 'I' : (type & BSF_INDIRECT_FUNCTION) ? 'i' : ' ', (type & BSF_DEBUGGING) ? 'd' : (type & BSF_DYNAMIC) ? 'D' : ' ', ((type & BSF_FUNCTION) ? 'F' @@ -672,6 +676,8 @@ bfd_decode_symclass (asymbol *symbol) } if (bfd_is_ind_section (symbol->section)) return 'I'; + if (symbol->flags & BSF_INDIRECT_FUNCTION) + return 'i'; if (symbol->flags & BSF_WEAK) { /* If weak, determine if it's specifically an object diff --git a/elfcpp/ChangeLog b/elfcpp/ChangeLog index 949ffeb3454..830cd6fb5d4 100644 --- a/elfcpp/ChangeLog +++ b/elfcpp/ChangeLog @@ -1,3 +1,7 @@ +2008-12-03 Nick Clifton + + * elfcpp.h (enum STT): Add STT_IFUNC. + 2008-06-12 David S. Miller * powerpc.h: New file. diff --git a/elfcpp/elfcpp.h b/elfcpp/elfcpp.h index 080eef15202..739ca1d00f3 100644 --- a/elfcpp/elfcpp.h +++ b/elfcpp/elfcpp.h @@ -1,6 +1,6 @@ // elfcpp.h -- main header file for elfcpp -*- C++ -*- -// Copyright 2006, 2007, Free Software Foundation, Inc. +// Copyright 2006, 2007, 2008, Free Software Foundation, Inc. // Written by Ian Lance Taylor . // This file is part of elfcpp. @@ -476,6 +476,7 @@ enum STT STT_COMMON = 5, STT_TLS = 6, STT_LOOS = 10, + STT_IFUNC = 10, STT_HIOS = 12, STT_LOPROC = 13, STT_HIPROC = 15, diff --git a/gas/ChangeLog b/gas/ChangeLog index d89a87e9464..c2abca58ad9 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,9 @@ +2008-12-03 Nick Clifton + + * config/obj-elf.c (obj_elf_type): Add support for STT_IFUNC type. + * doc/as.texinfo: Document new feature. + * NEWS: Mention new feature. + 2008-11-29 Kai Tietz * config/tc-i386.c (i386_target_format): For coff flavour in TE_PEP diff --git a/gas/NEWS b/gas/NEWS index 16324d6ce3a..327782f2985 100644 --- a/gas/NEWS +++ b/gas/NEWS @@ -1,5 +1,10 @@ -*- text -*- +* The .type pseudo-op now accepts a type of STT_IFUNC which can be used to + indicate that if the symbol is the target of a relocation, its value should + not be used. Instead the function should be invoked and its result used as + the value. + Changes in 2.19: * New pseudo op .cfi_val_encoded_addr, to record constant addresses in unwind diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c index cf3177087ab..0f0c7d30406 100644 --- a/gas/config/obj-elf.c +++ b/gas/config/obj-elf.c @@ -1663,6 +1663,20 @@ obj_elf_type (int ignore ATTRIBUTE_UNUSED) } } } + else if (strcmp (typename, "indirect_function") == 0 + || strcmp (typename, "10") == 0 + || strcmp (typename, "STT_IFUNC") == 0) + { + const struct elf_backend_data *bed; + + bed = get_elf_backend_data (stdoutput); + if (!(bed->elf_osabi == ELFOSABI_LINUX + /* GNU/Linux is still using the default value 0. */ + || bed->elf_osabi == ELFOSABI_NONE)) + as_bad (_("symbol type \"%s\" is supported only by GNU targets"), + typename); + type = BSF_FUNCTION | BSF_INDIRECT_FUNCTION; + } #ifdef md_elf_symbol_type else if ((type = md_elf_symbol_type (typename, sym, elfsym)) != -1) ; diff --git a/gas/doc/as.texinfo b/gas/doc/as.texinfo index fef736a21bd..5a655a5bfa1 100644 --- a/gas/doc/as.texinfo +++ b/gas/doc/as.texinfo @@ -6267,7 +6267,7 @@ The syntaxes supported are: .type STT_ .type ,# .type ,@@ - .type ,%>type> + .type ,% .type ,"" @end smallexample @@ -6289,6 +6289,15 @@ Mark the symbol as being a thead-local data object. @item STT_COMMON @itemx common Mark the symbol as being a common data object. + +@item STT_NOTYPE +@itemx notype +Does not mark the symbol in any way. It is supported just for completeness. + +@item STT_IFUNC +@itemx indirect_function +Mark the symbol as an indirect function when evaluated during reloc +processing. (This is only supported on Linux targeted assemblers). @end table Note: Some targets support extra types in addition to those listed above. diff --git a/gas/testsuite/ChangeLog b/gas/testsuite/ChangeLog index 60b8c907cee..523275aa66c 100644 --- a/gas/testsuite/ChangeLog +++ b/gas/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2008-12-03 Nick Clifton + + * 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. + 2008-11-27 M R Swami Reddy * gas/cr16/pic-1.s: New. diff --git a/gas/testsuite/gas/elf/elf.exp b/gas/testsuite/gas/elf/elf.exp index 55069035c76..637ce9a7d82 100644 --- a/gas/testsuite/gas/elf/elf.exp +++ b/gas/testsuite/gas/elf/elf.exp @@ -114,7 +114,7 @@ if { ([istarget "*-*-*elf*"] run_elf_list_test "section5" "" "-al" "-SW" "| grep \" \\\\.test\\\[0-9\\\]\"" run_dump_test "struct" run_dump_test "symver" - run_elf_list_test "type" "" "" "-s" "| grep \"1 \\\[FONTC\\\]\"" + run_elf_list_test "type" "" "" "-s" "| grep \"1 \\\[FIONTC\\\]\"" run_dump_test "section6" run_dump_test "section7" } diff --git a/gas/testsuite/gas/elf/type.e b/gas/testsuite/gas/elf/type.e index 50a49ab9572..2eb352d1d06 100644 --- a/gas/testsuite/gas/elf/type.e +++ b/gas/testsuite/gas/elf/type.e @@ -1,4 +1,5 @@ .: 0+0 1 FUNC LOCAL DEFAULT . function + .: 0+1 1 IFUNC LOCAL DEFAULT . indirect_function .: 0+0 1 OBJECT LOCAL DEFAULT . object .: 0+1 1 TLS LOCAL DEFAULT . tls_object .: 0+2 1 NOTYPE LOCAL DEFAULT . notype diff --git a/gas/testsuite/gas/elf/type.s b/gas/testsuite/gas/elf/type.s index 11f75bf53c7..5a6476cd20c 100644 --- a/gas/testsuite/gas/elf/type.s +++ b/gas/testsuite/gas/elf/type.s @@ -2,6 +2,10 @@ .size function,1 .type function,%function function: + .byte 0x0 + .size indirect_function,1 + .type indirect_function,%indirect_function +indirect_function: .byte 0x0 .data .type object,%object diff --git a/include/elf/ChangeLog b/include/elf/ChangeLog index 23b6ee147a3..23434c70fe3 100644 --- a/include/elf/ChangeLog +++ b/include/elf/ChangeLog @@ -1,3 +1,7 @@ +2008-12-03 Nick Clifton + + * common.h (STT_IFUNC): Define. + 2008-11-27 M R Swami Reddy * cr16.h (R_CR16_GOT_REGREL20, R_CR16_GOTC_REGREL20 and diff --git a/include/elf/common.h b/include/elf/common.h index 5a0c322996d..2424e64549d 100644 --- a/include/elf/common.h +++ b/include/elf/common.h @@ -546,6 +546,7 @@ #define STT_RELC 8 /* Complex relocation expression */ #define STT_SRELC 9 /* Signed Complex relocation expression */ #define STT_LOOS 10 /* OS-specific semantics */ +#define STT_IFUNC 10 /* Symbol is an indirect code object */ #define STT_HIOS 12 /* OS-specific semantics */ #define STT_LOPROC 13 /* Application-specific semantics */ #define STT_HIPROC 15 /* Application-specific semantics */ diff --git a/ld/ChangeLog b/ld/ChangeLog index 2adfb63ef27..b7d0cf2f00e 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,11 @@ +2008-12-03 Nick Clifton + + * 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. + 2008-12-02 Kai Tietz * pe-dll.c (make_runtime_pseudo_reloc): Make symtab big enough to diff --git a/ld/NEWS b/ld/NEWS index e838b4ddd41..4c7dc1e6dd9 100644 --- a/ld/NEWS +++ b/ld/NEWS @@ -1,4 +1,7 @@ -*- text -*- +* For GNU/Linux systems the linker will now forego processing any relocations + made against symbols of the STT_IFUNC type and instead emit them into + the resulting binary for processing by the loader. * Add CR16 ELF --embedded-relocs (used to embedded relocations into binaries for Embedded-PIC code) option. diff --git a/ld/pe-dll.c b/ld/pe-dll.c index 3e670680a8e..f5aa9dd19c6 100644 --- a/ld/pe-dll.c +++ b/ld/pe-dll.c @@ -633,7 +633,7 @@ process_def_file (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *info) We should not export undefined symbols. */ if (symbols[j]->section != &bfd_und_section && ((symbols[j]->flags & BSF_GLOBAL) - || (symbols[j]->flags == BFD_FORT_COMM_DEFAULT_VALUE))) + || (symbols[j]->flags == 0))) { const char *sn = symbols[j]->name; diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc index 120db064903..bb8c8080b26 100644 --- a/ld/scripttempl/elf.sc +++ b/ld/scripttempl/elf.sc @@ -333,12 +333,20 @@ EOF sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/ \1/' $COMBRELOC >> ldscripts/dyntmp.$$ cat >> ldscripts/dyntmp.$$ <> ldscripts/dyntmp.$$ cat >> ldscripts/dyntmp.$$ < + + * 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. + 2008-11-25 Joseph Myers * ld-arm/thumb2-bl-undefweak.d, ld-arm/thumb2-bl-undefweak.s: New. diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp index 6f75f3ae375..0446f18fff0 100644 --- a/ld/testsuite/ld-i386/i386.exp +++ b/ld/testsuite/ld-i386/i386.exp @@ -138,3 +138,4 @@ run_dump_test "hidden3" run_dump_test "protected1" run_dump_test "protected2" run_dump_test "protected3" +run_dump_test "ifunc" diff --git a/ld/testsuite/ld-i386/ifunc.d b/ld/testsuite/ld-i386/ifunc.d new file mode 100644 index 00000000000..4edf95d7282 --- /dev/null +++ b/ld/testsuite/ld-i386/ifunc.d @@ -0,0 +1,14 @@ +#name: Generatiion of dynamic relocs for STT_IFUNC symbols +#source: ifunc.s +#as: --32 +#ld: -melf_i386 -lc --defsym _start=0 -L/usr/lib +#readelf: --relocs --syms + +Relocation section '.rel.ifunc.dyn' at offset 0x[0-9a-f]+ contains 2 entries: + Offset Info Type Sym.Value Sym. Name +[0-9a-f]+ 00000202 R_386_PC32 func\(\) func +[0-9a-f]+ 00000102 R_386_PC32 long_fun\(\) long_func_name +#... + ..: 080482e0 29 IFUNC GLOBAL DEFAULT 10 long_func_name + ..: 08048300 29 IFUNC GLOBAL DEFAULT 10 func +#pass diff --git a/ld/testsuite/ld-i386/ifunc.s b/ld/testsuite/ld-i386/ifunc.s new file mode 100644 index 00000000000..3f34cfbfb5a --- /dev/null +++ b/ld/testsuite/ld-i386/ifunc.s @@ -0,0 +1,128 @@ + .file "ifunc.c" +#APP + .type func, %indirect_function + .type long_func_name, %indirect_function + .section .rodata.str1.1,"aMS",@progbits,1 +.LC0: + .string "arg is %d\n" +#NO_APP + .text + .p2align 4,,15 +.globl bar + .type bar, @function +bar: + pushl %ebp + movl %esp, %ebp + subl $8, %esp + movl 8(%ebp), %eax + movl $.LC0, (%esp) + movl %eax, 4(%esp) + call printf + leave + ret + .size bar, .-bar + .section .rodata.str1.1 +.LC1: + .string "main: calling func" + .section .rodata.str1.4,"aMS",@progbits,1 + .align 4 +.LC2: + .string "main: func finished, calling long_func_name" + .section .rodata.str1.1 +.LC3: + .string "main: long_func_name finished" + .text + .p2align 4,,15 +.globl main + .type main, @function +main: + leal 4(%esp), %ecx + andl $-16, %esp + pushl -4(%ecx) + pushl %ebp + movl %esp, %ebp + pushl %ecx + subl $4, %esp + movl $.LC1, (%esp) + call puts + call func + movl $.LC2, (%esp) + call puts + call long_func_name + movl $.LC3, (%esp) + call puts + addl $4, %esp + xorl %eax, %eax + popl %ecx + popl %ebp + leal -4(%ecx), %esp + ret + .size main, .-main + .p2align 4,,15 +.globl long_func_name + .type long_func_name, @function +long_func_name: + pushl %ebp + movl %esp, %ebp + subl $8, %esp + call rand + movl $func0, %edx + testl %eax, %eax + jne .L7 + movl $func1, %edx +.L7: + movl %edx, %eax + leave + ret + .size long_func_name, .-long_func_name + .p2align 4,,15 +.globl func + .type func, @function +func: + pushl %ebp + movl %esp, %ebp + subl $8, %esp + call rand + movl $func0, %edx + testl %eax, %eax + jne .L12 + movl $func1, %edx +.L12: + movl %edx, %eax + leave + ret + .size func, .-func + .section .rodata.str1.1 +.LC4: + .string "func1\n" + .text + .p2align 4,,15 +.globl func1 + .type func1, @function +func1: + pushl %ebp + movl %esp, %ebp + subl $8, %esp + movl $.LC4, (%esp) + call puts + leave + ret + .size func1, .-func1 + .section .rodata.str1.1 +.LC5: + .string "func0\n" + .text + .p2align 4,,15 +.globl func0 + .type func0, @function +func0: + pushl %ebp + movl %esp, %ebp + subl $8, %esp + movl $.LC5, (%esp) + call puts + leave + ret + .size func0, .-func0 + .ident "GCC: (GNU) 4.3.0 20080428 (Red Hat 4.3.0-8)" + .section .note.GNU-stack,"",@progbits diff --git a/ld/testsuite/ld-mips-elf/reloc-1-n32.d b/ld/testsuite/ld-mips-elf/reloc-1-n32.d index dd41822d502..87a55f9226e 100644 --- a/ld/testsuite/ld-mips-elf/reloc-1-n32.d +++ b/ld/testsuite/ld-mips-elf/reloc-1-n32.d @@ -8,10 +8,10 @@ Relocation section '\.rela\.text' .* # # Relocations against tstarta # -.* R_MIPS_HI16 .* \.text \+ ffff7ff0 -.* R_MIPS_LO16 .* \.text \+ ffff7ff0 -.* R_MIPS_HI16 .* \.text \+ ffff8000 -.* R_MIPS_LO16 .* \.text \+ ffff8000 +.* R_MIPS_HI16 .* \.text \- 8010 +.* R_MIPS_LO16 .* \.text \- 8010 +.* R_MIPS_HI16 .* \.text \- 8000 +.* R_MIPS_LO16 .* \.text \- 8000 .* R_MIPS_HI16 .* \.text \+ 0 .* R_MIPS_LO16 .* \.text \+ 0 .* R_MIPS_HI16 .* \.text \+ 7ff0 @@ -21,10 +21,10 @@ Relocation section '\.rela\.text' .* # # Relocations against t32a # -.* R_MIPS_HI16 .* \.text \+ ffff8010 -.* R_MIPS_LO16 .* \.text \+ ffff8010 -.* R_MIPS_HI16 .* \.text \+ ffff8020 -.* R_MIPS_LO16 .* \.text \+ ffff8020 +.* R_MIPS_HI16 .* \.text \- 7ff0 +.* R_MIPS_LO16 .* \.text \- 7ff0 +.* R_MIPS_HI16 .* \.text \- 7fe0 +.* R_MIPS_LO16 .* \.text \- 7fe0 .* R_MIPS_HI16 .* \.text \+ 20 .* R_MIPS_LO16 .* \.text \+ 20 .* R_MIPS_HI16 .* \.text \+ 8010 @@ -34,10 +34,10 @@ Relocation section '\.rela\.text' .* # # Relocations against _start # -.* R_MIPS_HI16 .* _start \+ ffff7ff0 -.* R_MIPS_LO16 .* _start \+ ffff7ff0 -.* R_MIPS_HI16 .* _start \+ ffff8000 -.* R_MIPS_LO16 .* _start \+ ffff8000 +.* R_MIPS_HI16 .* _start \- 8010 +.* R_MIPS_LO16 .* _start \- 8010 +.* R_MIPS_HI16 .* _start \- 8000 +.* R_MIPS_LO16 .* _start \- 8000 .* R_MIPS_HI16 .* _start \+ 0 .* R_MIPS_LO16 .* _start \+ 0 .* R_MIPS_HI16 .* _start \+ 7ff0 @@ -47,10 +47,10 @@ Relocation section '\.rela\.text' .* # # Relocations against tstarta # -.* R_MIPS_GOT16 .* \.text \+ ffff7ff0 -.* R_MIPS_LO16 .* \.text \+ ffff7ff0 -.* R_MIPS_GOT16 .* \.text \+ ffff8000 -.* R_MIPS_LO16 .* \.text \+ ffff8000 +.* R_MIPS_GOT16 .* \.text \- 8010 +.* R_MIPS_LO16 .* \.text \- 8010 +.* R_MIPS_GOT16 .* \.text \- 8000 +.* R_MIPS_LO16 .* \.text \- 8000 .* R_MIPS_GOT16 .* \.text \+ 0 .* R_MIPS_LO16 .* \.text \+ 0 .* R_MIPS_GOT16 .* \.text \+ 7ff0 @@ -60,10 +60,10 @@ Relocation section '\.rela\.text' .* # # Relocations against t32a # -.* R_MIPS_GOT16 .* \.text \+ ffff8010 -.* R_MIPS_LO16 .* \.text \+ ffff8010 -.* R_MIPS_GOT16 .* \.text \+ ffff8020 -.* R_MIPS_LO16 .* \.text \+ ffff8020 +.* R_MIPS_GOT16 .* \.text \- 7ff0 +.* R_MIPS_LO16 .* \.text \- 7ff0 +.* R_MIPS_GOT16 .* \.text \- 7fe0 +.* R_MIPS_LO16 .* \.text \- 7fe0 .* R_MIPS_GOT16 .* \.text \+ 20 .* R_MIPS_LO16 .* \.text \+ 20 .* R_MIPS_GOT16 .* \.text \+ 8010 @@ -73,20 +73,20 @@ Relocation section '\.rela\.text' .* # # Relocations against sdg # -.* R_MIPS_GPREL16 .* sdg \+ fffffffc +.* R_MIPS_GPREL16 .* sdg \- 4 .* R_MIPS_GPREL16 .* sdg \+ 0 .* R_MIPS_GPREL16 .* sdg \+ 4 # # Relocations against sdla. .sdata should be the first piece of gp-relative # data, which the linker script should put _gp - 0x7ff0. # -.* R_MIPS_GPREL16 .* \.sdata \+ ffff801c -.* R_MIPS_GPREL16 .* \.sdata \+ ffff8020 -.* R_MIPS_GPREL16 .* \.sdata \+ ffff8024 +.* R_MIPS_GPREL16 .* \.sdata \- 7fe4 +.* R_MIPS_GPREL16 .* \.sdata \- 7fe0 +.* R_MIPS_GPREL16 .* \.sdata \- 7fdc # # Relocations against tstarta # -.* R_MIPS_26 .* \.text \+ fffffffc +.* R_MIPS_26 .* \.text \- 4 .* R_MIPS_26 .* \.text \+ 0 .* R_MIPS_26 .* \.text \+ 4 # @@ -98,7 +98,7 @@ Relocation section '\.rela\.text' .* # # Relocations against _start # -.* R_MIPS_26 .* _start \+ fffffffc +.* R_MIPS_26 .* _start \- 4 .* R_MIPS_26 .* _start \+ 0 .* R_MIPS_26 .* _start \+ 4 # @@ -130,10 +130,10 @@ Relocation section '\.rela\.text' .* # # Relocations against _start # -.* R_MIPS_HI16 .* _start \+ ffff7ff0 -.* R_MIPS_LO16 .* _start \+ ffff7ff0 -.* R_MIPS_HI16 .* _start \+ ffff8000 -.* R_MIPS_LO16 .* _start \+ ffff8000 +.* R_MIPS_HI16 .* _start \- 8010 +.* R_MIPS_LO16 .* _start \- 8010 +.* R_MIPS_HI16 .* _start \- 8000 +.* R_MIPS_LO16 .* _start \- 8000 .* R_MIPS_HI16 .* _start \+ 0 .* R_MIPS_LO16 .* _start \+ 0 .* R_MIPS_HI16 .* _start \+ 7ff0 @@ -169,15 +169,15 @@ Relocation section '\.rela\.text' .* # # Relocations against sdg # -.* R_MIPS_GPREL16 .* sdg \+ fffffffc +.* R_MIPS_GPREL16 .* sdg \- 4 .* R_MIPS_GPREL16 .* sdg \+ 0 .* R_MIPS_GPREL16 .* sdg \+ 4 # # Relocations against sdlb # -.* R_MIPS_GPREL16 .* \.sdata \+ ffff803c -.* R_MIPS_GPREL16 .* \.sdata \+ ffff8040 -.* R_MIPS_GPREL16 .* \.sdata \+ ffff8044 +.* R_MIPS_GPREL16 .* \.sdata \- 7fc4 +.* R_MIPS_GPREL16 .* \.sdata \- 7fc0 +.* R_MIPS_GPREL16 .* \.sdata \- 7fbc # # Relocations against tstartb # @@ -193,7 +193,7 @@ Relocation section '\.rela\.text' .* # # Relocations against _start # -.* R_MIPS_26 .* _start \+ fffffffc +.* R_MIPS_26 .* _start \- 4 .* R_MIPS_26 .* _start \+ 0 .* R_MIPS_26 .* _start \+ 4 #pass diff --git a/ld/testsuite/ld-mips-elf/reloc-1-n64.d b/ld/testsuite/ld-mips-elf/reloc-1-n64.d index 42d74ea6be2..2cfbe9a5250 100644 --- a/ld/testsuite/ld-mips-elf/reloc-1-n64.d +++ b/ld/testsuite/ld-mips-elf/reloc-1-n64.d @@ -8,16 +8,16 @@ Relocation section '\.rela\.text' .* # # Relocations against tstarta # -.* R_MIPS_HI16 .* \.text \+ f+7ff0 +.* R_MIPS_HI16 .* \.text \- 8010 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_LO16 .* \.text \+ f+7ff0 +.* R_MIPS_LO16 .* \.text \- 8010 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_HI16 .* \.text \+ f+8000 +.* R_MIPS_HI16 .* \.text \- 8000 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_LO16 .* \.text \+ f+8000 +.* R_MIPS_LO16 .* \.text \- 8000 .* R_MIPS_NONE * .* R_MIPS_NONE * .* R_MIPS_HI16 .* \.text \+ 0 @@ -41,16 +41,16 @@ Relocation section '\.rela\.text' .* # # Relocations against t32a # -.* R_MIPS_HI16 .* \.text \+ f+8010 +.* R_MIPS_HI16 .* \.text \- 7ff0 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_LO16 .* \.text \+ f+8010 +.* R_MIPS_LO16 .* \.text \- 7ff0 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_HI16 .* \.text \+ f+8020 +.* R_MIPS_HI16 .* \.text \- 7fe0 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_LO16 .* \.text \+ f+8020 +.* R_MIPS_LO16 .* \.text \- 7fe0 .* R_MIPS_NONE * .* R_MIPS_NONE * .* R_MIPS_HI16 .* \.text \+ 20 @@ -74,16 +74,16 @@ Relocation section '\.rela\.text' .* # # Relocations against _start # -.* R_MIPS_HI16 .* _start \+ f+7ff0 +.* R_MIPS_HI16 .* _start \- 8010 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_LO16 .* _start \+ f+7ff0 +.* R_MIPS_LO16 .* _start \- 8010 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_HI16 .* _start \+ f+8000 +.* R_MIPS_HI16 .* _start \- 8000 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_LO16 .* _start \+ f+8000 +.* R_MIPS_LO16 .* _start \- 8000 .* R_MIPS_NONE * .* R_MIPS_NONE * .* R_MIPS_HI16 .* _start \+ 0 @@ -107,16 +107,16 @@ Relocation section '\.rela\.text' .* # # Relocations against tstarta # -.* R_MIPS_GOT16 .* \.text \+ f+7ff0 +.* R_MIPS_GOT16 .* \.text \- 8010 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_LO16 .* \.text \+ f+7ff0 +.* R_MIPS_LO16 .* \.text \- 8010 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_GOT16 .* \.text \+ f+8000 +.* R_MIPS_GOT16 .* \.text \- 8000 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_LO16 .* \.text \+ f+8000 +.* R_MIPS_LO16 .* \.text \- 8000 .* R_MIPS_NONE * .* R_MIPS_NONE * .* R_MIPS_GOT16 .* \.text \+ 0 @@ -140,16 +140,16 @@ Relocation section '\.rela\.text' .* # # Relocations against t32a # -.* R_MIPS_GOT16 .* \.text \+ f+8010 +.* R_MIPS_GOT16 .* \.text \- 7ff0 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_LO16 .* \.text \+ f+8010 +.* R_MIPS_LO16 .* \.text \- 7ff0 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_GOT16 .* \.text \+ f+8020 +.* R_MIPS_GOT16 .* \.text \- 7fe0 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_LO16 .* \.text \+ f+8020 +.* R_MIPS_LO16 .* \.text \- 7fe0 .* R_MIPS_NONE * .* R_MIPS_NONE * .* R_MIPS_GOT16 .* \.text \+ 20 @@ -173,7 +173,7 @@ Relocation section '\.rela\.text' .* # # Relocations against sdg # -.* R_MIPS_GPREL16 .* sdg \+ f+fffc +.* R_MIPS_GPREL16 .* sdg \- 4 .* R_MIPS_NONE * .* R_MIPS_NONE * .* R_MIPS_GPREL16 .* sdg \+ 0 @@ -186,19 +186,19 @@ Relocation section '\.rela\.text' .* # Relocations against sdla. .sdata should be the first piece of gp-relative # data, which the linker script should put _gp - 0x7ff0. # -.* R_MIPS_GPREL16 .* \.sdata \+ f+801c +.* R_MIPS_GPREL16 .* \.sdata \- 7fe4 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_GPREL16 .* \.sdata \+ f+8020 +.* R_MIPS_GPREL16 .* \.sdata \- 7fe0 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_GPREL16 .* \.sdata \+ f+8024 +.* R_MIPS_GPREL16 .* \.sdata \- 7fdc .* R_MIPS_NONE * .* R_MIPS_NONE * # # Relocations against tstarta # -.* R_MIPS_26 .* \.text \+ f+fffc +.* R_MIPS_26 .* \.text \- 4 .* R_MIPS_NONE * .* R_MIPS_NONE * .* R_MIPS_26 .* \.text \+ 0 @@ -222,7 +222,7 @@ Relocation section '\.rela\.text' .* # # Relocations against _start # -.* R_MIPS_26 .* _start \+ f+fffc +.* R_MIPS_26 .* _start \- 4 .* R_MIPS_NONE * .* R_MIPS_NONE * .* R_MIPS_26 .* _start \+ 0 @@ -300,16 +300,16 @@ Relocation section '\.rela\.text' .* # # Relocations against _start # -.* R_MIPS_HI16 .* _start \+ f+7ff0 +.* R_MIPS_HI16 .* _start \- 8010 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_LO16 .* _start \+ f+7ff0 +.* R_MIPS_LO16 .* _start \- 8010 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_HI16 .* _start \+ f+8000 +.* R_MIPS_HI16 .* _start \- 8000 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_LO16 .* _start \+ f+8000 +.* R_MIPS_LO16 .* _start \- 8000 .* R_MIPS_NONE * .* R_MIPS_NONE * .* R_MIPS_HI16 .* _start \+ 0 @@ -399,7 +399,7 @@ Relocation section '\.rela\.text' .* # # Relocations against sdg # -.* R_MIPS_GPREL16 .* sdg \+ f+fffc +.* R_MIPS_GPREL16 .* sdg \- 4 .* R_MIPS_NONE * .* R_MIPS_NONE * .* R_MIPS_GPREL16 .* sdg \+ 0 @@ -411,13 +411,13 @@ Relocation section '\.rela\.text' .* # # Relocations against sdlb # -.* R_MIPS_GPREL16 .* \.sdata \+ f+803c +.* R_MIPS_GPREL16 .* \.sdata \- 7fc4 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_GPREL16 .* \.sdata \+ f+8040 +.* R_MIPS_GPREL16 .* \.sdata \- 7fc0 .* R_MIPS_NONE * .* R_MIPS_NONE * -.* R_MIPS_GPREL16 .* \.sdata \+ f+8044 +.* R_MIPS_GPREL16 .* \.sdata \- 7fbc .* R_MIPS_NONE * .* R_MIPS_NONE * # @@ -447,7 +447,7 @@ Relocation section '\.rela\.text' .* # # Relocations against _start # -.* R_MIPS_26 .* _start \+ f+fffc +.* R_MIPS_26 .* _start \- 4 .* R_MIPS_NONE * .* R_MIPS_NONE * .* R_MIPS_26 .* _start \+ 0 -- 2.30.2