1
0
Fork 0

perf tools: Fix undefined symbol scnprintf in libperf-jvmti.so

Currently jvmti agent can not be used because function scnprintf is not
present in the agent libperf-jvmti.so. As a result the JVM when using
such agent to record JITed code profiling information will fail on
looking up scnprintf:

  java: symbol lookup error: lib/libperf-jvmti.so: undefined symbol: scnprintf

This commit fixes that by reverting to the use of snprintf, that can be
looked up, instead of scnprintf, adding a proper check for the returned
value in order to print a better error message when the jitdump file
pathname is too long. Checking the returned value also helps to comply
with some recent gcc versions, like gcc8, which will fail due to
truncated writing checks related to the -Werror=format-truncation= flag.

Signed-off-by: Gustavo Romero <gromero@linux.vnet.ibm.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
LPU-Reference: 1541117601-18937-2-git-send-email-gromero@linux.vnet.ibm.com
Link: https://lkml.kernel.org/n/tip-mvpxxxy7wnzaj74cq75muw3f@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
hifive-unleashed-5.1
Gustavo Romero 2018-11-01 20:13:21 -04:00 committed by Arnaldo Carvalho de Melo
parent e2c39f36c3
commit 6ac2226229
1 changed files with 38 additions and 11 deletions

View File

@ -125,7 +125,7 @@ perf_get_timestamp(void)
}
static int
debug_cache_init(void)
create_jit_cache_dir(void)
{
char str[32];
char *base, *p;
@ -144,8 +144,13 @@ debug_cache_init(void)
strftime(str, sizeof(str), JIT_LANG"-jit-%Y%m%d", &tm);
snprintf(jit_path, PATH_MAX - 1, "%s/.debug/", base);
ret = snprintf(jit_path, PATH_MAX, "%s/.debug/", base);
if (ret >= PATH_MAX) {
warnx("jvmti: cannot generate jit cache dir because %s/.debug/"
" is too long, please check the cwd, JITDUMPDIR, and"
" HOME variables", base);
return -1;
}
ret = mkdir(jit_path, 0755);
if (ret == -1) {
if (errno != EEXIST) {
@ -154,20 +159,32 @@ debug_cache_init(void)
}
}
snprintf(jit_path, PATH_MAX - 1, "%s/.debug/jit", base);
ret = snprintf(jit_path, PATH_MAX, "%s/.debug/jit", base);
if (ret >= PATH_MAX) {
warnx("jvmti: cannot generate jit cache dir because"
" %s/.debug/jit is too long, please check the cwd,"
" JITDUMPDIR, and HOME variables", base);
return -1;
}
ret = mkdir(jit_path, 0755);
if (ret == -1) {
if (errno != EEXIST) {
warn("cannot create jit cache dir %s", jit_path);
warn("jvmti: cannot create jit cache dir %s", jit_path);
return -1;
}
}
snprintf(jit_path, PATH_MAX - 1, "%s/.debug/jit/%s.XXXXXXXX", base, str);
ret = snprintf(jit_path, PATH_MAX, "%s/.debug/jit/%s.XXXXXXXX", base, str);
if (ret >= PATH_MAX) {
warnx("jvmti: cannot generate jit cache dir because"
" %s/.debug/jit/%s.XXXXXXXX is too long, please check"
" the cwd, JITDUMPDIR, and HOME variables",
base, str);
return -1;
}
p = mkdtemp(jit_path);
if (p != jit_path) {
warn("cannot create jit cache dir %s", jit_path);
warn("jvmti: cannot create jit cache dir %s", jit_path);
return -1;
}
@ -228,7 +245,7 @@ void *jvmti_open(void)
{
char dump_path[PATH_MAX];
struct jitheader header;
int fd;
int fd, ret;
FILE *fp;
init_arch_timestamp();
@ -245,12 +262,22 @@ void *jvmti_open(void)
memset(&header, 0, sizeof(header));
debug_cache_init();
/*
* jitdump file dir
*/
if (create_jit_cache_dir() < 0)
return NULL;
/*
* jitdump file name
*/
scnprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", jit_path, getpid());
ret = snprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", jit_path, getpid());
if (ret >= PATH_MAX) {
warnx("jvmti: cannot generate jitdump file full path because"
" %s/jit-%i.dump is too long, please check the cwd,"
" JITDUMPDIR, and HOME variables", jit_path, getpid());
return NULL;
}
fd = open(dump_path, O_CREAT|O_TRUNC|O_RDWR, 0666);
if (fd == -1)