From patchwork Mon Dec 11 12:51:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Pettersson X-Patchwork-Id: 176696 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7025739vqy; Mon, 11 Dec 2023 04:59:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IGUwMRYqTMncrvWwQP4slvJRKddMAEE7voX4Lpne7blkxiO3DeSVkmxvtpMmf6YuflX4g13 X-Received: by 2002:a05:6358:5e04:b0:16d:e151:a7d8 with SMTP id q4-20020a0563585e0400b0016de151a7d8mr1640318rwn.14.1702299587455; Mon, 11 Dec 2023 04:59:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702299587; cv=pass; d=google.com; s=arc-20160816; b=GkkiyGGG8PdnKcXCMccx8iFF31uSc9bb4P4bwZ920/7yC0Mm288WUq2hNXlZUkZ5zZ rxiPUthXoMgODg2whJNfb1QKhjvMqsf5dVmGsLf2lAZY0HGQnAL9TzN9Rd08VRjP6DFR DxrqL3LgR5aCydqAxAjZVRjQVfd8euBApGy1CL1zZ9OcNdIDr6iMmgih+GLg94P0PYnW Ndnt+0FanPPH82cG4C+jJIuBhmKchaOymPag8HRkXEarYrj89RuPLa2r+Fn6Zsg2gN0h Utbk4cKnAEZofxNt1zhDR0aPf3ErJpPnroDXp6BPr7bpcIoUlE65gfOnz7fHq/TKnOUk 8CFw== 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:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=hVz1l2KVDwsqfvPYCXyenfcZSoDMQYnbZ732lkY0jqs=; fh=CBvKQ9y8NVWPMEa/Zl52//dWBs0GicMkUCU0rjesBbs=; b=uNYPyG0nAEZDpGzstcFGmdc/hM6qqtzbVT2+N0nA9HNiq8o7K877BzJ7892B9JCbYI f2w/jElL0NW0/tqes6RkOhMxsFHyhyKv4iA5Pjc+2P/Iaehd1Mq/l5Osvk7M/4vhtcx9 A4f9rnv0SLT1b2vaaEzSy5Xv2CDuoEB+5QczInQm0yUN2iE0sapt1YHx//z3K43R+COi 9wzM8Kc8aDG13CL/6F+abOlFTXTvDTrpMCroXb+I6SfiWSmYfDZ65WQHmSMOtr8mEs1h G90LTP0kt4vhwet2A+6vPhdj0yfNDmqdpKK1oSvjq8LQreYQecFaCnimeI8eHUM/kMZr 2H2A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=O+BEg6PQ; 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"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id cd6-20020a05622a418600b004259d7fe850si7962546qtb.34.2023.12.11.04.59.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 04:59:47 -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=@gmail.com header.s=20230601 header.b=O+BEg6PQ; 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"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2C13738582AC for ; Mon, 11 Dec 2023 12:59:46 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by sourceware.org (Postfix) with ESMTPS id 761AF3858D28 for ; Mon, 11 Dec 2023 12:59:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 761AF3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 761AF3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702299562; cv=none; b=nEXB3WpwS/BluUydLa6PUQ/+c9pXoglzTWobLkZkkLR3uXwbYZJynQ14v01O0L4dDMMf6KypVyqY5txRyPcYpuQbUlA5zE875Ie5VZTMNsFE5ZzK+9BQyG4AHOJ0UJp90WNg4WGDOrX2RaejIkYYU5mYQESkwUAZcO2p4KXUpHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702299562; c=relaxed/simple; bh=slRBWA7WOMIuEmVEmUOEtnSlONdRWnbQtpH9do+Xr3E=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=t8Pjd0C5DgTtnK7NpvQ7cLBkYODrMeVY8dnLBh9aB0NOlNZWlArP0FzTmVM+hETKMQTOK2bwJDviW7QZr5R+PG17r2FgZ2Hnk0ZwNqbca1TjTVnL7MF7pNyHkPUyH8N5mfjR56Gw1+iOhQcaXlV7E9JnH4vCqM7+qdXft38OH6c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-50c0dbaf2baso4143350e87.3 for ; Mon, 11 Dec 2023 04:59:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702299555; x=1702904355; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=hVz1l2KVDwsqfvPYCXyenfcZSoDMQYnbZ732lkY0jqs=; b=O+BEg6PQhWcw2EtqldpwWzUvAh/HG20jvNHuiKkZ2vBsDUPaJjV24JrFEABH9SZKp4 xqDEO3x8kJORGtlr0suscIg0OKaEqomc2CGY6T4Ki8tLEOQNiwo7m1hud8CROnOXdNog CJv8R1mEdd40fAQtzQj442Tesd3Zrp+qsXSBFut3d4sr7nI3E7Sxr8zyFF5tS1lVRsJ+ o+/MdK2Wa9Hp9AtH/XFSh1Fj0q9tYTX8/Cyfu6kuIYTjFdEnYEYBWY8b20/tKNoonVwU tQH76s6cs40EAyLqVbDlE1rYBdNGiLplgnWeBJAiujC6Kg5xx8Da/ROOYfQwe1fpKtTC zfmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702299555; x=1702904355; 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=hVz1l2KVDwsqfvPYCXyenfcZSoDMQYnbZ732lkY0jqs=; b=ZYj0/5QrdoLlfKrkoa2C1p/t6z1q+TWaWPDKHjrYt+GJdEChcoxvvHPHas4gAuuFDX QLdcZPTfdJ0xP/R4LKTgiG2MZv6RaJb8pz2PbImcRm2uVcMKbItbNaZNmVuR5Dgp3Btv TfOjsQVcu1A5z3Xj3jXMDegwFjQaYXhkt+39vxQyyUowFGQy9cP9xWB/6CUWrXabylBF O28mYLdMCrXxIToK3Gi2llsG8Pl0rhJTuaXP+MCdlsHMXVKrvxn1jiFVQDF3O67EWY6g KRS23SHcUfLQ2Rw2wbruIFgKlCylQKE0HEIB1cibxXAIQpwBHTiQd4Jt+v0SuSwP3Q3C P7jA== X-Gm-Message-State: AOJu0Yx10vKlGgu+g3Stjz1wAM8YZ2GLPe4LWfxfFYj8Y7dPsdUYgymc ytN/oOUumwaVMQE6BHo682h+fI9/MwI6nA== X-Received: by 2002:a05:6512:2395:b0:50d:1e5d:c4d0 with SMTP id c21-20020a056512239500b0050d1e5dc4d0mr1065385lfv.68.1702299555370; Mon, 11 Dec 2023 04:59:15 -0800 (PST) Received: from hallertau.. (ip006.net-192-176-117.koping.net. [192.176.117.6]) by smtp.gmail.com with ESMTPSA id h36-20020a0565123ca400b0050be9c8b108sm1087318lfv.60.2023.12.11.04.59.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 04:59:14 -0800 (PST) From: Mikael Pettersson To: gcc-patches@gcc.gnu.org Cc: Mikael Pettersson Subject: [PATCH] wrong code on m68k with -mlong-jump-table-offsets and -malign-int (PR target/112413) Date: Mon, 11 Dec 2023 13:51:39 +0100 Message-ID: <20231211125158.2872910-2-mikpelinux@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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: 1784990492090969259 X-GMAIL-MSGID: 1784990492090969259 On m68k the compiler assumes that the PC-relative jump-via-jump-table instruction and the jump table are adjacent with no padding in between. When -mlong-jump-table-offsets is combined with -malign-int, a 2-byte nop may be inserted before the jump table, causing the jump to add the fetched offset to the wrong PC base and thus jump to the wrong address. Fixed by referencing the jump table via its label. On the test case in the PR the object code change is (the moveal at 16 is the nop): a: 6536 bcss 42 c: e588 lsll #2,%d0 e: 203b 0808 movel %pc@(18 ,%d0:l),%d0 - 12: 4efb 0802 jmp %pc@(16 ,%d0:l) + 12: 4efb 0804 jmp %pc@(18 ,%d0:l) 16: 284c moveal %a4,%a4 18: 0000 0020 orib #32,%d0 1c: 0000 002c orib #44,%d0 Bootstrapped and tested on m68k-linux-gnu, no regressions. Note: I don't have commit rights to I would need assistance applying this. 2023-12-11 Mikael Pettersson PR target/112413 * config/m68k/linux.h (ASM_RETURN_CASE_JUMP): For TARGET_LONG_JUMP_TABLE_OFFSETS, reference the jump table via its label. * config/m68k/m68kelf.h (ASM_RETURN_CASE_JUMP: Likewise. * config/m68k/netbsd-elf.h (ASM_RETURN_CASE_JUMP): Likewise. --- gcc/config/m68k/linux.h | 4 ++-- gcc/config/m68k/m68kelf.h | 4 ++-- gcc/config/m68k/netbsd-elf.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gcc/config/m68k/linux.h b/gcc/config/m68k/linux.h index 2e1cb5498b8..37069c4d082 100644 --- a/gcc/config/m68k/linux.h +++ b/gcc/config/m68k/linux.h @@ -102,12 +102,12 @@ along with GCC; see the file COPYING3. If not see if (ADDRESS_REG_P (operands[0])) \ return "jmp %%pc@(2,%0:l)"; \ else if (TARGET_LONG_JUMP_TABLE_OFFSETS) \ - return "jmp %%pc@(2,%0:l)"; \ + return "jmp %%pc@(%l1,%0:l)"; \ else \ return "ext%.l %0\n\tjmp %%pc@(2,%0:l)"; \ } \ else if (TARGET_LONG_JUMP_TABLE_OFFSETS) \ - return "jmp %%pc@(2,%0:l)"; \ + return "jmp %%pc@(%l1,%0:l)"; \ else \ return "jmp %%pc@(2,%0:w)"; \ } while (0) diff --git a/gcc/config/m68k/m68kelf.h b/gcc/config/m68k/m68kelf.h index 01ee724ef2b..f89c9b70455 100644 --- a/gcc/config/m68k/m68kelf.h +++ b/gcc/config/m68k/m68kelf.h @@ -59,12 +59,12 @@ along with GCC; see the file COPYING3. If not see if (ADDRESS_REG_P (operands[0])) \ return "jmp %%pc@(2,%0:l)"; \ else if (TARGET_LONG_JUMP_TABLE_OFFSETS) \ - return "jmp %%pc@(2,%0:l)"; \ + return "jmp %%pc@(%l1,%0:l)"; \ else \ return "ext%.l %0\n\tjmp %%pc@(2,%0:l)"; \ } \ else if (TARGET_LONG_JUMP_TABLE_OFFSETS) \ - return "jmp %%pc@(2,%0:l)"; \ + return "jmp %%pc@(%l1,%0:l)"; \ else \ return "jmp %%pc@(2,%0:w)"; \ } while (0) diff --git a/gcc/config/m68k/netbsd-elf.h b/gcc/config/m68k/netbsd-elf.h index 4d4a6d71cc4..6ba581b7b18 100644 --- a/gcc/config/m68k/netbsd-elf.h +++ b/gcc/config/m68k/netbsd-elf.h @@ -137,12 +137,12 @@ while (0) if (ADDRESS_REG_P (operands[0])) \ return "jmp %%pc@(2,%0:l)"; \ else if (TARGET_LONG_JUMP_TABLE_OFFSETS) \ - return "jmp %%pc@(2,%0:l)"; \ + return "jmp %%pc@(%l1,%0:l)"; \ else \ return "ext%.l %0\n\tjmp %%pc@(2,%0:l)"; \ } \ else if (TARGET_LONG_JUMP_TABLE_OFFSETS) \ - return "jmp %%pc@(2,%0:l)"; \ + return "jmp %%pc@(%l1,%0:l)"; \ else \ return "jmp %%pc@(2,%0:w)"; \ } while (0)