All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Makefile: describe XMALLOC_POISON
@ 2016-01-13 11:57 Alexander Kuleshov
  2016-01-13 16:56 ` Alexander Kuleshov
  0 siblings, 1 reply; 3+ messages in thread
From: Alexander Kuleshov @ 2016-01-13 11:57 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List, Alexander Kuleshov

The do_xmalloc() functions may fill an allocated buffer with the
known value (0xA5) for debugging if we will pass the XMALLOC_POISON
option during build.

This patch adds description of this option to the Makefile.

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

diff --git a/Makefile b/Makefile
index f3325de..673c244 100644
--- a/Makefile
+++ b/Makefile
@@ -367,6 +367,10 @@ all::
 # Define HAVE_BSD_SYSCTL if your platform has a BSD-compatible sysctl function.
 #
 # Define HAVE_GETDELIM if your system has the getdelim() function.
+#
+# Define XMALLOC_POISON if you are debugging the xmalloc(). In a XMALLOC_POISON
+# build, each allocated buffer by the xmalloc() will be in known state. After
+# memory allocation, a buffer will be filled with '0xA5' values.
 
 GIT-VERSION-FILE: FORCE
 	@$(SHELL_PATH) ./GIT-VERSION-GEN
-- 
2.7.0.25.gfc10eb5.dirty

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

* [PATCH] Makefile: describe XMALLOC_POISON
  2016-01-13 11:57 [PATCH] Makefile: describe XMALLOC_POISON Alexander Kuleshov
@ 2016-01-13 16:56 ` Alexander Kuleshov
  2016-01-13 18:23   ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Alexander Kuleshov @ 2016-01-13 16:56 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List, Alexander Kuleshov

The do_xmalloc() functions may fill an allocated buffer with the
known value (0xA5) for debugging if we will pass the XMALLOC_POISON
option during build.

This patch adds description of this option to the Makefile and
adds it to BASIC_CFLAGS if it was provided.

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

diff --git a/Makefile b/Makefile
index f3325de..3f942b5 100644
--- a/Makefile
+++ b/Makefile
@@ -367,6 +367,10 @@ all::
 # Define HAVE_BSD_SYSCTL if your platform has a BSD-compatible sysctl function.
 #
 # Define HAVE_GETDELIM if your system has the getdelim() function.
+#
+# Define XMALLOC_POISON if you are debugging the xmalloc(). In a XMALLOC_POISON
+# build, each allocated buffer by the xmalloc() will be in known state. After
+# memory allocation, a buffer will be filled with '0xA5' values.
 
 GIT-VERSION-FILE: FORCE
 	@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -1481,6 +1485,10 @@ ifdef HAVE_GETDELIM
 	BASIC_CFLAGS += -DHAVE_GETDELIM
 endif
 
+ifdef XMALLOC_POISON
+	BASIC_CFLAGS += -DXMALLOC_POISON
+endif
+
 ifeq ($(TCLTK_PATH),)
 NO_TCLTK = NoThanks
 endif
-- 
2.7.0.25.gfc10eb5

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

* Re: [PATCH] Makefile: describe XMALLOC_POISON
  2016-01-13 16:56 ` Alexander Kuleshov
@ 2016-01-13 18:23   ` Junio C Hamano
  0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2016-01-13 18:23 UTC (permalink / raw)
  To: Alexander Kuleshov; +Cc: Git List

Alexander Kuleshov <kuleshovmail@gmail.com> writes:

> The do_xmalloc() functions may fill an allocated buffer with the
> known value (0xA5) for debugging if we will pass the XMALLOC_POISON
> option during build.
>
> This patch adds description of this option to the Makefile and
> adds it to BASIC_CFLAGS if it was provided.
>
> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
> ---

I am guessing that the message this one is a response to is
(incomplete) v1 that I shouldn't look at, and this is v2 that is
expected to be useful.

XMALLOC_POISON is not about "if you are debugging the xmalloc()",
though.  By filling the memory returned with a non-NUL byte, what we
get is to catch callers that depended on the region of memory being
NUL-filled (often happens in early in a short-lived program), so it
is about catching more bugs in the callers of xmalloc() [*1*].

>  Makefile | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/Makefile b/Makefile
> index f3325de..3f942b5 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -367,6 +367,10 @@ all::
>  # Define HAVE_BSD_SYSCTL if your platform has a BSD-compatible sysctl function.
>  #
>  # Define HAVE_GETDELIM if your system has the getdelim() function.
> +#
> +# Define XMALLOC_POISON if you are debugging the xmalloc(). In a XMALLOC_POISON
> +# build, each allocated buffer by the xmalloc() will be in known state. After
> +# memory allocation, a buffer will be filled with '0xA5' values.

"will be in known state" is not an interesting bit, and I do not
think we want people relying on the exact contents of the
uninitialized bytes.

Personally, I feel that XMALLOC_POISON outlived its usefulness, with
the availability of --valgrind tests and other forms of checks
(including static analyzers) in the modern world.  While I do not
think it hurts to allow people who know what they are doing to say
"make XMALLOC_POISON=YesPlease", I suspect it would cause more harm
to have a wrong description on what it is about here than the new
makefile knob helps them.  Because of the above, this change is
somewhere between "Meh" and "Perhaps a bad idea" to me.

If you have a more compelling story to tell ("XMALLOC_POISON-enabled
build allowed me to hunt down this and that kind of bug because I
can scan the entire address space looking for regions filled with
0xA5 to do X") and description based on that story is in the log
message and also in the Makefile comment, on the other hand, my
above assessment may become vastly move positive, though.  During
the course of running the project since the XMALLOC_POISON was added
in April 2006, I didn't encounter any such interesting debugging
session that helped me myself.

Thanks.

>  
> +ifdef XMALLOC_POISON
> +	BASIC_CFLAGS += -DXMALLOC_POISON
> +endif
> +


[Footnote]

*1* Another reason for choosing 0xA5 is because it is 'odd' and more
likely to cause bus errors on architectures that do not allow
unaligned access when the uninitialized value is used as a pointer,
but its value is fairly limited.

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

end of thread, other threads:[~2016-01-13 18:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-13 11:57 [PATCH] Makefile: describe XMALLOC_POISON Alexander Kuleshov
2016-01-13 16:56 ` Alexander Kuleshov
2016-01-13 18:23   ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.