From patchwork Fri Feb 16 12:32:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rainer Orth X-Patchwork-Id: 85879 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2AF6E3858001 for ; Fri, 16 Feb 2024 12:32:33 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.CeBiTec.Uni-Bielefeld.DE (smtp.CeBiTec.Uni-Bielefeld.DE [129.70.160.84]) by sourceware.org (Postfix) with ESMTPS id 0697A3858292 for ; Fri, 16 Feb 2024 12:32:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0697A3858292 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=CeBiTec.Uni-Bielefeld.DE Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cebitec.uni-bielefeld.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0697A3858292 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=129.70.160.84 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708086728; cv=none; b=r8Mzukx4QLPzaPZM8qFnLhyAYTpm9vtcomYI4Iy3JJFhR7KFIkJXLWgkieJ2ja9u5Al1tL2ZUhdKQV+HfzhWGx4iotnLsoDtbvK9NDAHaBg6Sccv4DsK0Pxvy5YeHBDKYaXKKjpTwsze8DlYruyGiG/ZagSCMtRup2wOmZYCAuI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708086728; c=relaxed/simple; bh=lGs2FJIpKB3eBVeDemOxl5E+RzAw17UxhwjDp48i8w0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vNm1uMZBYlRd9vDBmc15rDXrxDGEuz2351Ic30sT5o0d8CmR2BEKz2wnvC1k4PJkVZpJ+b+72WoYJPlTJ5QPkpa4jCvWps4nPT579yUQAcaWwTKVRaLYWn24yNYdCcaZ0jvOMAfG3gk+ZL1zyab/kOjH2XrX+aWe9aZP+syN8sk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost (localhost [127.0.0.1]) by smtp.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTP id F3D01A9412; Fri, 16 Feb 2024 13:32:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= cebitec.uni-bielefeld.de; h=content-type:content-type :mime-version:user-agent:message-id:date:date:subject:subject :from:from:received:received; s=20200306; t=1708086724; bh=lGs2F JIpKB3eBVeDemOxl5E+RzAw17UxhwjDp48i8w0=; b=J8nzMCwtj2ez06aL/jvKq 3tXU+sVoOv/udL6oQkCv8gS5DivmMjja5V50BUJWMCWwKCAgRLgKs+Uso7ISswk3 lWXVHhMfsmYfKcH1ktZxS4QIgd/2cThV0fJUtEuT3wFP3f97TuTU+M1/N2Hc4xtv eI1SB5BBTU9x2RH+ulAAJn8IaeuHJQoLUUgItCljyQ8/oKOezlf6FUSXub9EZpdY c+N4Yw6AGgWOBiF59Bi0XxEPccwm4dajh213XnmM0UjfsunfxbuAUc+F4/ajW4v5 5Xp+MxlsgpdWDyVM3YJtp/VmJrPqC+ZRecGcmvVP16Cj5nUEi2DjiG89Kfw8okZw A== X-Virus-Scanned: amavisd-new at cebitec.uni-bielefeld.de Received: from smtp.CeBiTec.Uni-Bielefeld.DE ([127.0.0.1]) by localhost (smtp.cebitec.uni-bielefeld.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id IX_0fen1J0PT; Fri, 16 Feb 2024 13:32:04 +0100 (CET) Received: from manam.CeBiTec.Uni-Bielefeld.DE (p5085539e.dip0.t-ipconnect.de [80.133.83.158]) (Authenticated sender: ro) by smtp.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTPSA id 78705A8F71; Fri, 16 Feb 2024 13:32:04 +0100 (CET) From: Rainer Orth To: gcc-patches@gcc.gnu.org Cc: Jakub Jelinek Subject: [PATCH] libsanitizer: Intercept __makecontext_v2 on Solaris/SPARC [PR113785] Date: Fri, 16 Feb 2024 13:32:04 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1.90 (usg-unix-v) MIME-Version: 1.0 X-Spam-Status: No, score=-3791.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org 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. Ok to cherry-pick into trunk? Rainer # HG changeset patch # Parent 2fb800df7e0fd2d03a485601ad4683a29f78f2a4 libsanitizer: Intercept __makecontext_v2 on Solaris/SPARC [PR113785] diff --git a/libsanitizer/asan/asan_interceptors.cpp b/libsanitizer/asan/asan_interceptors.cpp --- a/libsanitizer/asan/asan_interceptors.cpp +++ b/libsanitizer/asan/asan_interceptors.cpp @@ -347,8 +347,16 @@ static void ClearShadowMemoryForContextS 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 uc 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);