From patchwork Wed May 3 17:11:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitar Dimitrov X-Patchwork-Id: 89794 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1484688vqo; Wed, 3 May 2023 10:12:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ46F6xLSaZUujEThY9IdsiHq4B+9ZMcCx9ZjK59lPpSlxI6/iGKuf1Vpk3sSZlap02bS/OV X-Received: by 2002:a17:907:3e17:b0:94e:d951:d4e7 with SMTP id hp23-20020a1709073e1700b0094ed951d4e7mr3781625ejc.59.1683133924758; Wed, 03 May 2023 10:12:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683133924; cv=none; d=google.com; s=arc-20160816; b=lTxuNRD23gxRLetJvM3BaZHjogyIp+e62OpQjszClX/CeSlunS7Z/dSNqyL7h199q+ RsE31nhL32FImaCPkxDWwYS/COAD6NfPEvBJVaO6pNmTapzh6pEb/Y3mejoRuYgt0v5c BLYO6F4vsv8UNTknxVwjMO8vFZUV9c3qdV42WIec453tOm9BSfakg4nSxyfRsk0iQko7 vcgoy89A81pVD+4HJK+gAJWdVgBpLWObaGAuj8Cguc27VIwU+4e3XrrFyxGtiRdXLhuQ vWLbdpAjUCOiMejoYn4cEOU5WwxrNF2CBY0LjhCTR5fyxVevrc9LUiWjwByePPgLHPNQ tjgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender: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 :dmarc-filter:delivered-to; bh=qkASL5yoAJJe0UhGVY0++xRUhCVDBlt4IKjUsGZYFk0=; b=AgO2Io0sqvqj2Wxiqh/Uv4jEH8YN+VKv5s27E3k/JPa9rik49jMlaebLN63P9rT+ps /T3RwdypFdw6u8aCrWP1en3vTS+eURsCwNd4PrbKhuDx3qizgNaNhPH0wBwXwtCahGNe qr0gfpUoJgvWGucWUu9zQcaUMOZ2w5GyY40e5TwCoRughMBzqOjIymoxDAQt1CbJIZuT dZrYzldwpN0URzY2HAFLoronUORQbXcn8ofjeAq6BynxrCBZJDvPbRR1SGWCUYDHwkrc FTmsiQzO8dE1bzKnS6Y24dqkqmGN3mwU+ZB7uYHxKg4/Q3XXyiCyPFCwLzZc78y8X8DO ql0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@dinux.eu header.s=default header.b=rkmSszT3; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id he7-20020a1709073d8700b00961878bed4fsi7675745ejc.137.2023.05.03.10.12.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 May 2023 10:12:04 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.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=fail header.i=@dinux.eu header.s=default header.b=rkmSszT3; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4051C3858439 for ; Wed, 3 May 2023 17:12:00 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from server28.superhosting.bg (server28.superhosting.bg [217.174.156.11]) by sourceware.org (Postfix) with ESMTPS id 4F3F1385840D for ; Wed, 3 May 2023 17:11:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4F3F1385840D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dinux.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dinux.eu DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=dinux.eu; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=qkASL5yoAJJe0UhGVY0++xRUhCVDBlt4IKjUsGZYFk0=; b=rkmSszT3Nx73MeP9bOnze6Uz+o GULt/2ylnf034tCfWJIpumBDWbylcHVfIoRGILRLBPS81pewxQRHs4QRJbvmGkJVE4e/7XNrSIdCy oy0Ef60xGjynfu375p1HOz/4Fhgq4Eqwlw7vZmEFmjZwE4nMLaFhsL4fDAYHan6JYiXDvxyioKSKs Q/++7JSVkvvJQzJKHnqKUSsXAQNvWO1UwqfI/akON4/EqGJMbi0A3y5Eu7ITxuV7XLqVBzCvysF3O CdxYDP7aIo+dTmeyCbw5XzFfarajJTYMlETGEGl+8pWpfrxn8Z8/+xe4DvAOno8Q5uNFhd4adIE+8 wFzm16yA==; Received: from 95-42-20-142.ip.btc-net.bg ([95.42.20.142]:60348 helo=kendros.lan) by server28.superhosting.bg with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1puG0o-00058b-QG; Wed, 03 May 2023 20:11:33 +0300 From: Dimitar Dimitrov To: binutils@sourceware.org Cc: Dimitar Dimitrov Subject: [PATCH] ld: pru: Place exception-handling sections correctly Date: Wed, 3 May 2023 20:11:24 +0300 Message-Id: <20230503171124.6710-1-dimitar@dinux.eu> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server28.superhosting.bg X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - dinux.eu X-Get-Message-Sender-Via: server28.superhosting.bg: authenticated_id: dimitar@dinux.eu X-Authenticated-Sender: server28.superhosting.bg: dimitar@dinux.eu X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_PASS, 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764893838331795757?= X-GMAIL-MSGID: =?utf-8?q?1764893838331795757?= A recent GCC commit [1] exposed a latent bug in the PRU default linker script. The exception-handling sections were not described in the linker script. When GCC started outputting read-only EH sections, their contents would erroneously be placed in the instruction memory (IMEM), which in turn is not readable at runtime. Thus any access to the read-only exception-handling data results in a runtime crash. Fix by declaring the EH output sections. Do not split in read-only and read-write sections because PRU has no true support for rodata. It has only one memory for data (DMEM). Tested pru-unknown-elf and found no regressions in Binutils. All GCC failures caused by [1] are now fixed. [1] https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=2744dbb9ecf104a113da3a0f39115da4653bb676 ld/ChangeLog: * scripttempl/pru.sc (OUTPUT_SECTION_ALIGN): New helper variable to place at end of DMEM output sections. (.eh_frame): New output section. (.gnu_extab): Ditto. (.gcc_except_table): Ditto. Signed-off-by: Dimitar Dimitrov --- ld/scripttempl/pru.sc | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/ld/scripttempl/pru.sc b/ld/scripttempl/pru.sc index 8531cb8d5be..3ff86bc61c7 100644 --- a/ld/scripttempl/pru.sc +++ b/ld/scripttempl/pru.sc @@ -24,6 +24,12 @@ ENTRY (_start) EOF +OUTPUT_SECTION_ALIGN=" + ${RELOCATING+/* In case this is the last input section, + align to keep the loadable segment size a multiple of the common page size. + Some SoCs have stricter memory size requirements than others. */ + . = ALIGN (CONSTANT (COMMONPAGESIZE));}" + cat < dmem} + + .eh_frame ${RELOCATING-0} : + { + KEEP (*(.eh_frame))${RELOCATING+ *(.eh_frame.*)} + ${OUTPUT_SECTION_ALIGN} + } ${RELOCATING+ > dmem} + + .gnu_extab ${RELOCATING-0} : + { + *(.gnu_extab) + ${OUTPUT_SECTION_ALIGN} + } ${RELOCATING+ > dmem} + + .gcc_except_table ${RELOCATING-0} : + { + *(.gcc_except_table${RELOCATING+ .gcc_except_table.*}) + ${OUTPUT_SECTION_ALIGN} } ${RELOCATING+ > dmem} /* Linux remoteproc loader requires the resource_table section @@ -175,10 +196,7 @@ SECTIONS .resource_table ${RELOCATING-0} ${RELOCATING+ ALIGN (CONSTANT (MAXPAGESIZE))} : { KEEP (*(.resource_table)) - ${RELOCATING+/* In case this is the last input section, align to - keep the loadable segment size a multiple of the common page size. - Some SoCs have stricter memory size requirements than others. */ - . = ALIGN (CONSTANT (COMMONPAGESIZE));} + ${OUTPUT_SECTION_ALIGN} } ${RELOCATING+ > dmem} /* Global data not cleared after reset. */