git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Don't optimize code in debug build

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 13, 2011, 19:28 UTC
Message-ID
<7vbp2fybs7.fsf@alter.siamese.dyndns.org>
In-Reply-To
<201102131036.51311.j6t@kdbg.org>
Johannes Sixt <j6t@kdbg.org> writes:
Show 18 quoted lines
>> @@ -262,7 +262,10 @@ endif
>>
>>  # CFLAGS and LDFLAGS are for the users to override from the command line.
>>
>> -CFLAGS = -g -O2 -Wall
>> +CFLAGS = -g -Wall
>> +ifndef DEBUG
>> +CFLAGS += -O2
>> +endif
>>  LDFLAGS =
>>  ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS)
>>  ALL_LDFLAGS = $(LDFLAGS)
>
> Instead of this, you can just write
>
>  CFLAGS = -g -Wall
>
> in your config.mak. Is anything wrong with that?

You then need to feed -O2 from the command line when you are not doing a debugging build. On the other hand, with the current Makefile, you need to feed "-g -O0" from the command line when you are doing a debugging build if you and your debugger get confused when seeing an optimized binary. So neither is a very good solution.

But having to feed DEBUG=Yes when running a debug build is not a good solution either. A single toggle is simply too coarse-grained; the next temptation after applying this patch would be to add

	ifdef DEBUG
        CFLAGS += -DDEBUG
        endif

and from there everything goes downhill. That is the last thing we would want to see happen.

So I would say the current Makefile is just fine as is.
Previous: Johannes SixtNext: Piotr Krukowiecki
Message 3 of 4 in “Don't optimize code in debug build”
  1. Don't optimize code in debug buildPiotr Krukowiecki, Feb 13, 2011
  2. Johannes SixtFeb 13, 2011
  3. Junio C HamanoFeb 13, 2011
  4. Piotr KrukowieckiFeb 13, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.