[v2] riscv: Ignore attributes in input file with empty code section
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_binutils_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_binutils_check--master-arm |
success
|
Test passed
|
Commit Message
On Thu, May 28, 2026 at 5:29 PM H.J. Lu <hjl.tools@gmail.com> 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.
Comments
On 28.05.2026 23:45, H.J. Lu wrote:
> On Thu, May 28, 2026 at 5:29 PM H.J. Lu <hjl.tools@gmail.com> 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.
I'm not sure if this is correct: Attributes may have a meaning even if there are
only empty code sections (or none at all). RISC-V folks will need to comment
here.
Jan
From 5ddc0d3a01f32b5f8c6bb3dacde2d490083fc592 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
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 <hjl.tools@gmail.com>
---
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(-)
@@ -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;
@@ -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
@@ -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
@@ -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
@@ -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