Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kbuild: Avoid weak external linkage where possible #6798

Closed

Commits on Apr 12, 2024

  1. adding ci files

    Kernel Patches Daemon committed Apr 12, 2024
    Configuration menu
    Copy the full SHA
    f56b981 View commit details
    Browse the repository at this point in the history

Commits on Apr 15, 2024

  1. kallsyms: Avoid weak references for kallsyms symbols

    kallsyms is a directory of all the symbols in the vmlinux binary, and so
    creating it is somewhat of a chicken-and-egg problem, as its non-zero
    size affects the layout of the binary, and therefore the values of the
    symbols.
    
    For this reason, the kernel is linked more than once, and the first pass
    does not include any kallsyms data at all. For the linker to accept
    this, the symbol declarations describing the kallsyms metadata are
    emitted as having weak linkage, so they can remain unsatisfied. During
    the subsequent passes, the weak references are satisfied by the kallsyms
    metadata that was constructed based on information gathered from the
    preceding passes.
    
    Weak references lead to somewhat worse codegen, because taking their
    address may need to produce NULL (if the reference was unsatisfied), and
    this is not usually supported by RIP or PC relative symbol references.
    
    Given that these references are ultimately always satisfied in the final
    link, let's drop the weak annotation, and instead, provide fallback
    definitions in the linker script that are only emitted if an unsatisfied
    reference exists.
    
    While at it, drop the FRV specific annotation that these symbols reside
    in .rodata - FRV is long gone.
    
    Tested-by: Nick Desaulniers <ndesaulniers@google.com> # Boot
    Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
    Reviewed-by: Kees Cook <keescook@chromium.org>
    Acked-by: Arnd Bergmann <arnd@arndb.de>
    Link: https://lkml.kernel.org/r/20230504174320.3930345-1-ardb%40kernel.org
    Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
    ardbiesheuvel authored and Kernel Patches Daemon committed Apr 15, 2024
    Configuration menu
    Copy the full SHA
    984f8d1 View commit details
    Browse the repository at this point in the history
  2. vmlinux: Avoid weak reference to notes section

    Weak references are references that are permitted to remain unsatisfied
    in the final link. This means they cannot be implemented using place
    relative relocations, resulting in GOT entries when using position
    independent code generation.
    
    The notes section should always exist, so the weak annotations can be
    omitted.
    
    Acked-by: Arnd Bergmann <arnd@arndb.de>
    Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
    ardbiesheuvel authored and Kernel Patches Daemon committed Apr 15, 2024
    Configuration menu
    Copy the full SHA
    d21b753 View commit details
    Browse the repository at this point in the history
  3. btf: Avoid weak external references

    If the BTF code is enabled in the build configuration, the start/stop
    BTF markers are guaranteed to exist. Only when CONFIG_DEBUG_INFO_BTF=n,
    the references in btf_parse_vmlinux() will remain unsatisfied, relying
    on the weak linkage of the external references to avoid breaking the
    build.
    
    Avoid GOT based relocations to these markers in the final executable by
    dropping the weak attribute and instead, make btf_parse_vmlinux() return
    ERR_PTR(-ENOENT) directly if CONFIG_DEBUG_INFO_BTF is not enabled to
    begin with.  The compiler will drop any subsequent references to
    __start_BTF and __stop_BTF in that case, allowing the link to succeed.
    
    Note that Clang will notice that taking the address of __start_BTF can
    no longer yield NULL, so testing for that condition becomes unnecessary.
    
    Acked-by: Andrii Nakryiko <andrii@kernel.org>
    Acked-by: Arnd Bergmann <arnd@arndb.de>
    Acked-by: Jiri Olsa <jolsa@kernel.org>
    Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
    ardbiesheuvel authored and Kernel Patches Daemon committed Apr 15, 2024
    Configuration menu
    Copy the full SHA
    e3ad94a View commit details
    Browse the repository at this point in the history