0005-libsanitizer-use-uclibc-getauxval.patch 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. libsanitizer: enable getauxval() on uClibc-ng
  2. uClibc-ng has provided getauxval() since 1.0.41 (commit d869bb1, 2022-12)
  3. but cannot satisfy __GLIBC_PREREQ(2, 16) because it deliberately reports
  4. __GLIBC__=2 / __GLIBC_MINOR__=2 for source compatibility. As a result
  5. SANITIZER_USE_GETAUXVAL evaluates to 0 on uClibc-ng and GetPageSize()
  6. falls back to sysconf(_SC_PAGESIZE).
  7. That sysconf() call is not safe to make from libsanitizer's .init_array
  8. constructor (runs before libc is fully initialized) and can return 0,
  9. which makes ReadFileToBuffer compute kMinFileLen = 0 and call
  10. MmapOrDie(0) -- the kernel rejects mmap(NULL, 0, ...) with EINVAL:
  11. ==NN==ERROR: AddressSanitizer failed to allocate 0x0 (0) bytes of
  12. ReadFileToBuffer (error code: 22)
  13. ERROR: Failed to mmap
  14. Add SANITIZER_UCLIBC to the SANITIZER_USE_GETAUXVAL activation predicate
  15. so libsanitizer uses uClibc-ng's getauxval() directly. This also gives
  16. correct AT_EXECFN (symbolizer) and AT_BASE (LSan) values via the
  17. auxiliary vector instead of the unsafe sysconf()/proc-based fallbacks.
  18. SANITIZER_UCLIBC is provided by the earlier
  19. 0001-libsanitizer-do-not-treat-uClibc-ng-as-glibc.patch and
  20. sanitizer_getauxval.h already includes sanitizer_platform.h, so the
  21. macro is in scope here.
  22. Signed-off-by: Ramin Moussavi <ramin.moussavi@yacoub.de>
  23. ---
  24. --- a/libsanitizer/sanitizer_common/sanitizer_getauxval.h
  25. +++ b/libsanitizer/sanitizer_common/sanitizer_getauxval.h
  26. @@ -21,7 +21,8 @@
  27. #if SANITIZER_LINUX || SANITIZER_FUCHSIA
  28. # if (__GLIBC_PREREQ(2, 16) || (SANITIZER_ANDROID && __ANDROID_API__ >= 21) || \
  29. - SANITIZER_FUCHSIA) && \
  30. + SANITIZER_FUCHSIA || \
  31. + SANITIZER_UCLIBC) && \
  32. !SANITIZER_GO
  33. # define SANITIZER_USE_GETAUXVAL 1
  34. # else