Skip to content

Commit

Permalink
kallsyms: Take callthunks into account
Browse files Browse the repository at this point in the history
Since the pre-symbol function padding is an integral part of the
symbol make kallsyms report it as part of the symbol by reporting it
as sym-x instead of prev_sym+y.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220915111148.409656012@infradead.org
  • Loading branch information
Peter Zijlstra committed Oct 17, 2022
1 parent 7825451 commit f138918
Showing 1 changed file with 40 additions and 5 deletions.
45 changes: 40 additions & 5 deletions kernel/kallsyms.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,20 +293,38 @@ static unsigned long get_symbol_pos(unsigned long addr,
return low;
}

#ifdef CONFIG_FUNCTION_PADDING_BYTES
#define PADDING_BYTES CONFIG_FUNCTION_PADDING_BYTES
#else
#define PADDING_BYTES 0
#endif

/*
* Lookup an address but don't bother to find any names.
*/
int kallsyms_lookup_size_offset(unsigned long addr, unsigned long *symbolsize,
unsigned long *offset)
{
char namebuf[KSYM_NAME_LEN];
int ret;

addr += PADDING_BYTES;

if (is_ksym_addr(addr)) {
get_symbol_pos(addr, symbolsize, offset);
return 1;
ret = 1;
goto found;
}

ret = !!module_address_lookup(addr, symbolsize, offset, NULL, NULL, namebuf);
if (!ret) {
ret = !!__bpf_address_lookup(addr, symbolsize,
offset, namebuf);
}
return !!module_address_lookup(addr, symbolsize, offset, NULL, NULL, namebuf) ||
!!__bpf_address_lookup(addr, symbolsize, offset, namebuf);
found:
if (ret && offset)
*offset -= PADDING_BYTES;
return ret;
}

static const char *kallsyms_lookup_buildid(unsigned long addr,
Expand All @@ -319,6 +337,8 @@ static const char *kallsyms_lookup_buildid(unsigned long addr,
namebuf[KSYM_NAME_LEN - 1] = 0;
namebuf[0] = 0;

addr += PADDING_BYTES;

if (is_ksym_addr(addr)) {
unsigned long pos;

Expand Down Expand Up @@ -348,6 +368,8 @@ static const char *kallsyms_lookup_buildid(unsigned long addr,

found:
cleanup_symbol_name(namebuf);
if (ret && offset)
*offset -= PADDING_BYTES;
return ret;
}

Expand All @@ -374,6 +396,8 @@ int lookup_symbol_name(unsigned long addr, char *symname)
symname[0] = '\0';
symname[KSYM_NAME_LEN - 1] = '\0';

addr += PADDING_BYTES;

if (is_ksym_addr(addr)) {
unsigned long pos;

Expand Down Expand Up @@ -401,6 +425,8 @@ int lookup_symbol_attrs(unsigned long addr, unsigned long *size,
name[0] = '\0';
name[KSYM_NAME_LEN - 1] = '\0';

addr += PADDING_BYTES;

if (is_ksym_addr(addr)) {
unsigned long pos;

Expand All @@ -417,6 +443,8 @@ int lookup_symbol_attrs(unsigned long addr, unsigned long *size,
return res;

found:
if (offset)
*offset -= PADDING_BYTES;
cleanup_symbol_name(name);
return 0;
}
Expand All @@ -442,8 +470,15 @@ static int __sprint_symbol(char *buffer, unsigned long address,
len = strlen(buffer);
offset -= symbol_offset;

if (add_offset)
len += sprintf(buffer + len, "+%#lx/%#lx", offset, size);
if (add_offset) {
char s = '+';

if ((long)offset < 0) {
s = '-';
offset = 0UL - offset;
}
len += sprintf(buffer + len, "%c%#lx/%#lx", s, offset, size);
}

if (modname) {
len += sprintf(buffer + len, " [%s", modname);
Expand Down

0 comments on commit f138918

Please sign in to comment.