Skip to contentSkip to conversation

tools lib api: Fix make DEBUG=1 build

PATCH Applied Jiri Olsa 3 participants 8 messages Sep 8, 2017 – Sep 22, 2017 perf events

lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

PATCH 1/3 tools lib api: Fix make DEBUG=1 build

Do not use -D_FORTIFY_SOURCE=2 for DEBUG build as it seems to mess up with debuginfo, which results in bad gdb experience.

We already do that for perf.

---
 tools/lib/api/Makefile | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/lib/api/Makefile +7 -1
index 4563ba7ede6f..1e83e3c07448 100644
@@ -17,13 +17,19 @@ MAKEFLAGS += --no-print-directory
 LIBFILE = $(OUTPUT)libapi.a
 
 CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
-CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fPIC
+CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -U_FORTIFY_SOURCE -fPIC
 
+ifeq ($(DEBUG),0)
 ifeq ($(CC_NO_CLANG), 0)
   CFLAGS += -O3
 else
   CFLAGS += -O6
 endif
+endif
+
+ifeq ($(DEBUG),0)
+  CFLAGS += -D_FORTIFY_SOURCE
+endif
 
 # Treat warnings as errors unless directed not to
 ifneq ($(WERROR),0)
Signature · 1 line
2.9.5
author reviewer
#1 lore raw

PATCH 2/3 perf tools: Open perf.data with O_CLOEXEC flag

Do not carry the perf.data file descriptor into
the workload process and close it when perf
executes the workload.

---
 tools/perf/util/data.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/data.c +2 -1
index e84bbc8ec058..6b9d3ec2c276 100644
@@ -96,7 +96,8 @@ static int open_file_write(struct perf_data_file *file)
 	if (check_backup(file))
 		return -1;
 
