Makefile: do not compile git with debugging symbols by default
PATCH 1/1 Makefile: do not compile git with debugging symbols by default
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.
--- Makefile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
Makefile +8 -1
@@ -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)
Signature · 1 line
2.3.0.rc1
Quoted 3 lines · Alexander Kuleshov
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
Quoted 18 lines · Jeff King
Quoted 3 lines · Alexander Kuleshov
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
Quoted 8 lines
$ strip git && wc -c <git 2109200So 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
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 <[email protected]>:
Quoted 28 lines · Alexander Kuleshov
Quoted 4 lines
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 2109200So 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
Signature · 2 lines
_________________________ 0xAX
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 <[email protected]>:
Quoted 58 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) stripendif
Thank you.
2015-01-22 19:00 GMT+06:00 Jeff King <[email protected]>:
Quoted 21 lines · Alexander Kuleshov
Quoted 4 lines
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 2109200Quoted 7 lines
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
Signature · 2 lines
_________________________ 0xAX
Quoted 3 lines · Alexander Kuleshov
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.
Signature · 2 lines
Matthieu Moy http://www-verimag.imag.fr/~moy/
Quoted 4 lines · Matthieu Moy
Quoted 1 line
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...
Quoted 3 lines
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.
Quoted 10 lines · Jeff King
Quoted 4 lines · Matthieu Moy
Quoted 1 line
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
Quoted 8 lines · Mike Hommey
Quoted 7 lines · Jeff King
Quoted 4 lines · Matthieu Moy
Quoted 1 line
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.
Quoted 7 lines
Quoted 3 lines
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,
Signature · 1 line
David