diff options
Diffstat (limited to 'kernel/kallsyms.c')
| -rw-r--r-- | kernel/kallsyms.c | 81 | 
1 files changed, 18 insertions, 63 deletions
| diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 22ea19a36e6e..a9a0ca605d4a 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -148,9 +148,6 @@ static unsigned int get_symbol_offset(unsigned long pos)  unsigned long kallsyms_sym_address(int idx)  { -	if (!IS_ENABLED(CONFIG_KALLSYMS_BASE_RELATIVE)) -		return kallsyms_addresses[idx]; -  	/* values are unsigned offsets if --absolute-percpu is not in effect */  	if (!IS_ENABLED(CONFIG_KALLSYMS_ABSOLUTE_PERCPU))  		return kallsyms_relative_base + (u32)kallsyms_offsets[idx]; @@ -163,38 +160,6 @@ unsigned long kallsyms_sym_address(int idx)  	return kallsyms_relative_base - 1 - kallsyms_offsets[idx];  } -static void cleanup_symbol_name(char *s) -{ -	char *res; - -	if (!IS_ENABLED(CONFIG_LTO_CLANG)) -		return; - -	/* -	 * LLVM appends various suffixes for local functions and variables that -	 * must be promoted to global scope as part of LTO.  This can break -	 * hooking of static functions with kprobes. '.' is not a valid -	 * character in an identifier in C. Suffixes only in LLVM LTO observed: -	 * - foo.llvm.[0-9a-f]+ -	 */ -	res = strstr(s, ".llvm."); -	if (res) -		*res = '\0'; - -	return; -} - -static int compare_symbol_name(const char *name, char *namebuf) -{ -	/* The kallsyms_seqs_of_names is sorted based on names after -	 * cleanup_symbol_name() (see scripts/kallsyms.c) if clang lto is enabled. -	 * To ensure correct bisection in kallsyms_lookup_names(), do -	 * cleanup_symbol_name(namebuf) before comparing name and namebuf. -	 */ -	cleanup_symbol_name(namebuf); -	return strcmp(name, namebuf); -} -  static unsigned int get_symbol_seq(int index)  {  	unsigned int i, seq = 0; @@ -222,7 +187,7 @@ static int kallsyms_lookup_names(const char *name,  		seq = get_symbol_seq(mid);  		off = get_symbol_offset(seq);  		kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf)); -		ret = compare_symbol_name(name, namebuf); +		ret = strcmp(name, namebuf);  		if (ret > 0)  			low = mid + 1;  		else if (ret < 0) @@ -239,7 +204,7 @@ static int kallsyms_lookup_names(const char *name,  		seq = get_symbol_seq(low - 1);  		off = get_symbol_offset(seq);  		kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf)); -		if (compare_symbol_name(name, namebuf)) +		if (strcmp(name, namebuf))  			break;  		low--;  	} @@ -251,7 +216,7 @@ static int kallsyms_lookup_names(const char *name,  			seq = get_symbol_seq(high + 1);  			off = get_symbol_offset(seq);  			kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf)); -			if (compare_symbol_name(name, namebuf)) +			if (strcmp(name, namebuf))  				break;  			high++;  		} @@ -325,7 +290,7 @@ static unsigned long get_symbol_pos(unsigned long addr,  	unsigned long symbol_start = 0, symbol_end = 0;  	unsigned long i, low, high, mid; -	/* Do a binary search on the sorted kallsyms_addresses array. */ +	/* Do a binary search on the sorted kallsyms_offsets array. */  	low = 0;  	high = kallsyms_num_syms; @@ -388,12 +353,12 @@ int kallsyms_lookup_size_offset(unsigned long addr, unsigned long *symbolsize,  	       !!__bpf_address_lookup(addr, symbolsize, offset, namebuf);  } -static const char *kallsyms_lookup_buildid(unsigned long addr, +static int kallsyms_lookup_buildid(unsigned long addr,  			unsigned long *symbolsize,  			unsigned long *offset, char **modname,  			const unsigned char **modbuildid, char *namebuf)  { -	const char *ret; +	int ret;  	namebuf[KSYM_NAME_LEN - 1] = 0;  	namebuf[0] = 0; @@ -410,8 +375,7 @@ static const char *kallsyms_lookup_buildid(unsigned long addr,  		if (modbuildid)  			*modbuildid = NULL; -		ret = namebuf; -		goto found; +		return strlen(namebuf);  	}  	/* See if it's in a module or a BPF JITed image. */ @@ -425,8 +389,6 @@ static const char *kallsyms_lookup_buildid(unsigned long addr,  		ret = ftrace_mod_address_lookup(addr, symbolsize,  						offset, modname, namebuf); -found: -	cleanup_symbol_name(namebuf);  	return ret;  } @@ -442,14 +404,17 @@ const char *kallsyms_lookup(unsigned long addr,  			    unsigned long *offset,  			    char **modname, char *namebuf)  { -	return kallsyms_lookup_buildid(addr, symbolsize, offset, modname, -				       NULL, namebuf); +	int ret = kallsyms_lookup_buildid(addr, symbolsize, offset, modname, +					  NULL, namebuf); + +	if (!ret) +		return NULL; + +	return namebuf;  }  int lookup_symbol_name(unsigned long addr, char *symname)  { -	int res; -  	symname[0] = '\0';  	symname[KSYM_NAME_LEN - 1] = '\0'; @@ -460,16 +425,10 @@ int lookup_symbol_name(unsigned long addr, char *symname)  		/* Grab name */  		kallsyms_expand_symbol(get_symbol_offset(pos),  				       symname, KSYM_NAME_LEN); -		goto found; +		return 0;  	}  	/* See if it's in a module. */ -	res = lookup_module_symbol_name(addr, symname); -	if (res) -		return res; - -found: -	cleanup_symbol_name(symname); -	return 0; +	return lookup_module_symbol_name(addr, symname);  }  /* Look up a kernel symbol and return it in a text buffer. */ @@ -478,19 +437,15 @@ static int __sprint_symbol(char *buffer, unsigned long address,  {  	char *modname;  	const unsigned char *buildid; -	const char *name;  	unsigned long offset, size;  	int len;  	address += symbol_offset; -	name = kallsyms_lookup_buildid(address, &size, &offset, &modname, &buildid, +	len = kallsyms_lookup_buildid(address, &size, &offset, &modname, &buildid,  				       buffer); -	if (!name) +	if (!len)  		return sprintf(buffer, "0x%lx", address - symbol_offset); -	if (name != buffer) -		strcpy(buffer, name); -	len = strlen(buffer);  	offset -= symbol_offset;  	if (add_offset) | 