-	fd = open(file->path, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR);
+	fd = open(file->path, O_CREAT|O_RDWR|O_TRUNC|O_CLOEXEC,
+		  S_IRUSR|S_IWUSR);
 
 	if (fd < 0)
 		pr_err("failed to open %s : %s\n", file->path,
Signature · 1 line
2.9.5
#2 lore raw

Re: [PATCH 2/3] perf tools: Open perf.data with O_CLOEXEC flag

Em Fri, Sep 08, 2017 at 10:46:20AM +0200, Jiri Olsa escreveu:

Quoted 3 lines

Do not carry the perf.data file descriptor into
the workload process and close it when perf
executes the workload.

Fails in some systems with:

util/data.c: In function 'open_file_write':
util/data.c:99: error: 'O_CLOEXEC' undeclared (first use in this function) util/data.c:99: error: (Each undeclared identifier is reported only once util/data.c:99: error: for each function it appears in.)
mv: cannot stat `/tmp/build/perf/util/.data.o.tmp': No such file or directory

just FYI, I'll get this fixed.

Thanks,

- Arnaldo

Quoted 22 lines
---
 tools/perf/util/data.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/data.c +2 -1
index e84bbc8ec058..6b9d3ec2c276 100644
@@ -96,7 +96,8 @@ static int open_file_write(struct perf_data_file *file)
 	if (check_backup(file))
 		return -1;
 
-	fd = open(file->path, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR);
+	fd = open(file->path, O_CREAT|O_RDWR|O_TRUNC|O_CLOEXEC,
+		  S_IRUSR|S_IWUSR);
 
 	if (fd < 0)
 		pr_err("failed to open %s : %s\n", file->path,
Signature · 1 line
2.9.5
#3 lore raw

[tip:perf/urgent] perf tools: Open perf.data with O_CLOEXEC flag

In reply to Jiri Olsa
perf tools: Open perf.data with O_CLOEXEC flag
Commit-ID:  cd6379ebb55ae53e77f17e22ce830bf3fe826736
Gitweb:     http://git.kernel.org/tip/cd6379ebb55ae53e77f17e22ce830bf3fe826736
Author:     Jiri Olsa <[email protected]>
AuthorDate: Fri, 8 Sep 2017 10:46:20 +0200
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 12 Sep 2017 12:34:23 -0300

perf tools: Open perf.data with O_CLOEXEC flag

Do not carry the perf.data file descriptor into the workload process and close it when perf executes the workload.

Cc David Ahern <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
[ Add definitions for O_CLOEXEC for older systems ]
---
 tools/perf/util/data.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
tools/perf/util/data.c +12 -1
index e84bbc8..263f5a9 100644
@@ -10,6 +10,16 @@
 #include "util.h"
 #include "debug.h"
 
+#ifndef O_CLOEXEC
+#ifdef __sparc__
+#define O_CLOEXEC	0x400000
+#elif defined(__alpha__) || defined(__hppa__)
+#define O_CLOEXEC	010000000
+#else
+#define O_CLOEXEC	02000000
+#endif
+#endif
+
 static bool check_pipe(struct perf_data_file *file)
 {
 	struct stat st;
@@ -96,7 +106,8 @@ static int open_file_write(struct perf_data_file *file)
 	if (check_backup(file))
 		return -1;
 
-	fd = open(file->path, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR);
+	fd = open(file->path, O_CREAT|O_RDWR|O_TRUNC|O_CLOEXEC,
+		  S_IRUSR|S_IWUSR);
 
 	if (fd < 0)
 		pr_err("failed to open %s : %s\n", file->path,
author reviewer
#4 lore raw

PATCH 3/3 perf tools: Add python-clean target

In reply to Jiri Olsa

To be able to cleanup only python related binaries.

---
 tools/perf/Makefile.perf | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
tools/perf/Makefile.perf +5 -3
index 91ef44bfaf3e..1df93b4c4648 100644
@@ -173,7 +173,7 @@ AWK     = awk
 # non-config cases
 config := 1
 
-NON_CONFIG_TARGETS := clean TAGS tags cscope help install-doc install-man install-html install-info install-pdf doc man html info pdf
+NON_CONFIG_TARGETS := clean python-clean TAGS tags cscope help install-doc install-man install-html install-info install-pdf doc man html info pdf
 
 ifdef MAKECMDGOALS
 ifeq ($(filter-out $(NON_CONFIG_TARGETS),$(MAKECMDGOALS)),)
@@ -802,7 +802,10 @@ config-clean:
 	$(call QUIET_CLEAN, config)
 	$(Q)$(MAKE) -C $(srctree)/tools/build/feature/ $(if $(OUTPUT),OUTPUT=$(OUTPUT)feature/,) clean >/dev/null
 
-clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean config-clean fixdep-clean
+python-clean:
+	$(python-clean)
+
+clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean config-clean fixdep-clean python-clean
 	$(call QUIET_CLEAN, core-objs)  $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS)
 	$(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
 	$(Q)$(RM) $(OUTPUT).config-detected
@@ -819,7 +822,6 @@ clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clea
 		$(OUTPUT)$(vhost_virtio_ioctl_array) \
 		$(OUTPUT)$(perf_ioctl_array)
 	$(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean
-	$(python-clean)
 
 #
 # To provide FEATURE-DUMP into $(FEATURE_DUMP_COPY)
Signature · 1 line
2.9.5
#5 lore raw

[tip:perf/core] perf tools: Add python-clean target

perf tools: Add python-clean target
Commit-ID:  80f873557112fc163f011cd131d4cfe4959100a6
Gitweb:     http://git.kernel.org/tip/80f873557112fc163f011cd131d4cfe4959100a6
Author:     Jiri Olsa <[email protected]>
AuthorDate: Fri, 8 Sep 2017 10:46:21 +0200
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 13 Sep 2017 09:49:15 -0300

perf tools: Add python-clean target

To be able to cleanup only python related binaries.

---
 tools/perf/Makefile.perf | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
tools/perf/Makefile.perf +5 -3
index 91ef44b..1df93b4 100644
@@ -173,7 +173,7 @@ AWK     = awk
 # non-config cases
 config := 1
 
-NON_CONFIG_TARGETS := clean TAGS tags cscope help install-doc install-man install-html install-info install-pdf doc man html info pdf
+NON_CONFIG_TARGETS := clean python-clean TAGS tags cscope help install-doc install-man install-html install-info install-pdf doc man html info pdf
 
 ifdef MAKECMDGOALS
 ifeq ($(filter-out $(NON_CONFIG_TARGETS),$(MAKECMDGOALS)),)
@@ -802,7 +802,10 @@ config-clean:
 	$(call QUIET_CLEAN, config)
 	$(Q)$(MAKE) -C $(srctree)/tools/build/feature/ $(if $(OUTPUT),OUTPUT=$(OUTPUT)feature/,) clean >/dev/null
 
-clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean config-clean fixdep-clean
+python-clean:
+	$(python-clean)
+
+clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean config-clean fixdep-clean python-clean
 	$(call QUIET_CLEAN, core-objs)  $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS)
 	$(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
 	$(Q)$(RM) $(OUTPUT).config-detected
@@ -819,7 +822,6 @@ clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clea
 		$(OUTPUT)$(vhost_virtio_ioctl_array) \
 		$(OUTPUT)$(perf_ioctl_array)
 	$(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean
-	$(python-clean)
 
 #
 # To provide FEATURE-DUMP into $(FEATURE_DUMP_COPY)
maintainer Applied
#6 lore raw
In reply to Jiri Olsa

Em Fri, Sep 08, 2017 at 10:46:19AM +0200, Jiri Olsa escreveu:

Quoted 4 lines

Do not use -D_FORTIFY_SOURCE=2 for DEBUG build as it seems to mess up with debuginfo, which results in bad gdb experience.

We already do that for perf.

Thanks, applied 1-3.

- Arnaldo

#7 lore raw
In reply to Jiri Olsa
tools lib api: Fix make DEBUG=1 build
Commit-ID:  58b79186c34306f4a14e98119afc10744a42fa40
Gitweb:     http://git.kernel.org/tip/58b79186c34306f4a14e98119afc10744a42fa40
Author:     Jiri Olsa <[email protected]>
AuthorDate: Fri, 8 Sep 2017 10:46:19 +0200
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 12 Sep 2017 12:34:14 -0300

tools lib api: Fix make DEBUG=1 build

Do not use -D_FORTIFY_SOURCE=2 for DEBUG build as it seems to mess up with debuginfo, which results in bad gdb experience.

We already do that for tools/perf/.

---
 tools/lib/api/Makefile | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/lib/api/Makefile +7 -1
index 4563ba7..1e83e3c 100644
@@ -17,13 +17,19 @@ MAKEFLAGS += --no-print-directory
 LIBFILE = $(OUTPUT)libapi.a
 
 CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
-CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fPIC
+CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -U_FORTIFY_SOURCE -fPIC
 
+ifeq ($(DEBUG),0)
 ifeq ($(CC_NO_CLANG), 0)
   CFLAGS += -O3
 else
   CFLAGS += -O6
 endif
+endif
+
+ifeq ($(DEBUG),0)
+  CFLAGS += -D_FORTIFY_SOURCE
+endif
 
 # Treat warnings as errors unless directed not to
 ifneq ($(WERROR),0)