Skip to content

2025.10: Linker crashes with "Segmentation fault (core dumped)" when linking empty files or files with invalid format #53

@bigmagic123

Description

@bigmagic123

Description

When using the 2025.10 version of the toolchain, the linker (riscv64-unknown-linux-gnu-ld/riscv64-unknown-elf-ld) crashes with a segmentation fault when attempting to link empty files or files that do not conform to the expected linking format, see Nuclei-Software/nuclei-linux-sdk#26 (comment).

Current Behavior

Command that triggers the crash

riscv64-unknown-linux-gnu-ld -r -o perf-test-in.o /test/perf-test-in.o
Segmentation fault (core dumped)

Examples of when this issue occurs:
This may occur during the perf compilation process when linking object files that are empty or do not contain proper section information

Root Cause

The issue stems from the zcmt parsing logic in the linker. The current implementation:

riscv-mcu/riscv-binutils-gdb@f76b0c5#diff-b5dac993e9ea7e46299d5eb9b310fe729620e12c6616e47fc641cd12c71b5818R183-R190

Reads the section information from the file being linked
Determines whether zcmt is enabled based on the section information
Does NOT handle the edge case where the file contains no section information
This lack of null pointer checking leads to a segmentation fault when the linker attempts to access missing section information, resulting in the core dump.

Workaround / Solutions

If the archive or object file input during the linking process is not empty, this issue will not occur. If you do encounter this problem in specific scenarios, you need to apply a workaround or modify your linking process as described below. Currently, we have found that this situation arises when building the Linux perf tool.

Temporary Workaround

To workaround it, just replace riscv64-unknown-linux-gnu-ld/riscv64-unknown-elf-ld and riscv64-unknown-linux-gnu-ld.bfd/riscv64-unknown-elf-ld.bfd in gcc/bin folder using the ld tools of 2025.02 version.

Note

  • Please note that if you replace the ld from version 2025.02, then some new features from linker in 2025.10 will not be available.
  • You can refer to https://doc.nucleisys.com/nuclei_tools/toolchain/changelog.html regarding the changes in linker functionality, which mainly involves support for the newly added zcmt extension, Xxlvw extension support, and other related issues.
  • If your project involves linking empty files or files that do not conform to the expected format, and you are not using the newly added extension features, you can directly replace the ld-related files.

Permanent Fix

This issue is scheduled to be fixed in an upcoming toolchain release. Users can either:

Use the ld in 2025.02 version as a workaround, other tools such as gcc keep as 2025.10

Wait for the new version of the toolchain with the fix to be released

Environment

Toolchain version: 2025.10
Architecture: RISC-V
Component affected: Linker (ld)
Feature related: zcmt parsing logic

Metadata

Metadata

Assignees

Labels

P:0High impact/importance bugbugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions