Subject: Re: [PATCH 3/9] Makefile: turn on NO_MMAP when building with ASan

From: Junio C Hamano <[email-masked]>
Date: Thu, 13 Nov 2025 08:30:03 -0800

Patrick Steinhardt <[email-masked]> writes:

> On Wed, Nov 12, 2025 at 03:02:15AM -0500, Jeff King wrote:
>> diff --git a/Makefile b/Makefile
>> index 7e0f77e298..0f44268405 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -1587,6 +1587,7 @@ SANITIZE_LEAK = YesCompiledWithIt
>>  endif
>>  ifneq ($(filter address,$(SANITIZERS)),)
>>  NO_REGEX = NeededForASAN
>> +NO_MMAP = NeededForASAN
>>  SANITIZE_ADDRESS = YesCompiledWithIt
>>  endif
>>  endif
>
> Let's also apply this to Meson. Thanks!
>
> Patrick

Do you two want me to squash this into the Makefile patch?

>
> diff --git a/meson.build b/meson.build
> index ad4eb2c4fa..668f8769d2 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -1408,12 +1408,18 @@ if host_machine.system() == 'windows'
>    libgit_c_args += '-DUSE_WIN32_MMAP'
>  else
>    checkfuncs += {
> -    'mmap' : ['mmap.c'],
>      # provided by compat/mingw.c.
>      'unsetenv' : ['unsetenv.c'],
>      # provided by compat/mingw.c.
>      'getpagesize' : [],
>    }
> +
> +  if get_option('b_sanitize').contains('address')
> +    libgit_c_args += '-DNO_MMAP'
> +    libgit_sources += 'compat/mmap.c'
> +  else
> +    checkfuncs += { 'mmap': ['mmap.c'] }
> +  endif
>  endif
>  
>  foreach func, impls : checkfuncs