From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from vimdzmsp-nwas02.bluewin.ch (vimdzmsp-nwas02.bluewin.ch [195.186.228.50]) by sourceware.org (Postfix) with ESMTPS id 6E7F53858039 for ; Sat, 12 Nov 2022 12:46:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6E7F53858039 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=monnerat.net Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=monnerat.net Received: from patrick.monnerat ([178.199.112.145]) by vimdzmsp-nwas02.bluewin.ch Swisscom AG with ESMTP id tptSou6hhdAK5tptXoi0id; Sat, 12 Nov 2022 13:46:00 +0100 Received: from patrick.monnerat (localhost [127.0.0.1]) by patrick.monnerat (8.17.1/8.16.1) with ESMTPS id 2ACCjmZ5005098 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 12 Nov 2022 13:45:48 +0100 Received: (from patrick@localhost) by patrick.monnerat (8.17.1/8.17.1/Submit) id 2ACCjmoq005097; Sat, 12 Nov 2022 13:45:48 +0100 X-Authentication-Warning: patrick.monnerat: patrick set sender to patrick@monnerat.net using -f From: Patrick Monnerat To: binutils@sourceware.org Cc: Patrick Monnerat Subject: [PATCH] binutils/objcopy: keep relocation while renaming a section with explicit flags Date: Sat, 12 Nov 2022 13:44:41 +0100 Message-Id: <20221112124441.5084-1-patrick@monnerat.net> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4xfBvAtsyHFEdigAD594lxQ+ebfo4icsWlWAHutH+WXKpXUJDYYyTdpUxN4yYx+gItSVXj05zCpREa/n1JxW6T4ykc7YGcY060g2gk03zU8MwgBtMx7TP0 gOWlOkFe9mxFbu6qxZ1XwevG7bBA9Zu1GLGb1wJ9n+twV4t6aEhB2cxRN+DTpTiDf6t1Fq7whx3zzwYwPA46tD4t0viceatykBI= X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_NONE,KAM_DMARC_STATUS,SPF_HELO_NONE,SPF_NEUTRAL,TXREP,T_FILL_THIS_FORM_SHORT 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: When explicit flags are listed in a --rename-section option, they override the input section's flags. There is no way to list the "reloc" flag explicitly, thus the original one must be kept. Failure to do so causes the section's relocation to be dropped. This patch merges the original SEC_RELOC flag within the renamed section flags. It also introduces a test case for it. --- binutils/objcopy.c | 1 + binutils/testsuite/binutils-all/objcopy.exp | 2 ++ binutils/testsuite/binutils-all/rename-section-01.d | 12 ++++++++++++ 3 files changed, 15 insertions(+) create mode 100644 binutils/testsuite/binutils-all/rename-section-01.d diff --git a/binutils/objcopy.c b/binutils/objcopy.c index d886e3ae343..f195e4d875e 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -4052,6 +4052,7 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg) if (new_name != name) { name = new_name; + flags |= bfd_section_flags (isection) & SEC_RELOC; flags = check_new_section_flags (flags, obfd, name); } diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp index 5871d431eea..aebfdb2090b 100644 --- a/binutils/testsuite/binutils-all/objcopy.exp +++ b/binutils/testsuite/binutils-all/objcopy.exp @@ -1448,3 +1448,5 @@ if { [istarget *-*-cygwin] || [istarget *-*-mingw*] } { if { ![is_xcoff_format] } { objcopy_test "pr25662" $src executable "" $ldflags } + +run_dump_test "rename-section-01" diff --git a/binutils/testsuite/binutils-all/rename-section-01.d b/binutils/testsuite/binutils-all/rename-section-01.d new file mode 100644 index 00000000000..b0282fc9552 --- /dev/null +++ b/binutils/testsuite/binutils-all/rename-section-01.d @@ -0,0 +1,12 @@ +#PROG: objcopy +#name: objcopy rename-section with flags - keep relocation +#source: needed-by-reloc.s +#objcopy: --rename-section .data=rodata,contents,alloc,load,readonly +#objdump: -r + +.*: +file format .* + +RELOCATION RECORDS FOR \[rodata\]: +OFFSET +TYPE +VALUE +0+ +[^ ]+ +foo + -- 2.38.1