git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Regression: git no longer works with musl libc's regex impl

From
Jeff King <peff@peff.net>
Date
Oct 4, 2016, 15:27 UTC
Message-ID
<20161004152722.ex2nox43oj5ak4yi@sigill.intra.peff.net>
In-Reply-To
<20161004150848.GA7949@brightrain.aerifal.cx>
On Tue, Oct 04, 2016 at 11:08:48AM -0400, Rich Felker wrote:
> This commit broke support for using git with musl libc:
> 
> https://github.com/git/git/commit/2f8952250a84313b74f96abb7b035874854cf202

Yep. The idea is that you would compile git with NO_REGEX=1, and it would use the included compat routines.

Is there something in particular you want to get out of using musl's regex that is not supported in the compat library?

Show 7 quoted lines
> Rather than depending on non-portable GNU regex extensions, there is a
> simple portable fix for the issue this code was added to work around:
> When a text file is being mmapped for use with string functions which
> depend on null termination, if the file size:
> 
> 1. is nonzero mod page size, it just works; the remainder of the last
>    page reads as zero bytes when mmapped.
Is that a portable assumption?
Show 5 quoted lines
> 2. if an exact multiple of the page size, then instead of directly
>    mmapping the file, first mmap a mapping 1 byte (thus 1 page) larger
>    with MAP_ANON, then use MAP_FIXED to map the file over top of all
>    but the last page. Now the mmapped buffer can safely be used as a C
>    string.

I'm not sure whether all of our compat layers for mmap would be happy with that (e.g., see compat/win32mmap.c).

So it seems like any mmap-related solutions would have to be conditional, too. And then regexec_buf() would have to become something like:

  int regexec_buf(...)
  {
  #if defined(REG_STARTEND)
	... set up match ...
	return regexec(..., REG_STARTEND);
  #elif defined(MMAP_ALWAYS_HAS_NUL)
	/*
	 * We assume that every buffer we see is always NUL-terminated
	 * eventually, either because it comes from xmallocz() or our
	 * mmap layer always ensures an extra NUL.
	 */
	 return regexec(...);
  #else
  #error "Nope, you need either NO_REGEX or USE_MMAP_NUL"
  #endif
  }

The assumption in the middle case feels pretty hacky, though. It fails if we get a buffer from somewhere besides those two sources. It fails if somebody calls regexec_buf() on a subset of a string.

It also doesn't handle matching past embedded NULs in the string. That's not something we're relying on yet, but it would be nice to support consistently in the long run.

If there's a compelling reason, it might be worth making that tradeoff. But I am not sure what the compelling reason is to use musl's regex (aside from the obvious of "less code in the resulting executable").

-Peff
Previous: Rich FelkerNext: Rich Felker
Message 2 of 28 in “Regression: git no longer works with musl libc's regex impl”
  1. Rich FelkerOct 4, 2016
  2. Jeff KingOct 4, 2016
  3. Rich FelkerOct 4, 2016
  4. Johannes SchindelinOct 4, 2016
  5. Rich FelkerOct 4, 2016
  6. Johannes SchindelinOct 4, 2016
  7. Ray DonnellyOct 4, 2016
  8. Rich FelkerOct 4, 2016
  9. Johannes SchindelinOct 5, 2016
  10. Szabolcs NagyOct 5, 2016
  11. Rich FelkerOct 5, 2016
  12. James BOct 4, 2016
  13. Rich FelkerOct 4, 2016
  14. Junio C HamanoOct 4, 2016
  15. Jakub NarębskiOct 5, 2016
  16. Rich FelkerOct 5, 2016
  17. Johannes SchindelinOct 5, 2016
  18. James BOct 5, 2016
  19. Jeff KingOct 5, 2016
  20. Rich FelkerOct 5, 2016
  21. Johannes SchindelinOct 6, 2016
  22. Ævar Arnfjörð BjarmasonOct 6, 2016
  23. Jeff KingOct 6, 2016
  24. Rich FelkerOct 6, 2016
  25. Jeff KingOct 6, 2016
  26. Ramsay JonesOct 6, 2016
  27. Jakub NarębskiOct 7, 2016
  28. Johannes SchindelinOct 4, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.