From patchwork Thu May 28 21:45:06 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 136003 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 371F24BA2E33 for ; Thu, 28 May 2026 21:46:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 371F24BA2E33 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=EWxZokNd X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id C280C4BA2E19 for ; Thu, 28 May 2026 21:45:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C280C4BA2E19 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C280C4BA2E19 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=2607:f8b0:4864:20::634 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1780004745; cv=pass; b=u7zX49GZNzidIkL4gUuvMMyrE0lITGTG5fdNcjSFK5xiAIYxiWI8KPL/q2uJVV8XYmeLYDkDjDZVsbXhFWlkcjOFYosBAfdkg2vxXmYuslgv7gXNt3sCIcvYS6H5qOAiHUKhvFHtnx2pYdVnVt88wX3pzaYOmu1R+o+/uni9BsQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1780004745; c=relaxed/simple; bh=AZLIBJsO/nqF2vKkEmOJU4TIxgIndJb1xVKET5zlAi8=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=PspJeKSFirBZhOlQEK/tjw/qx2gMfnBQJbZlQN5pTMOe8JHnXj5TlRIXYkppPOylGlVnZW0QyMdHJ7xujXvnC9G0ZJa+XK8UeUwobOKz9UminpdHNaUBVWV5Nh7u26S1/wkWWjbiMthLASVwEWoX6+Twpznroh28c8p2/igqbNo= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=EWxZokNd DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C280C4BA2E19 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-2bf0ddaf50fso6465425ad.1 for ; Thu, 28 May 2026 14:45:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1780004744; cv=none; d=google.com; s=arc-20240605; b=G0a06ZwzkO3yauJnNjPguf0KV8sOB0+fvoW/+TIVYI8WrvtyUP+WGPyK2Wl1rTj9HG 8cQZL+J9jrrZKZv+I0uKBdDeQ9H6XEGmwTObgFSZbMadHld+eH5unwwQAWKCU0fXlsvZ bCo0BQ9DJEZ7MkRYmoAYzdOZ8MM2arwXUTeqvYu0Y3rq956hfzxINq/9uXsV9P+3mqND t+o4KcYGpIYmsvoUn6zUqip7LHzpAtdaBxGLfZJFXK/zAeay9fJxs982kpIrdckJ04O0 vrro/txzkkQEiLIzwhTegZB5PEhJmRJxiuJXu/ocVrH4adCNNwshEi67HFRLRQPD02em LCeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=irk/8LzPai5XdAmAAsFPvzD8hlAF7smRdse2Isq0xxs=; fh=oGDgfB4hmgWUBUhG8YUlVirJQRcTlRfSWXUX56hQeAA=; b=QVZmSjp2oWcU6OLdM5mAaoIw4aFdvRg/YhCnih4f0xb2fp4+yU8jKIEUBrjXYYYm0a t76poZsKKq4RvhOEJ/3qsRPQHKaX6DRKNQpg4Z5fIQb95EuGuC8RaZ2OKNXUHnNXocqX UCDFOy7eMMXAaVXkrx6Tjq8eebmfyVCH/xbsgW+YDAJWYiAADxGDOdv12352TZoQXEFf 9vi2+oUWPUmTpGX2ZrQOiVofKyLFB7ZlpEqPCjNZYoI58QTQPyl0jEJ7QyI5lpNQD5d5 rhahMwrb8PVAoYFJHZT9v5YMk6HhUM45tmep5lBsGUCsI3Xac6eiuMY57W7WV+rDxRaf OETQ==; darn=sourceware.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780004744; x=1780609544; darn=sourceware.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=irk/8LzPai5XdAmAAsFPvzD8hlAF7smRdse2Isq0xxs=; b=EWxZokNdrljsLm6f3dtpqtkcVSysKS5vfZlHKGTfxK3K1FQg6Y8udloEhoNC1yFffN fV2kddxXwfoe0vPCbFapJ4pA9gLuRUtOwAkkOWD5vu8cM2Z+QEkawjdlfuBe9Ls9ftt+ zETu7tMngzPiG8p5NeGMaMQ7WT27Zg0S/5+aGWxjDaTlFHabPE4XaUK5dhFhvVxQs9BE iPXJf3K/wycdiVRd3+1hujDDHeth3lTTdmuC5ZMujZuiQfnlHYLWfTGIMX6I9lb6poft sKgEJz+0nzuVZC+h/wJS5QJPhtv44PJpsFP6q0xjY05gUVF3YGnr0lB3C+2juMBmbn5e Uqkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780004744; x=1780609544; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=irk/8LzPai5XdAmAAsFPvzD8hlAF7smRdse2Isq0xxs=; b=hHNsr+pdGgl/wo5zX7dmL6znEebX5sTAN4k04ECpvsYt7DaB8Qu4gQDN+BP/OBh+OQ rjzSha9Oskq4iver901Mj1luEo2AJ2b5/wOm3+zTMAqiHCsaPrYLDdtW+9fACtUfI6zl Ql8aLKd0E38hvBDl3Amv+XaQhbWrAWwsrW1oAJWeaBuO1bX45XbeSDQaIfLa0zBrF59q g4JRC8jovsPMuo/5cEaeLLsfdGWRR6jZSUMI2xsNDHGVY4ukpUO96o+xgkO5D7ZQV26z LVP+9wbNrYv7HyNNi2LqT7nxA31PLHgDaws/KrYg9Sh9JP0LCvApxeo845axYovHzMt7 eh4g== X-Gm-Message-State: AOJu0YwK2yjIVarxc0MVvi0mb8+uBnYzDmUxIUeaSuZWJOyS15QAO6zj CZbQAia+zCFKGMIgQZGJBkBjYehRw/E8o8vVfGqP9O4PriSjTCB7XmoTLtNOtRT5C6PQLTcjVr1 krVPbUucDxcb8VBCd1NWZTYDjm8T1MgtxS2pw0skIGQ== X-Gm-Gg: Acq92OE95IEcvr05+PYQ2zYTIqSF5syImpRf9bSUQT5giey3KgqUaPSyl9hwzePrffn ZKOcwqYF6YVq9rByZeq/RMK65omOHj5ENbUoraVZLIYQ6rIgJqZFCuA8zLQ5057mODmkmRGCcyX IgOoHhqeNuaxlN4KLMgm3oQaqpIcAZJBV+18YErpjNFIm3oVUuCrm/TRhFxetoQEkaSDq6vT3Ex K5FzbWIk8NCdQ86lsD9CynzVj8kk/g9QsWpfleUUW6w1GwEHya40oHVUVI77LSAeqOAZdKAlh9F 2FJlQMZe07c9qp4M6XyInSLKiu9bSls= X-Received: by 2002:a17:902:d48a:b0:2b2:4260:109 with SMTP id d9443c01a7336-2bf207636b7mr2535665ad.23.1780004743801; Thu, 28 May 2026 14:45:43 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: "H.J. Lu" Date: Fri, 29 May 2026 05:45:06 +0800 X-Gm-Features: AVHnY4LTg2y9kjahg9Id62UljZL1L5xjGdGIjxv8QoZJhVgReiMvUNdlcpxmMiY Message-ID: Subject: [PATCH v2] riscv: Ignore attributes in input file with empty code section To: Binutils , Palmer Dabbelt , Andrew Waterman , nelson.chu1990@gmail.com, Nick Clifton , Alan Modra , Jan Beulich X-Spam-Status: No, score=-3009.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org On Thu, May 28, 2026 at 5:29 PM H.J. Lu wrote: > > Ignore empty and .note.gnu.build-id sections when merging attributes. > The following linker tests now pass for riscv: > > FAIL: Diagnostics - Wrong magic number mixed with valid CTF sections > FAIL: --gc-sections with --defsym > FAIL: --gc-sections with KEEP > FAIL: --gc-sections with __start_SECTIONNAME > FAIL: ld-plugin/lto-10r > FAIL: ld-plugin/lto-3r > FAIL: ld-plugin/lto-4r-a > FAIL: ld-plugin/lto-4r-b > FAIL: ld-plugin/lto-4r-c > FAIL: ld-plugin/lto-4r-d > FAIL: ld-plugin/lto-5r > FAIL: PR ld/19317 (2) > FAIL: PR ld/19317 (3) > > PR ld/34185 > * elfnn-riscv.c (_bfd_riscv_elf_merge_private_bfd_data): Ignore > attributes in empty input file > Here is the v2 patch to ignore attributes in input file with empty code section when merging attributes. From 5ddc0d3a01f32b5f8c6bb3dacde2d490083fc592 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Thu, 28 May 2026 16:10:19 +0800 Subject: [PATCH v2] riscv: Ignore attributes in input file with empty code section Ignore attributes in input file with empty code section when merging attributes. The following linker tests now pass for riscv: FAIL: Diagnostics - Wrong magic number mixed with valid CTF sections FAIL: --gc-sections with --defsym FAIL: --gc-sections with KEEP FAIL: --gc-sections with __start_SECTIONNAME FAIL: ld-plugin/lto-10r FAIL: ld-plugin/lto-3r FAIL: ld-plugin/lto-4r-a FAIL: ld-plugin/lto-4r-b FAIL: ld-plugin/lto-4r-c FAIL: ld-plugin/lto-4r-d FAIL: ld-plugin/lto-5r FAIL: PR ld/19317 (2) FAIL: PR ld/19317 (3) bfd/ PR ld/34185 * elfnn-riscv.c (_bfd_riscv_elf_merge_private_bfd_data): Ignore attributes in input file with empty code section. ld/ PR ld/34185 * testsuite/ld-elf/pr17068d.s: Make text section non-empty in the only input file to create a shared library with the proper ELF header for riscv. * testsuite/ld-elf/pr20995c.s: Likewise. * testsuite/ld-elf/pr22471a.s: Likewise. * testsuite/ld-elf/pr25458b.s: Likewise. Signed-off-by: H.J. Lu --- bfd/elfnn-riscv.c | 8 +++++--- ld/testsuite/ld-elf/pr17068d.s | 4 ++++ ld/testsuite/ld-elf/pr20995c.s | 4 ++++ ld/testsuite/ld-elf/pr22471a.s | 5 ++++- ld/testsuite/ld-elf/pr25458b.s | 4 ++++ 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index 295d02e69c2..e8e5f862155 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -4420,9 +4420,11 @@ _bfd_riscv_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info) { null_input_bfd = false; - if ((bfd_section_flags (sec) - & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) - == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) + /* Ignore empty code section. */ + if (sec->size != 0 + && ((bfd_section_flags (sec) + & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) + == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))) { only_data_sections = false; break; diff --git a/ld/testsuite/ld-elf/pr17068d.s b/ld/testsuite/ld-elf/pr17068d.s index 6165128a672..464606927e9 100644 --- a/ld/testsuite/ld-elf/pr17068d.s +++ b/ld/testsuite/ld-elf/pr17068d.s @@ -1,3 +1,7 @@ +# Make text section non-empty in the only input file to create a shared +# library with the proper ELF header for riscv. + .text + .byte 0 .data .globl d .type d,%object diff --git a/ld/testsuite/ld-elf/pr20995c.s b/ld/testsuite/ld-elf/pr20995c.s index ccca92d1aae..aa8e252ad69 100644 --- a/ld/testsuite/ld-elf/pr20995c.s +++ b/ld/testsuite/ld-elf/pr20995c.s @@ -1,3 +1,7 @@ +# Make text section non-empty in the only input file to create a shared +# library with the proper ELF header for riscv. + .text + .byte 0 .data .type rw,%object .globl rw diff --git a/ld/testsuite/ld-elf/pr22471a.s b/ld/testsuite/ld-elf/pr22471a.s index 3bb6a92bdbd..f659423e8c1 100644 --- a/ld/testsuite/ld-elf/pr22471a.s +++ b/ld/testsuite/ld-elf/pr22471a.s @@ -1 +1,4 @@ -# Empty input. +# Make text section non-empty in the only input file to create a shared +# library with the proper ELF header for riscv. + .text + .byte 0 diff --git a/ld/testsuite/ld-elf/pr25458b.s b/ld/testsuite/ld-elf/pr25458b.s index ff64cc7584b..7a4943cb9c2 100644 --- a/ld/testsuite/ld-elf/pr25458b.s +++ b/ld/testsuite/ld-elf/pr25458b.s @@ -1,3 +1,7 @@ +# Make text section non-empty in the only input file to create a shared +# library with the proper ELF header for riscv. + .text + .byte 0 .data .globl __environ .type __environ,%object -- 2.54.0