Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc88b3ab authored by Gustavo Romero's avatar Gustavo Romero Committed by Greg Kroah-Hartman
Browse files

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



[ Upstream commit 6ac2226229d931153331a93d90655a3de05b9290 ]

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: default avatarGustavo Romero <gromero@linux.vnet.ibm.com>
Acked-by: default avatarJiri 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent ef8d2a5d
Loading
Loading
Loading
Loading
+38 −11
Original line number Diff line number Diff line
@@ -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)