{ "preserve_access_index", 0, -1, false, true, false, true,
bpf_handle_preserve_access_index_attribute, NULL },
+ /* Support for `naked' function attribute. */
+ { "naked", 0, 1, false, false, false, false,
+ bpf_handle_fndecl_attribute, NULL },
+
/* The last attribute spec is set to be NULL. */
{ NULL, 0, 0, false, false, false, false, NULL, NULL }
};
#undef TARGET_FUNCTION_VALUE_REGNO_P
#define TARGET_FUNCTION_VALUE_REGNO_P bpf_function_value_regno_p
+
+/* Determine whether to warn about lack of return statement in a
+ function. */
+
+static bool
+bpf_warn_func_return (tree decl)
+{
+ /* Naked functions are implemented entirely in assembly, including
+ the return instructions. */
+ return lookup_attribute ("naked", DECL_ATTRIBUTES (decl)) == NULL_TREE;
+}
+
+#undef TARGET_WARN_FUNC_RETURN
+#define TARGET_WARN_FUNC_RETURN bpf_warn_func_return
+
/* Compute the size of the function's stack frame, including the local
area and the register-save area. */
dynamically. This should have been checked already and an error
emitted. */
gcc_assert (!cfun->calls_alloca);
+
+ /* If we ever need to have a proper prologue here, please mind the
+ `naked' function attribute. */
}
/* Expand to the instructions in a function epilogue. This function
/* See note in bpf_expand_prologue for an explanation on why we are
not restoring callee-saved registers in BPF. */
+ /* If we ever need to do anything else than just generating a return
+ instruction here, please mind the `naked' function attribute. */
+
emit_jump_insn (gen_exit ());
}
int bpf_probe_read (void *dst, int size, const void *unsafe_ptr)
__attribute__ ((kernel_helper (4)));
@end smallexample
+
+@cindex @code{naked} function attribute, BPF
+@item naked
+This attribute allows the compiler to construct the requisite function
+declaration, while allowing the body of the function to be assembly
+code. The specified function will not have prologue/epilogue
+sequences generated by the compiler. Only basic @code{asm} statements
+can safely be included in naked functions (@pxref{Basic Asm}). While
+using extended @code{asm} or a mixture of basic @code{asm} and C code
+may appear to work, they cannot be depended upon to work reliably and
+are not supported.
@end table
@node C-SKY Function Attributes
--- /dev/null
+/* Verify that __attribute__((naked)) is accepted and
+ produces a naked function. Also, the compiler must not
+ warn for the lack of return statement. */
+/* { dg-do compile } */
+/* { dg-options "-O0 -Wreturn-type" } */
+
+int __attribute__((naked)) foo()
+{
+ __asm__ volatile ("@ naked");
+}
+/* { dg-final { scan-assembler "\t@ naked" } } */
+/* { dg-final { scan-assembler "\texit\n" } } */