From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1147) id 6674438582BC; Fri, 16 Feb 2024 13:06:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6674438582BC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708088816; bh=KJi4c3xZOyj3bRsi+D27Ea1LGlMRafoIFXWz+kLnmXw=; h=From:To:Subject:Date:From; b=Iti1goFAwzSBbFFZ09G7MAdvDMhcS+1a/NOwWLT+FiuRPmXXSgiKVLGIJo4lxjLzl yU16bh5VXxr9YZoLMh5WL+zrWSJY4cVaNsMGoD+2HvGiHB7UdZsXFurDDx8OxDav4I iADFE5vg3aJZVGirQztpY57j+6egl84mf+mW3H54= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Rainer Orth To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-9030] libsanitizer: Intercept __makecontext_v2 on Solaris/SPARC [PR113785] X-Act-Checkin: gcc X-Git-Author: Rainer Orth X-Git-Refname: refs/heads/master X-Git-Oldrev: 5fd1cbfd65ef2b6dd87cd78ce6509e7d561981ac X-Git-Newrev: 7c6071a66f32f43cea7aa4aa32d89b338e768307 Message-Id: <20240216130656.6674438582BC@sourceware.org> Date: Fri, 16 Feb 2024 13:06:56 +0000 (GMT) List-Id: https://gcc.gnu.org/g:7c6071a66f32f43cea7aa4aa32d89b338e768307 commit r14-9030-g7c6071a66f32f43cea7aa4aa32d89b338e768307 Author: Rainer Orth Date: Fri Feb 16 14:06:24 2024 +0100 libsanitizer: Intercept __makecontext_v2 on Solaris/SPARC [PR113785] c-c++-common/asan/swapcontext-test-1.c FAILs on Solaris/SPARC: FAIL: c-c++-common/asan/swapcontext-test-1.c -O0 execution test FAIL: c-c++-common/asan/swapcontext-test-1.c -O1 execution test FAIL: c-c++-common/asan/swapcontext-test-1.c -O2 execution test FAIL: c-c++-common/asan/swapcontext-test-1.c -O2 -flto execution test FAIL: c-c++-common/asan/swapcontext-test-1.c -O2 -flto -flto-partition=none execution test FAIL: c-c++-common/asan/swapcontext-test-1.c -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions execution test FAIL: c-c++-common/asan/swapcontext-test-1.c -O3 -g execution test FAIL: c-c++-common/asan/swapcontext-test-1.c -Os execution test As detailed in PR sanitizer/113785, this happens because an ABI change in Solaris 10/SPARC caused the external symbol for makecontext to be changed to __makecontext_v2, which isn't intercepted. The following patch, submitted upstream at https://github.com/llvm/llvm-project/pull/81588, fixes that. Tested on sparc-sun-solaris2.11 and i386-pc-solaris2.11. 2024-02-16 Rainer Orth libsanitizer: PR sanitizer/113785 * asan/asan_interceptors.cpp: Cherry-pick llvm-project revision 8c2033719a843a1880427a5e8caa5563248bce78. Diff: --- libsanitizer/asan/asan_interceptors.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libsanitizer/asan/asan_interceptors.cpp b/libsanitizer/asan/asan_interceptors.cpp index 234b18bd83aa..635546b525ce 100644 --- a/libsanitizer/asan/asan_interceptors.cpp +++ b/libsanitizer/asan/asan_interceptors.cpp @@ -347,8 +347,16 @@ static void ClearShadowMemoryForContextStack(uptr stack, uptr ssize) { PoisonShadow(bottom, ssize, 0); } +// Since Solaris 10/SPARC, ucp->uc_stack.ss_sp refers to the stack base address +// as on other targets. For binary compatibility, the new version uses a +// different external name, so we intercept that. +# if SANITIZER_SOLARIS && defined(__sparc__) +INTERCEPTOR(void, __makecontext_v2, struct ucontext_t *ucp, void (*func)(), + int argc, ...) { +# else INTERCEPTOR(void, makecontext, struct ucontext_t *ucp, void (*func)(), int argc, ...) { +# endif va_list ap; uptr args[64]; // We don't know a better way to forward ... into REAL function. We can @@ -368,7 +376,11 @@ INTERCEPTOR(void, makecontext, struct ucontext_t *ucp, void (*func)(), int argc, ENUMERATE_ARRAY_16(0), ENUMERATE_ARRAY_16(16), ENUMERATE_ARRAY_16(32), \ ENUMERATE_ARRAY_16(48) +# if SANITIZER_SOLARIS && defined(__sparc__) + REAL(__makecontext_v2) +# else REAL(makecontext) +# endif ((struct ucontext_t *)ucp, func, argc, ENUMERATE_ARRAY_64()); # undef ENUMERATE_ARRAY_4 @@ -783,7 +795,12 @@ void InitializeAsanInterceptors() { # if ASAN_INTERCEPT_SWAPCONTEXT ASAN_INTERCEPT_FUNC(swapcontext); + // See the makecontext interceptor above for an explanation. +# if SANITIZER_SOLARIS && defined(__sparc__) + ASAN_INTERCEPT_FUNC(__makecontext_v2); +# else ASAN_INTERCEPT_FUNC(makecontext); +# endif # endif # if ASAN_INTERCEPT__LONGJMP ASAN_INTERCEPT_FUNC(_longjmp);