But it turns out that, with this configuration, __nss_endent() *also* wants to call the implementation of endgrent(3) from each of these services. And the one from libnss_db.so, named _nss_db_endgrent(), is just a wrapper around a munmap(2) system call, via an intermediate internal_endent() function:
Impressive investigative work, congratulations on having found the root of the problem! :)
I have no idea what changed, why this used to work before my upgrade of the libc, or why it apparently never failed for anyone else not on Gentoo.
Let this be a reminder for everyone that complexity always, always has unintended consequences... -- Laurent