• Mark Rutland's avatar
    linkage: add SYM_FUNC_ALIAS{,_LOCAL,_WEAK}() · e0891269
    Mark Rutland authored
    Currently aliasing an asm function requires adding START and END
    annotations for each name, as per Documentation/asm-annotations.rst:
    
    	SYM_FUNC_START_ALIAS(__memset)
    	SYM_FUNC_START(memset)
    	    ... asm insns ...
    	SYM_FUNC_END(memset)
    	SYM_FUNC_END_ALIAS(__memset)
    
    This is more painful than necessary to maintain, especially where a
    function has many aliases, some of which we may wish to define
    conditionally. For example, arm64's memcpy/memmove implementation (which
    uses some arch-specific SYM_*() helpers) has:
    
    	SYM_FUNC_START_ALIAS(__memmove)
    	SYM_FUNC_START_ALIAS_WEAK_PI(memmove)
    	SYM_FUNC_START_ALIAS(__memcpy)
    	SYM_FUNC_START_WEAK_PI(memcpy)
    	    ... asm insns ...
    	SYM_FUNC_END_PI(memcpy)
    	EXPORT_SYMBOL(memcpy)
    	SYM_FUNC_END_ALIAS(__memcpy)
    	EXPORT_SYMBOL(__memcpy)
    	SYM_FUNC_END_ALIAS_PI(memmove)
    	EXPORT_SYMBOL(memmove)
    	SYM_FUNC_END_ALIAS(__memmove)
    	EXPORT_SYMBOL(__memmove)
    	SYM_FUNC_START(name)
    
    It would be much nicer if we could define the aliases *after* the
    standard function definition. This would avoid the need to specify each
    symbol name twice, and would make it easier to spot the canonical
    function definition.
    
    This patch adds new macros to allow us to do so, which allows the above
    example to be rewritten more succinctly as:
    
    	SYM_FUNC_START(__pi_memcpy)
    	    ... asm insns ...
    	SYM_FUNC_END(__pi_memcpy)
    
    	SYM_FUNC_ALIAS(__memcpy, __pi_memcpy)
    	EXPORT_SYMBOL(__memcpy)
    	SYM_FUNC_ALIAS_WEAK(memcpy, __memcpy)
    	EXPORT_SYMBOL(memcpy)
    
    	SYM_FUNC_ALIAS(__pi_memmove, __pi_memcpy)
    	SYM_FUNC_ALIAS(__memmove, __pi_memmove)
    	EXPORT_SYMBOL(__memmove)
    	SYM_FUNC_ALIAS_WEAK(memmove, __memmove)
    	EXPORT_SYMBOL(memmove)
    
    The reduction in duplication will also make it possible to replace some
    uses of WEAK with more accurate Kconfig guards, e.g.
    
    	#ifndef CONFIG_KASAN
    	SYM_FUNC_ALIAS(memmove, __memmove)
    	EXPORT_SYMBOL(memmove)
    	#endif
    
    ... which should make it easier to ensure that symbols are neither used
    nor overidden unexpectedly.
    
    The existing SYM_FUNC_START_ALIAS() and SYM_FUNC_START_LOCAL_ALIAS() are
    marked as deprecated, and will be removed once existing users are moved
    over to the new scheme.
    
    The tools/perf/ copy of linkage.h is updated to match. A subsequent
    patch will depend upon this when updating the x86 asm annotations.
    Signed-off-by: default avatarMark Rutland <mark.rutland@arm.com>
    Acked-by: default avatarArd Biesheuvel <ardb@kernel.org>
    Acked-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
    Acked-by: default avatarMark Brown <broonie@kernel.org>
    Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Borislav Petkov <bp@alien8.de>
    Cc: Jiri Slaby <jslaby@suse.cz>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lore.kernel.org/r/20220216162229.1076788-2-mark.rutland@arm.comSigned-off-by: default avatarWill Deacon <will@kernel.org>
    e0891269
asm-annotations.rst 9.9 KB