Commit 972f393b authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo Committed by Arnaldo Carvalho de Melo

perf symbols: Make sure --symfs usage includes the path separator

Minchan reported that perf failed to load vmlinux if --symfs argument
doesn't end with '/' character.

Fix it by making sure that the '/' path separator is used when composing
pathnames with a --symfs provided directory name.
Reported-by: default avatarMinchan Kim <minchan@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/n/tip-8n4s6b6zvsez5ktanw006125@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 5f1c4225
...@@ -899,10 +899,8 @@ int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize) ...@@ -899,10 +899,8 @@ int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize)
struct kcore_extract kce; struct kcore_extract kce;
bool delete_extract = false; bool delete_extract = false;
if (filename) { if (filename)
snprintf(symfs_filename, sizeof(symfs_filename), "%s%s", symbol__join_symfs(symfs_filename, filename);
symbol_conf.symfs, filename);
}
if (filename == NULL) { if (filename == NULL) {
if (dso->has_build_id) { if (dso->has_build_id) {
...@@ -922,8 +920,7 @@ int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize) ...@@ -922,8 +920,7 @@ int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize)
* DSO is the same as when 'perf record' ran. * DSO is the same as when 'perf record' ran.
*/ */
filename = (char *)dso->long_name; filename = (char *)dso->long_name;
snprintf(symfs_filename, sizeof(symfs_filename), "%s%s", symbol__join_symfs(symfs_filename, filename);
symbol_conf.symfs, filename);
free_filename = false; free_filename = false;
} }
......
...@@ -37,6 +37,7 @@ int dso__read_binary_type_filename(const struct dso *dso, ...@@ -37,6 +37,7 @@ int dso__read_binary_type_filename(const struct dso *dso,
{ {
char build_id_hex[BUILD_ID_SIZE * 2 + 1]; char build_id_hex[BUILD_ID_SIZE * 2 + 1];
int ret = 0; int ret = 0;
size_t len;
switch (type) { switch (type) {
case DSO_BINARY_TYPE__DEBUGLINK: { case DSO_BINARY_TYPE__DEBUGLINK: {
...@@ -60,26 +61,25 @@ int dso__read_binary_type_filename(const struct dso *dso, ...@@ -60,26 +61,25 @@ int dso__read_binary_type_filename(const struct dso *dso,
break; break;
case DSO_BINARY_TYPE__FEDORA_DEBUGINFO: case DSO_BINARY_TYPE__FEDORA_DEBUGINFO:
snprintf(filename, size, "%s/usr/lib/debug%s.debug", len = __symbol__join_symfs(filename, size, "/usr/lib/debug");
symbol_conf.symfs, dso->long_name); snprintf(filename + len, size - len, "%s.debug", dso->long_name);
break; break;
case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO: case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO:
snprintf(filename, size, "%s/usr/lib/debug%s", len = __symbol__join_symfs(filename, size, "/usr/lib/debug");
symbol_conf.symfs, dso->long_name); snprintf(filename + len, size - len, "%s", dso->long_name);
break; break;
case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO: case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO:
{ {
const char *last_slash; const char *last_slash;
size_t len;
size_t dir_size; size_t dir_size;
last_slash = dso->long_name + dso->long_name_len; last_slash = dso->long_name + dso->long_name_len;
while (last_slash != dso->long_name && *last_slash != '/') while (last_slash != dso->long_name && *last_slash != '/')
last_slash--; last_slash--;
len = scnprintf(filename, size, "%s", symbol_conf.symfs); len = __symbol__join_symfs(filename, size, "");
dir_size = last_slash - dso->long_name + 2; dir_size = last_slash - dso->long_name + 2;
if (dir_size > (size - len)) { if (dir_size > (size - len)) {
ret = -1; ret = -1;
...@@ -100,26 +100,24 @@ int dso__read_binary_type_filename(const struct dso *dso, ...@@ -100,26 +100,24 @@ int dso__read_binary_type_filename(const struct dso *dso,
build_id__sprintf(dso->build_id, build_id__sprintf(dso->build_id,
sizeof(dso->build_id), sizeof(dso->build_id),
build_id_hex); build_id_hex);
snprintf(filename, size, len = __symbol__join_symfs(filename, size, "/usr/lib/debug/.build-id/");
"%s/usr/lib/debug/.build-id/%.2s/%s.debug", snprintf(filename + len, size - len, "%.2s/%s.debug",
symbol_conf.symfs, build_id_hex, build_id_hex + 2); build_id_hex, build_id_hex + 2);
break; break;
case DSO_BINARY_TYPE__VMLINUX: case DSO_BINARY_TYPE__VMLINUX:
case DSO_BINARY_TYPE__GUEST_VMLINUX: case DSO_BINARY_TYPE__GUEST_VMLINUX:
case DSO_BINARY_TYPE__SYSTEM_PATH_DSO: case DSO_BINARY_TYPE__SYSTEM_PATH_DSO:
snprintf(filename, size, "%s%s", __symbol__join_symfs(filename, size, dso->long_name);
symbol_conf.symfs, dso->long_name);
break; break;
case DSO_BINARY_TYPE__GUEST_KMODULE: case DSO_BINARY_TYPE__GUEST_KMODULE:
snprintf(filename, size, "%s%s%s", symbol_conf.symfs, path__join3(filename, size, symbol_conf.symfs,
root_dir, dso->long_name); root_dir, dso->long_name);
break; break;
case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE: case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE:
snprintf(filename, size, "%s%s", symbol_conf.symfs, __symbol__join_symfs(filename, size, dso->long_name);
dso->long_name);
break; break;
case DSO_BINARY_TYPE__KCORE: case DSO_BINARY_TYPE__KCORE:
......
...@@ -1468,8 +1468,7 @@ int dso__load_vmlinux(struct dso *dso, struct map *map, ...@@ -1468,8 +1468,7 @@ int dso__load_vmlinux(struct dso *dso, struct map *map,
if (vmlinux[0] == '/') if (vmlinux[0] == '/')
snprintf(symfs_vmlinux, sizeof(symfs_vmlinux), "%s", vmlinux); snprintf(symfs_vmlinux, sizeof(symfs_vmlinux), "%s", vmlinux);
else else
snprintf(symfs_vmlinux, sizeof(symfs_vmlinux), "%s%s", symbol__join_symfs(symfs_vmlinux, vmlinux);
symbol_conf.symfs, vmlinux);
if (dso->kernel == DSO_TYPE_GUEST_KERNEL) if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
symtab_type = DSO_BINARY_TYPE__GUEST_VMLINUX; symtab_type = DSO_BINARY_TYPE__GUEST_VMLINUX;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <libgen.h> #include <libgen.h>
#include "build-id.h" #include "build-id.h"
#include "event.h" #include "event.h"
#include "util.h"
#ifdef HAVE_LIBELF_SUPPORT #ifdef HAVE_LIBELF_SUPPORT
#include <libelf.h> #include <libelf.h>
...@@ -143,6 +144,14 @@ struct symbol_conf { ...@@ -143,6 +144,14 @@ struct symbol_conf {
}; };
extern struct symbol_conf symbol_conf; extern struct symbol_conf symbol_conf;
static inline int __symbol__join_symfs(char *bf, size_t size, const char *path)
{
return path__join(bf, size, symbol_conf.symfs, path);
}
#define symbol__join_symfs(bf, path) __symbol__join_symfs(bf, sizeof(bf), path)
extern int vmlinux_path__nr_entries; extern int vmlinux_path__nr_entries;
extern char **vmlinux_path; extern char **vmlinux_path;
......
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <inttypes.h> #include <inttypes.h>
#include <linux/kernel.h>
#include <linux/magic.h> #include <linux/magic.h>
#include <linux/types.h> #include <linux/types.h>
#include <sys/ttydefaults.h> #include <sys/ttydefaults.h>
...@@ -317,6 +318,21 @@ unsigned long parse_tag_value(const char *str, struct parse_tag *tags); ...@@ -317,6 +318,21 @@ unsigned long parse_tag_value(const char *str, struct parse_tag *tags);
#define SRCLINE_UNKNOWN ((char *) "??:0") #define SRCLINE_UNKNOWN ((char *) "??:0")
static inline int path__join(char *bf, size_t size,
const char *path1, const char *path2)
{
return scnprintf(bf, size, "%s%s%s", path1, path1[0] ? "/" : "", path2);
}
static inline int path__join3(char *bf, size_t size,
const char *path1, const char *path2,
const char *path3)
{
return scnprintf(bf, size, "%s%s%s%s%s",
path1, path1[0] ? "/" : "",
path2, path2[0] ? "/" : "", path3);
}
struct dso; struct dso;
char *get_srcline(struct dso *dso, unsigned long addr); char *get_srcline(struct dso *dso, unsigned long addr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment