git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] Makefile: use CXXFLAGS for linking fuzzers
@ 2018-11-12 22:02 steadmon
  2018-11-12 22:47 ` Stefan Beller
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: steadmon @ 2018-11-12 22:02 UTC (permalink / raw)
  To: git

OSS-Fuzz requires C++-specific flags to link fuzzers. Passing these in
CFLAGS causes lots of build warnings. Using separate CXXFLAGS avoids
this.

Signed-off-by: Josh Steadmon <steadmon@google.com>
---
 Makefile | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index bbfbb4292d..5462bc4b6b 100644
--- a/Makefile
+++ b/Makefile
@@ -497,6 +497,7 @@ GIT-VERSION-FILE: FORCE
 # CFLAGS and LDFLAGS are for the users to override from the command line.
 
 CFLAGS = -g -O2 -Wall
+CXXFLAGS ?= $(CFLAGS)
 LDFLAGS =
 ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS)
 ALL_LDFLAGS = $(LDFLAGS)
@@ -3098,14 +3099,14 @@ cover_db_html: cover_db
 # An example command to build against libFuzzer from LLVM 4.0.0:
 #
 # make CC=clang CXX=clang++ \
-#      CFLAGS="-fsanitize-coverage=trace-pc-guard -fsanitize=address" \
+#      CXXFLAGS="-fsanitize-coverage=trace-pc-guard -fsanitize=address" \
 #      LIB_FUZZING_ENGINE=/usr/lib/llvm-4.0/lib/libFuzzer.a \
 #      fuzz-all
 #
 .PHONY: fuzz-all
 
 $(FUZZ_PROGRAMS): all
-	$(QUIET_LINK)$(CXX) $(CFLAGS) $(LIB_OBJS) $(BUILTIN_OBJS) \
+	$(QUIET_LINK)$(CXX) $(CXXFLAGS) $(LIB_OBJS) $(BUILTIN_OBJS) \
 		$(XDIFF_OBJS) $(EXTLIBS) git.o $@.o $(LIB_FUZZING_ENGINE) -o $@
 
 fuzz-all: $(FUZZ_PROGRAMS)
-- 
2.19.1.930.g4563a0d9d0-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Makefile: use CXXFLAGS for linking fuzzers
  2018-11-12 22:02 [PATCH] Makefile: use CXXFLAGS for linking fuzzers steadmon
@ 2018-11-12 22:47 ` Stefan Beller
  2018-11-13  3:12 ` Junio C Hamano
  2018-11-14 19:41 ` [PATCH v2] Makefile: use FUZZ_CXXFLAGS " Josh Steadmon
  2 siblings, 0 replies; 6+ messages in thread
From: Stefan Beller @ 2018-11-12 22:47 UTC (permalink / raw)
  To: Josh Steadmon; +Cc: git

On Mon, Nov 12, 2018 at 2:03 PM <steadmon@google.com> wrote:
>
> OSS-Fuzz requires C++-specific flags to link fuzzers. Passing these in
> CFLAGS causes lots of build warnings. Using separate CXXFLAGS avoids
> this.
>

That makes sense in this context, ....

>  CFLAGS = -g -O2 -Wall
> +CXXFLAGS ?= $(CFLAGS)

... but out of context, just by reading the relevant part of the Makefile,
a user might mistakenly assume we do some C++ trickery for standard
compilation of Git. (Is that bad or do we just not care?)

I wonder if setting the CXXFLAGS near or in the fuzz target
would be better.

>  LDFLAGS =
>  ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS)
>  ALL_LDFLAGS = $(LDFLAGS)
> @@ -3098,14 +3099,14 @@ cover_db_html: cover_db
>  # An example command to build against libFuzzer from LLVM 4.0.0:
>  #
>  # make CC=clang CXX=clang++ \
> -#      CFLAGS="-fsanitize-coverage=trace-pc-guard -fsanitize=address" \
> +#      CXXFLAGS="-fsanitize-coverage=trace-pc-guard -fsanitize=address" \
>  #      LIB_FUZZING_ENGINE=/usr/lib/llvm-4.0/lib/libFuzzer.a \
>  #      fuzz-all
>  #
>  .PHONY: fuzz-all

Maybe here?

>
>  $(FUZZ_PROGRAMS): all
> -       $(QUIET_LINK)$(CXX) $(CFLAGS) $(LIB_OBJS) $(BUILTIN_OBJS) \
> +       $(QUIET_LINK)$(CXX) $(CXXFLAGS) $(LIB_OBJS) $(BUILTIN_OBJS) \
>                 $(XDIFF_OBJS) $(EXTLIBS) git.o $@.o $(LIB_FUZZING_ENGINE) -o $@

