Skip to content

Commit 972f393

Browse files
committed
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: Minchan 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.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 5f1c422 commit 972f393

5 files changed

Lines changed: 42 additions & 23 deletions

File tree

‎tools/perf/util/annotate.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -899,10 +899,8 @@ int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize)
899899
struct kcore_extract kce;
900900
bool delete_extract = false;
901901

902-
if (filename) {
903-
snprintf(symfs_filename, sizeof(symfs_filename), "%s%s",
904-
symbol_conf.symfs, filename);
905-
}
902+
if (filename)
903+
symbol__join_symfs(symfs_filename, filename);
906904

907905
if (filename == NULL) {
908906
if (dso->has_build_id) {
@@ -922,8 +920,7 @@ int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize)
922920
* DSO is the same as when 'perf record' ran.
923921
*/
924922
filename = (char *)dso->long_name;
925-
snprintf(symfs_filename, sizeof(symfs_filename), "%s%s",
926-
symbol_conf.symfs, filename);
923+
symbol__join_symfs(symfs_filename, filename);
927924
free_filename = false;
928925
}
929926

‎tools/perf/util/dso.c‎

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ int dso__read_binary_type_filename(const struct dso *dso,
3737
{
3838
char build_id_hex[BUILD_ID_SIZE * 2 + 1];
3939
int ret = 0;
40+
size_t len;
4041

4142
switch (type) {
4243
case DSO_BINARY_TYPE__DEBUGLINK: {
@@ -60,26 +61,25 @@ int dso__read_binary_type_filename(const struct dso *dso,
6061
break;
6162

6263
case DSO_BINARY_TYPE__FEDORA_DEBUGINFO:
63-
snprintf(filename, size, "%s/usr/lib/debug%s.debug",
64-
symbol_conf.symfs, dso->long_name);
64+
len = __symbol__join_symfs(filename, size, "/usr/lib/debug");
65+
snprintf(filename + len, size - len, "%s.debug", dso->long_name);
6566
break;
6667

6768
case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO:
68-
snprintf(filename, size, "%s/usr/lib/debug%s",
69-
symbol_conf.symfs, dso->long_name);
69+
len = __symbol__join_symfs(filename, size, "/usr/lib/debug");
70+
snprintf(filename + len, size - len, "%s", dso->long_name);
7071
break;
7172

7273
case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO:
7374
{
7475
const char *last_slash;
75-
size_t len;
7676
size_t dir_size;
7777

7878
last_slash = dso->long_name + dso->long_name_len;
7979
while (last_slash != dso->long_name && *last_slash != '/')
8080
last_slash--;
8181

82-
len = scnprintf(filename, size, "%s", symbol_conf.symfs);
82+
len = __symbol__join_symfs(filename, size, "");
8383
dir_size = last_slash - dso->long_name + 2;
8484
if (dir_size > (size - len)) {
8585
ret = -1;
@@ -100,26 +100,24 @@ int dso__read_binary_type_filename(const struct dso *dso,
100100
build_id__sprintf(dso->build_id,
101101
sizeof(dso->build_id),
102102
build_id_hex);
103-
snprintf(filename, size,
104-
"%s/usr/lib/debug/.build-id/%.2s/%s.debug",
105-
symbol_conf.symfs, build_id_hex, build_id_hex + 2);
103+
len = __symbol__join_symfs(filename, size, "/usr/lib/debug/.build-id/");
104+
snprintf(filename + len, size - len, "%.2s/%s.debug",
105+
build_id_hex, build_id_hex + 2);
106106
break;
107107

108108
case DSO_BINARY_TYPE__VMLINUX:
109109
case DSO_BINARY_TYPE__GUEST_VMLINUX:
110110
case DSO_BINARY_TYPE__SYSTEM_PATH_DSO:
111-
snprintf(filename, size, "%s%s",
112-
symbol_conf.symfs, dso->long_name);
111+
__symbol__join_symfs(filename, size, dso->long_name);
113112
break;
114113

115114
case DSO_BINARY_TYPE__GUEST_KMODULE:
116-
snprintf(filename, size, "%s%s%s", symbol_conf.symfs,
117-
root_dir, dso->long_name);
115+
path__join3(filename, size, symbol_conf.symfs,
116+
root_dir, dso->long_name);
118117
break;
119118

120119
case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE:
121-
snprintf(filename, size, "%s%s", symbol_conf.symfs,
122-
dso->long_name);
120+
__symbol__join_symfs(filename, size, dso->long_name);
123121
break;
124122

125123
case DSO_BINARY_TYPE__KCORE:

‎tools/perf/util/symbol.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,8 +1468,7 @@ int dso__load_vmlinux(struct dso *dso, struct map *map,
14681468
if (vmlinux[0] == '/')
14691469
snprintf(symfs_vmlinux, sizeof(symfs_vmlinux), "%s", vmlinux);
14701470
else
1471-
snprintf(symfs_vmlinux, sizeof(symfs_vmlinux), "%s%s",
1472-
symbol_conf.symfs, vmlinux);
1471+
symbol__join_symfs(symfs_vmlinux, vmlinux);
14731472

14741473
if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
14751474
symtab_type = DSO_BINARY_TYPE__GUEST_VMLINUX;

‎tools/perf/util/symbol.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <libgen.h>
1414
#include "build-id.h"
1515
#include "event.h"
16+
#include "util.h"
1617

1718
#ifdef HAVE_LIBELF_SUPPORT
1819
#include <libelf.h>
@@ -143,6 +144,14 @@ struct symbol_conf {
143144
};
144145

145146
extern struct symbol_conf symbol_conf;
147+
148+
static inline int __symbol__join_symfs(char *bf, size_t size, const char *path)
149+
{
150+
return path__join(bf, size, symbol_conf.symfs, path);
151+
}
152+
153+
#define symbol__join_symfs(bf, path) __symbol__join_symfs(bf, sizeof(bf), path)
154+
146155
extern int vmlinux_path__nr_entries;
147156
extern char **vmlinux_path;
148157

‎tools/perf/util/util.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#include <sys/socket.h>
6969
#include <sys/ioctl.h>
7070
#include <inttypes.h>
71+
#include <linux/kernel.h>
7172
#include <linux/magic.h>
7273
#include <linux/types.h>
7374
#include <sys/ttydefaults.h>
@@ -317,6 +318,21 @@ unsigned long parse_tag_value(const char *str, struct parse_tag *tags);
317318

318319
#define SRCLINE_UNKNOWN ((char *) "??:0")
319320

321+
static inline int path__join(char *bf, size_t size,
322+
const char *path1, const char *path2)
323+
{
324+
return scnprintf(bf, size, "%s%s%s", path1, path1[0] ? "/" : "", path2);
325+
}
326+
327+
static inline int path__join3(char *bf, size_t size,
328+
const char *path1, const char *path2,
329+
const char *path3)
330+
{
331+
return scnprintf(bf, size, "%s%s%s%s%s",
332+
path1, path1[0] ? "/" : "",
333+
path2, path2[0] ? "/" : "", path3);
334+
}
335+
320336
struct dso;
321337

322338
char *get_srcline(struct dso *dso, unsigned long addr);

0 commit comments

Comments
 (0)