From patchwork Fri Jun 2 19:25:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 102680 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1248828vqr; Fri, 2 Jun 2023 12:25:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5KSfXIMZ3ci2qV7XrPT3/SIRHv08xsvlA2WU9u7JaLz8UxHXpL7mlgplA43sjUxX+wVzpC X-Received: by 2002:a17:907:724b:b0:96a:316f:8abf with SMTP id ds11-20020a170907724b00b0096a316f8abfmr11603018ejc.20.1685733939937; Fri, 02 Jun 2023 12:25:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685733939; cv=none; d=google.com; s=arc-20160816; b=d+T9gVhf6bxKHSNa+Cj43jJGKFP7eeh/Rcj9TXhSMIll0o+p5WbfO/yYQ6sRHBRZ7D mV8gz2I2BGMsE4XlLhkrbtfQQLKPFDL64sWWxtZrqbP8SGaDX0oyVyLue3stGdmLC9hH RIGO/py3d2Raq0K9O0eGdGmsGiz+X6KEDo79L/JUTiGa6EOhJUPfNMu3Ot9k3Odrvv8y yAbgkyRKuQf+Sr7ekbSI9p/Uuvu0McmU4tChdixxcuOFv+tmSQxrNhuxWjRLHitgXRaT RvRSQIt9rfOrYPkSd7Zr3d79xsH5IDEX0Y+SpIajibkOUyCFhlMvhEN/U4ITJ3H6cfj5 8pvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=4rfhIKcrdynAk5nHv6iQXJTeJHrYKTdKan8ynG1Rdwc=; b=Mo5uqbEXHUAcJM8DqKVKVfmjrdPe3L0p9xQA7OhAgadaIDbmA4qYP2hNEZ8J9CF7S7 ACBqeW1i4jHAykz+FVssVFyergYGzLN/2g6YbMl5z57fUFsisNf3eTKZK30R1MVQbv5q P+FAvzJTrgERqYftXsmFeqphfltzkQiRTuGpYVhz3PbCq7ut2ls8Bz52xpiDrMdQENiH 8d/Yp92qjEuQ4FNONuJHjJv45Cd1IoR1lSQ2gZJZkIWS0wbsw0ybBpI96RQVdexj3mz+ 4PTJmdo7XTGg4DOodWAQ6VZ6BYxojTjIkNNrKDuLyLOUBKqNqtWeKbM1r6ce50O6apJg ROkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=NU26YU2U; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id di21-20020a170906731500b0096a1843be21si1436636ejc.599.2023.06.02.12.25.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 12:25:39 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=NU26YU2U; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D92433857706 for ; Fri, 2 Jun 2023 19:25:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D92433857706 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685733938; bh=4rfhIKcrdynAk5nHv6iQXJTeJHrYKTdKan8ynG1Rdwc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=NU26YU2UObssz1t5VcHGgUAoGVFOAI9KrRAHY88KZfFcFQfSv9vRFi8IKBTOI+X+C fEjszHVF0JMQCFvi0OohyHWlplqXjei52NROdoQf0Aq8NrjWJzurkSC1sEagiXDbuN paWGQML+PW4lgjrXs6sDnrtgYBGZ7ZCMliiTG8hY= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 01E813858D3C for ; Fri, 2 Jun 2023 19:25:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 01E813858D3C Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-652699e72f7so1191264b3a.3 for ; Fri, 02 Jun 2023 12:25:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685733930; x=1688325930; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4rfhIKcrdynAk5nHv6iQXJTeJHrYKTdKan8ynG1Rdwc=; b=d57KeadlRVeEHLre1TtwrKSppLzecjS67oWGQ6GPlw2vl1tZ4mj8iAS0B5x7cLTcsH SXom3vOWS1fXfmMk7osh6VXl44bfPI78RcuSk0dvz2EuYp4jKZ8/zEdaHatD5uWk0owJ V91YSb8IXgt6H2TXJe6Lm58vCdyVbS6LXSTTkn0CiNNjPZ1GqMuJ6b0Y0JjE5eUKTMto fLcDUyaflN/mf9tVyHkG1wS0/UHN216kf9FLChLqYaEKi+EwqCEAlWAT2c0B1sSTfVnt F+Yu1+UcvUuZ8fULCUa85UyV6dM4nwr4HAZW5t8XE43pDxSOV/9euaD4CVZBkM/uZ81B tsEw== X-Gm-Message-State: AC+VfDyKi1nPmxXvyN4uIW1vCyJDg2jEmrf615fHzvvIF0xwVHNy1XYf erGolMEksihqhZ+ly05cttCnkB1oelU= X-Received: by 2002:a17:903:2285:b0:1a9:bdf8:f551 with SMTP id b5-20020a170903228500b001a9bdf8f551mr802204plh.69.1685733929523; Fri, 02 Jun 2023 12:25:29 -0700 (PDT) Received: from gnu-cfl-3.localdomain ([172.59.160.123]) by smtp.gmail.com with ESMTPSA id u9-20020a170902e5c900b001b016313b1dsm1736891plf.86.2023.06.02.12.25.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 12:25:29 -0700 (PDT) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id E39CA7400A0 for ; Fri, 2 Jun 2023 12:25:27 -0700 (PDT) To: binutils@sourceware.org Subject: [PATCH] ELF: Don't warn an empty PT_LOAD with the program headers Date: Fri, 2 Jun 2023 12:25:27 -0700 Message-Id: <20230602192527.1532280-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3025.2 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: 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: , X-Patchwork-Original-From: "H.J. Lu via Binutils" From: "H.J. Lu" Reply-To: "H.J. Lu" 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?1767620151659999872?= X-GMAIL-MSGID: =?utf-8?q?1767620151659999872?= When rewriting the program headers, don't warn an empty PT_LOAD with the program headers. bfd/ PR binutils/30508 * elf.c (rewrite_elf_program_header): Don't warn if an empty PT_LOAD contains the program headers. ld/ PR binutils/30508 * testsuite/ld-elf/pr30508.d: New file. * testsuite/ld-elf/pr30508.s: Likewise. --- bfd/elf.c | 2 ++ ld/testsuite/ld-elf/pr30508.d | 13 +++++++++++++ ld/testsuite/ld-elf/pr30508.s | 14 ++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 ld/testsuite/ld-elf/pr30508.d create mode 100644 ld/testsuite/ld-elf/pr30508.s 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, bfd_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 == PT_LOAD + && !map->includes_phdrs && (segment->p_filesz > 0 || segment->p_memsz == 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. +#... + 0. .text 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