17 Dec, 2020

1 commit

  • With LTO, everything is compiled into LLVM bitcode, so we have to link
    each module into native code before modpost. Kbuild uses the .lto.o
    suffix for these files, which also ends up in module information. This
    change strips the unnecessary .lto suffix from the module name.

    Bug: 145210207
    Change-Id: I25b97a586f273b1b8d1f153b71e567136b0016ec
    Link: https://lore.kernel.org/lkml/20201211184633.3213045-11-samitolvanen@google.com/
    Suggested-by: Bill Wendling
    Signed-off-by: Sami Tolvanen
    Reviewed-by: Kees Cook

    Sami Tolvanen
     

06 Jun, 2020

9 commits

  • Align with the mmap / munmap APIs.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     
  • new_module() conditionally strips the .o because the modname has .o
    suffix when it is called from read_symbols(), but no .o when it is
    called from read_dump().

    It is clearer to strip .o in read_symbols().

    I also used flexible-array for mod->name.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     
  • The meaning of 'skip' is obscure since it does not explain
    "what to skip".

    mod->skip is set when it is vmlinux or the module info came from
    a dump file.

    So, mod->skip is equivalent to (mod->is_vmlinux || mod->from_dump).

    For the check in write_namespace_deps_files(), mod->is_vmlinux is
    unneeded because the -d option is not passed in the first pass of
    modpost.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     
  • is_vmlinux() is called in several places to check whether the current
    module is vmlinux or not.

    It is faster and clearer to check mod->is_vmlinux flag.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     
  • Previously, there were two cases where mod->is_dot_o is unset:

    [1] the executable 'vmlinux' in the second pass of modpost
    [2] modules loaded by read_dump()

    I think [1] was intended usage to distinguish 'vmlinux.o' and 'vmlinux'.
    Now that modpost does not parse the executable 'vmlinux', this case
    does not happen.

    [2] is obscure, maybe a bug. Module.symver stores module paths without
    extension. So, none of modules loaded by read_dump() has the .o suffix,
    and new_module() unsets ->is_dot_o. Anyway, it is not a big deal because
    handle_symbol() is not called for the case.

    To sum up, all the parsed ELF files are .o files.

    mod->is_dot_o is unneeded.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     
  • get_next_line() is no longer used. Remove.

    grab_file() and release_file() are only used in modpost.c. Make them
    static.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     
  • modpost uses grab_file() to open a file, but it is not suitable for
    a text file because the mmap'ed file is not terminated by null byte.
    Actually, I see some issues for the use of grab_file().

    The new helper, read_text_file() loads the whole file content into a
    malloc'ed buffer, and appends a null byte. Then, get_line() reads
    each line.

    To handle text files, I intend to replace as follows:

    grab_file() -> read_text_file()
    get_new_line() -> get_line()

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     
  • As far as I understood, this code gets rid of '$Revision$' or '$Revision:'
    of CVS, RCS or whatever in MODULE_VERSION() tags.

    Remove the primeval code.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     
  • The meaning of sym->kernel is obscure; it is set for in-kernel symbols
    loaded from Modules.symvers. This happens only when we are building
    external modules, and it is used to determine whether to dump symbols
    to $(KBUILD_EXTMOD)/Modules.symvers

    It is clearer to remember whether the symbol or module came from a dump
    file or ELF object.

    This changes the KBUILD_EXTRA_SYMBOLS behavior. Previously, symbols
    loaded from KBUILD_EXTRA_SYMBOLS are accumulated into the current
    $(KBUILD_EXTMOD)/Modules.symvers

    Going forward, they will be only used to check symbol references, but
    not dumped into the current $(KBUILD_EXTMOD)/Modules.symvers. I believe
    this makes more sense.

    sym->vmlinux will have no user. Remove it too.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     

25 May, 2020