Thanks,
Stefan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Makefile: use CXXFLAGS for linking fuzzers
  2018-11-12 22:02 [PATCH] Makefile: use CXXFLAGS for linking fuzzers steadmon
  2018-11-12 22:47 ` Stefan Beller
@ 2018-11-13  3:12 ` Junio C Hamano
  2018-11-13 18:50   ` Josh Steadmon
  2018-11-14 19:41 ` [PATCH v2] Makefile: use FUZZ_CXXFLAGS " Josh Steadmon
  2 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2018-11-13  3:12 UTC (permalink / raw)
  To: steadmon; +Cc: git

steadmon@google.com writes:

> OSS-Fuzz requires C++-specific flags to link fuzzers. Passing these in
> CFLAGS causes lots of build warnings. Using separate CXXFLAGS avoids
> this.

We are not a C++ shop, so allow me to show ignorance about how
projects that are OSS-Fuzz-enabled work.  Do they use one set of
CXXFLAGS when compiling the "real thing" and a separate set (perhaps
one is subset of the other, or perhaps these two just have overlap)
of CXXFLAGS when building to link with the fuzzer?

What I am trying to get at is if this should be CXXFLAGS or
CXX_FUZZER_FLAGS.  If the OSS-Fuzz-enabled C++ projects use one set
of flags for the "main" part of the project (to produce binaries to
be run by the end users) and then link with extra flags to work with
fuzzers, I would imagine that they won't call the latter CXXFLAGS
but call it something else, and we probably should follow suit if
that is the case.

Not that we plan to (re)write the maint part of Git in C++ ever, so
I am personally OK with sacrificing the most generic CXXFLAGS macro
for the sole use of OSS-Fuzz linkage, but I'd prefer to leave the
door open so that other things like OSS-Fuzz that require C++ can be
added like your work does to the project.

Thanks.


> Signed-off-by: Josh Steadmon <steadmon@google.com>
> ---
>  Makefile | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index bbfbb4292d..5462bc4b6b 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -497,6 +497,7 @@ GIT-VERSION-FILE: FORCE
>  # CFLAGS and LDFLAGS are for the users to override from the command line.
>  
>  CFLAGS = -g -O2 -Wall
> +CXXFLAGS ?= $(CFLAGS)
>  LDFLAGS =
>  ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS)
>  ALL_LDFLAGS = $(LDFLAGS)
> @@ -3098,14 +3099,14 @@ cover_db_html: cover_db
>  # An example command to build against libFuzzer from LLVM 4.0.0:
>  #
>  # make CC=clang CXX=clang++ \
> -#      CFLAGS="-fsanitize-coverage=trace-pc-guard -fsanitize=address" \
> +#      CXXFLAGS="-fsanitize-coverage=trace-pc-guard -fsanitize=address" \
>  #      LIB_FUZZING_ENGINE=/usr/lib/llvm-4.0/lib/libFuzzer.a \
>  #      fuzz-all
>  #
>  .PHONY: fuzz-all
>  
>  $(FUZZ_PROGRAMS): all
> -	$(QUIET_LINK)$(CXX) $(CFLAGS) $(LIB_OBJS) $(BUILTIN_OBJS) \
> +	$(QUIET_LINK)$(CXX) $(CXXFLAGS) $(LIB_OBJS) $(BUILTIN_OBJS) \
>  		$(XDIFF_OBJS) $(EXTLIBS) git.o $@.o $(LIB_FUZZING_ENGINE) -o $@
>  
>  fuzz-all: $(FUZZ_PROGRAMS)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Makefile: use CXXFLAGS for linking fuzzers
  2018-11-13  3:12 ` Junio C Hamano
@ 2018-11-13 18:50   ` Josh Steadmon
  2018-11-14  2:56     ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Josh Steadmon @ 2018-11-13 18:50 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On 2018.11.13 12:12, Junio C Hamano wrote:
> steadmon@google.com writes:
> 
> > OSS-Fuzz requires C++-specific flags to link fuzzers. Passing these in
> > CFLAGS causes lots of build warnings. Using separate CXXFLAGS avoids
> > this.
> 
> We are not a C++ shop, so allow me to show ignorance about how
> projects that are OSS-Fuzz-enabled work.  Do they use one set of
> CXXFLAGS when compiling the "real thing" and a separate set (perhaps
> one is subset of the other, or perhaps these two just have overlap)
> of CXXFLAGS when building to link with the fuzzer?
> 
> What I am trying to get at is if this should be CXXFLAGS or
> CXX_FUZZER_FLAGS.  If the OSS-Fuzz-enabled C++ projects use one set
> of flags for the "main" part of the project (to produce binaries to
> be run by the end users) and then link with extra flags to work with
> fuzzers, I would imagine that they won't call the latter CXXFLAGS
> but call it something else, and we probably should follow suit if
> that is the case.
> 
> Not that we plan to (re)write the maint part of Git in C++ ever, so
> I am personally OK with sacrificing the most generic CXXFLAGS macro
> for the sole use of OSS-Fuzz linkage, but I'd prefer to leave the
> door open so that other things like OSS-Fuzz that require C++ can be
> added like your work does to the project.
> 
> Thanks.

