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: 81901 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 A3FEE3858418 for ; Mon, 11 Dec 2023 12:59:38 +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-Google-Smtp-Source: AGHT+IGKU7sqXVbTf/q8Kfln/WqssstHH79r81Hd85AaEorV0vQ0NxsEoM2Hx3KSmdK9ziD1JDHQtQ== 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+patchwork=sourceware.org@gcc.gnu.org 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)