{"thread":{"id":"57502","subject":"[PATCH v2] test-lib.sh: Use GLIBC_TUNABLES instead of MALLOC_CHECK_ on glibc >= 2.34","startedAt":"2022-03-03T09:07:00Z","lastAt":"2022-03-03T22:12:22Z","messageCount":2,"participants":["Elia Pinto","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"450250","messageId":"20220303090640.190307-1-gitter.spiros@gmail.com","threadId":"57502","inReplyTo":null,"subject":"[PATCH v2] test-lib.sh: Use GLIBC_TUNABLES instead of MALLOC_CHECK_ on glibc >= 2.34","fromName":"Elia Pinto","fromEmail":"gitter.spiros@gmail.com","sentAt":"2022-03-03T09:06:40Z","receivedAt":"2022-03-03T09:07:00Z","isPatch":true,"sender":{"key":"gitter.spiros@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158490?v=4"},"body":"In glibc >= 2.34 MALLOC_CHECK_ and MALLOC_PERTURB_ environment\nvariables have been replaced by GLIBC_TUNABLES.  Also the new\nglibc requires that you preload a library called libc_malloc_debug.so\nto get these features.\n\nUsing the ordinary glibc system variable detect if this is glibc >= 2.34 and\nuse GLIBC_TUNABLES and the new library.\n\nThis patch was inspired by a Richard W.M. Jones ndbkit patch\n\nHelped-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Elia Pinto <gitter.spiros@gmail.com>\n---\nThis is the second version of the patch.\n\nCompared to the first version, the code has been simplified, based on Junio's\nindications, introducing some redundancy in the setting of the glibc variables\ncovered by the patch\n(https://lore.kernel.org/all/20220228160827.465488-1-gitter.spiros@gmail.com/)\n t/test-lib.sh | 21 +++++++++++++++++++++\n 1 file changed, 21 insertions(+)\n\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 9af5fb7674..b545013a14 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -548,11 +548,32 @@ then\n \t}\n else\n \tsetup_malloc_check () {\n+\t\tif _GLIBC_VERSION=$(getconf GNU_LIBC_VERSION 2>/dev/null) &&\n+\t\t_GLIBC_VERSION=${_GLIBC_VERSION#\"glibc \"} &&\n+\t\texpr 2.34 \\<= \"$_GLIBC_VERSION\" >/dev/null\n+\t\tthen\n+\t\t\tUSE_GLIBC_TUNABLES=YesPlease\n+\t\tfi\n \t\tMALLOC_CHECK_=3\tMALLOC_PERTURB_=165\n \t\texport MALLOC_CHECK_ MALLOC_PERTURB_\n+\t\tcase \"$USE_GLIBC_TUNABLES\" in\n+\t\tYesPlease)\n+\t\t\tg=\n+\t\t\tLD_PRELOAD=\"libc_malloc_debug.so.0\"\n+\t\t\tfor t in \\\n+\t\t\t\tglibc.malloc.check=1 \\\n+\t\t\t\tglibc.malloc.perturb=165\n+\t\t\tdo\n+\t\t\t\tg=\"${g##:}:$t\"\n+\t\t\tdone\n+\t\t\tGLIBC_TUNABLES=$g\n+\t\t\texport LD_PRELOAD GLIBC_TUNABLES\n+\t\t\t;;\n+\t\tesac\n \t}\n \tteardown_malloc_check () {\n \t\tunset MALLOC_CHECK_ MALLOC_PERTURB_\n+\t\tunset LD_PRELOAD GLIBC_TUNABLES\n \t}\n fi\n \n-- \n2.35.1\n\n"},{"id":"450312","messageId":"xmqq8rtq8z41.fsf@gitster.g","threadId":"57502","inReplyTo":"20220303090640.190307-1-gitter.spiros@gmail.com","subject":"Re: [PATCH v2] test-lib.sh: Use GLIBC_TUNABLES instead of MALLOC_CHECK_ on glibc >= 2.34","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-03-03T22:12:14Z","receivedAt":"2022-03-03T22:12:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Elia Pinto <gitter.spiros@gmail.com> writes:\n\n> Compared to the first version, the code has been simplified, based on Junio's\n> indications, introducing some redundancy in the setting of the glibc variables\n> covered by the patch\n\nI think we can even lose the separate case statement and write its\nbody inside if/then...fi.  The following shows the result of\nshuffling the lines to do so.\n\n>  \tsetup_malloc_check () {\n> +\t\tif _GLIBC_VERSION=$(getconf GNU_LIBC_VERSION 2>/dev/null) &&\n> +\t\t   _GLIBC_VERSION=${_GLIBC_VERSION#\"glibc \"} &&\n> +\t\t   expr 2.34 \\<= \"$_GLIBC_VERSION\" >/dev/null\n\nI am wondering if we want to make sure \"getconf\" returned a string\nthat begins with \"glibc \" before stripping that prefix.  Hopefully\nsuch a paranoia is probably unneeded.\n\n> +\t\tthen\n> +\t\t\tg=\n> +\t\t\tLD_PRELOAD=\"libc_malloc_debug.so.0\"\n> +\t\t\tfor t in \\\n> +\t\t\t\tglibc.malloc.check=1 \\\n> +\t\t\t\tglibc.malloc.perturb=165\n> +\t\t\tdo\n> +\t\t\t\tg=\"${g##:}:$t\"\n\nCute.  As this strips a constant, we do not need to be ##greedy\nand using just a single # would suffice, right?\n\n> +\t\t\tdone\n> +\t\t\tGLIBC_TUNABLES=$g\n> +\t\t\texport LD_PRELOAD GLIBC_TUNABLES\n> +\t\t\t;;\n> +\t\tfi\n>  \t\tMALLOC_CHECK_=3\tMALLOC_PERTURB_=165\n>  \t\texport MALLOC_CHECK_ MALLOC_PERTURB_\n>  \t}\n>  \tteardown_malloc_check () {\n>  \t\tunset MALLOC_CHECK_ MALLOC_PERTURB_\n> +\t\tunset LD_PRELOAD GLIBC_TUNABLES\n>  \t}\n>  fi\n\nespecially the teardown side unsets these unconditionally.\n"}]}