2019-10-11 12:25:15

by Jiri Olsa

[permalink] [raw]
Subject: [PATCH] perf tools: Propagate CFLAGS to libperf

Andi reported that 'make DEBUG=1' does not propagate
to the libbperf code. It's true also for the other
flags. Changing the code to propagate the global
build flags to libperf compilation.

Reported-by: Andi Kleen <[email protected]>
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/Makefile.config | 28 +++++++++++++++-------------
tools/perf/Makefile.perf | 2 +-
tools/perf/lib/core.c | 3 ++-
3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 46f7fba2306c..063202c53b64 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -188,7 +188,7 @@ endif

# Treat warnings as errors unless directed not to
ifneq ($(WERROR),0)
- CFLAGS += -Werror
+ CORE_CFLAGS += -Werror
CXXFLAGS += -Werror
endif

@@ -198,9 +198,9 @@ endif

ifeq ($(DEBUG),0)
ifeq ($(CC_NO_CLANG), 0)
- CFLAGS += -O3
+ CORE_CFLAGS += -O3
else
- CFLAGS += -O6
+ CORE_CFLAGS += -O6
endif
endif

@@ -245,12 +245,12 @@ FEATURE_CHECK_LDFLAGS-libaio = -lrt

FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes -ldl

-CFLAGS += -fno-omit-frame-pointer
-CFLAGS += -ggdb3
-CFLAGS += -funwind-tables
-CFLAGS += -Wall
-CFLAGS += -Wextra
-CFLAGS += -std=gnu99
+CORE_CFLAGS += -fno-omit-frame-pointer
+CORE_CFLAGS += -ggdb3
+CORE_CFLAGS += -funwind-tables
+CORE_CFLAGS += -Wall
+CORE_CFLAGS += -Wextra
+CORE_CFLAGS += -std=gnu99

CXXFLAGS += -std=gnu++11 -fno-exceptions -fno-rtti
CXXFLAGS += -Wall
@@ -272,12 +272,12 @@ include $(FEATURES_DUMP)
endif

ifeq ($(feature-stackprotector-all), 1)
- CFLAGS += -fstack-protector-all
+ CORE_CFLAGS += -fstack-protector-all
endif

ifeq ($(DEBUG),0)
ifeq ($(feature-fortify-source), 1)
- CFLAGS += -D_FORTIFY_SOURCE=2
+ CORE_CFLAGS += -D_FORTIFY_SOURCE=2
endif
endif

@@ -301,10 +301,12 @@ INC_FLAGS += -I$(src-perf)/util
INC_FLAGS += -I$(src-perf)
INC_FLAGS += -I$(srctree)/tools/lib/

-CFLAGS += $(INC_FLAGS)
+CORE_CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
+
+CFLAGS += $(CORE_CFLAGS) $(INC_FLAGS)
CXXFLAGS += $(INC_FLAGS)

-CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
+LIBPERF_CFLAGS := $(CORE_CFLAGS) $(EXTRA_CFLAGS)

ifeq ($(feature-sync-compare-and-swap), 1)
CFLAGS += -DHAVE_SYNC_COMPARE_AND_SWAP_SUPPORT
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 45c14dc24f4b..a099a8a89447 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -769,7 +769,7 @@ $(LIBBPF)-clean:
$(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) clean >/dev/null

$(LIBPERF): FORCE
- $(Q)$(MAKE) -C $(LIBPERF_DIR) O=$(OUTPUT) $(OUTPUT)libperf.a
+ $(Q)$(MAKE) -C $(LIBPERF_DIR) EXTRA_CFLAGS="$(LIBPERF_CFLAGS)" O=$(OUTPUT) $(OUTPUT)libperf.a

$(LIBPERF)-clean:
$(call QUIET_CLEAN, libperf)
diff --git a/tools/perf/lib/core.c b/tools/perf/lib/core.c
index d0b9ae422b9f..58fc894b76c5 100644
--- a/tools/perf/lib/core.c
+++ b/tools/perf/lib/core.c
@@ -5,11 +5,12 @@
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
+#include <linux/compiler.h>
#include <perf/core.h>
#include <internal/lib.h>
#include "internal.h"

