aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Tietz <kai.tietz@onevision.com>2010-07-06 18:27:41 +0000
committerKai Tietz <ktietz@gcc.gnu.org>2010-07-06 20:27:41 +0200
commit4bbf141cf116e3c59cba66e9c51fb33bc90793f1 (patch)
treeef3126f4513a4254e0be8e50d4e20304bb60603a
parent15a1f8c52d3c4a019730742c4e802b0458b85b7e (diff)
downloadgcc-4bbf141cf116e3c59cba66e9c51fb33bc90793f1.zip
gcc-4bbf141cf116e3c59cba66e9c51fb33bc90793f1.tar.gz
gcc-4bbf141cf116e3c59cba66e9c51fb33bc90793f1.tar.bz2
i386.c (ix86_function_ms_hook_prologue): Enable x64 support.
2010-07-06 Kai Tietz <kai.tietz@onevision.com> * config/i386/i386.c (ix86_function_ms_hook_prologue): Enable x64 support. (ix86_expand_prologue): Likewise. (ix86_handle_fndecl_attribute): Likewise. (ix86_asm_declare_function_name): New function for ASM_DECLARE_FUNCTION_NAME. * config/i386/i386.h (ASM_DECLARE_FUNCTION_NAME): New macro. * config/i386/cygming.h (ASM_DECLARE_FUNCTION_NAME): Removed. (SUBTARGET_ASM_DECLARE_FUNCTION_NAME): New macro. * config/i386/i386-protos.h (ix86_asm_declare_function_name): New. * doc/extend.texi: Adjust documentation about ms_hook_prologue attribute. From-SVN: r161876
-rw-r--r--gcc/ChangeLog15
-rw-r--r--gcc/config/i386/cygming.h5
-rw-r--r--gcc/config/i386/i386-protos.h1
-rw-r--r--gcc/config/i386/i386.c79
-rw-r--r--gcc/config/i386/i386.h8
-rw-r--r--gcc/doc/extend.texi8
6 files changed, 86 insertions, 30 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b27f23b..164b890 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,18 @@
+2010-07-06 Kai Tietz <kai.tietz@onevision.com>
+
+ * config/i386/i386.c (ix86_function_ms_hook_prologue): Enable x64
+ support.
+ (ix86_expand_prologue): Likewise.
+ (ix86_handle_fndecl_attribute): Likewise.
+ (ix86_asm_declare_function_name): New function for
+ ASM_DECLARE_FUNCTION_NAME.
+ * config/i386/i386.h (ASM_DECLARE_FUNCTION_NAME): New macro.
+ * config/i386/cygming.h (ASM_DECLARE_FUNCTION_NAME): Removed.
+ (SUBTARGET_ASM_DECLARE_FUNCTION_NAME): New macro.
+ * config/i386/i386-protos.h (ix86_asm_declare_function_name): New.
+ * doc/extend.texi: Adjust documentation about ms_hook_prologue
+ attribute.
+
2010-07-06 Uros Bizjak <ubizjak@gmail.com>
* config/i386/i386.md (immediate_operand): New mode attribute.
diff --git a/gcc/config/i386/cygming.h b/gcc/config/i386/cygming.h
index f2b70af..a970ca2 100644
--- a/gcc/config/i386/cygming.h
+++ b/gcc/config/i386/cygming.h
@@ -269,14 +269,13 @@ do { \
/* Write the extra assembler code needed to declare a function
properly. If we are generating SDB debugging information, this
will happen automatically, so we only need to handle other cases. */
-#undef ASM_DECLARE_FUNCTION_NAME
-#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
+#undef SUBTARGET_ASM_DECLARE_FUNCTION_NAME
+#define SUBTARGET_ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
do \
{ \
i386_pe_maybe_record_exported_symbol (DECL, NAME, 0); \
if (write_symbols != SDB_DEBUG) \
i386_pe_declare_function_type (FILE, NAME, TREE_PUBLIC (DECL)); \
- ASM_OUTPUT_LABEL (FILE, NAME); \
} \
while (0)
diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h
index 4a0e306..021cbe7 100644
--- a/gcc/config/i386/i386-protos.h
+++ b/gcc/config/i386/i386-protos.h
@@ -136,6 +136,7 @@ extern enum machine_mode ix86_fp_compare_mode (enum rtx_code);
extern rtx ix86_libcall_value (enum machine_mode);
extern bool ix86_function_arg_regno_p (int);
+extern void ix86_asm_declare_function_name (FILE *, const char *, tree);
extern int ix86_function_arg_boundary (enum machine_mode, tree);
extern bool ix86_sol10_return_in_memory (const_tree,const_tree);
extern rtx ix86_force_to_memory (enum machine_mode, rtx);
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 7dfd7bb..0c404ae 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -5078,18 +5078,15 @@ ix86_function_type_abi (const_tree fntype)
static bool
ix86_function_ms_hook_prologue (const_tree fntype)
{
- if (!TARGET_64BIT)
+ if (lookup_attribute ("ms_hook_prologue", DECL_ATTRIBUTES (fntype)))
{
- if (lookup_attribute ("ms_hook_prologue", DECL_ATTRIBUTES (fntype)))
- {
- if (decl_function_context (fntype) != NULL_TREE)
- {
- error_at (DECL_SOURCE_LOCATION (fntype),
- "ms_hook_prologue is not compatible with nested function");
- }
+ if (decl_function_context (fntype) != NULL_TREE)
+ {
+ error_at (DECL_SOURCE_LOCATION (fntype),
+ "ms_hook_prologue is not compatible with nested function");
+ }
- return true;
- }
+ return true;
}
return false;
}
@@ -5112,6 +5109,45 @@ ix86_cfun_abi (void)
return cfun->machine->call_abi;
}
+/* Write the extra assembler code needed to declare a function properly. */
+
+void
+ix86_asm_declare_function_name (FILE *asm_out_file, const char *fname,
+ tree decl)
+{
+ bool is_ms_hook = ((decl && ix86_function_ms_hook_prologue (decl)) ? true
+ : false);
+#ifdef SUBTARGET_ASM_DECLARE_FUNCTION_NAME
+ SUBTARGET_ASM_DECLARE_FUNCTION_NAME (asm_out_file, fname, decl);
+#endif
+
+ if (is_ms_hook)
+ {
+ int i, filler_count = (TARGET_64BIT ? 32 : 16);
+ unsigned int filler_cc = 0xcccccccc;
+
+ for (i = 0; i < filler_count; i += 4)
+ fprintf (asm_out_file, ASM_LONG " %#x\n", filler_cc);
+ }
+
+ ASM_OUTPUT_LABEL (asm_out_file, fname);
+
+ /* Output magic byte marker, if hot-patch attribute is set.
+ For x86 case frame-pointer prologue will be emitted in
+ expand_prologue. */
+ if (is_ms_hook)
+ {
+ if (TARGET_64BIT)
+ /* leaq [%rsp + 0], %rsp */
+ asm_fprintf (asm_out_file, ASM_BYTE
+ "0x48, 0x8d, 0xa4, 0x24, "
+ "0x00, 0x00, 0x00, 0x00\n");
+ else
+ /* movl.s %edi, %edi. */
+ asm_fprintf (asm_out_file, ASM_BYTE "0x8b, 0xff\n");
+ }
+}
+
/* regclass.c */
extern void init_regs (void);
@@ -8757,21 +8793,24 @@ ix86_expand_prologue (void)
ix86_compute_frame_layout (&frame);
- if (ix86_function_ms_hook_prologue (current_function_decl))
+ if (!TARGET_64BIT && ix86_function_ms_hook_prologue (current_function_decl))
{
rtx push, mov;
/* Make sure the function starts with
- 8b ff movl.s %edi,%edi
+ 8b ff movl.s %edi,%edi (see below in text)
55 push %ebp
8b ec movl.s %esp,%ebp
This matches the hookable function prologue in Win32 API
functions in Microsoft Windows XP Service Pack 2 and newer.
Wine uses this to enable Windows apps to hook the Win32 API
- functions provided by Wine. */
- insn = emit_insn (gen_vswapmov (gen_rtx_REG (SImode, DI_REG),
- gen_rtx_REG (SImode, DI_REG)));
+ functions provided by Wine.
+ Remark: Initial nop-move gets emitted by the function
+ ix86_asm_declare_function_name and isn't part of this
+ function. The following instruction don't get hard-coded
+ in ix86_asm_declare_function_name too, as here notes
+ for those instructions are necessary for unwinder/debug. */
push = emit_insn (gen_push (hard_frame_pointer_rtx));
mov = emit_insn (gen_vswapmov (hard_frame_pointer_rtx,
stack_pointer_rtx));
@@ -26553,15 +26592,9 @@ ix86_handle_fndecl_attribute (tree *node, tree name,
return NULL_TREE;
}
- if (TARGET_64BIT)
- {
- warning (OPT_Wattributes, "%qE attribute only available for 32-bit",
- name);
- return NULL_TREE;
- }
-
#ifndef HAVE_AS_IX86_SWAP
- sorry ("ms_hook_prologue attribute needs assembler swap suffix support");
+ if (!TARGET_64BIT)
+ sorry ("ms_hook_prologue attribute needs assembler swap suffix support");
#endif
return NULL_TREE;
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index d036bf0..e7bd36a 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -2082,6 +2082,14 @@ do { \
}
#endif
+/* Write the extra assembler code needed to declare a function
+ properly. Target can add additional code by the sub-target
+ macro SUBTARGET_ASM_DECLARE_FUNCTION_NAME. */
+
+#undef ASM_DECLARE_FUNCTION_NAME
+#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
+ ix86_asm_declare_function_name (FILE, NAME, DECL)
+
/* Under some conditions we need jump tables in the text section,
because the assembler cannot handle label differences between
sections. This is the case for x86_64 on Mach-O for example. */
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 967be91..b9b4a44 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -2736,10 +2736,10 @@ the @option{-maccumulate-outgoing-args} option.
@item ms_hook_prologue
@cindex @code{ms_hook_prologue} attribute
-On 32 bit i[34567]86-*-* targets, you can use this function attribute to make
-gcc generate the "hot-patching" function prologue used in Win32 API
-functions in Microsoft Windows XP Service Pack 2 and newer. This requires
-support for the swap suffix in the assembler. (GNU Binutils 2.19.51 or later)
+On 32 bit i[34567]86-*-* targets and 64 bit x86_64-*-* targets, you can use
+this function attribute to make gcc generate the "hot-patching" function
+prologue used in Win32 API functions in Microsoft Windows XP Service Pack 2
+and newer.
@item naked
@cindex function without a prologue/epilogue code