From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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. */ -- 2.40.1