aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorGustavo Romero <gromero@linux.vnet.ibm.com>2018-11-01 20:13:21 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2018-11-05 14:28:00 -0500
commit6ac2226229d931153331a93d90655a3de05b9290 (patch)
tree1b7c85e39465c5dcca44f34d088195295399b8d3 /tools/perf
parente2c39f36c354a06c6e9d32d4fdf8660b41803d82 (diff)
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>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/jvmti/jvmti_agent.c49
1 files changed, 38 insertions, 11 deletions
diff --git a/tools/perf/jvmti/jvmti_agent.c b/tools/perf/jvmti/jvmti_agent.c
index ac1bcdc17dae..f7eb63cbbc65 100644
--- a/tools/perf/jvmti/jvmti_agent.c
+++ b/tools/perf/jvmti/jvmti_agent.c
@@ -125,7 +125,7 @@ perf_get_timestamp(void)
125} 125}
126 126
127static int 127static int
128debug_cache_init(void) 128create_jit_cache_dir(void)
129{ 129{
130 char str[32]; 130 char str[32];
131 char *base, *p; 131 char *base, *p;
@@ -144,8 +144,13 @@ debug_cache_init(void)
144 144
145 strftime(str, sizeof(str), JIT_LANG"-jit-%Y%m%d", &tm); 145 strftime(str, sizeof(str), JIT_LANG"-jit-%Y%m%d", &tm);
146 146
147 snprintf(jit_path, PATH_MAX - 1, "%s/.debug/", base); 147 ret = snprintf(jit_path, PATH_MAX, "%s/.debug/", base);
148 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 }
149 ret = mkdir(jit_path, 0755); 154 ret = mkdir(jit_path, 0755);
150 if (ret == -1) { 155 if (ret == -1) {
151 if (errno != EEXIST) { 156 if (errno != EEXIST) {
@@ -154,20 +159,32 @@ debug_cache_init(void)
154 } 159 }
155 } 160 }
156 161
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 }
158 ret = mkdir(jit_path, 0755); 169 ret = mkdir(jit_path, 0755);
159 if (ret == -1) { 170 if (ret == -1) {
160 if (errno != EEXIST) { 171 if (errno != EEXIST) {
161 warn("cannot create jit cache dir %s", jit_path); 172 warn("jvmti: cannot create jit cache dir %s", jit_path);
162 return -1; 173 return -1;
163 } 174 }
164 } 175 }
165 176
166 snprintf(jit_path, PATH_MAX - 1, "%s/.debug/jit/%s.XXXXXXXX", base, str); 177 ret = snprintf(jit_path, PATH_MAX, "%s/.debug/jit/%s.XXXXXXXX", base, str);
167 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 }
168 p = mkdtemp(jit_path); 185 p = mkdtemp(jit_path);
169 if (p != jit_path) { 186 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);
171 return -1; 188 return -1;
172 } 189 }
173 190
@@ -228,7 +245,7 @@ void *jvmti_open(void)
228{ 245{
229 char dump_path[PATH_MAX]; 246 char dump_path[PATH_MAX];
230 struct jitheader header; 247 struct jitheader header;
231 int fd; 248 int fd, ret;
232 FILE *fp; 249 FILE *fp;
233 250
234 init_arch_timestamp(); 251 init_arch_timestamp();
@@ -245,12 +262,22 @@ void *jvmti_open(void)
245 262
246 memset(&header, 0, sizeof(header)); 263 memset(&header, 0, sizeof(header));
247 264
248 debug_cache_init(); 265 /*
266 * jitdump file dir
267 */
268 if (create_jit_cache_dir() < 0)
269 return NULL;
249 270
250 /* 271 /*
251 * jitdump file name 272 * jitdump file name
252 */ 273 */
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 }
254 281
255 fd = open(dump_path, O_CREAT|O_TRUNC|O_RDWR, 0666); 282 fd = open(dump_path, O_CREAT|O_TRUNC|O_RDWR, 0666);
256 if (fd == -1) 283 if (fd == -1)