-static int __base_pr(enum libperf_print_level level, const char *format,
+static int __base_pr(enum libperf_print_level level __maybe_unused, const char *format,
va_list args)
{
return vfprintf(stderr, format, args);
--
2.21.0


2019-10-11 13:56:27

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH] perf tools: Propagate CFLAGS to libperf

Em Fri, Oct 11, 2019 at 02:21:55PM +0200, Jiri Olsa escreveu:
> Andi reported that 'make DEBUG=1' does not propagate
> to the libbperf code. It's true also for the other
> flags. Changing the code to propagate the global
> build flags to libperf compilation.

Thanks, applied.

- Arnaldo

> Reported-by: Andi Kleen <[email protected]>
> Link: http://lkml.kernel.org/n/[email protected]
> Signed-off-by: Jiri Olsa <[email protected]>
> ---
> tools/perf/Makefile.config | 28 +++++++++++++++-------------
> tools/perf/Makefile.perf | 2 +-
> tools/perf/lib/core.c | 3 ++-
> 3 files changed, 18 insertions(+), 15 deletions(-)
>
> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> index 46f7fba2306c..063202c53b64 100644
> --- a/tools/perf/Makefile.config
> +++ b/tools/perf/Makefile.config
> @@ -188,7 +188,7 @@ endif
>
> # Treat warnings as errors unless directed not to
> ifneq ($(WERROR),0)
> - CFLAGS += -Werror
> + CORE_CFLAGS += -Werror
> CXXFLAGS += -Werror
> endif
>
> @@ -198,9 +198,9 @@ endif
>
> ifeq ($(DEBUG),0)
> ifeq ($(CC_NO_CLANG), 0)
> - CFLAGS += -O3
> + CORE_CFLAGS += -O3
> else
> - CFLAGS += -O6
> + CORE_CFLAGS += -O6
> endif
> endif
>
> @@ -245,12 +245,12 @@ FEATURE_CHECK_LDFLAGS-libaio = -lrt
>
> FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes -ldl
>
> -CFLAGS += -fno-omit-frame-pointer
> -CFLAGS += -ggdb3
> -CFLAGS += -funwind-tables
> -CFLAGS += -Wall
> -CFLAGS += -Wextra
> -CFLAGS += -std=gnu99
> +CORE_CFLAGS += -fno-omit-frame-pointer
> +CORE_CFLAGS += -ggdb3
> +CORE_CFLAGS += -funwind-tables
> +CORE_CFLAGS += -Wall
> +CORE_CFLAGS += -Wextra
> +CORE_CFLAGS += -std=gnu99
>
> CXXFLAGS += -std=gnu++11 -fno-exceptions -fno-rtti
> CXXFLAGS += -Wall
> @@ -272,12 +272,12 @@ include $(FEATURES_DUMP)
> endif
>
> ifeq ($(feature-stackprotector-all), 1)
> - CFLAGS += -fstack-protector-all
> + CORE_CFLAGS += -fstack-protector-all
> endif
>
> ifeq ($(DEBUG),0)
> ifeq ($(feature-fortify-source), 1)
> - CFLAGS += -D_FORTIFY_SOURCE=2
> + CORE_CFLAGS += -D_FORTIFY_SOURCE=2
> endif
> endif
>
> @@ -301,10 +301,12 @@ INC_FLAGS += -I$(src-perf)/util
> INC_FLAGS += -I$(src-perf)
> INC_FLAGS += -I$(srctree)/tools/lib/
>
> -CFLAGS += $(INC_FLAGS)
> +CORE_CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
> +
> +CFLAGS += $(CORE_CFLAGS) $(INC_FLAGS)
> CXXFLAGS += $(INC_FLAGS)
>
> -CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
> +LIBPERF_CFLAGS := $(CORE_CFLAGS) $(EXTRA_CFLAGS)
>
> ifeq ($(feature-sync-compare-and-swap), 1)
> CFLAGS += -DHAVE_SYNC_COMPARE_AND_SWAP_SUPPORT
> diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> index 45c14dc24f4b..a099a8a89447 100644
> --- a/tools/perf/Makefile.perf
> +++ b/tools/perf/Makefile.perf
> @@ -769,7 +769,7 @@ $(LIBBPF)-clean:
> $(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) clean >/dev/null
>
> $(LIBPERF): FORCE
> - $(Q)$(MAKE) -C $(LIBPERF_DIR) O=$(OUTPUT) $(OUTPUT)libperf.a
> + $(Q)$(MAKE) -C $(LIBPERF_DIR) EXTRA_CFLAGS="$(LIBPERF_CFLAGS)" O=$(OUTPUT) $(OUTPUT)libperf.a
>
> $(LIBPERF)-clean:
> $(call QUIET_CLEAN, libperf)
> diff --git a/tools/perf/lib/core.c b/tools/perf/lib/core.c
> index d0b9ae422b9f..58fc894b76c5 100644
> --- a/tools/perf/lib/core.c
> +++ b/tools/perf/lib/core.c
> @@ -5,11 +5,12 @@
> #include <stdio.h>
> #include <stdarg.h>
> #include <unistd.h>
> +#include <linux/compiler.h>
> #include <perf/core.h>
> #include <internal/lib.h>
> #include "internal.h"
>
> -static int __base_pr(enum libperf_print_level level, const char *format,
> +static int __base_pr(enum libperf_print_level level __maybe_unused, const char *format,
> va_list args)
> {
> return vfprintf(stderr, format, args);
> --
> 2.21.0

--

- Arnaldo

Subject: [tip: perf/core] perf tools: Propagate CFLAGS to libperf

The following commit has been merged into the perf/core branch of tip:

Commit-ID: 55542113c690a567e728e40d4181d7d037fc21b0
Gitweb: https://git.kernel.org/tip/55542113c690a567e728e40d4181d7d037fc21b0
Author: Jiri Olsa <[email protected]>
AuthorDate: Fri, 11 Oct 2019 14:21:55 +02:00
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Fri, 11 Oct 2019 10:55:22 -03:00

perf tools: Propagate CFLAGS to libperf

Andi reported that 'make DEBUG=1' does not propagate to the libbperf
code. It's true also for the other flags. Changing the code to propagate
the global build flags to libperf compilation.

Reported-by: Andi Kleen <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Michael Petlan <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/Makefile.config | 28 +++++++++++++++-------------
tools/perf/Makefile.perf | 2 +-
tools/perf/lib/core.c | 3 ++-
3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 46f7fba..063202c 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -188,7 +188,7 @@ endif

# Treat warnings as errors unless directed not to
ifneq ($(WERROR),0)
- CFLAGS += -Werror
+ CORE_CFLAGS += -Werror
CXXFLAGS += -Werror
endif

@@ -198,9 +198,9 @@ endif

ifeq ($(DEBUG),0)
ifeq ($(CC_NO_CLANG), 0)
- CFLAGS += -O3
+ CORE_CFLAGS += -O3
else
- CFLAGS += -O6
+ CORE_CFLAGS += -O6
endif
endif

@@ -245,12 +245,12 @@ FEATURE_CHECK_LDFLAGS-libaio = -lrt

FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes -ldl

-CFLAGS += -fno-omit-frame-pointer
-CFLAGS += -ggdb3
-CFLAGS += -funwind-tables
-CFLAGS += -Wall
-CFLAGS += -Wextra
-CFLAGS += -std=gnu99
+CORE_CFLAGS += -fno-omit-frame-pointer
+CORE_CFLAGS += -ggdb3
+CORE_CFLAGS += -funwind-tables
+CORE_CFLAGS += -Wall
+CORE_CFLAGS += -Wextra
+CORE_CFLAGS += -std=gnu99

CXXFLAGS += -std=gnu++11 -fno-exceptions -fno-rtti
CXXFLAGS += -Wall
@@ -272,12 +272,12 @@ include $(FEATURES_DUMP)
endif

ifeq ($(feature-stackprotector-all), 1)
- CFLAGS += -fstack-protector-all
+ CORE_CFLAGS += -fstack-protector-all
endif

ifeq ($(DEBUG),0)
ifeq ($(feature-fortify-source), 1)
- CFLAGS += -D_FORTIFY_SOURCE=2
+ CORE_CFLAGS += -D_FORTIFY_SOURCE=2
endif
endif

@@ -301,10 +301,12 @@ INC_FLAGS += -I$(src-perf)/util
INC_FLAGS += -I$(src-perf)
INC_FLAGS += -I$(srctree)/tools/lib/

-CFLAGS += $(INC_FLAGS)
+CORE_CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
+
+CFLAGS += $(CORE_CFLAGS) $(INC_FLAGS)
CXXFLAGS += $(INC_FLAGS)

-CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
+LIBPERF_CFLAGS := $(CORE_CFLAGS) $(EXTRA_CFLAGS)

ifeq ($(feature-sync-compare-and-swap), 1)
CFLAGS += -DHAVE_SYNC_COMPARE_AND_SWAP_SUPPORT
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 45c14dc..a099a8a 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -769,7 +769,7 @@ $(LIBBPF)-clean:
$(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) clean >/dev/null

$(LIBPERF): FORCE
- $(Q)$(MAKE) -C $(LIBPERF_DIR) O=$(OUTPUT) $(OUTPUT)libperf.a
+ $(Q)$(MAKE) -C $(LIBPERF_DIR) EXTRA_CFLAGS="$(LIBPERF_CFLAGS)" O=$(OUTPUT) $(OUTPUT)libperf.a

$(LIBPERF)-clean:
$(call QUIET_CLEAN, libperf)
diff --git a/tools/perf/lib/core.c b/tools/perf/lib/core.c
index d0b9ae4..58fc894 100644
--- a/tools/perf/lib/core.c
+++ b/tools/perf/lib/core.c
@@ -5,11 +5,12 @@
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
+#include <linux/compiler.h>
#include <perf/core.h>
#include <internal/lib.h>
#include "internal.h"

-static int __base_pr(enum libperf_print_level level, const char *format,
+static int __base_pr(enum libperf_print_level level __maybe_unused, const char *format,
va_list args)
{
return vfprintf(stderr, format, args);