Skip to content

Commit 2e36463

Browse files
author
Ingo Molnar
committed
Merge tag 'perf-urgent-for-mingo-4.15-20171218' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent
Pull perf/urgent fixes from Arnaldo Carvalho de Melo: - Fix up build in hardened environments, such as fedora 27 (Jiri Olsa) - Do not include header files from the kernel sources for the s/390 arch, fixing the detached tarball building (Arnaldo Carvalho de Melo) - Allow again using asm.h when building for the 'bpf' clang target, guarding x86 specific bits under ifndef __BPF__ (Arnaldo Carvalho de Melo) - Generate correct debug information for inlined code when generating ELF images for JITted java programs (Ben Gainey) Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Ingo Molnar <mingo@kernel.org>
2 parents 1291a0d + ca26cff commit 2e36463

File tree

8 files changed

+186
-42
lines changed

8 files changed

+186
-42
lines changed

arch/x86/include/asm/asm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
#endif
137137

138138
#ifndef __ASSEMBLY__
139+
#ifndef __BPF__
139140
/*
140141
* This output constraint should be used for any inline asm which has a "call"
141142
* instruction. Otherwise the asm may be inserted before the frame pointer
@@ -145,5 +146,6 @@
145146
register unsigned long current_stack_pointer asm(_ASM_SP);
146147
#define ASM_CALL_CONSTRAINT "+r" (current_stack_pointer)
147148
#endif
149+
#endif
148150

149151
#endif /* _ASM_X86_ASM_H */
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2+
#ifndef _ASM_S390_PERF_REGS_H
3+
#define _ASM_S390_PERF_REGS_H
4+
5+
enum perf_event_s390_regs {
6+
PERF_REG_S390_R0,
7+
PERF_REG_S390_R1,
8+
PERF_REG_S390_R2,
9+
PERF_REG_S390_R3,
10+
PERF_REG_S390_R4,
11+
PERF_REG_S390_R5,
12+
PERF_REG_S390_R6,
13+
PERF_REG_S390_R7,
14+
PERF_REG_S390_R8,
15+
PERF_REG_S390_R9,
16+
PERF_REG_S390_R10,
17+
PERF_REG_S390_R11,
18+
PERF_REG_S390_R12,
19+
PERF_REG_S390_R13,
20+
PERF_REG_S390_R14,
21+
PERF_REG_S390_R15,
22+
PERF_REG_S390_FP0,
23+
PERF_REG_S390_FP1,
24+
PERF_REG_S390_FP2,
25+
PERF_REG_S390_FP3,
26+
PERF_REG_S390_FP4,
27+
PERF_REG_S390_FP5,
28+
PERF_REG_S390_FP6,
29+
PERF_REG_S390_FP7,
30+
PERF_REG_S390_FP8,
31+
PERF_REG_S390_FP9,
32+
PERF_REG_S390_FP10,
33+
PERF_REG_S390_FP11,
34+
PERF_REG_S390_FP12,
35+
PERF_REG_S390_FP13,
36+
PERF_REG_S390_FP14,
37+
PERF_REG_S390_FP15,
38+
PERF_REG_S390_MASK,
39+
PERF_REG_S390_PC,
40+
41+
PERF_REG_S390_MAX
42+
};
43+
44+
#endif /* _ASM_S390_PERF_REGS_H */

tools/perf/Makefile.config

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,7 @@ ifdef PYTHON_CONFIG
188188
PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
189189
PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil
190190
PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
191-
ifeq ($(CC_NO_CLANG), 1)
192-
PYTHON_EMBED_CCOPTS := $(filter-out -specs=%,$(PYTHON_EMBED_CCOPTS))
193-
endif
191+
PYTHON_EMBED_CCOPTS := $(filter-out -specs=%,$(PYTHON_EMBED_CCOPTS))
194192
FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
195193
endif
196194

@@ -576,14 +574,15 @@ ifndef NO_GTK2
576574
endif
577575
endif
578576

579-
580577
ifdef NO_LIBPERL
581578
CFLAGS += -DNO_LIBPERL
582579
else
583580
PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
584581
PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
585582
PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
586-
PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
583+
PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null)
584+
PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS))
585+
PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS))
587586
FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
588587

