threads / patch / 38431

patchMakefile: do not compile git with debugging symbols by default

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

## tl;dr

9 messages between Jan 22, 2015 and Jan 27, 2015. Diffs are folded; open one to read it.

replies: 8people: 5as markdown or json

Alexander Kuleshov· Jan 22, 2015, 12:50 UTC · lore

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(-)
Show changes to Makefile +8 −1
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· Jan 22, 2015, 13:00 UTC · re: Alexander Kuleshov · lore

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

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· Jan 22, 2015, 15:09 UTC · re: Jeff King · lore

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

On Thu, Jan 22, 2015 at 08:00:36AM -0500, Jeff King wrote:
Show 26 quoted lines
> 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· Jan 22, 2015, 16:51 UTC · re: Jeff King · lore

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

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>:
Show 28 quoted lines
> 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· Jan 22, 2015, 16:53 UTC · re: Alexander Kuleshov · lore

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

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>:
Show 58 quoted lines
> 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· Jan 22, 2015, 17:36 UTC · re: Alexander Kuleshov · lore

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

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· Jan 22, 2015, 18:35 UTC · re: Matthieu Moy · lore

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

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· Jan 22, 2015, 22:55 UTC · re: Jeff King · lore

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

On Thu, Jan 22, 2015 at 01:35:38PM -0500, Jeff King wrote:
Show 10 quoted lines
> 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· Jan 27, 2015, 08:43 UTC · re: Mike Hommey · lore

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

On Fri, Jan 23, 2015 at 07:55:17AM +0900, Mike Hommey wrote:
Show 15 quoted lines
> 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

← back to recent threads