17 Jan, 2020

1 commit

  • 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: https://lore.kernel.org/r/20200115184305.1187-1-will@kernel.org
    Signed-off-by: Jonathan Corbet

    Will Deacon
     

25 Oct, 2019

1 commit

  • 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: linux-doc@vger.kernel.org
    Cc: linux-kernel@vger.kernel.org
    Cc: Peter Zijlstra
    Cc: "Steven Rostedt (VMware)"
    Cc: Thomas Gleixner
    Cc: x86@kernel.org
    Link: http://lkml.kernel.org/r/20191018124800.0a7006bb@gandalf.local.home

    Borislav Petkov
     

18 Oct, 2019

1 commit

  • 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: linux-arch@vger.kernel.org
    Cc: linux-doc@vger.kernel.org
    Cc: linux-kernel@vger.kernel.org
    Cc: linux-pm@vger.kernel.org
    Cc: Mark Rutland
    Cc: Pavel Machek
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Will Deacon
    Cc: x86-ml
    Cc: xen-devel@lists.xenproject.org
    Link: https://lkml.kernel.org/r/20191011115108.12392-2-jslaby@suse.cz

    Jiri Slaby