lkml.org 
[lkml]   [2022]   [Sep]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH v6 06/11] kallsyms: Add helper kallsyms_lookup_clang_name()
    Date
    Literally, there is no sense that cleanup_symbol_name() is associated
    with CLANG. So add helper kallsyms_lookup_clang_name() can enhance the
    readability of the code. More importantly, if CONFIG_LTO_CLANG=n, there
    is no need to execute that loop at all.

    Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
    ---
    kernel/kallsyms.c | 34 ++++++++++++++++++++++++++--------
    1 file changed, 26 insertions(+), 8 deletions(-)

    diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
    index 22281dc9a49e35d..7366995f40395ec 100644
    --- a/kernel/kallsyms.c
    +++ b/kernel/kallsyms.c
    @@ -266,6 +266,28 @@ static bool cleanup_symbol_name(char *s)
    return false;
    }

    +static int kallsyms_lookup_clang_name(unsigned char *namebuf, int len,
    + const char *name,
    + unsigned long *addr)
    +{
    + unsigned long i;
    + unsigned int off;
    +
    + if (!IS_ENABLED(CONFIG_LTO_CLANG))
    + return -ENOENT;
    +
    + for (i = 0, off = 0; i < kallsyms_num_syms; i++) {
    + off = kallsyms_expand_symbol(off, namebuf, len);
    +
    + if (cleanup_symbol_name(namebuf) && strcmp(namebuf, name) == 0) {
    + *addr = kallsyms_sym_address(i);
    + return 0;
    + }
    + }
    +
    + return -ENOENT;
    +}
    +
    static int kallsyms_lookup_compressed_name(unsigned char *namebuf, int len,
    unsigned long *addr)
    {
    @@ -302,8 +324,7 @@ static int kallsyms_lookup_compressed_name(unsigned char *namebuf, int len,
    unsigned long kallsyms_lookup_name(const char *name)
    {
    char namebuf[KSYM_NAME_LEN];
    - unsigned long i, addr;
    - unsigned int off;
    + unsigned long addr;
    int ret, len;

    /* Skip the search for empty string. */
    @@ -315,12 +336,9 @@ unsigned long kallsyms_lookup_name(const char *name)
    if (!ret)
    return addr;

    - for (i = 0, off = 0; i < kallsyms_num_syms; i++) {
    - off = kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf));
    -
    - if (cleanup_symbol_name(namebuf) && strcmp(namebuf, name) == 0)
    - return kallsyms_sym_address(i);
    - }
    + ret = kallsyms_lookup_clang_name(namebuf, len, name, &addr);
    + if (!ret)
    + return addr;

    return module_kallsyms_lookup_name(name);
    }
    --
    2.25.1
    \
     
     \ /
      Last update: 2022-09-24 14:23    [W:3.083 / U:0.004 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site