path: root/Documentation/asm-annotations.rst
Commit message (Collapse)AuthorAgeFilesLines
* linkage: remove SYM_FUNC_{START,END}_ALIAS()Mark Rutland2022-02-221-13/+0
| | | | | | | | | | | | | | | | | | | Now that all aliases are defined using SYM_FUNC_ALIAS(), remove the old SYM_FUNC_{START,END}_ALIAS() macros. There should be no functional change as a result of this patch. Signed-off-by: Mark Rutland <> Acked-by: Ard Biesheuvel <> Acked-by: Josh Poimboeuf <> Acked-by: Mark Brown <> Cc: Arnaldo Carvalho de Melo <> Cc: Borislav Petkov <> Cc: Jiri Slaby <> Cc: Peter Zijlstra <> Acked-by: Peter Zijlstra (Intel) <> Link: Signed-off-by: Will Deacon <>
* linkage: add SYM_FUNC_ALIAS{,_LOCAL,_WEAK}()Mark Rutland2022-02-221-2/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: Mark Rutland <> Acked-by: Ard Biesheuvel <> Acked-by: Josh Poimboeuf <> Acked-by: Mark Brown <> Cc: Arnaldo Carvalho de Melo <> Cc: Borislav Petkov <> Cc: Jiri Slaby <> Cc: Peter Zijlstra <> Acked-by: Peter Zijlstra (Intel) <> Link: Signed-off-by: Will Deacon <>
* docs: use the lore redirector everywhereThorsten Leemhuis2021-10-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | Change all links from using the lkml redirector to the lore redirector, as the admin recently indicated: we shouldn't be using anymore because the domain can create confusion, as it indicates it is only valid for messages sent to the LKML; the convention has been to use for this reason. In this process also change three links from using http to https. Link: CC: Thomas Gleixner <> CC: Ingo Molnar <> CC: Borislav Petkov <> CC: Hu Haowen <> CC: Alex Shi <> CC: Federico Vaga <> Signed-off-by: Thorsten Leemhuis <> Reviewed-by: Konstantin Ryabitsev <> Link: Signed-off-by: Jonathan Corbet <>
* x86/entry: Emit a symbol for register restoring thunkNick Desaulniers2021-01-141-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Arnd found a randconfig that produces the warning: arch/x86/entry/thunk_64.o: warning: objtool: missing symbol for insn at offset 0x3e when building with LLVM_IAS=1 (Clang's integrated assembler). Josh notes: With the LLVM assembler not generating section symbols, objtool has no way to reference this code when it generates ORC unwinder entries, because this code is outside of any ELF function. The limitation now being imposed by objtool is that all code must be contained in an ELF symbol. And .L symbols don't create such symbols. So basically, you can use an .L symbol *inside* a function or a code segment, you just can't use the .L symbol to contain the code using a SYM_*_START/END annotation pair. Fangrui notes that this optimization is helpful for reducing image size when compiling with -ffunction-sections and -fdata-sections. I have observed on the order of tens of thousands of symbols for the kernel images built with those flags. A patch has been authored against GNU binutils to match this behavior of not generating unused section symbols ([1]), so this will also become a problem for users of GNU binutils once they upgrade to 2.36. Omit the .L prefix on a label so that the assembler will emit an entry into the symbol table for the label, with STB_LOCAL binding. This enables objtool to generate proper unwind info here with LLVM_IAS=1 or GNU binutils 2.36+. [ bp: Massage commit message. ] Reported-by: Arnd Bergmann <> Suggested-by: Josh Poimboeuf <> Suggested-by: Borislav Petkov <> Suggested-by: Mark Brown <> Signed-off-by: Nick Desaulniers <> Signed-off-by: Borislav Petkov <> Acked-by: Peter Zijlstra (Intel) <> Acked-by: Josh Poimboeuf <> Link: Link: Link: Link: Link:;a=commit;h=d1bcae833b32f1408485ce69f844dcd7ded093a8 [1]
* Documentation: Call out example SYM_FUNC_* usage as x86-specificWill Deacon2020-01-161-4/+5
| | | | | | | | | | | | | | | The example given in asm-annotations.rst to describe the constraints that a function should meet in order to be annotated with a SYM_FUNC_* macro is x86-specific, and not necessarily applicable to architectures using branch-and-link style calling conventions such as arm64. Tweak the example text to call out the x86-specific text. Cc: Mark Brown <> Cc: Jiri Slaby <> Signed-off-by: Will Deacon <> Link: Signed-off-by: Jonathan Corbet <>
* x86/ftrace: Get rid of function_hookBorislav Petkov2019-10-251-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | History lesson courtesy of Steve: "When ftrace first was introduced to the kernel, it used gcc's mcount profiling mechanism. The mcount mechanism would add a call to "mcount" at the start of every function but after the stack frame was set up. Later, in gcc 4.6, gcc introduced -mfentry, that would create a call to "__fentry__" instead of "mcount", before the stack frame was set up. In order to handle both cases, ftrace defined a macro "function_hook" that would be either "mcount" or "__fentry__" depending on which one was being used. The Linux kernel no longer supports the "mcount" method, thus there's no reason to keep the "function_hook" define around. Simply use "__fentry__", as there is no ambiguity to the name anymore." Drop it everywhere. Signed-off-by: Borislav Petkov <> Acked-by: Jiri Slaby <> Cc: "H. Peter Anvin" <> Cc: Ingo Molnar <> Cc: Jonathan Corbet <> Cc: Josh Poimboeuf <> Cc: Cc: Cc: Peter Zijlstra <> Cc: "Steven Rostedt (VMware)" <> Cc: Thomas Gleixner <> Cc: Link:
* linkage: Introduce new macros for assembler symbolsJiri Slaby2019-10-181-0/+216
Introduce new C macros for annotations of functions and data in assembly. There is a long-standing mess in macros like ENTRY, END, ENDPROC and similar. They are used in different manners and sometimes incorrectly. So introduce macros with clear use to annotate assembly as follows: a) Support macros for the ones below SYM_T_FUNC -- type used by assembler to mark functions SYM_T_OBJECT -- type used by assembler to mark data SYM_T_NONE -- type used by assembler to mark entries of unknown type They are defined as STT_FUNC, STT_OBJECT, and STT_NOTYPE respectively. According to the gas manual, this is the most portable way. I am not sure about other assemblers, so this can be switched back to %function and %object if this turns into a problem. Architectures can also override them by something like ", @function" if they need. SYM_A_ALIGN, SYM_A_NONE -- align the symbol? SYM_L_GLOBAL, SYM_L_WEAK, SYM_L_LOCAL -- linkage of symbols b) Mostly internal annotations, used by the ones below SYM_ENTRY -- use only if you have to (for non-paired symbols) SYM_START -- use only if you have to (for paired symbols) SYM_END -- use only if you have to (for paired symbols) c) Annotations for code SYM_INNER_LABEL_ALIGN -- only for labels in the middle of code SYM_INNER_LABEL -- only for labels in the middle of code SYM_FUNC_START_LOCAL_ALIAS -- use where there are two local names for one function SYM_FUNC_START_ALIAS -- use where there are two global names for one function SYM_FUNC_END_ALIAS -- the end of LOCAL_ALIASed or ALIASed function SYM_FUNC_START -- use for global functions SYM_FUNC_START_NOALIGN -- use for global functions, w/o alignment SYM_FUNC_START_LOCAL -- use for local functions SYM_FUNC_START_LOCAL_NOALIGN -- use for local functions, w/o alignment SYM_FUNC_START_WEAK -- use for weak functions SYM_FUNC_START_WEAK_NOALIGN -- use for weak functions, w/o alignment SYM_FUNC_END -- the end of SYM_FUNC_START_LOCAL, SYM_FUNC_START, SYM_FUNC_START_WEAK, ... For functions with special (non-C) calling conventions: SYM_CODE_START -- use for non-C (special) functions SYM_CODE_START_NOALIGN -- use for non-C (special) functions, w/o alignment SYM_CODE_START_LOCAL -- use for local non-C (special) functions SYM_CODE_START_LOCAL_NOALIGN -- use for local non-C (special) functions, w/o alignment SYM_CODE_END -- the end of SYM_CODE_START_LOCAL or SYM_CODE_START d) For data SYM_DATA_START -- global data symbol SYM_DATA_START_LOCAL -- local data symbol SYM_DATA_END -- the end of the SYM_DATA_START symbol SYM_DATA_END_LABEL -- the labeled end of SYM_DATA_START symbol SYM_DATA -- start+end wrapper around simple global data SYM_DATA_LOCAL -- start+end wrapper around simple local data ========== The macros allow to pair starts and ends of functions and mark functions correctly in the output ELF objects. All users of the old macros in x86 are converted to use these in further patches. Signed-off-by: Jiri Slaby <> Signed-off-by: Borislav Petkov <> Acked-by: Rafael J. Wysocki <> Cc: Andrew Morton <> Cc: Andrey Ryabinin <> Cc: Boris Ostrovsky <> Cc: "H. Peter Anvin" <> Cc: Ingo Molnar <> Cc: Jonathan Corbet <> Cc: Josh Poimboeuf <> Cc: Juergen Gross <> Cc: Len Brown <> Cc: Linus Torvalds <> Cc: Cc: Cc: Cc: Cc: Mark Rutland <> Cc: Pavel Machek <> Cc: Peter Zijlstra <> Cc: Thomas Gleixner <> Cc: Will Deacon <> Cc: x86-ml <> Cc: Link: