From patchwork Wed Jan 17 09:37:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YunQiang Su X-Patchwork-Id: 188741 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp794588dye; Wed, 17 Jan 2024 01:38:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IGx/UIXMPsUvI5vjZvex0Orq8oFhNpP/Bt1Ki+L75eVKIK+Gzf1W4EinOgEbYJChAik3DWM X-Received: by 2002:a05:622a:307:b0:429:ab20:ee57 with SMTP id q7-20020a05622a030700b00429ab20ee57mr746549qtw.0.1705484337488; Wed, 17 Jan 2024 01:38:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705484337; cv=pass; d=google.com; s=arc-20160816; b=fNZUFXYN7dwjHJYdeCw+aZ2kJWm0yk9m6z1u4Ly7SS1vIOAWgaRHPCdYvNBSZXjfXu 8ojr7EGRLquhZZ2pbm/Ya5qOBe3v07ZDxGy54hgm9X6kjF/5+9cucPt/sbrENSdogb3a 11VdnxLgfrbr0jEDxIlmnVSvbkfRKSYdDaYQ036WmtU7QWRI0O6pV+LAVqf5k79Q5Bn5 ndvqxs+tH6KUf5XGYH/31rHge2ulKmzQNH/Ls4r7bi7mU6Ro84OdW2wm4oX8IAqviuq3 8FOVT8pQ84OSNywzF3vRenKP+5N870h/FlS3CCdT4Ws9sB6f3A5AFXguX+yz0mq++nBv QR4Q== 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:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:arc-filter :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=dVJO0IK62NKsrR6C5SRe8HpSRZxbCgRo01qo8pEIQ0I=; fh=nYBLt0Q5rB8cKOPog3yIiDnG6zgJkAyIfFnCQCJfNOA=; b=mlux49UYIYUTL5+uJgI4WH0StPgy9axF2TBeS/sB8T7nKOsQFXp6GjEyObm2FR3Nmu JfWeMAh3chuobo0DnSm/i2iHQqLjYO9fCeAWl2nSPRN8gwCmieEjWjQgvKT1eGvTv4yj fYq8XpLCSdj4T4KB5NJAXXf8DCL1BhypbHQ5A7UdlOQjAuFAOMHr/OjF2hWSuHr7chup yqYhlabPqobWnibu6/FT0xhhlR7YYblFDzT9pCc5svxEcSCGZVQ627nQsMsi2N2A/juK wipmQELS7LFjvqjL1hk0BKXD9jiTtThK+zXzcFZ/A3hfIk9UQhAQVL7w8hr1m1x66F/Y sTwg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DUlaP19w; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id bk7-20020a05620a1a0700b0078345f5c20dsi11592943qkb.562.2024.01.17.01.38.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 01:38:57 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DUlaP19w; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 298BB3858C54 for ; Wed, 17 Jan 2024 09:38:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 298BB3858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705484337; bh=dVJO0IK62NKsrR6C5SRe8HpSRZxbCgRo01qo8pEIQ0I=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=DUlaP19wNM4LJ20Ntl0caTOgQRuQGF4nmX7QJmghlOnrzxFFcvAfXHi0KwDvPOEHq OAFv5vqAo4iKNyvm+bN8yxQvtET/xNz4ECGeW7VYf5sKRg4pTTtijUzSRIWnOvkFcA HkZ5wiuNS/OMbWMURqXQYO+95WGoeqwcazV+iHJ8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by sourceware.org (Postfix) with ESMTPS id BC4223858C42 for ; Wed, 17 Jan 2024 09:37:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BC4223858C42 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BC4223858C42 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705484271; cv=none; b=d2RHIiLsyhZZaVnhudp5BhxlSAdUGFGX32z1GPHq610yddPNaUpfumrbdfJRmL1at0wJNADYcG72q680Ix7Kh9LElknSYVFpBx1Z7YcT9D0+Nz2/i6q2zG4CdKhxO/qZamVM2Opf4bRryYBVRmIKzrote+cReea4nvObOYA+KDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705484271; c=relaxed/simple; bh=naDCWkpPuNINcyOsE55Q4DCZ3xl8zypXEXUVx7W8Akc=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=h/MJb9mrXHlLdBX//kFEbjrLLp3HvGMDy2NnkJ7OD/GC2pohZSJLyBDPmRd5Bc8sQVv0Lv74mDGQk9LGooYAMEoqkH+zqT8hzQ/1T9RpteH00rhHdCm13h7eTew0RXEwliEBpOgkLMfpykYUKxgSkmHRrdOnZetDA2TU4N5i9xE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1d427518d52so79611205ad.0 for ; Wed, 17 Jan 2024 01:37:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705484268; x=1706089068; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dVJO0IK62NKsrR6C5SRe8HpSRZxbCgRo01qo8pEIQ0I=; b=pmABzYoGp/ajK4p/JpPG3j8UXFRwga9GZ+PknNpIqKZS2QorWPM4Ob97q8FWEuLzeD gBFvQxU6iS8WMyP812ic6QqIcskFvayG9vfLvH/PXj8A1v9B2L1HRwmWwJauKIeTyhzn u4PNW7wxDJsQg/UXQ4Rd4ajacUYpwYqcJh/KwIiei8ml2ozM0w0I+Xn8AlB3/jcBZpxM 5Z1LzPdM1vd/51B3BOYWi+7bkO8Fub/UmNdDCZW1ONcUBZHYcxWkxGKxpKw9DqyrWITL Q9ikCmzXIcT1vCRgH84qdodbK/WcVBxSdhNzmAeWTySm6z/MaTFjsAjvvr2nJ18FKFJt TqKQ== X-Gm-Message-State: AOJu0YxCYr3Bp6Iew+2qUGIlH5bVW0MqPHUCCzaoa1fOCIG8Vv0+ak17 /7nKED8oJe+fUgsmOynBBra8vmbE3Ao= X-Received: by 2002:a17:903:278f:b0:1d3:b609:eb0b with SMTP id jw15-20020a170903278f00b001d3b609eb0bmr749537plb.27.1705484267983; Wed, 17 Jan 2024 01:37:47 -0800 (PST) Received: from localhost.localdomain ([149.248.38.156]) by smtp.gmail.com with ESMTPSA id v18-20020a170902d09200b001d5e88b31e5sm2515691plv.203.2024.01.17.01.37.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 01:37:47 -0800 (PST) From: YunQiang Su To: gcc-patches@gcc.gnu.org Cc: YunQiang Su Subject: [commit] Sanitizer/MIPS: Use $t9 for preemptible function call Date: Wed, 17 Jan 2024 17:37:40 +0800 Message-Id: <20240117093740.2784008-1-syq@gcc.gnu.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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: 1788329944628090847 X-GMAIL-MSGID: 1788329944628090847 From: YunQiang Su Currently, almost all of the shared libraries of MIPS, rely on $t9 to get the address of current function, instead of PCREL instructions, even on MIPSr6. So we have to set $t9 properly. To get the address of preemptible function, we need the help of GOT. MIPS/O32 has .cpload, which can help to generate 3 instructions to get GOT. For __mips64, we can get GOT by: lui $t8, %hi(%neg(%gp_rel(SANITIZER_STRINGIFY(TRAMPOLINE(func))))) daddu $t8, $t8, $t9 daddiu $t8, $t8, %hi(%neg(%gp_rel(SANITIZER_STRINGIFY(TRAMPOLINE(func))))) And then get the address of __interceptor_func, and jump to it ld $t9, %got_disp(_interceptor" SANITIZER_STRINGIFY(func) ")($t8) jr $t9 Upstream-Commit: 0a64367a72f1634321f5051221f05f2f364bd882 libsanitizer * interception/interception.h (substitution_##func_name): Use macro C_ASM_TAIL_CALL. * sanitizer_common/sanitizer_asm.h: Define C_ASM_TAIL_CALL for MIPS with help of t9. --- libsanitizer/interception/interception.h | 5 ++-- libsanitizer/sanitizer_common/sanitizer_asm.h | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/libsanitizer/interception/interception.h b/libsanitizer/interception/interception.h index 9d8b60b2eef..58e969378a9 100644 --- a/libsanitizer/interception/interception.h +++ b/libsanitizer/interception/interception.h @@ -205,8 +205,9 @@ const interpose_substitution substitution_##func_name[] \ ASM_TYPE_FUNCTION_STR "\n" \ SANITIZER_STRINGIFY(TRAMPOLINE(func)) ":\n" \ SANITIZER_STRINGIFY(CFI_STARTPROC) "\n" \ - SANITIZER_STRINGIFY(ASM_TAIL_CALL) " __interceptor_" \ - SANITIZER_STRINGIFY(ASM_PREEMPTIBLE_SYM(func)) "\n" \ + C_ASM_TAIL_CALL(SANITIZER_STRINGIFY(TRAMPOLINE(func)), \ + "__interceptor_" \ + SANITIZER_STRINGIFY(ASM_PREEMPTIBLE_SYM(func))) "\n" \ SANITIZER_STRINGIFY(CFI_ENDPROC) "\n" \ ".size " SANITIZER_STRINGIFY(TRAMPOLINE(func)) ", " \ ".-" SANITIZER_STRINGIFY(TRAMPOLINE(func)) "\n" \ diff --git a/libsanitizer/sanitizer_common/sanitizer_asm.h b/libsanitizer/sanitizer_common/sanitizer_asm.h index bbb18cfbdf1..3af66a4e449 100644 --- a/libsanitizer/sanitizer_common/sanitizer_asm.h +++ b/libsanitizer/sanitizer_common/sanitizer_asm.h @@ -53,6 +53,29 @@ # define ASM_TAIL_CALL tail #endif +// Currently, almost all of the shared libraries rely on the value of +// $t9 to get the address of current function, instead of PCREL, even +// on MIPSr6. To be compatiable with them, we have to set $t9 properly. +// MIPS uses GOT to get the address of preemptible functions. +#if defined(__mips64) +# define C_ASM_TAIL_CALL(t_func, i_func) \ + "lui $t8, %hi(%neg(%gp_rel(" t_func ")))\n" \ + "daddu $t8, $t8, $t9\n" \ + "daddiu $t8, $t8, %lo(%neg(%gp_rel(" t_func ")))\n" \ + "ld $t9, %got_disp(" i_func ")($t8)\n" \ + "jr $t9\n" +#elif defined(__mips__) +# define C_ASM_TAIL_CALL(t_func, i_func) \ + ".set noreorder\n" \ + ".cpload $t9\n" \ + ".set reorder\n" \ + "lw $t9, %got(" i_func ")($gp)\n" \ + "jr $t9\n" +#elif defined(ASM_TAIL_CALL) +# define C_ASM_TAIL_CALL(t_func, i_func) \ + SANITIZER_STRINGIFY(ASM_TAIL_CALL) " " i_func +#endif + #if defined(__ELF__) && defined(__x86_64__) || defined(__i386__) || \ defined(__riscv) # define ASM_PREEMPTIBLE_SYM(sym) sym@plt