+2018-11-29 Andi Kleen <ak@linux.intel.com>
+
+ * config/i386/i386.c (x86_print_call_or_nop): Handle nop name.
+ (current_fentry_name): Add.
+ (x86_function_profiler): Handle fentry_name attribute.
+ (ix86_handle_fentry_name): Add.
+ (ix86_attribute_table): Add fentry_name.
+ * config/i386/i386.opt: Add -mfentry-name
+ * doc/extend.texi: Document fentry_name.
+ * doc/invoke.texi: Document minstrument-return.
+
2018-11-29 Andi Kleen <ak@linux.intel.com>
* config/i386/i386-opts.h (enum instrument_return): Add.
static void
x86_print_call_or_nop (FILE *file, const char *target)
{
- if (flag_nop_mcount)
+ if (flag_nop_mcount || !strcmp (target, "nop"))
/* 5 byte nop: nopl 0(%[re]ax,%[re]ax,1) */
fprintf (file, "1:" ASM_BYTE "0x0f, 0x1f, 0x44, 0x00, 0x00\n");
else
fprintf (file, "1:\tcall\t%s\n", target);
}
+static bool
+current_fentry_name (const char **name)
+{
+ tree attr = lookup_attribute ("fentry_name",
+ DECL_ATTRIBUTES (current_function_decl));
+ if (!attr)
+ return false;
+ *name = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
+ return true;
+}
+
/* Output assembler code to FILE to increment profiler label # LABELNO
for profiling a function entry. */
void
x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
{
- const char *mcount_name = (flag_fentry ? MCOUNT_NAME_BEFORE_PROLOGUE
- : MCOUNT_NAME);
-
if (cfun->machine->endbr_queued_at_entrance)
fprintf (file, "\t%s\n", TARGET_64BIT ? "endbr64" : "endbr32");
+ const char *mcount_name = MCOUNT_NAME;
+
+ if (current_fentry_name (&mcount_name))
+ ;
+ else if (fentry_name)
+ mcount_name = fentry_name;
+ else if (flag_fentry)
+ mcount_name = MCOUNT_NAME_BEFORE_PROLOGUE;
+
if (TARGET_64BIT)
{
#ifndef NO_PROFILE_COUNTERS
emit_move_insn (op0, res);
}
+
+/* Handle fentry_name attribute. */
+
+static tree
+ix86_handle_fentry_name (tree *node, tree name, tree args,
+ int, bool *no_add_attrs)
+{
+ if (TREE_CODE (*node) == FUNCTION_DECL
+ && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
+ /* Do nothing else, just set the attribute. We'll get at
+ it later with lookup_attribute. */
+ ;
+ else
+ {
+ warning (OPT_Wattributes, "%qE attribute ignored", name);
+ *no_add_attrs = true;
+ }
+
+ return NULL_TREE;
+}
\f
/* Table of valid machine attributes. */
ix86_handle_fndecl_attribute, NULL },
{ "indirect_return", 0, 0, false, true, true, false,
NULL, NULL },
-
+ { "fentry_name", 1, 1, true, false, false, false,
+ ix86_handle_fentry_name, NULL },
/* End element. */
{ NULL, 0, 0, false, false, false, false, NULL, NULL }
};
as well as variable or type of function pointer to inform the
compiler that the function may return via indirect branch.
+@item fentry_name("@var{name}")
+@cindex @code{fentry_name} function attribute, x86
+On x86 targets, the @code{fentry_name} attribute sets the function to
+call on function entry when function instrumentation is enabled
+with @option{-pg -mfentry}. When @var{name} is nop then a 5 byte
+nop sequence is generated.
+
@end table
On the x86, the inliner does not inline a
-mcmodel=@var{code-model} -mabi=@var{name} -maddress-mode=@var{mode} @gol
-m32 -m64 -mx32 -m16 -miamcu -mlarge-data-threshold=@var{num} @gol
-msse2avx -mfentry -mrecord-mcount -mnop-mcount -m8bit-idiv @gol
--minstrument-return=@var{type} @gol
+-minstrument-return=@var{type} -mfentry-name=@var{name} @gol
-mavx256-split-unaligned-load -mavx256-split-unaligned-store @gol
-malign-data=@var{type} -mstack-protector-guard=@var{guard} @gol
-mstack-protector-guard-reg=@var{reg} @gol
@opindex mrecord-return
Generate a __return_loc section pointing to all return instrumentation code.
+@item -mfentry-name=@var{name}
+@opindex mfentry-name
+Set name of __fentry__ symbol called at function entry for -pg -mfentry functions.
+
@item -mskip-rax-setup
@itemx -mno-skip-rax-setup
@opindex mskip-rax-setup