1 commit

  • The current codebase makes use of the zero-length array language
    extension to the C90 standard, but the preferred mechanism to declare
    variable-length types such as these ones is a flexible array member[1][2],
    introduced in C99:

    struct foo {
    int stuff;
    struct boo array[];
    };

    By making use of the mechanism above, we will get a compiler warning
    in case the flexible array does not occur last in the structure, which
    will help us prevent some kind of undefined behavior bugs from being
    inadvertently introduced[3] to the codebase from now on.

    Also, notice that, dynamic memory allocations won't be affected by
    this change:

    "Flexible array members have incomplete type, and so the sizeof operator
    may not be applied. As a quirk of the original implementation of
    zero-length arrays, sizeof evaluates to zero."[1]

    sizeof(flexible-array-member) triggers a warning because flexible array
    members have incomplete type[1]. There are some instances of code in
    which the sizeof operator is being incorrectly/erroneously applied to
    zero-length arrays and the result is zero. Such instances may be hiding
    some bugs. So, this work (flexible-array member conversions) will also
    help to get completely rid of those sorts of issues.

    This issue was found with the help of Coccinelle.

    [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
    [2] https://github.com/KSPP/linux/issues/21
    [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour")

    Signed-off-by: Gustavo A. R. Silva
    Signed-off-by: Masahiro Yamada

    Gustavo A. R. Silva
     

13 Mar, 2020

1 commit

  • Rework modpost's logging interface by consolidating merror(), warn(), and
    fatal() to use a single function, modpost_log(). Introduce different
    logging levels (WARN, ERROR, FATAL) as well. The purpose of this cleanup is
    to reduce code duplication when deciding whether or not to warn or error
    out based on a condition.

    Signed-off-by: Jessica Yu
    Signed-off-by: Masahiro Yamada

    Jessica Yu
     

23 Nov, 2019

1 commit

  • Currently, namespace_from_kstrtabns() relies on the fact that
    namespace strings are recorded in the __ksymtab_strings section.
    Actually, it is coded in include/linux/export.h, but modpost does
    not need to hard-code the section name.

    Elf_Sym::st_shndx holds the index of the relevant section. Using it is
    a more portable way to get the namespace string.

    Make namespace_from_kstrtabns() simply call sym_get_data(), and delete
    the info->ksymtab_strings .

    While I was here, I added more 'const' qualifiers to pointers.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     

11 Nov, 2019

1 commit

  • The modpost, with the -d option given, generates per-module .ns_deps
    files.

    Kbuild generates per-module .mod files to carry module information.
    This is convenient because Make handles multiple jobs in parallel
    when the -j option is given.

    On the other hand, the modpost always runs as a single thread.
    I do not see a strong reason to produce separate .ns_deps files.

    This commit changes the modpost to generate just one file,
    modules.nsdeps, each line of which has the following format:

    :

    Please note it contains *missing* namespaces instead of required ones.
    So, modules.nsdeps is empty if the namespace dependency is all good.

    This will work more efficiently because spatch will no longer process
    already imported namespaces. I removed the '(if needed)' from the
    nsdeps log since spatch is invoked only when needed.

    This also solves the stale .ns_deps problem reported by Jessica Yu:

    https://lkml.org/lkml/2019/10/28/467

    Signed-off-by: Masahiro Yamada
    Tested-by: Jessica Yu
    Acked-by: Jessica Yu
    Reviewed-by: Matthias Maennich
    Tested-by: Matthias Maennich

    Masahiro Yamada
     

18 Oct, 2019

1 commit

  • The introduction of Symbol Namespaces changed the naming schema of the
    __ksymtab entries from __kysmtab__symbol to __ksymtab_NAMESPACE.symbol.

    That caused some breakages in tools that depend on the name layout in
    either the binaries(vmlinux,*.ko) or in System.map. E.g. kmod's depmod
    would not be able to read System.map without a patch to support symbol
    namespaces. A warning reported by depmod for namespaced symbols would
    look like

    depmod: WARNING: [...]/uas.ko needs unknown symbol usb_stor_adjust_quirks

    In order to address this issue, revert to the original naming scheme and
    rather read the __kstrtabns_ entries and their corresponding
    values from __ksymtab_strings to update the namespace values for
    symbols. After having read all symbols and handled them in
    handle_modversions(), the symbols are created. In a second pass, read
    the __kstrtabns_ entries and update the namespaces accordingly.

    Fixes: 8651ec01daed ("module: add support for symbol namespaces.")
    Reported-by: Stefan Wahren
    Suggested-by: Masahiro Yamada
    Acked-by: Will Deacon
    Reviewed-by: Greg Kroah-Hartman
    Reviewed-by: Masahiro Yamada
    Signed-off-by: Matthias Maennich
    Signed-off-by: Jessica Yu

    Matthias Maennich
     

10 Sep, 2019

2 commits

  • This patch adds an option to modpost to generate a .ns_deps file
    per module, containing the namespace dependencies for that module.

    E.g. if the linked module my-module.ko would depend on the symbol
    myfunc.MY_NS in the namespace MY_NS, the my-module.ns_deps file created
    by modpost would contain the entry MY_NS to express the namespace
    dependency of my-module imposed by using the symbol myfunc.

    These files can subsequently be used by static analysis tools (like
    coccinelle scripts) to address issues with missing namespace imports. A
    later patch of this series will introduce such a script 'nsdeps' and a
    corresponding make target to automatically add missing
    MODULE_IMPORT_NS() definitions to the module's sources. For that it uses
    the information provided in the generated .ns_deps files.

    Co-developed-by: Martijn Coenen
    Signed-off-by: Martijn Coenen
    Reviewed-by: Greg Kroah-Hartman
    Signed-off-by: Matthias Maennich
    Signed-off-by: Jessica Yu

    Matthias Maennich
     
  • Add support for symbols that are exported into namespaces. For that,
    extract any namespace suffix from the symbol name. In addition, emit a
    warning whenever a module refers to an exported symbol without
    explicitly importing the namespace that it is defined in. This patch
    consistently adds the namespace suffix to symbol names exported into
    Module.symvers.

    Example warning emitted by modpost in case of the above violation:

    WARNING: module ums-usbat uses symbol usb_stor_resume from namespace
    USB_STORAGE, but does not import it.

    Co-developed-by: Martijn Coenen
    Signed-off-by: Martijn Coenen
    Reviewed-by: Joel Fernandes (Google)
    Reviewed-by: Greg Kroah-Hartman
    Signed-off-by: Matthias Maennich
    Signed-off-by: Jessica Yu

    Matthias Maennich
     

02 Nov, 2017

1 commit

  • Many source files in the tree are missing licensing information, which
    makes it harder for compliance tools to determine the correct license.

    By default all files without license information are under the default
    license of the kernel, which is GPL version 2.

    Update the files which contain no license information with the 'GPL-2.0'
    SPDX license identifier. The SPDX identifier is a legally binding
    shorthand, which can be used instead of the full boiler plate text.

    This patch is based on work done by Thomas Gleixner and Kate Stewart and
    Philippe Ombredanne.

    How this work was done:

    Patches were generated and checked against linux-4.14-rc6 for a subset of
    the use cases:
    - file had no licensing information it it.
    - file was a */uapi/* one with no licensing information in it,
    - file was a */uapi/* one with existing licensing information,

    Further patches will be generated in subsequent months to fix up cases
    where non-standard license headers were used, and references to license
    had to be inferred by heuristics based on keywords.

    The analysis to determine which SPDX License Identifier to be applied to
    a file was done in a spreadsheet of side by side results from of the
    output of two independent scanners (ScanCode & Windriver) producing SPDX
    tag:value files created by Philippe Ombredanne. Philippe prepared the
    base worksheet, and did an initial spot review of a few 1000 files.

    The 4.13 kernel was the starting point of the analysis with 60,537 files
    assessed. Kate Stewart did a file by file comparison of the scanner
    results in the spreadsheet to determine which SPDX license identifier(s)
    to be applied to the file. She confirmed any determination that was not
    immediately clear with lawyers working with the Linux Foundation.

    Criteria used to select files for SPDX license identifier tagging was:
    - Files considered eligible had to be source code files.
    - Make and config files were included as candidates if they contained >5
    lines of source
    - File already had some variant of a license header in it (even if
    Reviewed-by: Philippe Ombredanne
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

20 Aug, 2015

1 commit


14 Feb, 2014

1 commit

  • LTO turns all global symbols effectively into statics. This
    has the side effect that they all have a .NUMBER postfix to make
    them unique. In modpost drop this postfix because it confuses
    it.

    Signed-off-by: Andi Kleen
    Link: http://lkml.kernel.org/r/1391846481-31491-8-git-send-email-ak@linux.intel.com
    Signed-off-by: H. Peter Anvin

    Andi Kleen
     

10 Apr, 2012

1 commit

  • Commit f02e8a6596b7 ("module: Sort exported symbols") sorts symbols
    placing each of them in its own elf section. This sorting and merging
    into the canonical sections are done by the linker.

    Unfortunately modpost to generate Module.symvers file parses vmlinux.o
    (which is not linked yet) and all modules object files (which aren't
    linked yet). These aren't sanitized by the linker yet. That breaks
    modpost that can't detect license properly for modules.

    This patch makes modpost aware of the new exported symbols structure.

    [ This above is a slightly corrected version of the explanation of the
    problem, copied from commit 62a2635610db ("modpost: Fix modpost's
    license checking V3"). That commit fixed the problem for module
    object files, but not for vmlinux.o. This patch fixes modpost for
    vmlinux.o. ]

    Signed-off-by: Frank Rowand
    Signed-off-by: Alessio Igor Bogani
    Signed-off-by: Linus Torvalds

    Frank Rowand
     

19 May, 2011

1 commit

  • Binutils 2.18.50 made a backwards-incompatible change in the way it
    writes ELF objects with over 65280 sections, to improve conformance
    with the ELF specification and interoperability with other ELF tools.
    Specifically, it no longer adds 256 to section indices SHN_LORESERVE
    and higher to skip over the reserved range SHN_LORESERVE through
    SHN_HIRESERVE; those values are only considered special in the
    st_shndx field, and not in other places where section indices are
    stored. See:

    http://sourceware.org/bugzilla/show_bug.cgi?id=5900
    http://groups.google.com/group/generic-abi/browse_thread/thread/e8bb63714b072e67/6c63738f12cc8a17

    Signed-off-by: Anders Kaseorg
    Signed-off-by: Rusty Russell

    Anders Kaseorg
     

03 Aug, 2010

1 commit

  • This patch makes modpost able to process object files with more than
    64k sections. Needed for huge kernel builds (allyesconfig, for example)
    with -ffunction-sections. 64k sections handling is covered, for example,
    by this document:

    "IA-64 gABI Proposal 74: Section Indexes"
    http://www.codesourcery.com/public/cxx-abi/abi/prop-74-sindex.html

    Signed-off-by: Denys Vlasenko
    Signed-off-by: Anders Kaseorg
    Acked-by: Sam Ravnborg
    Cc: Rusty Russell
    Cc: Andi Kleen
    Signed-off-by: Michal Marek

    Denys Vlasenko
     

15 Dec, 2009

1 commit


24 Mar, 2008

1 commit

  • The module alias support in the kernel have a consistency
    check where it is checked that the size of a structure
    in the kernel and on the build host are the same.
    For cross builds this check does not make sense so detect
    when we do cross builds and silently skip the check in these
    situations.
    This fixes a build bug for a wireless driver when cross building
    for arm.

    Acked-by: Michael Buesch
    Tested-by: Gordon Farquharson
    Signed-off-by: Sam Ravnborg
    Cc: stable@kernel.org

    Sam Ravnborg
     

14 Feb, 2008

1 commit

  • This adds some new magic in the MODPOST phase for CONFIG_MARKERS. Analogous
    to the Module.symvers file, the build will now write a Module.markers file
    when CONFIG_MARKERS=y is set. This file lists the name, defining module, and
    format string of each marker, separated by \t characters. This simple text
    file can be used by offline build procedures for instrumentation code,
    analogous to how System.map and Module.symvers can be useful to have for
    kernels other than the one you are running right now.

    The strings are made easy to extract by having the __trace_mark macro define
    the name and format together in a single array called __mstrtab_* in the
    __markers_strings section. This is straightforward and reliable as long as
    the marker structs are always defined by this macro. It is an unreasonable
    amount of hairy work to extract the string pointers from the __markers section
    structs, which entails handling a relocation type for every machine under the
    sun.

    Mathieu :
    - Ran through checkpatch.pl

    Signed-off-by: Roland McGrath
    Signed-off-by: Mathieu Desnoyers
    Cc: David Smith
    Cc: Sam Ravnborg
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Mathieu Desnoyers
     

29 Jan, 2008

1 commit

  • The relocation record sometimes contained an address
    which was not an exactly match for a symbol.

    Implment some simple logic such that if there
    is a symbol within 20 bytes of the address contained
    in the relocation record then print the name of this
    symbol.

    With this change modpost could find symbol names
    for the remaining .init.text symbols in my
    allyesconfig build for x86_64.

    Signed-off-by: Sam Ravnborg

    Sam Ravnborg
     

13 Oct, 2007

1 commit


17 Jul, 2007

1 commit


22 May, 2007

1 commit


19 May, 2007

1 commit

  • On i386, ARM and MIPS, warn_sec_mismatch() sometimes fails to show
    usefull symbol name. This is because empty 'refsym' due to 0 r_addend
    value. This patch is to adjust r_addend value, consulting with
    apply_relocate() routine in kernel code.

    Without this patch:
    MODPOST vmlinux
    WARNING: init/built-in.o - Section mismatch: reference to .init.text: from .text between 'rest_init' (at offset 0xf4) and 'try_name'
    WARNING: mm/built-in.o - Section mismatch: reference to .init.text: from .text between 'kmem_cache_create' (at offset 0x18a39) and 'cache_reap'
    WARNING: mm/built-in.o - Section mismatch: reference to .init.text: from .text between 'kmem_cache_create' (at offset 0x18a6b) and 'cache_reap'

    With this patch:
    MODPOST vmlinux
    WARNING: mm/built-in.o - Section mismatch: reference to .init.text:set_up_list3s from .text between 'kmem_cache_create' (at offset 0x18a39) and 'cache_reap'
    WARNING: mm/built-in.o - Section mismatch: reference to .init.text:set_up_list3s from .text between 'kmem_cache_create' (at offset 0x18a6b) and 'cache_reap'

    Now modpost can detect "kernel_init" name (and whitelist it) and show
    "set_up_list3s" name.

    Signed-off-by: Atsushi Nemoto
    Signed-off-by: Sam Ravnborg

    Atsushi Nemoto
     

03 May, 2007

1 commit


01 Jul, 2006

1 commit


10 Jun, 2006

2 commits

  • Modules that uses GPL symbols can no longer be build with kbuild,
    the build will fail during the modpost step.
    When a GPL-incompatible module uses a EXPORT_SYMBOL_GPL_FUTURE symbol
    then warn during modpost so author are actually notified.

    The actual license compatibility check is shared with the kernel
    to make sure it is in sync.

    Patch originally from: Andreas Gruenbacher and
    Ram Pai

    Signed-off-by: Sam Ravnborg

    Sam Ravnborg
     
  • This patch provides the ability to identify the export-type of each
    exported symbols in Module.symvers.

    NOTE: It updates the Module.symvers file with the additional
    information as shown below.

    0x0f8b92af platform_device_add_resources vmlinux EXPORT_SYMBOL_GPL
    0xcf7efb2a ethtool_op_set_tx_csum vmlinux EXPORT_SYMBOL

    Signed-off-by: Andreas Gruenbacher
    Signed-off-by: Ram Pai
    Signed-off-by: Avantika Mathur
    Signed-off-by: Valdis Kletnieks
    Signed-off-by: Andrew Morton
    Signed-off-by: Sam Ravnborg

    Ram Pai
     

22 May, 2006

2 commits

  • Here is an updated r_info layout fix. Please apply "check SHT_REL
    sections" patch before this.

    64bit mips has different r_info layout. This patch fixes modpost
    segfault for 64bit little endian mips kernel.

    Signed-off-by: Atsushi Nemoto
    Cc: Sam Ravnborg
    Cc: Ralf Baechle
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Atsushi Nemoto
     
  • I found that modpost can not detect section mismatch on mips and i386. On
    mips64, the modpost (with r_info layout fix) can detect it. The current
    modpst only checks SHT_RELA section but I suppose SHT_REL section should be
    checked also. This patch does not contain r_info layout fix. I'll post an
    updated r_info layout fix on next mail.

    Check SHT_REL sections as like as SHT_RELA sections to detect section
    mismatch.

    Signed-off-by: Atsushi Nemoto
    Cc: Sam Ravnborg
    Cc: Ralf Baechle
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Atsushi Nemoto
     

09 May, 2006

1 commit


01 May, 2006

1 commit


03 Mar, 2006

1 commit