OSS-Fuzz only provides one set of CXXFLAGS for use on both compiling
project C++ project files as well linking the fuzzers themselves. So in
the event that Git ever added any C++ sources, they would need to use
the same set of CXXFLAGS.

Given that, do you agree with Stefan that it is more intuitive to define
CXXFLAGS next to the fuzzer build rules, since that's the only place
it's used for now?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Makefile: use CXXFLAGS for linking fuzzers
  2018-11-13 18:50   ` Josh Steadmon
@ 2018-11-14  2:56     ` Junio C Hamano
  0 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2018-11-14  2:56 UTC (permalink / raw)
  To: Josh Steadmon; +Cc: git

Josh Steadmon <steadmon@google.com> writes:

> OSS-Fuzz only provides one set of CXXFLAGS for use on both compiling
> project C++ project files as well linking the fuzzers themselves. So in
> the event that Git ever added any C++ sources, they would need to use
> the same set of CXXFLAGS.

OK.

> Given that, do you agree with Stefan that it is more intuitive to define
> CXXFLAGS next to the fuzzer build rules, since that's the only place
> it's used for now?

I am not sure.  Until we gain other C++ targets (in other words,
while linking with fuzzer is the only consumer of CXXFLAGS), I'd
consider it similar to SPARSE_FLAGS and SPATCH_FLAGS, i.e. settings
specific to an auxiliary tool that supports our development process,
and it would make more sense to define it near them higher in the
Makefile.

I'd probably feel differently if this were called FUZZ_CXXFLAGS or
something like that, which would make its natural home next to
the rule to build $(FUZZ_PROGRAMS), though.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] Makefile: use FUZZ_CXXFLAGS for linking fuzzers
  2018-11-12 22:02 [PATCH] Makefile: use CXXFLAGS for linking fuzzers steadmon
  2018-11-12 22:47 ` Stefan Beller
  2018-11-13  3:12 ` Junio C Hamano
@ 2018-11-14 19:41 ` Josh Steadmon
  2 siblings, 0 replies; 6+ messages in thread
From: Josh Steadmon @ 2018-11-14 19:41 UTC (permalink / raw)
  To: git; +Cc: sbeller, gitster

OSS-Fuzz requires C++-specific flags to link fuzzers. Passing these in
CFLAGS causes lots of build warnings. Using separate FUZZ_CXXFLAGS
avoids this.

Signed-off-by: Josh Steadmon <steadmon@google.com>
---
Since there's nothing else using CXXFLAGS, let's just make it explicit
that these apply to the fuzzers.


Range-diff against v1:
1:  1630a93f82 < -:  ---------- Makefile: use CXXFLAGS for linking fuzzers
-:  ---------- > 1:  6b3d6dd7f0 Makefile: use FUZZ_CXXFLAGS for linking fuzzers

 Makefile | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index bbfbb4292d..0c05896797 100644
--- a/Makefile
+++ b/Makefile
@@ -3098,14 +3098,16 @@ cover_db_html: cover_db
 # An example command to build against libFuzzer from LLVM 4.0.0:
 #
 # make CC=clang CXX=clang++ \
-#      CFLAGS="-fsanitize-coverage=trace-pc-guard -fsanitize=address" \
+#      FUZZ_CXXFLAGS="-fsanitize-coverage=trace-pc-guard -fsanitize=address" \
 #      LIB_FUZZING_ENGINE=/usr/lib/llvm-4.0/lib/libFuzzer.a \
 #      fuzz-all
 #
+FUZZ_CXXFLAGS ?= $(CFLAGS)
+
 .PHONY: fuzz-all
 
 $(FUZZ_PROGRAMS): all
-	$(QUIET_LINK)$(CXX) $(CFLAGS) $(LIB_OBJS) $(BUILTIN_OBJS) \
+	$(QUIET_LINK)$(CXX) $(FUZZ_CXXFLAGS) $(LIB_OBJS) $(BUILTIN_OBJS) \
 		$(XDIFF_OBJS) $(EXTLIBS) git.o $@.o $(LIB_FUZZING_ENGINE) -o $@
 
 fuzz-all: $(FUZZ_PROGRAMS)
-- 
2.19.1.930.g4563a0d9d0-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-11-14 19:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-12 22:02 [PATCH] Makefile: use CXXFLAGS for linking fuzzers steadmon
2018-11-12 22:47 ` Stefan Beller
2018-11-13  3:12 ` Junio C Hamano
2018-11-13 18:50   ` Josh Steadmon
2018-11-14  2:56     ` Junio C Hamano
2018-11-14 19:41 ` [PATCH v2] Makefile: use FUZZ_CXXFLAGS " Josh Steadmon

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).