589588
ifneq ($(feature-libperl), 1)

tools/perf/arch/s390/include/perf_regs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <stdlib.h>
55
#include <linux/types.h>
6-
#include <../../../../arch/s390/include/uapi/asm/perf_regs.h>
6+
#include <asm/perf_regs.h>
77

88
void perf_regs_load(u64 *regs);
99

tools/perf/check-headers.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ arch/x86/include/asm/cpufeatures.h
2121
arch/arm/include/uapi/asm/perf_regs.h
2222
arch/arm64/include/uapi/asm/perf_regs.h
2323
arch/powerpc/include/uapi/asm/perf_regs.h
24+
arch/s390/include/uapi/asm/perf_regs.h
2425
arch/x86/include/uapi/asm/perf_regs.h
2526
arch/x86/include/uapi/asm/kvm.h
2627
arch/x86/include/uapi/asm/kvm_perf.h

tools/perf/jvmti/jvmti_agent.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,13 @@ jvmti_write_code(void *agent, char const *sym,
384384
}
385385

386386
int
387-
jvmti_write_debug_info(void *agent, uint64_t code, const char *file,
388-
jvmti_line_info_t *li, int nr_lines)
387+
jvmti_write_debug_info(void *agent, uint64_t code,
388+
int nr_lines, jvmti_line_info_t *li,
389+
const char * const * file_names)
389390
{
390391
struct jr_code_debug_info rec;
391-
size_t sret, len, size, flen;
392+
size_t sret, len, size, flen = 0;
392393
uint64_t addr;
393-
const char *fn = file;
394394
FILE *fp = agent;
395395
int i;
396396

@@ -405,7 +405,9 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file,
405405
return -1;
406406
}
407407

408-
flen = strlen(file) + 1;
408+
for (i = 0; i < nr_lines; ++i) {
409+
flen += strlen(file_names[i]) + 1;
410+
}
409411

410412
rec.p.id = JIT_CODE_DEBUG_INFO;
411413
size = sizeof(rec);
@@ -421,7 +423,7 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file,
421423
* file[] : source file name
422424
*/
423425
size += nr_lines * sizeof(struct debug_entry);
424-
size += flen * nr_lines;
426+
size += flen;
425427
rec.p.total_size = size;
426428

427429
/*
@@ -452,7 +454,7 @@ jvmti_write_debug_info(void *agent, uint64_t code, const char *file,
452454
if (sret != 1)
453455
goto error;
454456

455-
sret = fwrite_unlocked(fn, flen, 1, fp);
457+
sret = fwrite_unlocked(file_names[i], strlen(file_names[i]) + 1, 1, fp);
456458
if (sret != 1)
457459
goto error;
458460
}

tools/perf/jvmti/jvmti_agent.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ typedef struct {
1414
unsigned long pc;
1515
int line_number;
1616
int discrim; /* discriminator -- 0 for now */
17+
jmethodID methodID;
1718
} jvmti_line_info_t;
1819

1920
void *jvmti_open(void);
@@ -22,11 +23,9 @@ int jvmti_write_code(void *agent, char const *symbol_name,
2223
uint64_t vma, void const *code,
2324
const unsigned int code_size);
2425

25-
int jvmti_write_debug_info(void *agent,
26-
uint64_t code,
27-
const char *file,
26+
int jvmti_write_debug_info(void *agent, uint64_t code, int nr_lines,
2827
jvmti_line_info_t *li,
29-
int nr_lines);
28+
const char * const * file_names);
3029

3130
#if defined(__cplusplus)
3231
}

tools/perf/jvmti/libjvmti.c

