Skip to content

Commit 6ac2226

Browse files
Gustavo Romeroacmel
authored andcommitted
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>
1 parent e2c39f3 commit 6ac2226

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

tools/perf/jvmti/jvmti_agent.c

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ perf_get_timestamp(void)
125125
}
126126

127127
static int
128-
debug_cache_init(void)
128+
create_jit_cache_dir(void)
129129
{
130130
char str[32];
131131
char *base, *p;
@@ -144,8 +144,13 @@ debug_cache_init(void)
144144

145145
strftime(str, sizeof(str), JIT_LANG"-jit-%Y%m%d", &tm);
146146

147-
snprintf(jit_path, PATH_MAX - 1, "%s/.debug/", base);
148-
147+
ret = snprintf(jit_path, PATH_MAX, "%s/.debug/", base);
148+
if (ret >= PATH_MAX) {
149+
warnx("jvmti: cannot generate jit cache dir because %s/.debug/"
150+
" is too long, please check the cwd, JITDUMPDIR, and"
151+
" HOME variables", base);
152+
return -1;
153+
}
149154
ret = mkdir(jit_path, 0755);
150155
if (ret == -1) {
151156
if (errno != EEXIST) {
@@ -154,20 +159,32 @@ debug_cache_init(void)
154159
}
155160
}
156161

157-
snprintf(jit_path, PATH_MAX - 1, "%s/.debug/jit", base);
162+
ret = snprintf(jit_path, PATH_MAX, "%s/.debug/jit", base);
163+
if (ret >= PATH_MAX) {
164+
warnx("jvmti: cannot generate jit cache dir because"
165+
" %s/.debug/jit is too long, please check the cwd,"
166+
" JITDUMPDIR, and HOME variables", base);
167+
return -1;
168+
}
158169
ret = mkdir(jit_path, 0755);
159170
if (ret == -1) {
160171
if (errno != EEXIST) {
161-
warn("cannot create jit cache dir %s", jit_path);
172+
warn("jvmti: cannot create jit cache dir %s", jit_path);
162173
return -1;
163174
}
164175
}
165176

166-
snprintf(jit_path, PATH_MAX - 1, "%s/.debug/jit/%s.XXXXXXXX", base, str);
167-
177+
ret = snprintf(jit_path, PATH_MAX, "%s/.debug/jit/%s.XXXXXXXX", base, str);
178+
if (ret >= PATH_MAX) {
179+
warnx("jvmti: cannot generate jit cache dir because"
180+
" %s/.debug/jit/%s.XXXXXXXX is too long, please check"
181+
" the cwd, JITDUMPDIR, and HOME variables",
182+
base, str);
183+
return -1;
184+
}
168185
p = mkdtemp(jit_path);
169186
if (p != jit_path) {
170-
warn("cannot create jit cache dir %s", jit_path);
187+
warn("jvmti: cannot create jit cache dir %s", jit_path);
171188
return -1;
172189
}
173190

@@ -228,7 +245,7 @@ void *jvmti_open(void)
228245
{
229246
char dump_path[PATH_MAX];
230247
struct jitheader header;
231-
int fd;
248+
int fd, ret;
232249
FILE *fp;
233250

234251
init_arch_timestamp();
@@ -245,12 +262,22 @@ void *jvmti_open(void)
245262

246263
memset(&header, 0, sizeof(header));
247264

248-
debug_cache_init();
265+
/*
266+
* jitdump file dir
267+
*/
268+
if (create_jit_cache_dir() < 0)
269+
return NULL;
249270

250271
/*
251272
* jitdump file name
252273
*/
253-
scnprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", jit_path, getpid());
274+
ret = snprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", jit_path, getpid());
275+
if (ret >= PATH_MAX) {
276+
warnx("jvmti: cannot generate jitdump file full path because"
277+
" %s/jit-%i.dump is too long, please check the cwd,"
278+
" JITDUMPDIR, and HOME variables", jit_path, getpid());
279+
return NULL;
280+
}
254281

255282
fd = open(dump_path, O_CREAT|O_TRUNC|O_RDWR, 0666);
256283
if (fd == -1)

0 commit comments

Comments
 (0)