libc/amd64/strrchr.S: rewrite and fix scalar implementation
The original scalar implementation of strrchr() had incorrect
logic that failed if the character searched for was the NUL
character. It was also possibly affected by the issue fixed
in 3d8ef251a for strchrnul().
Rewrite the function with logic that actually works. We defer
checking for the character until after we have checked for NUL.
When we encounter the final NUL byte, we mask out the characters
beyond the tail before checking for a match.
This bug only affects users running on amd64 with ARCHLEVEL=scalar
(cf. simd(7)). The default configuration is not affected.
The bug was unfortunately not caught by the unit test inherited
from NetBSD. An extended unit test catching the issue is proposed
in D56037.
PR: 293915
Reported by: safonov.paul@gmail.com
Tested by: safonov.paul@gmail.com
Fixes: 2ed514a220edbac6ca5ec9f40a3e0b3f2804796d
See also: https://reviews.freebsd.org/D56037
MFC after: 1 week
(cherry picked from commit 253f15c016ca699906f78b8e522a3f7ed675929b)
(cherry picked from commit 23d6516773916d8f324bea51867b0713c476f379)