Lines changed: 122 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ do_get_line_numbers(jvmtiEnv *jvmti, void *pc, jmethodID m, jint bci,
4747
tab[lines].pc = (unsigned long)pc;
4848
tab[lines].line_number = loc_tab[i].line_number;
4949
tab[lines].discrim = 0; /* not yet used */
50+
tab[lines].methodID = m;
5051
lines++;
5152
} else {
5253
break;
@@ -125,6 +126,99 @@ get_line_numbers(jvmtiEnv *jvmti, const void *compile_info, jvmti_line_info_t **
125126
return JVMTI_ERROR_NONE;
126127
}
127128

129+
static void
130+
copy_class_filename(const char * class_sign, const char * file_name, char * result, size_t max_length)
131+
{
132+
/*
133+
* Assume path name is class hierarchy, this is a common practice with Java programs
134+
*/
135+
if (*class_sign == 'L') {
136+
int j, i = 0;
137+
char *p = strrchr(class_sign, '/');
138+
if (p) {
139+
/* drop the 'L' prefix and copy up to the final '/' */
140+
for (i = 0; i < (p - class_sign); i++)
141+
result[i] = class_sign[i+1];
142+
}
143+
/*
144+
* append file name, we use loops and not string ops to avoid modifying
145+
* class_sign which is used later for the symbol name
146+
*/
147+
for (j = 0; i < (max_length - 1) && file_name && j < strlen(file_name); j++, i++)
148+
result[i] = file_name[j];
149+
150+
result[i] = '\0';
151+
} else {
152+
/* fallback case */
153+
size_t file_name_len = strlen(file_name);
154+
strncpy(result, file_name, file_name_len < max_length ? file_name_len : max_length);
155+
}
156+
}
157+
158+
static jvmtiError
159+
get_source_filename(jvmtiEnv *jvmti, jmethodID methodID, char ** buffer)
160+
{
161+
jvmtiError ret;
162+
jclass decl_class;
163+
char *file_name = NULL;
164+
char *class_sign = NULL;
165+
char fn[PATH_MAX];
166+
size_t len;
167+
168+
ret = (*jvmti)->GetMethodDeclaringClass(jvmti, methodID, &decl_class);
169+
if (ret != JVMTI_ERROR_NONE) {
170+
print_error(jvmti, "GetMethodDeclaringClass", ret);
171+
return ret;
172+
}
173+
174+
ret = (*jvmti)->GetSourceFileName(jvmti, decl_class, &file_name);
175+
if (ret != JVMTI_ERROR_NONE) {
176+
print_error(jvmti, "GetSourceFileName", ret);
177+
return ret;
178+
}
179+
180+
ret = (*jvmti)->GetClassSignature(jvmti, decl_class, &class_sign, NULL);
181+
if (ret != JVMTI_ERROR_NONE) {
182+
print_error(jvmti, "GetClassSignature", ret);
183+
goto free_file_name_error;
184+
}
185+
186+
copy_class_filename(class_sign, file_name, fn, PATH_MAX);
187+
len = strlen(fn);
188+
*buffer = malloc((len + 1) * sizeof(char));
189+
if (!*buffer) {
190+
print_error(jvmti, "GetClassSignature", ret);
191+
ret = JVMTI_ERROR_OUT_OF_MEMORY;
192+
goto free_class_sign_error;
193+
}
194+
strcpy(*buffer, fn);
195+
ret = JVMTI_ERROR_NONE;
196+
197+
free_class_sign_error:
198+
(*jvmti)->Deallocate(jvmti, (unsigned char *)class_sign);
199+
free_file_name_error:
200+
(*jvmti)->Deallocate(jvmti, (unsigned char *)file_name);
201+
202+
return ret;
203+
}
204+
205+
static jvmtiError
206+
fill_source_filenames(jvmtiEnv *jvmti, int nr_lines,
207+
const jvmti_line_info_t * line_tab,
208+
char ** file_names)
209+
{
210+
int index;
211+
jvmtiError ret;
212+
213+
for (index = 0; index < nr_lines; ++index) {
214+
ret = get_source_filename(jvmti, line_tab[index].methodID, &(file_names[index]));
215+
if (ret != JVMTI_ERROR_NONE)
216+
return ret;
217+
}
218+
219+
return JVMTI_ERROR_NONE;
220+
}
221+
128222
static void JNICALL
129223
compiled_method_load_cb(jvmtiEnv *jvmti,
130224
jmethodID method,
@@ -135,16 +229,18 @@ compiled_method_load_cb(jvmtiEnv *jvmti,
135229
const void *compile_info)
136230
{
137231
jvmti_line_info_t *line_tab = NULL;
232+
char ** line_file_names = NULL;
138233
jclass decl_class;
139234
char *class_sign = NULL;
140235
char *func_name = NULL;
141236
char *func_sign = NULL;
142-
char *file_name= NULL;
237+
char *file_name = NULL;
143238
char fn[PATH_MAX];
144239
uint64_t addr = (uint64_t)(uintptr_t)code_addr;
145240
jvmtiError ret;
146241
int nr_lines = 0; /* in line_tab[] */
147242
size_t len;
243+
int output_debug_info = 0;
148244

149245
ret = (*jvmti)->GetMethodDeclaringClass(jvmti, method,
150246
&decl_class);
@@ -158,6 +254,19 @@ compiled_method_load_cb(jvmtiEnv *jvmti,
158254
if (ret != JVMTI_ERROR_NONE) {
159255
warnx("jvmti: cannot get line table for method");
160256
nr_lines = 0;
257+
} else if (nr_lines > 0) {
258+
line_file_names = malloc(sizeof(char*) * nr_lines);
259+
if (!line_file_names) {
260+
warnx("jvmti: cannot allocate space for line table method names");
261+
} else {
262+
memset(line_file_names, 0, sizeof(char*) * nr_lines);
263+
ret = fill_source_filenames(jvmti, nr_lines, line_tab, line_file_names);
264+
if (ret != JVMTI_ERROR_NONE) {
265+
warnx("jvmti: fill_source_filenames failed");
266+
} else {
267+
output_debug_info = 1;
268+
}
269+
}
161270
}
162271
}
163272

@@ -181,33 +290,14 @@ compiled_method_load_cb(jvmtiEnv *jvmti,
181290
goto error;
182291
}
183292

184-
/*
185-
* Assume path name is class hierarchy, this is a common practice with Java programs
186-
*/
187-
if (*class_sign == 'L') {
188-
int j, i = 0;
189-
char *p = strrchr(class_sign, '/');
190-
if (p) {
191-
/* drop the 'L' prefix and copy up to the final '/' */
192-
for (i = 0; i < (p - class_sign); i++)
193-
fn[i] = class_sign[i+1];
194-
}
195-
/*
196-
* append file name, we use loops and not string ops to avoid modifying
197-
* class_sign which is used later for the symbol name
198-
*/
199-
for (j = 0; i < (PATH_MAX - 1) && file_name && j < strlen(file_name); j++, i++)
200-
fn[i] = file_name[j];
201-
fn[i] = '\0';
202-
} else {
203-
/* fallback case */
204-
strcpy(fn, file_name);
205-
}
293+
copy_class_filename(class_sign, file_name, fn, PATH_MAX);
294+
206295
/*
207296
* write source line info record if we have it
208297
*/
209-
if (jvmti_write_debug_info(jvmti_agent, addr, fn, line_tab, nr_lines))
210-
warnx("jvmti: write_debug_info() failed");
298+
if (output_debug_info)
299+
if (jvmti_write_debug_info(jvmti_agent, addr, nr_lines, line_tab, (const char * const *) line_file_names))
300+
warnx("jvmti: write_debug_info() failed");
211301

212302
len = strlen(func_name) + strlen(class_sign) + strlen(func_sign) + 2;
213303
{
@@ -223,6 +313,13 @@ compiled_method_load_cb(jvmtiEnv *jvmti,
223313
(*jvmti)->Deallocate(jvmti, (unsigned char *)class_sign);
224314
(*jvmti)->Deallocate(jvmti, (unsigned char *)file_name);
225315
free(line_tab);
316+
while (line_file_names && (nr_lines > 0)) {
317+
if (line_file_names[nr_lines - 1]) {
318+
free(line_file_names[nr_lines - 1]);
319+
}
320+
nr_lines -= 1;
321+
}
322+
free(line_file_names);
226323
}
227324

228325
static void JNICALL

0 commit comments

Comments
 (0)