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: 202107 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp477859dyb; Fri, 16 Feb 2024 04:32:47 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU/r8apOZATBtp8YSWnF1smWnnW7I5R4t+wpyJNpt+10z0d9hFZXdlGR/QDnfrh6u85frjUuBHgDcojLjXb5Hm/naEoIw== X-Google-Smtp-Source: AGHT+IE6XVVtiMFHRmC6pOmWrhN0wlts+YGII79+P/YZ0bPzRk873xIKhEt2yyMgMn0Gxa7aoAt/ X-Received: by 2002:a05:6214:cae:b0:68f:2d21:d62f with SMTP id s14-20020a0562140cae00b0068f2d21d62fmr4272347qvs.40.1708086766977; Fri, 16 Feb 2024 04:32:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708086766; cv=pass; d=google.com; s=arc-20160816; b=kq0oEC6SzsPTv1PrMsXkV41jFcby6dSUvgnVH1JsGg2kNdvhAnKfMj/lzk9VEHh4VN T0AVo34983fs4dlQVa04tSNs/37CuF8a2ye9/dL/xQX5Gk5wefAygW4Weq7YvLdxLsiQ 8JCJMwwjl8Mpeb4WdSTh+Frg8fL7GQukKWr+mqII8/hF/KQ4ZM4WK6lbOBnNhqYkMohi anj7eksTQkNlqzqpB7+cPbpluMxmAGnem1GDktCrfjpcNzW3wUyRkn7vdTK1HhROULcr CkHz1Xic9caUlGweF6ZnunUYl9WN3u7zK4QSELCRxP/yYNAsgV1XcPc4n2j4a0A5ZeGr /0yg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:user-agent :message-id:date:subject:cc:to:from:dkim-signature:arc-filter :dmarc-filter:delivered-to; bh=tMqE6LEbaAA2h6qX9daGoLsHi+SP7EJuKKHEDUvJKf4=; fh=Hz/QWAL2vMAbrm3W16QrnQrLktFWGNewssxaKtdN1w4=; b=YXXGjA93oQbht7Nygs6+b2A+HW1jbtBqyXSzikbPyt/9RAlvMn1cx6z0qeloFISKok 2ugQLangrRSDyhTnNItONE4XBLAmhyWGjDgHJeFFuijFtYB3OY+sZ8WArz6VatXqnT5e Mwqf7M5xYtWXhPeHeRwA4QFO//+++2gkL1YF2fvdYktGoq4puYPQCHN557hx8sVBw4/U 7f+o/mRL/HzpaKXKJL2Nkx+ioQ4kIx34wigisFm4VOFu/bB0qqKvTlrMNvGnibKzWR9+ zq1fuTNR5lzz64L8ELUYWay0/biSNKjvJRuzG2HfOgfpjeIDEqUJJm3294LGisloD2Gi Aaqg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cebitec.uni-bielefeld.de header.s=20200306 header.b=J8nzMCwt; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id r9-20020a056214124900b0068f144bdd81si3915567qvv.358.2024.02.16.04.32.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 04:32:46 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@cebitec.uni-bielefeld.de header.s=20200306 header.b=J8nzMCwt; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7BBE03858292 for ; Fri, 16 Feb 2024 12:32:46 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791058789484117313 X-GMAIL-MSGID: 1791058789484117313 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);