@@ -89,6 +89,8 @@ extern int sprint_symbol_build_id(char *buffer, unsigned long address);
extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
extern int sprint_backtrace(char *buffer, unsigned long address);
extern int sprint_backtrace_build_id(char *buffer, unsigned long address);
+extern int sprint_kallsym_common(char *buffer, unsigned long address, int build_id,
+ int backtrace, int symbol);
int lookup_symbol_name(unsigned long addr, char *symname);
int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
@@ -682,6 +682,20 @@ static inline bool is_livepatch_module(struct module *mod)
void set_module_sig_enforced(void);
+static inline int fill_name_build_id(char *buffer, char *modname,
+ int add_buildid, const unsigned char *buildid,
+ int len)
+{
+ len += sprintf(buffer + len, " [%s", modname);
+#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID)
+ if (add_buildid && buildid) {
+ /* build ID should match length of sprintf */
+ static_assert(sizeof(typeof_member(struct module, build_id)) == 20);
+ len += sprintf(buffer + len, " %20phN", buildid);
+ }
+#endif
+ return len + sprintf(buffer + len, "]");
+}
#else /* !CONFIG_MODULES... */
static inline struct module *__module_address(unsigned long addr)
@@ -818,6 +832,12 @@ void *dereference_module_function_descriptor(struct module *mod, void *ptr)
return ptr;
}
+static inline int fill_name_build_id(char *buffer, char *modname,
+ int add_buildid, const unsigned char *buildid,
+ int len)
+{
+ return 0;
+}
#endif /* CONFIG_MODULES */
#ifdef CONFIG_SYSFS
@@ -461,19 +461,8 @@ static int __sprint_symbol(char *buffer, unsigned long address,
if (add_offset)
len += sprintf(buffer + len, "+%#lx/%#lx", offset, size);
- if (modname) {
- len += sprintf(buffer + len, " [%s", modname);
-#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID)
- if (add_buildid && buildid) {
- /* build ID should match length of sprintf */
-#if IS_ENABLED(CONFIG_MODULES)
- static_assert(sizeof(typeof_member(struct module, build_id)) == 20);
-#endif
- len += sprintf(buffer + len, " %20phN", buildid);
- }
-#endif
- len += sprintf(buffer + len, "]");
- }
+ if (modname)
+ len += fill_name_build_id(buffer, modname, add_buildid, buildid, len);
return len;
}
@@ -568,6 +557,18 @@ int sprint_backtrace_build_id(char *buffer, unsigned long address)
return __sprint_symbol(buffer, address, -1, 1, 1);
}
+int sprint_kallsym_common(char *buffer, unsigned long address, int build_id,
+ int backtrace, int symbol)
+{
+ if (backtrace)
+ return __sprint_symbol(buffer, address, -1, 1, build_id);
+
+ if (symbol)
+ return __sprint_symbol(buffer, address, 0, 1, build_id);
+
+ return __sprint_symbol(buffer, address, 0, 0, 0);
+}
+
/* To avoid using get_symbol_offset for every symbol, we carry prefix along. */
struct kallsym_iter {
loff_t pos;
@@ -206,21 +206,20 @@ static inline void kmemleak_load_module(const struct module *mod,
#endif /* CONFIG_DEBUG_KMEMLEAK */
#ifdef CONFIG_KALLSYMS
-void init_build_id(struct module *mod, const struct load_info *info);
void layout_symtab(struct module *mod, struct load_info *info);
void add_kallsyms(struct module *mod, const struct load_info *info);
unsigned long find_kallsyms_symbol_value(struct module *mod, const char *name);
-static inline bool sect_empty(const Elf_Shdr *sect)
-{
- return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
-}
#else /* !CONFIG_KALLSYMS */
-static inline void init_build_id(struct module *mod, const struct load_info *info) { }
static inline void layout_symtab(struct module *mod, struct load_info *info) { }
static inline void add_kallsyms(struct module *mod, const struct load_info *info) { }
#endif /* CONFIG_KALLSYMS */
+static inline bool sect_empty(const Elf_Shdr *sect)
+{
+ return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
+}
+
#ifdef CONFIG_SYSFS
int mod_sysfs_setup(struct module *mod, const struct load_info *info,
struct kernel_param *kparam, unsigned int num_params);
@@ -209,26 +209,6 @@ void add_kallsyms(struct module *mod, const struct load_info *info)
mod->core_kallsyms.num_symtab = ndst;
}
-#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID)
-void init_build_id(struct module *mod, const struct load_info *info)
-{
- const Elf_Shdr *sechdr;
- unsigned int i;
-
- for (i = 0; i < info->hdr->e_shnum; i++) {
- sechdr = &info->sechdrs[i];
- if (!sect_empty(sechdr) && sechdr->sh_type == SHT_NOTE &&
- !build_id_parse_buf((void *)sechdr->sh_addr, mod->build_id,
- sechdr->sh_size))
- break;
- }
-}
-#else
-void init_build_id(struct module *mod, const struct load_info *info)
-{
-}
-#endif
-
/*
* This ignores the intensely annoying "mapping symbols" found
* in ARM ELF files: $a, $t and $d.
@@ -2657,6 +2657,26 @@ static int unknown_module_param_cb(char *param, char *val, const char *modname,
static void cfi_init(struct module *mod);
+#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID)
+static void init_build_id(struct module *mod, const struct load_info *info)
+{
+ const Elf_Shdr *sechdr;
+ unsigned int i;
+
+ for (i = 0; i < info->hdr->e_shnum; i++) {
+ sechdr = &info->sechdrs[i];
+ if (!sect_empty(sechdr) && sechdr->sh_type == SHT_NOTE &&
+ !build_id_parse_buf((void *)sechdr->sh_addr, mod->build_id,
+ sechdr->sh_size))
+ break;
+ }
+}
+#else
+static inline void init_build_id(struct module *mod, const struct load_info *info)
+{
+}
+#endif
+
/*
* Allocate and load the module: note that size of section 0 is always
* zero, and we rely on this for optional sections.
@@ -981,33 +981,92 @@ char *bdev_name(char *buf, char *end, struct block_device *bdev,
}
#endif
+#if !defined(CONFIG_KALLSYMS) && defined(CONFIG_MODULES)
+static int sprint_module_info(char *buf, unsigned long value,
+ int modbuildid, int backtrace, int symbol)
+{
+ struct module *mod;
+ unsigned long offset;
+ void *base;
+ char *modname;
+ int len;
+ const unsigned char *buildid = NULL;
+ bool add_offset;
+
+ if (is_ksym_addr(value))
+ return 0;
+
+ if (backtrace || symbol)
+ add_offset = true;
+ else
+ add_offset = false;
+
+ preempt_disable();
+ mod = __module_address(value);
+ if (mod) {
+ modname = mod->name;
+#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID)
+ if (modbuildid)
+ buildid = mod->build_id;
+#endif
+ if (add_offset) {
+ base = mod->core_layout.base;
+ offset = value - (unsigned long)base;
+ }
+ }
+ preempt_enable();
+ if (!mod)
+ return 0;
+
+ /* address belongs to module */
+ if (add_offset)
+ len = sprintf(buf, "0x%p+0x%lx", base, offset);
+ else
+ len = sprintf(buf, "0x%lx", value);
+
+ return len + fill_name_build_id(buf, modname, modbuildid, buildid, len);
+}
+#else
+static inline int sprint_module_info(char *buf, unsigned long value,
+ int modbuildid, int backtrace, int symbol)
+{
+ return 0;
+}
+#endif
+
static noinline_for_stack
char *symbol_string(char *buf, char *end, void *ptr,
struct printf_spec spec, const char *fmt)
{
unsigned long value;
-#ifdef CONFIG_KALLSYMS
char sym[KSYM_SYMBOL_LEN];
-#endif
+ int backtrace = 0, symbol = 0, build_id = 0;
if (fmt[1] == 'R')
ptr = __builtin_extract_return_addr(ptr);
value = (unsigned long)ptr;
-#ifdef CONFIG_KALLSYMS
- if (*fmt == 'B' && fmt[1] == 'b')
- sprint_backtrace_build_id(sym, value);
- else if (*fmt == 'B')
- sprint_backtrace(sym, value);
- else if (*fmt == 'S' && (fmt[1] == 'b' || (fmt[1] == 'R' && fmt[2] == 'b')))
- sprint_symbol_build_id(sym, value);
- else if (*fmt != 's')
- sprint_symbol(sym, value);
- else
- sprint_symbol_no_offset(sym, value);
+ if (fmt[0] == 'B' && fmt[1] == 'b') {
+ backtrace = 1;
+ build_id = 1;
+ } else if (fmt[0] == 'B')
+ backtrace = 1;
+ else if (fmt[0] == 'S' && (fmt[1] == 'b' || (fmt[1] == 'R' && fmt[2] == 'b'))) {
+ symbol = 1;
+ build_id = 1;
+ } else if (fmt[0] != 's')
+ symbol = 1;
+ else {
+ /* Do Nothing, no offset */
+ }
+#ifdef CONFIG_KALLSYMS
+ sprint_kallsym_common(sym, value, build_id, backtrace, symbol);
return string_nocheck(buf, end, sym, spec);
#else
+ if (sprint_module_info(sym, value, build_id, backtrace, symbol))
+ return string_nocheck(buf, end, sym, spec);
+
return special_hex_number(buf, end, value, sizeof(void *));
#endif
}