diff options
Diffstat (limited to 'gcc/config/i386/i386.c')
-rw-r--r-- | gcc/config/i386/i386.c | 151 |
1 files changed, 143 insertions, 8 deletions
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index f1c58faa035..4bfe2fa8c1d 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -7188,6 +7188,31 @@ ix86_set_indirect_branch_type (tree fndecl) else cfun->machine->indirect_branch_type = ix86_indirect_branch; } + + if (cfun->machine->function_return_type == indirect_branch_unset) + { + tree attr = lookup_attribute ("function_return", + DECL_ATTRIBUTES (fndecl)); + if (attr != NULL) + { + tree args = TREE_VALUE (attr); + if (args == NULL) + gcc_unreachable (); + tree cst = TREE_VALUE (args); + if (strcmp (TREE_STRING_POINTER (cst), "keep") == 0) + cfun->machine->function_return_type = indirect_branch_keep; + else if (strcmp (TREE_STRING_POINTER (cst), "thunk") == 0) + cfun->machine->function_return_type = indirect_branch_thunk; + else if (strcmp (TREE_STRING_POINTER (cst), "thunk-inline") == 0) + cfun->machine->function_return_type = indirect_branch_thunk_inline; + else if (strcmp (TREE_STRING_POINTER (cst), "thunk-extern") == 0) + cfun->machine->function_return_type = indirect_branch_thunk_extern; + else + gcc_unreachable (); + } + else + cfun->machine->function_return_type = ix86_function_return; + } } /* Establish appropriate back-end context for processing the function @@ -11990,8 +12015,12 @@ static int indirect_thunks_bnd_used; /* Fills in the label name that should be used for the indirect thunk. */ static void -indirect_thunk_name (char name[32], int regno, bool need_bnd_p) +indirect_thunk_name (char name[32], int regno, bool need_bnd_p, + bool ret_p) { + if (regno >= 0 && ret_p) + gcc_unreachable (); + if (USE_HIDDEN_LINKONCE) { const char *bnd = need_bnd_p ? "_bnd" : ""; @@ -12006,7 +12035,10 @@ indirect_thunk_name (char name[32], int regno, bool need_bnd_p) bnd, reg_prefix, reg_names[regno]); } else - sprintf (name, "__x86_indirect_thunk%s", bnd); + { + const char *ret = ret_p ? "return" : "indirect"; + sprintf (name, "__x86_%s_thunk%s", ret, bnd); + } } else { @@ -12019,10 +12051,20 @@ indirect_thunk_name (char name[32], int regno, bool need_bnd_p) } else { - if (need_bnd_p) - ASM_GENERATE_INTERNAL_LABEL (name, "LITB", 0); + if (ret_p) + { + if (need_bnd_p) + ASM_GENERATE_INTERNAL_LABEL (name, "LRTB", 0); + else + ASM_GENERATE_INTERNAL_LABEL (name, "LRT", 0); + } else - ASM_GENERATE_INTERNAL_LABEL (name, "LIT", 0); + { + if (need_bnd_p) + ASM_GENERATE_INTERNAL_LABEL (name, "LITB", 0); + else + ASM_GENERATE_INTERNAL_LABEL (name, "LIT", 0); + } } } } @@ -12117,7 +12159,7 @@ output_indirect_thunk_function (bool need_bnd_p, int regno) tree decl; /* Create __x86_indirect_thunk/__x86_indirect_thunk_bnd. */ - indirect_thunk_name (name, regno, need_bnd_p); + indirect_thunk_name (name, regno, need_bnd_p, false); decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL, get_identifier (name), build_function_type_list (void_type_node, NULL_TREE)); @@ -12160,6 +12202,35 @@ output_indirect_thunk_function (bool need_bnd_p, int regno) ASM_OUTPUT_LABEL (asm_out_file, name); } + if (regno < 0) + { + /* Create alias for __x86.return_thunk/__x86.return_thunk_bnd. */ + char alias[32]; + + indirect_thunk_name (alias, regno, need_bnd_p, true); + ASM_OUTPUT_DEF (asm_out_file, alias, name); +#if TARGET_MACHO + if (TARGET_MACHO) + { + fputs ("\t.weak_definition\t", asm_out_file); + assemble_name (asm_out_file, alias); + fputs ("\n\t.private_extern\t", asm_out_file); + assemble_name (asm_out_file, alias); + putc ('\n', asm_out_file); + } +#else + if (USE_HIDDEN_LINKONCE) + { + fputs ("\t.globl\t", asm_out_file); + assemble_name (asm_out_file, alias); + putc ('\n', asm_out_file); + fputs ("\t.hidden\t", asm_out_file); + assemble_name (asm_out_file, alias); + putc ('\n', asm_out_file); + } +#endif + } + DECL_INITIAL (decl) = make_node (BLOCK); current_function_decl = decl; allocate_struct_function (decl, false); @@ -28760,7 +28831,7 @@ ix86_output_indirect_branch_via_reg (rtx call_op, bool sibcall_p) else indirect_thunks_used |= 1 << i; } - indirect_thunk_name (thunk_name_buf, regno, need_bnd_p); + indirect_thunk_name (thunk_name_buf, regno, need_bnd_p, false); thunk_name = thunk_name_buf; } else @@ -28869,7 +28940,7 @@ ix86_output_indirect_branch_via_push (rtx call_op, const char *xasm, else indirect_thunk_needed = true; } - indirect_thunk_name (thunk_name_buf, regno, need_bnd_p); + indirect_thunk_name (thunk_name_buf, regno, need_bnd_p, false); thunk_name = thunk_name_buf; } else @@ -29004,6 +29075,46 @@ ix86_output_indirect_jmp (rtx call_op, bool ret_p) return "%!jmp\t%A0"; } +/* Output function return. CALL_OP is the jump target. Add a REP + prefix to RET if LONG_P is true and function return is kept. */ + +const char * +ix86_output_function_return (bool long_p) +{ + if (cfun->machine->function_return_type != indirect_branch_keep) + { + char thunk_name[32]; + bool need_bnd_p = ix86_bnd_prefixed_insn_p (current_output_insn); + + if (cfun->machine->function_return_type + != indirect_branch_thunk_inline) + { + bool need_thunk = (cfun->machine->function_return_type + == indirect_branch_thunk); + indirect_thunk_name (thunk_name, -1, need_bnd_p, true); + if (need_bnd_p) + { + indirect_thunk_bnd_needed |= need_thunk; + fprintf (asm_out_file, "\tbnd jmp\t%s\n", thunk_name); + } + else + { + indirect_thunk_needed |= need_thunk; + fprintf (asm_out_file, "\tjmp\t%s\n", thunk_name); + } + } + else + output_indirect_thunk (need_bnd_p, -1); + + return ""; + } + + if (!long_p || ix86_bnd_prefixed_insn_p (current_output_insn)) + return "%!ret"; + + return "rep%; ret"; +} + /* Output the assembly for a call instruction. */ const char * @@ -42075,6 +42186,28 @@ ix86_handle_fndecl_attribute (tree *node, tree name, tree args, int, } } + if (is_attribute_p ("function_return", name)) + { + tree cst = TREE_VALUE (args); + if (TREE_CODE (cst) != STRING_CST) + { + warning (OPT_Wattributes, + "%qE attribute requires a string constant argument", + name); + *no_add_attrs = true; + } + else if (strcmp (TREE_STRING_POINTER (cst), "keep") != 0 + && strcmp (TREE_STRING_POINTER (cst), "thunk") != 0 + && strcmp (TREE_STRING_POINTER (cst), "thunk-inline") != 0 + && strcmp (TREE_STRING_POINTER (cst), "thunk-extern") != 0) + { + warning (OPT_Wattributes, + "argument to %qE attribute is not " + "(keep|thunk|thunk-inline|thunk-extern)", name); + *no_add_attrs = true; + } + } + return NULL_TREE; } @@ -46385,6 +46518,8 @@ static const struct attribute_spec ix86_attribute_table[] = ix86_handle_no_caller_saved_registers_attribute, false }, { "indirect_branch", 1, 1, true, false, false, ix86_handle_fndecl_attribute, false }, + { "function_return", 1, 1, true, false, false, + ix86_handle_fndecl_attribute, false }, /* End element. */ { NULL, 0, 0, false, false, false, NULL, false } |