Commit 44ea70c1 authored by Miguel Ojeda's avatar Miguel Ojeda Committed by Enrico Scholz

Compiler Attributes: add support for __copy (gcc >= 9)

commit c0d9782f upstream.

From the GCC manual:


    The copy attribute applies the set of attributes with which function
    has been declared to the declaration of the function to which
    the attribute is applied. The attribute is designed for libraries
    that define aliases or function resolvers that are expected
    to specify the same set of attributes as their targets. The copy
    attribute can be used with functions, variables, or types. However,
    the kind of symbol to which the attribute is applied (either
    function or variable) must match the kind of symbol to which
    the argument refers. The copy attribute copies only syntactic and
    semantic attributes but not attributes that affect a symbol’s
    linkage or visibility such as alias, visibility, or weak.
    The deprecated attribute is also not copied.

The upcoming GCC 9 release extends the -Wmissing-attributes warnings
(enabled by -Wall) to C and aliases: it warns when particular function
attributes are missing in the aliases but not in their target, e.g.:

    void __cold f(void) {}
    void __alias("f") g(void);


    warning: 'g' specifies less restrictive attribute than
    its target 'f': 'cold' [-Wmissing-attributes]

Using __copy(f) we can copy the __cold attribute from f to g:

    void __cold f(void) {}
    void __copy(f) __alias("f") g(void);

This attribute is most useful to deal with situations where an alias
is declared but we don't know the exact attributes the target has.

For instance, in the kernel, the widely used module_init/exit macros
define the init/cleanup_module aliases, but those cannot be marked
always as __init/__exit since some modules do not have their
functions marked as such.
Suggested-by: default avatarMartin Sebor <>
Reviewed-by: default avatarNick Desaulniers <>
Signed-off-by: default avatarMiguel Ojeda <>
Signed-off-by: default avatarStefan Agner <>
Signed-off-by: default avatarGreg Kroah-Hartman <>
parent 85f8197a
......@@ -343,6 +343,10 @@
#define __designated_init __attribute__((designated_init))
#if GCC_VERSION >= 90100
#define __copy(symbol) __attribute__((__copy__(symbol)))
#endif /* gcc version >= 40000 specific checks */
#if !defined(__noclone)
......@@ -230,6 +230,10 @@ struct ftrace_likely_data {
# define __latent_entropy
#ifndef __copy
# define __copy(symbol)
#ifndef __randomize_layout
# define __randomize_layout __designated_init
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment