# [PATCH] Makefile: do not compile git with debugging symbols by default

9 messages from 2015-01-22 to 2015-01-27. Participants: Alexander Kuleshov, Jeff King, Mike Hommey, Matthieu Moy, David Aguilar.
Thread: https://gitlist.dev/t/38431

## Alexander Kuleshov, 2015-01-22 12:50

Subject: [PATCH] Makefile: do not compile git with debugging symbols by default
Message-ID: <1421931037-21368-1-git-send-email-kuleshovmail@gmail.com>
URL: https://gitlist.dev/e/1421931037-21368-1-git-send-email-kuleshovmail%40gmail.com

```
Standard user has no need in debugging information. This patch adds
DEBUG=1 option to compile git with debugging symbols and compile without
it by default.

Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
---
 Makefile | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index b5b4cee..83ff691 100644
--- a/Makefile
+++ b/Makefile
@@ -3,6 +3,8 @@ all::
 
 # Define V=1 to have a more verbose compile.
 #
+# Define DEBUG=1 to compile git with debugging symbols.
+#
 # Define SHELL_PATH to a POSIX shell if your /bin/sh is broken.
 #
 # Define SANE_TOOL_PATH to a colon-separated list of paths to prepend
@@ -363,8 +365,13 @@ GIT-VERSION-FILE: FORCE
 -include GIT-VERSION-FILE
 
 # CFLAGS and LDFLAGS are for the users to override from the command line.
+DEBUG_CFLAGS=
+
+ifdef DEBUG
+	DEBUG_CFLAGS = -g
+endif
 
-CFLAGS = -g -O2 -Wall
+CFLAGS = $(DEBUG_CFLAGS) -O2 -Wall
 LDFLAGS =
 ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS)
 ALL_LDFLAGS = $(LDFLAGS)
-- 
2.3.0.rc1

```

## Jeff King, 2015-01-22 13:00

Subject: Re: [PATCH] Makefile: do not compile git with debugging symbols by default
Message-ID: <20150122130036.GC19681@peff.net>
URL: https://gitlist.dev/e/20150122130036.GC19681%40peff.net
In-Reply-To: <1421931037-21368-1-git-send-email-kuleshovmail@gmail.com>

```
On Thu, Jan 22, 2015 at 06:50:37PM +0600, Alexander Kuleshov wrote:

> Standard user has no need in debugging information. This patch adds
> DEBUG=1 option to compile git with debugging symbols and compile without
> it by default.

This explanation is missing why it is beneficial _not_ to have the
debugging information.

I expect the answer is "it makes the executable smaller". And that is
true, but it gets smaller still if you run "strip" on the result:

  $ make CFLAGS= >/dev/null 2>&1 && wc -c <git
  2424248

  $ make CFLAGS=-g >/dev/null 2>&1 && wc -c <git
  4500816

  $ strip git && wc -c <git
  2109200

So I am not sure who this is helping. If you are size-conscious, you
should use strip, in which case the "-g" flag does not matter (and we
even have "make strip" to help you).

Is there some other reason to avoid the debugging information?

-Peff

```

## Mike Hommey, 2015-01-22 15:09

Subject: Re: [PATCH] Makefile: do not compile git with debugging symbols by default
Message-ID: <20150122150914.GA20135@glandium.org>
URL: https://gitlist.dev/e/20150122150914.GA20135%40glandium.org
In-Reply-To: <20150122130036.GC19681@peff.net>

```
On Thu, Jan 22, 2015 at 08:00:36AM -0500, Jeff King wrote:
> On Thu, Jan 22, 2015 at 06:50:37PM +0600, Alexander Kuleshov wrote:
> 
> > Standard user has no need in debugging information. This patch adds
> > DEBUG=1 option to compile git with debugging symbols and compile without
> > it by default.
> 
> This explanation is missing why it is beneficial _not_ to have the
> debugging information.
> 
> I expect the answer is "it makes the executable smaller". And that is
> true, but it gets smaller still if you run "strip" on the result:
> 
>   $ make CFLAGS= >/dev/null 2>&1 && wc -c <git
>   2424248
> 
>   $ make CFLAGS=-g >/dev/null 2>&1 && wc -c <git
>   4500816
> 
>   $ strip git && wc -c <git
>   2109200
> 
> So I am not sure who this is helping. If you are size-conscious, you
> should use strip, in which case the "-g" flag does not matter (and we
> even have "make strip" to help you).
> 
> Is there some other reason to avoid the debugging information?

Maybe this comes from the misconception that debugging information
changes the generated code, which, in fact, it doesn't.

  $ make CFLAGS=-g LDFLAGS=-Wl,--build-id=none >/dev/null 2>&1 && wc -c <git
  4432768
  $ strip --strip-debug git && wc -c < git
  2391120
  $ cp git git_
  $ make -j4 CFLAGS= LDFLAGS=-Wl,--build-id=none >/dev/null 2>&1 && wc -c <git
  2400192
  $ strip --strip-debug git && wc -c < git
  2391120
  $ diff -s git git_
  Files git and git_ are identical

LDFLAGS=-Wl,--build-id=none just avoids creating a .note.gnu.build-id
section containing a uuid that varies between builds. The 9k difference
between unstripped vs stripped for the no-debug-info case comes from the
removal of the few symbols for source file names (all the symbols from
readelf -s git | grep ABS).

Mike

```

## Alexander Kuleshov, 2015-01-22 16:51

Subject: Re: [PATCH] Makefile: do not compile git with debugging symbols by default
Message-ID: <CANCZXo7ocgG27Y48NjYxurVMWOvHkvGqDrLuntkSTxHUK6hcNw@mail.gmail.com>
URL: https://gitlist.dev/e/CANCZXo7ocgG27Y48NjYxurVMWOvHkvGqDrLuntkSTxHUK6hcNw%40mail.gmail.com
In-Reply-To: <20150122130036.GC19681@peff.net>

```
Hello Jeff,

Yes, main point is size of executable. I'm sorry, didn't see 'strip' target.

What if we will strip git and other executable files by default and
add -g option and don't strip it if DEBUG=1 passed to make. Something
like this:

git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS)

    $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) git.o \

        $(BUILTIN_OBJS) $(LIBS)

ifneq ($(DEBUG),1)

    $(MAKE) strip

endif


Thank you.

2015-01-22 19:00 GMT+06:00 Jeff King <peff@peff.net>:
> On Thu, Jan 22, 2015 at 06:50:37PM +0600, Alexander Kuleshov wrote:
>
>> Standard user has no need in debugging information. This patch adds
>> DEBUG=1 option to compile git with debugging symbols and compile without
>> it by default.
>
> This explanation is missing why it is beneficial _not_ to have the
> debugging information.
>
> I expect the answer is "it makes the executable smaller". And that is
> true, but it gets smaller still if you run "strip" on the result:
>
>   $ make CFLAGS= >/dev/null 2>&1 && wc -c <git
>   2424248
>
>   $ make CFLAGS=-g >/dev/null 2>&1 && wc -c <git
>   4500816
>
>   $ strip git && wc -c <git
>   2109200
>
> So I am not sure who this is helping. If you are size-conscious, you
> should use strip, in which case the "-g" flag does not matter (and we
> even have "make strip" to help you).
>
> Is there some other reason to avoid the debugging information?
>
> -Peff



-- 
_________________________
0xAX

```

## Alexander Kuleshov, 2015-01-22 16:53

Subject: Re: [PATCH] Makefile: do not compile git with debugging symbols by default
Message-ID: <CANCZXo6qnfjaYLh8WN8xSocGQcoaX4UTjzFm1FhF6sg8vhng5A@mail.gmail.com>
URL: https://gitlist.dev/e/CANCZXo6qnfjaYLh8WN8xSocGQcoaX4UTjzFm1FhF6sg8vhng5A%40mail.gmail.com
In-Reply-To: <CANCZXo7ocgG27Y48NjYxurVMWOvHkvGqDrLuntkSTxHUK6hcNw@mail.gmail.com>

```
Or even still -g as it now, because anyway debugging info will be
removed with stripping

2015-01-22 22:51 GMT+06:00 Alexander Kuleshov <kuleshovmail@gmail.com>:
> Hello Jeff,
>
> Yes, main point is size of executable. I'm sorry, didn't see 'strip' target.
>
> What if we will strip git and other executable files by default and
> add -g option and don't strip it if DEBUG=1 passed to make. Something
> like this:
>
> git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS)
>
>     $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) git.o \
>
>         $(BUILTIN_OBJS) $(LIBS)
>
> ifneq ($(DEBUG),1)
>
>     $(MAKE) strip
>
> endif
>
>
> Thank you.
>
> 2015-01-22 19:00 GMT+06:00 Jeff King <peff@peff.net>:
>> On Thu, Jan 22, 2015 at 06:50:37PM +0600, Alexander Kuleshov wrote:
>>
>>> Standard user has no need in debugging information. This patch adds
>>> DEBUG=1 option to compile git with debugging symbols and compile without
>>> it by default.
>>
>> This explanation is missing why it is beneficial _not_ to have the
>> debugging information.
>>
>> I expect the answer is "it makes the executable smaller". And that is
>> true, but it gets smaller still if you run "strip" on the result:
>>
>>   $ make CFLAGS= >/dev/null 2>&1 && wc -c <git
>>   2424248
>>
>>   $ make CFLAGS=-g >/dev/null 2>&1 && wc -c <git
>>   4500816
>>
>>   $ strip git && wc -c <git
>>   2109200
>>
>> So I am not sure who this is helping. If you are size-conscious, you
>> should use strip, in which case the "-g" flag does not matter (and we
>> even have "make strip" to help you).
>>
>> Is there some other reason to avoid the debugging information?
>>
>> -Peff
>
>
>
> --
> _________________________
> 0xAX



-- 
_________________________
0xAX

```

## Matthieu Moy, 2015-01-22 17:36

Subject: Re: [PATCH] Makefile: do not compile git with debugging symbols by default
Message-ID: <vpqa91ahg46.fsf@anie.imag.fr>
URL: https://gitlist.dev/e/vpqa91ahg46.fsf%40anie.imag.fr
In-Reply-To: <CANCZXo7ocgG27Y48NjYxurVMWOvHkvGqDrLuntkSTxHUK6hcNw@mail.gmail.com>

```
Alexander Kuleshov <kuleshovmail@gmail.com> writes:

> Hello Jeff,
>
> Yes, main point is size of executable.

The Git executable is a few megabytes, i.e. 0.001% the size of a really
small hard disk. The benefit seems really negligible to me.

OTOH, debug information allow users to do better bug reports in case of
crash (gdb, valgrind), which outweights by far the benefit of saving a
handfull of megabytes IMHO.

On a side note, I find it very frustrating when a program I use
crashes, opens a bug report wizard, and end up telling me "sorry, your
distro removed the debug symbols, recompile everything if you want to
report a bug".

I understand that for a few users, the size of executable matters. But
this category of users should be able to find the "strip" target or
something equivalent.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

```

## Jeff King, 2015-01-22 18:35

Subject: Re: [PATCH] Makefile: do not compile git with debugging symbols by default
Message-ID: <20150122183538.GA20085@peff.net>
URL: https://gitlist.dev/e/20150122183538.GA20085%40peff.net
In-Reply-To: <vpqa91ahg46.fsf@anie.imag.fr>

```
On Thu, Jan 22, 2015 at 06:36:41PM +0100, Matthieu Moy wrote:

> > Yes, main point is size of executable.
> 
> The Git executable is a few megabytes, i.e. 0.001% the size of a really
> small hard disk. The benefit seems really negligible to me.

I don't know the layout of the symbols with respect to the code, or
whether the stripped version might reduce memory pressure. So in theory
it could have a performance impact.

But...

> OTOH, debug information allow users to do better bug reports in case of
> crash (gdb, valgrind), which outweights by far the benefit of saving a
> handfull of megabytes IMHO.

Me too. Especially for people who are building git themselves, I feel
like leaving the symbols is a sane default. Package builders are already
using "make strip", or some feature of their package-build system (e.g.,
"dh_strip") to take care of this for the "normal" users. But
fundamentally this is a packaging issue, not a build issue.

-Peff

PS We could still add a "DEBUG" knob to the Makefile and default it to
   off. But I do not see much point. If you want to change the CFLAGS,
   then change the CFLAGS knob. It's much more flexible.

```

## Mike Hommey, 2015-01-22 22:55

Subject: Re: [PATCH] Makefile: do not compile git with debugging symbols by default
Message-ID: <20150122225517.GB31912@glandium.org>
URL: https://gitlist.dev/e/20150122225517.GB31912%40glandium.org
In-Reply-To: <20150122183538.GA20085@peff.net>

```
On Thu, Jan 22, 2015 at 01:35:38PM -0500, Jeff King wrote:
> On Thu, Jan 22, 2015 at 06:36:41PM +0100, Matthieu Moy wrote:
> 
> > > Yes, main point is size of executable.
> > 
> > The Git executable is a few megabytes, i.e. 0.001% the size of a really
> > small hard disk. The benefit seems really negligible to me.
> 
> I don't know the layout of the symbols with respect to the code, or
> whether the stripped version might reduce memory pressure. So in theory
> it could have a performance impact.

It doesn't. Debugging info is in a part of the file that is not mapped
in memory, and in a part that can be removed without affecting the rest
of the file, so it's more or less at the end.

Mike

```

## David Aguilar, 2015-01-27 08:43

Subject: Re: [PATCH] Makefile: do not compile git with debugging symbols by default
Message-ID: <20150127084338.GA37443@gmail.com>
URL: https://gitlist.dev/e/20150127084338.GA37443%40gmail.com
In-Reply-To: <20150122225517.GB31912@glandium.org>

```
On Fri, Jan 23, 2015 at 07:55:17AM +0900, Mike Hommey wrote:
> On Thu, Jan 22, 2015 at 01:35:38PM -0500, Jeff King wrote:
> > On Thu, Jan 22, 2015 at 06:36:41PM +0100, Matthieu Moy wrote:
> > 
> > > > Yes, main point is size of executable.
> > > 
> > > The Git executable is a few megabytes, i.e. 0.001% the size of a really
> > > small hard disk. The benefit seems really negligible to me.
> > 
> > I don't know the layout of the symbols with respect to the code, or
> > whether the stripped version might reduce memory pressure. So in theory
> > it could have a performance impact.
> 
> It doesn't. Debugging info is in a part of the file that is not mapped
> in memory, and in a part that can be removed without affecting the rest
> of the file, so it's more or less at the end.

It goes even further.  These days Fedora systems strip debug
info out into separate files and packages while creating rpms
debuginfo packages are created automatically and provide
debuginfo files under /usr/lib/debug, where gdb knows to look by
default.

Alexander, one nice thing about the Makefile is that it supports
you creating a file in your Git worktree called "config.mak"
with the following content:

CFLAGS = -O2 -Wall

If you do that then git will build without debug info and you
won't have to specify CFLAGS when invoking "make".
Hopefully that's easy and convenient enough.

cheers,
-- 
David

```
