From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1039) id 14704388200C; Mon, 5 Jun 2023 15:24:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 14704388200C Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: H.J. Lu To: bfd-cvs@sourceware.org Subject: [binutils-gdb] ELF: Don't warn an empty PT_LOAD with the program headers X-Act-Checkin: binutils-gdb X-Git-Author: H.J. Lu X-Git-Refname: refs/heads/master X-Git-Oldrev: baab375361c365afee2577c94cbbd3fdd443d6da X-Git-Newrev: 3f60b98298fd77dec3a9182797c9dd6d7796bcaf Message-Id: <20230605152428.14704388200C@sourceware.org> Date: Mon, 5 Jun 2023 15:24:28 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Jun 2023 15:24:28 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D3f60b98298fd= 77dec3a9182797c9dd6d7796bcaf commit 3f60b98298fd77dec3a9182797c9dd6d7796bcaf Author: H.J. Lu Date: Fri Jun 2 11:54:21 2023 -0700 ELF: Don't warn an empty PT_LOAD with the program headers =20 When rewriting the program headers, don't warn an empty PT_LOAD with the program headers. =20 bfd/ =20 PR binutils/30508 * elf.c (rewrite_elf_program_header): Don't warn if an empty PT_LOAD contains the program headers. =20 ld/ =20 PR binutils/30508 * testsuite/ld-elf/pr30508.d: New file. * testsuite/ld-elf/pr30508.s: Likewise. Diff: --- bfd/elf.c | 2 ++ ld/testsuite/ld-elf/pr30508.d | 13 +++++++++++++ ld/testsuite/ld-elf/pr30508.s | 14 ++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/bfd/elf.c b/bfd/elf.c index 94954a8fbb9..81eb3ef71fa 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -7210,10 +7210,12 @@ rewrite_elf_program_header (bfd *ibfd, bfd *obfd, b= fd_vma maxpagesize) no sections, but ordinary, loadable segments should contain something. They are allowed by the ELF spec however, so only a warning is produced. + Don't warn if an empty PT_LOAD contains the program headers. There is however the valid use case of embedded systems which have segments with p_filesz of 0 and a p_memsz > 0 to initialize flash memory with zeros. No warning is shown for that case. */ if (segment->p_type =3D=3D PT_LOAD + && !map->includes_phdrs && (segment->p_filesz > 0 || segment->p_memsz =3D=3D 0)) /* xgettext:c-format */ _bfd_error_handler diff --git a/ld/testsuite/ld-elf/pr30508.d b/ld/testsuite/ld-elf/pr30508.d new file mode 100644 index 00000000000..35f66159283 --- /dev/null +++ b/ld/testsuite/ld-elf/pr30508.d @@ -0,0 +1,13 @@ +#ld: -z separate-code +#objcopy_linked_file: -R .foo +#readelf: -lW +#target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi +#xfail: h8300-*-* mips*-*-* rx-*-linux* + +#... + Section to Segment mapping: + Segment Sections... +#... + 0. =20 +#... + 0. .text=20 diff --git a/ld/testsuite/ld-elf/pr30508.s b/ld/testsuite/ld-elf/pr30508.s new file mode 100644 index 00000000000..5a2778c9bff --- /dev/null +++ b/ld/testsuite/ld-elf/pr30508.s @@ -0,0 +1,14 @@ + .text + .global start /* Used by SH targets. */ +start: + .global _start +_start: + .global __start +__start: + .global main /* Used by HPPA targets. */ +main: + .globl _main /* Used by LynxOS targets. */ +_main: + .dc.a 0 + .section .foo,"ax",%progbits + .dc.a 0